mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Update pixels::unmultiply_inplace
to support RB swap and use it in canvas_state (#35313)
* update unmultiply_inplace to handle reversed RGB Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com> * Reuse unmultiply_inplace instead of manual compute; remove unused Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com> --------- Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
parent
cb7688314b
commit
0de6d1bc3a
6 changed files with 13 additions and 4116 deletions
|
@ -20,7 +20,7 @@ fn bench(c: &mut Criterion) {
|
|||
c.bench_function("unmultiply_inplace", move |b| {
|
||||
b.iter_batched(
|
||||
|| data.clone(),
|
||||
|mut data| pixels::unmultiply_inplace(&mut data),
|
||||
|mut data| pixels::unmultiply_inplace::<false>(&mut data),
|
||||
BatchSize::SmallInput,
|
||||
)
|
||||
});
|
||||
|
|
|
@ -197,7 +197,7 @@ pub fn detect_image_format(buffer: &[u8]) -> Result<ImageFormat, &str> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn unmultiply_inplace(pixels: &mut [u8]) {
|
||||
pub fn unmultiply_inplace<const SWAP_RB: bool>(pixels: &mut [u8]) {
|
||||
for rgba in pixels.chunks_mut(4) {
|
||||
let a = rgba[3] as u32;
|
||||
let mut b = rgba[2] as u32;
|
||||
|
@ -209,9 +209,15 @@ pub fn unmultiply_inplace(pixels: &mut [u8]) {
|
|||
g = g * 255 / a;
|
||||
b = b * 255 / a;
|
||||
|
||||
rgba[2] = b as u8;
|
||||
rgba[1] = g as u8;
|
||||
rgba[0] = r as u8;
|
||||
if SWAP_RB {
|
||||
rgba[2] = r as u8;
|
||||
rgba[1] = g as u8;
|
||||
rgba[0] = b as u8;
|
||||
} else {
|
||||
rgba[2] = b as u8;
|
||||
rgba[1] = g as u8;
|
||||
rgba[0] = r as u8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue