Don't use premultiply table for put_image_data

This commit is contained in:
Paul Padier 2016-03-08 18:14:57 +09:00
parent 436f7316d9
commit 1e8e5d61d2
3 changed files with 6 additions and 4109 deletions

View file

@ -15,7 +15,6 @@ use gfx_traits::color;
use ipc_channel::ipc::IpcSharedMemory; use ipc_channel::ipc::IpcSharedMemory;
use ipc_channel::ipc::{self, IpcSender}; use ipc_channel::ipc::{self, IpcSender};
use num::ToPrimitive; use num::ToPrimitive;
use premultiplytable::PREMULTIPLY_TABLE;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::mem; use std::mem;
use util::opts; use util::opts;
@ -615,11 +614,12 @@ impl<'a> CanvasPaintThread<'a> {
for _ in 0 .. dest_rect.size.height { for _ in 0 .. dest_rect.size.height {
let mut src_offset = src_line; let mut src_offset = src_line;
for _ in 0 .. dest_rect.size.width { for _ in 0 .. dest_rect.size.width {
// Premultiply alpha and swap RGBA -> BGRA. let alpha = imagedata[src_offset + 3] as u16;
let alpha = imagedata[src_offset + 3] as usize; // add 127 before dividing for more accurate rounding
dest.push(PREMULTIPLY_TABLE[256 * alpha + imagedata[src_offset + 2] as usize]); let premultiply_channel = |channel: u8| (((channel as u16 * alpha) + 127) / 255) as u8;
dest.push(PREMULTIPLY_TABLE[256 * alpha + imagedata[src_offset + 1] as usize]); dest.push(premultiply_channel(imagedata[src_offset + 2]));
dest.push(PREMULTIPLY_TABLE[256 * alpha + imagedata[src_offset + 0] as usize]); dest.push(premultiply_channel(imagedata[src_offset + 1]));
dest.push(premultiply_channel(imagedata[src_offset + 0]));
dest.push(imagedata[src_offset + 3]); dest.push(imagedata[src_offset + 3]);
src_offset += 4; src_offset += 4;
} }

View file

@ -23,5 +23,4 @@ extern crate util;
extern crate webrender_traits; extern crate webrender_traits;
pub mod canvas_paint_thread; pub mod canvas_paint_thread;
mod premultiplytable;
pub mod webgl_paint_thread; pub mod webgl_paint_thread;

File diff suppressed because it is too large Load diff