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