Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
236: Pre-release polishing r=Ogeon a=Ogeon This is a catch-all PR for anything I find while preparing for the release. Nothing that should affect already released functionality. Changes: * `Oklab` and `Oklch` no longer implements `ColorDifference`, since I can't find any sign of CIEDE2000 being correct there. * Separated the first sentence for named gradients as its own paragraph. This makes nicer looking docs. * Added an example of the difference between "naive" randomization and our implementation. Co-authored-by: Erik Hedvall <erikwhedvall@gmail.com>
- Loading branch information
Showing
4 changed files
with
120 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#[cfg(not(feature = "random"))] | ||
fn main() { | ||
println!("You can't use the `rand` integration without the \"random\" feature"); | ||
} | ||
|
||
#[cfg(feature = "random")] | ||
fn main() { | ||
use palette::{FromColor, Hsl, Hsv, Hwb, Pixel, RgbHue, Srgb}; | ||
|
||
use image::{GenericImage, GenericImageView, RgbImage}; | ||
use rand::Rng; | ||
|
||
let mut image = RgbImage::new(512, 256); | ||
let mut rng = rand_mt::Mt::default(); | ||
|
||
// RGB | ||
{ | ||
let mut sub_image = image.sub_image(0, 0, 128, 128); | ||
let (width, height) = sub_image.dimensions(); | ||
for x in 0..width { | ||
for y in 0..height { | ||
let random_color = Srgb::<f32>::new(rng.gen(), rng.gen(), rng.gen()); | ||
sub_image.put_pixel(x, y, image::Rgb(random_color.into_format().into_raw())); | ||
} | ||
} | ||
} | ||
|
||
{ | ||
let mut sub_image = image.sub_image(0, 128, 128, 128); | ||
let (width, height) = sub_image.dimensions(); | ||
for x in 0..width { | ||
for y in 0..height { | ||
let random_color = rng.gen::<Srgb>(); | ||
sub_image.put_pixel(x, y, image::Rgb(random_color.into_format().into_raw())); | ||
} | ||
} | ||
} | ||
|
||
// HSV | ||
{ | ||
let mut sub_image = image.sub_image(128, 0, 128, 128); | ||
let (width, height) = sub_image.dimensions(); | ||
for x in 0..width { | ||
for y in 0..height { | ||
let random_color = | ||
Srgb::from_color(Hsv::new(rng.gen::<RgbHue>(), rng.gen(), rng.gen())); | ||
sub_image.put_pixel(x, y, image::Rgb(random_color.into_format().into_raw())); | ||
} | ||
} | ||
} | ||
|
||
{ | ||
let mut sub_image = image.sub_image(128, 128, 128, 128); | ||
let (width, height) = sub_image.dimensions(); | ||
for x in 0..width { | ||
for y in 0..height { | ||
let random_color = Srgb::from_color(rng.gen::<Hsv>()); | ||
sub_image.put_pixel(x, y, image::Rgb(random_color.into_format().into_raw())); | ||
} | ||
} | ||
} | ||
|
||
// HSL | ||
{ | ||
let mut sub_image = image.sub_image(256, 0, 128, 128); | ||
let (width, height) = sub_image.dimensions(); | ||
for x in 0..width { | ||
for y in 0..height { | ||
let random_color = | ||
Srgb::from_color(Hsl::new(rng.gen::<RgbHue>(), rng.gen(), rng.gen())); | ||
sub_image.put_pixel(x, y, image::Rgb(random_color.into_format().into_raw())); | ||
} | ||
} | ||
} | ||
|
||
{ | ||
let mut sub_image = image.sub_image(256, 128, 128, 128); | ||
let (width, height) = sub_image.dimensions(); | ||
for x in 0..width { | ||
for y in 0..height { | ||
let random_color = Srgb::from_color(rng.gen::<Hsl>()); | ||
sub_image.put_pixel(x, y, image::Rgb(random_color.into_format().into_raw())); | ||
} | ||
} | ||
} | ||
|
||
// HWB | ||
{ | ||
let mut sub_image = image.sub_image(384, 0, 128, 128); | ||
let (width, height) = sub_image.dimensions(); | ||
for x in 0..width { | ||
for y in 0..height { | ||
let random_color = | ||
Srgb::from_color(Hwb::new(rng.gen::<RgbHue>(), rng.gen(), rng.gen())); | ||
sub_image.put_pixel(x, y, image::Rgb(random_color.into_format().into_raw())); | ||
} | ||
} | ||
} | ||
|
||
{ | ||
let mut sub_image = image.sub_image(384, 128, 128, 128); | ||
let (width, height) = sub_image.dimensions(); | ||
for x in 0..width { | ||
for y in 0..height { | ||
let random_color = Srgb::from_color(rng.gen::<Hwb>()); | ||
sub_image.put_pixel(x, y, image::Rgb(random_color.into_format().into_raw())); | ||
} | ||
} | ||
} | ||
|
||
let _ = std::fs::create_dir("example-data/output"); | ||
match image.save("example-data/output/random.png") { | ||
Ok(()) => println!("see 'example-data/output/random.png' for the result"), | ||
Err(e) => println!("failed to write 'example-data/output/random.png': {}", e), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters