Skip to content

Commit b42e08c

Browse files
committed
add new formats to test.rs
1 parent 7378c3e commit b42e08c

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

examples/test.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use image::{RgbImage, RgbaImage};
1+
use image::{GrayAlphaImage, GrayImage, RgbImage, RgbaImage};
22
use ispc_downsampler::{downsample, Format, Image};
33
use stb_image::image::{load, LoadResult};
44
use std::path::Path;
@@ -11,10 +11,15 @@ fn main() {
1111
LoadResult::ImageU8(img) => {
1212
assert!(!img.data.is_empty());
1313

14-
let src_fmt = if img.data.len() / (img.width * img.height) == 4 {
14+
let num_channels = img.data.len() / (img.width * img.height);
15+
let src_fmt = if num_channels == 4 {
1516
Format::RGBA8
16-
} else {
17+
} else if num_channels == 3 {
1718
Format::RGB8
19+
} else if num_channels == 2 {
20+
Format::RG8
21+
} else {
22+
Format::R8
1823
};
1924

2025
println!("Loaded image!");
@@ -47,6 +52,22 @@ fn main() {
4752
.save("example_outputs/square_test_result.png")
4853
.unwrap()
4954
}
55+
Format::RG8 => {
56+
let save_image =
57+
GrayAlphaImage::from_vec(target_width, target_height, downsampled_pixels)
58+
.unwrap();
59+
save_image
60+
.save("example_outputs/square_test_result.png")
61+
.unwrap()
62+
}
63+
Format::R8 => {
64+
let save_image =
65+
GrayImage::from_vec(target_width, target_height, downsampled_pixels)
66+
.unwrap();
67+
save_image
68+
.save("example_outputs/square_test_result.png")
69+
.unwrap()
70+
}
5071
}
5172
}
5273
_ => panic!("This test only works with 8-bit per channel textures"),

0 commit comments

Comments
 (0)