Skip to content

Commit b4f0dcd

Browse files
bors[bot]darakshan
andauthored
Merge #186
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 <[email protected]> Co-authored-by: darakshan <[email protected]>
2 parents 48453b6 + 4c7adf5 commit b4f0dcd

File tree

11 files changed

+32
-25
lines changed

11 files changed

+32
-25
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
target
22
Cargo.lock
3-
*/examples/*.png
3+
example-data/output/*
File renamed without changes.
File renamed without changes.
File renamed without changes.

palette/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ version = "0.3"
6363
default-features = false
6464

6565
[dev-dependencies.image]
66-
version = "0.22"
66+
version = "0.23"
6767
default-features = false
68+
features = ["png"]
6869

6970
[build-dependencies.phf_codegen]
7071
version = "0.8"

palette/examples/color_scheme.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,10 @@ fn main() {
156156
);
157157
}
158158

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

palette/examples/gradient.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ fn main() {
9393
}
9494
}
9595

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

palette/examples/hue.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use palette::{FromColor, Hsl, Hue, Lch, Pixel, Srgb};
22

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

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

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

palette/examples/readme_examples.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod color_spaces {
1313
let new_color = Srgb::from_color(lch_color.shift_hue(180.0));
1414

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

3434
display_colors(
35-
"examples/readme_manipulation.png",
35+
"example-data/output/readme_manipulation.png",
3636
&[
3737
Srgb::from_linear(color.into()).into_format(),
3838
Srgb::from_linear(lighter.into()).into_format(),
@@ -58,7 +58,7 @@ mod gradients {
5858
Hsv::from_color(LinSrgb::new(0.1, 1.0, 1.0)),
5959
]);
6060

61-
display_gradients("examples/readme_gradients.png", grad1, grad2);
61+
display_gradients("example-data/output/readme_gradients.png", grad1, grad2);
6262
}
6363
}
6464

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

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

palette/examples/saturate.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use palette::{FromColor, Hsl, IntoColor, Lch, Pixel, Saturate, Srgb};
33
use image::{GenericImage, GenericImageView};
44

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

1010
let width = image.width();
@@ -49,9 +49,10 @@ fn main() {
4949
}
5050
}
5151
}
52-
53-
match image.save("examples/saturate.png") {
54-
Ok(()) => println!("see 'examples/saturate.png' for the result"),
55-
Err(e) => println!("failed to write 'examples/saturate.png': {}", e),
52+
53+
let _ = std::fs::create_dir("example-data/output");
54+
match image.save("example-data/output/saturate.png") {
55+
Ok(()) => println!("see 'example-data/output/saturate.png' for the result"),
56+
Err(e) => println!("failed to write 'example-data/output/saturate.png': {}", e),
5657
}
5758
}

0 commit comments

Comments
 (0)