mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Fix colorspace correction
This commit is contained in:
parent
07c17fdef4
commit
43d2871926
1 changed files with 6 additions and 3 deletions
|
@ -24,19 +24,22 @@ fn test_image_bin() -> ~[u8] {
|
|||
fn load_from_memory(buffer: &[u8]) -> option<Image> {
|
||||
do stb_image::load_from_memory(buffer).map |image| {
|
||||
|
||||
assert image.depth == 4;
|
||||
// Do color space conversion :(
|
||||
let data = do vec::from_fn(image.width * image.height * 4) |i| {
|
||||
let color = i % 4;
|
||||
let pixel = i / 4;
|
||||
match color {
|
||||
0 => image.data[pixel * 3 + 2],
|
||||
1 => image.data[pixel * 3 + 1],
|
||||
2 => image.data[pixel * 3 + 0],
|
||||
0 => image.data[pixel * 4 + 2],
|
||||
1 => image.data[pixel * 4 + 1],
|
||||
2 => image.data[pixel * 4 + 0],
|
||||
3 => 0xffu8,
|
||||
_ => fail
|
||||
}
|
||||
};
|
||||
|
||||
assert image.data.len() == data.len();
|
||||
|
||||
stb_image::image(image.width, image.height, image.depth, data)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue