add premultiply table for PutImageData

This commit is contained in:
Nathan Froyd 2015-10-19 23:35:27 -04:00
parent 50b14e6670
commit 9e348e2e8e
5 changed files with 4108 additions and 15 deletions

View file

@ -17,6 +17,7 @@ use ipc_channel::ipc::{self, IpcSender};
use ipc_channel::router::ROUTER; use ipc_channel::router::ROUTER;
use layers::platform::surface::NativeSurface; use layers::platform::surface::NativeSurface;
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 std::sync::mpsc::{Sender, channel}; use std::sync::mpsc::{Sender, channel};
@ -597,11 +598,10 @@ impl<'a> CanvasPaintTask<'a> {
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. // Premultiply alpha and swap RGBA -> BGRA.
// TODO: may want a precomputed premultiply table to make this fast. (#6969) let alpha = imagedata[src_offset + 3] as usize;
let alpha = imagedata[src_offset + 3] as f32 / 255.; dest.push(PREMULTIPLY_TABLE[256 * alpha + imagedata[src_offset + 2] as usize]);
dest.push((imagedata[src_offset + 2] as f32 * alpha) as u8); dest.push(PREMULTIPLY_TABLE[256 * alpha + imagedata[src_offset + 1] as usize]);
dest.push((imagedata[src_offset + 1] as f32 * alpha) as u8); dest.push(PREMULTIPLY_TABLE[256 * alpha + imagedata[src_offset + 0] as usize]);
dest.push((imagedata[src_offset + 0] as f32 * alpha) as u8);
dest.push(imagedata[src_offset + 3]); dest.push(imagedata[src_offset + 3]);
src_offset += 4; src_offset += 4;
} }

View file

@ -25,4 +25,5 @@ extern crate offscreen_gl_context;
extern crate util; extern crate util;
pub mod canvas_paint_task; pub mod canvas_paint_task;
mod premultiplytable;
pub mod webgl_paint_task; pub mod webgl_paint_task;

File diff suppressed because it is too large Load diff

View file

@ -1,5 +0,0 @@
[2d.imageData.put.alpha.html]
type: testharness
[putImageData() puts non-solid image data correctly]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.imageData.put.unchanged.html]
type: testharness
[putImageData(getImageData(...), ...) has no effect]
expected: FAIL