Fix colorspace correction

This commit is contained in:
Brian Anderson 2012-08-22 10:44:25 -07:00
parent 07c17fdef4
commit 43d2871926

View file

@ -24,19 +24,22 @@ fn test_image_bin() -> ~[u8] {
fn load_from_memory(buffer: &[u8]) -> option<Image> { fn load_from_memory(buffer: &[u8]) -> option<Image> {
do stb_image::load_from_memory(buffer).map |image| { do stb_image::load_from_memory(buffer).map |image| {
assert image.depth == 4;
// Do color space conversion :( // Do color space conversion :(
let data = do vec::from_fn(image.width * image.height * 4) |i| { let data = do vec::from_fn(image.width * image.height * 4) |i| {
let color = i % 4; let color = i % 4;
let pixel = i / 4; let pixel = i / 4;
match color { match color {
0 => image.data[pixel * 3 + 2], 0 => image.data[pixel * 4 + 2],
1 => image.data[pixel * 3 + 1], 1 => image.data[pixel * 4 + 1],
2 => image.data[pixel * 3 + 0], 2 => image.data[pixel * 4 + 0],
3 => 0xffu8, 3 => 0xffu8,
_ => fail _ => fail
} }
}; };
assert image.data.len() == data.len();
stb_image::image(image.width, image.height, image.depth, data) stb_image::image(image.width, image.height, image.depth, data)
} }
} }