Auto merge of #21877 - servo:webgl, r=jdm

Improve some byte-swap and premultiply operations

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21877)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-10-09 20:15:40 -04:00 committed by GitHub
commit 7a88a2e28a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 369 additions and 439 deletions

View file

@ -24,6 +24,7 @@ malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
msg = {path = "../msg"}
num-traits = "0.2"
pixels = {path = "../pixels"}
serde = "1.0"
servo_arc = {path = "../servo_arc"}
servo_config = {path = "../config"}

View file

@ -4,6 +4,7 @@
use ipc_channel::ipc::IpcSharedMemory;
use piston_image::{self, DynamicImage, ImageFormat};
use pixels;
use std::fmt;
use webrender_api;
@ -46,24 +47,6 @@ pub struct ImageMetadata {
// FIXME: Images must not be copied every frame. Instead we should atomically
// reference count them.
// TODO(pcwalton): Speed up with SIMD, or better yet, find some way to not do this.
fn byte_swap_and_premultiply(data: &mut [u8]) {
let length = data.len();
let mut i = 0;
while i < length {
let r = data[i + 2];
let g = data[i + 1];
let b = data[i + 0];
data[i + 0] = r;
data[i + 1] = g;
data[i + 2] = b;
i += 4;
}
}
pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
if buffer.is_empty() {
return None;
@ -82,7 +65,7 @@ pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
DynamicImage::ImageRgba8(rgba) => rgba,
image => image.to_rgba(),
};
byte_swap_and_premultiply(&mut *rgba);
pixels::byte_swap_colors_inplace(&mut *rgba);
Some(Image {
width: rgba.width(),
height: rgba.height(),

View file

@ -17,6 +17,7 @@ extern crate ipc_channel;
#[macro_use] extern crate malloc_size_of_derive;
extern crate msg;
extern crate num_traits;
extern crate pixels;
#[macro_use] extern crate serde;
extern crate servo_arc;
extern crate servo_url;