mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Premultiply RGBA image data before sending to webrender
This commit is contained in:
parent
ee223798cc
commit
ec3142e811
4 changed files with 21 additions and 0 deletions
|
@ -336,6 +336,21 @@ fn get_placeholder_image(webrender_api: &webrender_traits::RenderApi) -> io::Res
|
|||
Ok(Arc::new(image))
|
||||
}
|
||||
|
||||
fn premultiply(data: &mut [u8]) {
|
||||
let length = data.len();
|
||||
|
||||
for i in (0..length).step_by(4) {
|
||||
let b = data[i + 0] as u32;
|
||||
let g = data[i + 1] as u32;
|
||||
let r = data[i + 2] as u32;
|
||||
let a = data[i + 3] as u32;
|
||||
|
||||
data[i + 0] = (b * a / 255) as u8;
|
||||
data[i + 1] = (g * a / 255) as u8;
|
||||
data[i + 2] = (r * a / 255) as u8;
|
||||
}
|
||||
}
|
||||
|
||||
impl ImageCache {
|
||||
fn run(webrender_api: webrender_traits::RenderApi,
|
||||
ipc_command_receiver: IpcReceiver<ImageCacheCommand>) {
|
||||
|
@ -484,6 +499,9 @@ impl ImageCache {
|
|||
let format = convert_format(image.format);
|
||||
let mut bytes = Vec::new();
|
||||
bytes.extend_from_slice(&*image.bytes);
|
||||
if format == webrender_traits::ImageFormat::RGBA8 {
|
||||
premultiply(bytes.as_mut_slice());
|
||||
}
|
||||
let descriptor = webrender_traits::ImageDescriptor {
|
||||
width: image.width,
|
||||
height: image.height,
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#![deny(unsafe_code)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(mpsc_select)]
|
||||
#![feature(step_by)]
|
||||
|
||||
extern crate brotli;
|
||||
extern crate cookie as cookie_rs;
|
||||
|
|
|
@ -106,6 +106,7 @@
|
|||
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);
|
||||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
||||
gl.generateMipmap(gl.TEXTURE_2D);
|
||||
|
||||
|
|
|
@ -106,6 +106,7 @@
|
|||
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
||||
|
||||
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue