Auto merge of #9911 - magni-:dont_use_lookup_tables, r=michaelwu

Do not use lookup tables for put_image_data

Fixes #9599

"This is the first Rust code I have ever written" (and also my first time writing real browser code, it's been quite the learning experience).

Some questions:

> For really fast CPU results, use integer SIMD instructions to handle more than one pixel at a time.

This was out of the scope of #9599, right? I started looking into doing that, but it seems to be a lot more work than the `E-easy` label would suggest. [`std::simd`](https://doc.rust-lang.org/1.0.0/std/simd/index.html) is marked as "unstable", is that a blocker?

> 128 can be added before dividing to round more accurately.

@michaelwu, what did you mean by that?

Also, the #9599 is `Do not use lookup tables for {Get,Put}ImageData operations`, but we only use lookup tables for the `Put`, not the `Get`, right?

Sorry for all the noobish questions.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9911)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-04-01 23:57:19 +05:30
commit 4e4a213c73
4 changed files with 12 additions and 4113 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;
@ -538,10 +537,7 @@ impl<'a> CanvasPaintThread<'a> {
})
}
fn image_data(&self,
dest_rect: Rect<i32>,
canvas_size: Size2D<f64>,
chan: IpcSender<Vec<u8>>) {
fn image_data(&self, dest_rect: Rect<i32>, canvas_size: Size2D<f64>, chan: IpcSender<Vec<u8>>) {
let mut dest_data = self.read_pixels(dest_rect, canvas_size);
// bgra -> rgba
@ -615,11 +611,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;
}

View file

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

File diff suppressed because it is too large Load diff