mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Prefix some pixels functions with rgba8_
This commit is contained in:
parent
adf363a208
commit
a5779ad372
9 changed files with 15 additions and 15 deletions
|
@ -69,7 +69,7 @@ impl<'a> CanvasData<'a> {
|
||||||
let source_rect = source_rect.ceil();
|
let source_rect = source_rect.ceil();
|
||||||
// It discards the extra pixels (if any) that won't be painted
|
// It discards the extra pixels (if any) that won't be painted
|
||||||
let image_data = if Rect::from_size(image_size).contains_rect(&source_rect) {
|
let image_data = if Rect::from_size(image_size).contains_rect(&source_rect) {
|
||||||
pixels::get_rect(&image_data, image_size.to_u32(), source_rect.to_u32()).into()
|
pixels::rgba8_get_rect(&image_data, image_size.to_u32(), source_rect.to_u32()).into()
|
||||||
} else {
|
} else {
|
||||||
image_data.into()
|
image_data.into()
|
||||||
};
|
};
|
||||||
|
@ -510,7 +510,7 @@ impl<'a> CanvasData<'a> {
|
||||||
pub fn put_image_data(&mut self, mut imagedata: Vec<u8>, rect: Rect<u32>) {
|
pub fn put_image_data(&mut self, mut imagedata: Vec<u8>, rect: Rect<u32>) {
|
||||||
assert_eq!(imagedata.len() % 4, 0);
|
assert_eq!(imagedata.len() % 4, 0);
|
||||||
assert_eq!(rect.size.area() as usize, imagedata.len() / 4);
|
assert_eq!(rect.size.area() as usize, imagedata.len() / 4);
|
||||||
pixels::byte_swap_and_premultiply_inplace(&mut imagedata);
|
pixels::rgba8_byte_swap_and_premultiply_inplace(&mut imagedata);
|
||||||
let source_surface = self
|
let source_surface = self
|
||||||
.drawtarget
|
.drawtarget
|
||||||
.create_source_surface_from_data(
|
.create_source_surface_from_data(
|
||||||
|
@ -602,7 +602,7 @@ impl<'a> CanvasData<'a> {
|
||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
let data_surface = self.drawtarget.snapshot().get_data_surface();
|
let data_surface = self.drawtarget.snapshot().get_data_surface();
|
||||||
pixels::get_rect(
|
pixels::rgba8_get_rect(
|
||||||
unsafe { data_surface.data() },
|
unsafe { data_surface.data() },
|
||||||
canvas_size.to_u32(),
|
canvas_size.to_u32(),
|
||||||
read_rect.to_u32(),
|
read_rect.to_u32(),
|
||||||
|
|
|
@ -635,7 +635,7 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> {
|
||||||
let src_slice = &orig_pixels[src_start..src_start + stride];
|
let src_slice = &orig_pixels[src_start..src_start + stride];
|
||||||
(&mut pixels[dst_start..dst_start + stride]).clone_from_slice(&src_slice[..stride]);
|
(&mut pixels[dst_start..dst_start + stride]).clone_from_slice(&src_slice[..stride]);
|
||||||
}
|
}
|
||||||
pixels::byte_swap_colors_inplace(&mut pixels);
|
pixels::rgba8_byte_swap_colors_inplace(&mut pixels);
|
||||||
pixels
|
pixels
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -950,7 +950,7 @@ pub fn rgba8_image_to_tex_image_data(
|
||||||
pub fn premultiply_inplace(format: TexFormat, data_type: TexDataType, pixels: &mut [u8]) {
|
pub fn premultiply_inplace(format: TexFormat, data_type: TexDataType, pixels: &mut [u8]) {
|
||||||
match (format, data_type) {
|
match (format, data_type) {
|
||||||
(TexFormat::RGBA, TexDataType::UnsignedByte) => {
|
(TexFormat::RGBA, TexDataType::UnsignedByte) => {
|
||||||
pixels::premultiply_inplace(pixels);
|
pixels::rgba8_premultiply_inplace(pixels);
|
||||||
},
|
},
|
||||||
(TexFormat::LuminanceAlpha, TexDataType::UnsignedByte) => {
|
(TexFormat::LuminanceAlpha, TexDataType::UnsignedByte) => {
|
||||||
for la in pixels.chunks_mut(2) {
|
for la in pixels.chunks_mut(2) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ fn set_webrender_image_key(webrender_api: &webrender_api::RenderApi, image: &mut
|
||||||
let is_opaque = match image.format {
|
let is_opaque = match image.format {
|
||||||
PixelFormat::BGRA8 => {
|
PixelFormat::BGRA8 => {
|
||||||
bytes.extend_from_slice(&*image.bytes);
|
bytes.extend_from_slice(&*image.bytes);
|
||||||
pixels::premultiply_inplace(bytes.as_mut_slice())
|
pixels::rgba8_premultiply_inplace(bytes.as_mut_slice())
|
||||||
},
|
},
|
||||||
PixelFormat::RGB8 => {
|
PixelFormat::RGB8 => {
|
||||||
for bgr in image.bytes.chunks(3) {
|
for bgr in image.bytes.chunks(3) {
|
||||||
|
|
|
@ -65,7 +65,7 @@ pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
|
||||||
DynamicImage::ImageRgba8(rgba) => rgba,
|
DynamicImage::ImageRgba8(rgba) => rgba,
|
||||||
image => image.to_rgba(),
|
image => image.to_rgba(),
|
||||||
};
|
};
|
||||||
pixels::byte_swap_colors_inplace(&mut *rgba);
|
pixels::rgba8_byte_swap_colors_inplace(&mut *rgba);
|
||||||
Some(Image {
|
Some(Image {
|
||||||
width: rgba.width(),
|
width: rgba.width(),
|
||||||
height: rgba.height(),
|
height: rgba.height(),
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use euclid::{Point2D, Rect, Size2D};
|
use euclid::{Point2D, Rect, Size2D};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
pub fn get_rect(pixels: &[u8], size: Size2D<u32>, rect: Rect<u32>) -> Cow<[u8]> {
|
pub fn rgba8_get_rect(pixels: &[u8], size: Size2D<u32>, rect: Rect<u32>) -> Cow<[u8]> {
|
||||||
assert!(!rect.is_empty());
|
assert!(!rect.is_empty());
|
||||||
assert!(Rect::from_size(size).contains_rect(&rect));
|
assert!(Rect::from_size(size).contains_rect(&rect));
|
||||||
assert_eq!(pixels.len() % 4, 0);
|
assert_eq!(pixels.len() % 4, 0);
|
||||||
|
@ -29,7 +29,7 @@ pub fn get_rect(pixels: &[u8], size: Size2D<u32>, rect: Rect<u32>) -> Cow<[u8]>
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(pcwalton): Speed up with SIMD, or better yet, find some way to not do this.
|
// TODO(pcwalton): Speed up with SIMD, or better yet, find some way to not do this.
|
||||||
pub fn byte_swap_colors_inplace(pixels: &mut [u8]) {
|
pub fn rgba8_byte_swap_colors_inplace(pixels: &mut [u8]) {
|
||||||
assert!(pixels.len() % 4 == 0);
|
assert!(pixels.len() % 4 == 0);
|
||||||
for rgba in pixels.chunks_mut(4) {
|
for rgba in pixels.chunks_mut(4) {
|
||||||
let b = rgba[0];
|
let b = rgba[0];
|
||||||
|
@ -38,7 +38,7 @@ pub fn byte_swap_colors_inplace(pixels: &mut [u8]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn byte_swap_and_premultiply_inplace(pixels: &mut [u8]) {
|
pub fn rgba8_byte_swap_and_premultiply_inplace(pixels: &mut [u8]) {
|
||||||
assert!(pixels.len() % 4 == 0);
|
assert!(pixels.len() % 4 == 0);
|
||||||
for rgba in pixels.chunks_mut(4) {
|
for rgba in pixels.chunks_mut(4) {
|
||||||
let b = rgba[0];
|
let b = rgba[0];
|
||||||
|
@ -49,7 +49,7 @@ pub fn byte_swap_and_premultiply_inplace(pixels: &mut [u8]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the pixels were found to be completely opaque.
|
/// Returns true if the pixels were found to be completely opaque.
|
||||||
pub fn premultiply_inplace(pixels: &mut [u8]) -> bool {
|
pub fn rgba8_premultiply_inplace(pixels: &mut [u8]) -> bool {
|
||||||
assert!(pixels.len() % 4 == 0);
|
assert!(pixels.len() % 4 == 0);
|
||||||
let mut is_opaque = true;
|
let mut is_opaque = true;
|
||||||
for rgba in pixels.chunks_mut(4) {
|
for rgba in pixels.chunks_mut(4) {
|
||||||
|
|
|
@ -403,7 +403,7 @@ impl CanvasRenderingContext2D {
|
||||||
) -> ErrorResult {
|
) -> ErrorResult {
|
||||||
debug!("Fetching image {}.", url);
|
debug!("Fetching image {}.", url);
|
||||||
let (mut image_data, image_size) = self.fetch_image_data(url).ok_or(Error::InvalidState)?;
|
let (mut image_data, image_size) = self.fetch_image_data(url).ok_or(Error::InvalidState)?;
|
||||||
pixels::premultiply_inplace(&mut image_data);
|
pixels::rgba8_premultiply_inplace(&mut image_data);
|
||||||
let image_size = image_size.to_f64();
|
let image_size = image_size.to_f64();
|
||||||
|
|
||||||
let dw = dw.unwrap_or(image_size.width);
|
let dw = dw.unwrap_or(image_size.width);
|
||||||
|
|
|
@ -162,7 +162,7 @@ impl ImageData {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub unsafe fn get_rect(&self, rect: Rect<u32>) -> Cow<[u8]> {
|
pub unsafe fn get_rect(&self, rect: Rect<u32>) -> Cow<[u8]> {
|
||||||
pixels::get_rect(self.as_slice(), self.get_size(), rect)
|
pixels::rgba8_get_rect(self.as_slice(), self.get_size(), rect)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_size(&self) -> Size2D<u32> {
|
pub fn get_size(&self) -> Size2D<u32> {
|
||||||
|
|
|
@ -559,7 +559,7 @@ impl WebGLRenderingContext {
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
pixels::byte_swap_colors_inplace(&mut data);
|
pixels::rgba8_byte_swap_colors_inplace(&mut data);
|
||||||
|
|
||||||
TexPixels::new(data, size, false)
|
TexPixels::new(data, size, false)
|
||||||
},
|
},
|
||||||
|
@ -572,7 +572,7 @@ impl WebGLRenderingContext {
|
||||||
}
|
}
|
||||||
if let Some((mut data, size)) = canvas.fetch_all_data() {
|
if let Some((mut data, size)) = canvas.fetch_all_data() {
|
||||||
// Pixels got from Canvas have already alpha premultiplied
|
// Pixels got from Canvas have already alpha premultiplied
|
||||||
pixels::byte_swap_colors_inplace(&mut data);
|
pixels::rgba8_byte_swap_colors_inplace(&mut data);
|
||||||
TexPixels::new(data, size, true)
|
TexPixels::new(data, size, true)
|
||||||
} else {
|
} else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue