Skip to content

Commit

Permalink
Merge #186
Browse files Browse the repository at this point in the history
186: Fix some problems with examples  r=Ogeon a=darakshan

Example input files are now read from `example-data/input` and ouput files are now written to `example-data/output`.  The directory is created if necessary.
Image dependency in `Cargo.toml` now includes `.png` support.

Co-authored-by: Darakshan Farber <darakshan@glenmuse.com>
Co-authored-by: darakshan <darakshan@glenmuse.com>
  • Loading branch information
bors[bot] and darakshan committed May 16, 2020
2 parents 48453b6 + 4c7adf5 commit b4f0dcd
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
target
Cargo.lock
*/examples/*.png
example-data/output/*
File renamed without changes.
File renamed without changes
File renamed without changes
3 changes: 2 additions & 1 deletion palette/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ version = "0.3"
default-features = false

[dev-dependencies.image]
version = "0.22"
version = "0.23"
default-features = false
features = ["png"]

[build-dependencies.phf_codegen]
version = "0.8"
Expand Down
7 changes: 4 additions & 3 deletions palette/examples/color_scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ fn main() {
);
}

match image.save("examples/color_scheme.png") {
Ok(()) => println!("see 'examples/color_scheme.png' for the result"),
Err(e) => println!("failed to write 'examples/color_scheme.png': {}", e),
let _ = std::fs::create_dir("example-data/output");
match image.save("example-data/output/color_scheme.png") {
Ok(()) => println!("see 'example-data/output/color_scheme.png' for the result"),
Err(e) => println!("failed to write 'example-data/output/color_scheme.png': {}", e),
}
}

Expand Down
7 changes: 4 additions & 3 deletions palette/examples/gradient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ fn main() {
}
}

match image.save("examples/gradient.png") {
Ok(()) => println!("see 'examples/gradient.png' for the result"),
Err(e) => println!("failed to write 'examples/gradient.png': {}", e),
let _ = std::fs::create_dir("example-data/output");
match image.save("example-data/output/gradient.png") {
Ok(()) => println!("see 'example-data/output/gradient.png' for the result"),
Err(e) => println!("failed to write 'example-data/output/gradient.png': {}", e),
}
}
11 changes: 6 additions & 5 deletions palette/examples/hue.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use palette::{FromColor, Hsl, Hue, Lch, Pixel, Srgb};

fn main() {
let mut image = image::open("res/fruits.png")
.expect("could not open 'res/fruits.png'")
let mut image = image::open("example-data/input/fruits.png")
.expect("could not open 'example-data/input/fruits.png'")
.to_rgb();

//Shift hue by 180 degrees as HSL in bottom left part, and as LCh in top
Expand All @@ -20,8 +20,9 @@ fn main() {
};
}

match image.save("examples/hue.png") {
Ok(()) => println!("see 'examples/hue.png' for the result"),
Err(e) => println!("failed to write 'examples/hue.png': {}", e),
let _ = std::fs::create_dir("example-data/output");
match image.save("example-data/output/hue.png") {
Ok(()) => println!("see 'example-data/output/hue.png' for the result"),
Err(e) => println!("failed to write 'example-data/output/hue.png': {}", e),
}
}
7 changes: 4 additions & 3 deletions palette/examples/readme_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod color_spaces {
let new_color = Srgb::from_color(lch_color.shift_hue(180.0));

display_colors(
"examples/readme_color_spaces.png",
"example-data/output/readme_color_spaces.png",
&[
::palette::Srgb::new(0.8, 0.2, 0.1).into_format(),
new_color.into_format(),
Expand All @@ -32,7 +32,7 @@ mod manipulation {
let desaturated = Lch::from_color(color).desaturate(0.5);

display_colors(
"examples/readme_manipulation.png",
"example-data/output/readme_manipulation.png",
&[
Srgb::from_linear(color.into()).into_format(),
Srgb::from_linear(lighter.into()).into_format(),
Expand All @@ -58,7 +58,7 @@ mod gradients {
Hsv::from_color(LinSrgb::new(0.1, 1.0, 1.0)),
]);

display_gradients("examples/readme_gradients.png", grad1, grad2);
display_gradients("example-data/output/readme_gradients.png", grad1, grad2);
}
}

Expand All @@ -74,6 +74,7 @@ fn display_colors(filename: &str, colors: &[Srgb<u8>]) {
}
}

let _ = std::fs::create_dir("example-data/output");
match image.save(filename) {
Ok(()) => println!("see '{}' for the result", filename),
Err(e) => println!("failed to write '{}': {}", filename, e),
Expand Down
13 changes: 7 additions & 6 deletions palette/examples/saturate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use palette::{FromColor, Hsl, IntoColor, Lch, Pixel, Saturate, Srgb};
use image::{GenericImage, GenericImageView};

fn main() {
let mut image = image::open("res/cat.png")
.expect("could not open 'res/cat.png'")
let mut image = image::open("example-data/input/cat.png")
.expect("could not open 'example-data/input/cat.png'")
.to_rgb();

let width = image.width();
Expand Down Expand Up @@ -49,9 +49,10 @@ fn main() {
}
}
}

match image.save("examples/saturate.png") {
Ok(()) => println!("see 'examples/saturate.png' for the result"),
Err(e) => println!("failed to write 'examples/saturate.png': {}", e),

let _ = std::fs::create_dir("example-data/output");
match image.save("example-data/output/saturate.png") {
Ok(()) => println!("see 'example-data/output/saturate.png' for the result"),
Err(e) => println!("failed to write 'example-data/output/saturate.png': {}", e),
}
}
7 changes: 4 additions & 3 deletions palette/examples/shade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ fn main() {
}
}

match image.save("examples/shade.png") {
Ok(()) => println!("see 'examples/shade.png' for the result"),
Err(e) => println!("failed to write 'examples/shade.png': {}", e),
let _ = std::fs::create_dir("example-data/output");
match image.save("example-data/output/shade.png") {
Ok(()) => println!("see 'example-data/output/shade.png' for the result"),
Err(e) => println!("failed to write 'example-data/output/shade.png': {}", e),
}
}

0 comments on commit b4f0dcd

Please sign in to comment.