Auto merge of #8086 - froydnj:premultiply-tables, r=jdm

add (un)premultiply tables for canvas {Get,Put}ImageData operations

Pretty straightforward use of lookup tables to replace a bunch of expensive float operations.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8086)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-10-21 17:48:49 -06:00
commit 9a34decec2
8 changed files with 8216 additions and 21 deletions

View file

@ -41,6 +41,7 @@ use std::cell::RefCell;
use std::str::FromStr;
use std::sync::mpsc::channel;
use std::{cmp, fmt};
use unpremultiplytable::UNPREMULTIPLY_TABLE;
use url::Url;
use util::str::DOMString;
use util::vec::byte_swap;
@ -887,13 +888,11 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
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;
let alpha = chunk[3] as usize;
chunk[0] = UNPREMULTIPLY_TABLE[256 * alpha + chunk[0] as usize];
chunk[1] = UNPREMULTIPLY_TABLE[256 * alpha + chunk[1] as usize];
chunk[2] = UNPREMULTIPLY_TABLE[256 * alpha + chunk[2] as usize];
}
Ok(ImageData::new(self.global.root().r(), sw, sh, Some(data)))

View file

@ -95,6 +95,7 @@ pub mod parse;
pub mod script_task;
pub mod textinput;
mod timers;
mod unpremultiplytable;
mod webdriver_handlers;
use dom::bindings::codegen::RegisterBindings;

File diff suppressed because it is too large Load diff