mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Fix canvas image tests when using webrender.
When webrender is enabled, image decoding doesn't pre-multiply by alpha, but the canvas code expects the image data to be pre-multiplied form.
This commit is contained in:
parent
a338beaa70
commit
119716acb2
2 changed files with 28 additions and 2 deletions
|
@ -552,3 +552,21 @@ pub fn byte_swap(data: &mut [u8]) {
|
|||
i += 4;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn byte_swap_and_premultiply(data: &mut [u8]) {
|
||||
let length = data.len();
|
||||
|
||||
let mut i = 0;
|
||||
while i < length {
|
||||
let r = data[i + 2];
|
||||
let g = data[i + 1];
|
||||
let b = data[i + 0];
|
||||
let a = data[i + 3];
|
||||
|
||||
data[i + 0] = ((r as u32) * (a as u32) / 255) as u8;
|
||||
data[i + 1] = ((g as u32) * (a as u32) / 255) as u8;
|
||||
data[i + 2] = ((b as u32) * (a as u32) / 255) as u8;
|
||||
|
||||
i += 4;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue