mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Merge some byte swap/premultiply functions in their own crate
This commit is contained in:
parent
a2e3dd4e86
commit
784fbb2bc1
18 changed files with 85 additions and 96 deletions
|
@ -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"}
|
||||
|
|
|
@ -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_colors_inplace(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_colors_inplace(&mut *rgba);
|
||||
pixels::byte_swap_colors_inplace(&mut *rgba);
|
||||
Some(Image {
|
||||
width: rgba.width(),
|
||||
height: rgba.height(),
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue