mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +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
|
@ -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(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue