mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Auto merge of #6970 - dzbarsky:getimagedata, r=Ms2ger
GetImageData should return un-premultiplied alpha values <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6970) <!-- Reviewable:end -->
This commit is contained in:
commit
4726f58d15
37 changed files with 12 additions and 181 deletions
|
@ -901,7 +901,18 @@ impl<'a> CanvasRenderingContext2DMethods for &'a CanvasRenderingContext2D {
|
|||
self.ipc_renderer
|
||||
.send(CanvasMsg::Canvas2d(Canvas2dMsg::GetImageData(dest_rect, canvas_size, sender)))
|
||||
.unwrap();
|
||||
let data = receiver.recv().unwrap();
|
||||
let mut data = receiver.recv().unwrap();
|
||||
|
||||
// Un-premultiply alpha
|
||||
// TODO: may want a precomputed un-premultiply table to make this fast.
|
||||
// https://github.com/servo/servo/issues/6969
|
||||
for chunk in data.chunks_mut(4) {
|
||||
let alpha = chunk[3] as f32 / 255.;
|
||||
chunk[0] = (chunk[0] as f32 / alpha) as u8;
|
||||
chunk[1] = (chunk[1] as f32 / alpha) as u8;
|
||||
chunk[2] = (chunk[2] as f32 / alpha) as u8;
|
||||
}
|
||||
|
||||
Ok(ImageData::new(self.global.root().r(), sw.abs().to_u32().unwrap(), sh.abs().to_u32().unwrap(), Some(data)))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue