mirror of
https://github.com/servo/servo.git
synced 2025-06-13 19:04:30 +00: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
|
@ -75,6 +75,7 @@ num-traits = "0.2"
|
|||
offscreen_gl_context = {version = "0.21", features = ["serde"]}
|
||||
parking_lot = "0.6"
|
||||
phf = "0.7.18"
|
||||
pixels = {path = "../pixels"}
|
||||
profile_traits = {path = "../profile_traits"}
|
||||
ref_filter_map = "1.0.1"
|
||||
ref_slice = "1.0"
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use canvas_traits::canvas::{Canvas2dMsg, CanvasMsg, CanvasId};
|
||||
use canvas_traits::canvas::{CompositionOrBlending, FillOrStrokeStyle, FillRule};
|
||||
use canvas_traits::canvas::{LineCapStyle, LineJoinStyle, LinearGradientStyle};
|
||||
use canvas_traits::canvas::{RadialGradientStyle, RepetitionStyle, byte_swap_and_premultiply};
|
||||
use canvas_traits::canvas::{RadialGradientStyle, RepetitionStyle};
|
||||
use cssparser::{Parser, ParserInput, RGBA};
|
||||
use cssparser::Color as CSSColor;
|
||||
use dom::bindings::cell::DomRefCell;
|
||||
|
@ -41,6 +41,7 @@ use net_traits::image_cache::ImageResponse;
|
|||
use net_traits::image_cache::ImageState;
|
||||
use net_traits::image_cache::UsePlaceholder;
|
||||
use num_traits::ToPrimitive;
|
||||
use pixels;
|
||||
use profile_traits::ipc as profiled_ipc;
|
||||
use script_traits::ScriptMsg;
|
||||
use servo_url::ServoUrl;
|
||||
|
@ -410,7 +411,7 @@ impl CanvasRenderingContext2D {
|
|||
Some((mut data, size)) => {
|
||||
// Pixels come from cache in BGRA order and drawImage expects RGBA so we
|
||||
// have to swap the color values
|
||||
byte_swap_and_premultiply(&mut data);
|
||||
pixels::byte_swap_and_premultiply_inplace(&mut data);
|
||||
let size = Size2D::new(size.width as f64, size.height as f64);
|
||||
(data, size)
|
||||
},
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#[cfg(feature = "webgl_backtrace")]
|
||||
use backtrace::Backtrace;
|
||||
use byteorder::{ByteOrder, NativeEndian, WriteBytesExt};
|
||||
use canvas_traits::canvas::{byte_swap, multiply_u8_pixel};
|
||||
use canvas_traits::webgl::{DOMToTextureCommand, Parameter, WebGLCommandBacktrace};
|
||||
use canvas_traits::webgl::{TexParameter, WebGLCommand, WebGLContextShareMode, WebGLError};
|
||||
use canvas_traits::webgl::{WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSender};
|
||||
|
@ -65,6 +64,7 @@ use js::typedarray::{TypedArray, TypedArrayElementCreator};
|
|||
use net_traits::image::base::PixelFormat;
|
||||
use net_traits::image_cache::ImageResponse;
|
||||
use offscreen_gl_context::{GLContextAttributes, GLLimits};
|
||||
use pixels;
|
||||
use script_layout_interface::HTMLCanvasDataSource;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_config::prefs::PREFS;
|
||||
|
@ -550,7 +550,7 @@ impl WebGLRenderingContext {
|
|||
_ => unimplemented!(),
|
||||
};
|
||||
|
||||
byte_swap(&mut data);
|
||||
pixels::byte_swap_colors_inplace(&mut data);
|
||||
|
||||
(data, size, false)
|
||||
},
|
||||
|
@ -563,7 +563,7 @@ impl WebGLRenderingContext {
|
|||
}
|
||||
if let Some((mut data, size)) = canvas.fetch_all_data() {
|
||||
// Pixels got from Canvas have already alpha premultiplied
|
||||
byte_swap(&mut data);
|
||||
pixels::byte_swap_colors_inplace(&mut data);
|
||||
(data, size, true)
|
||||
} else {
|
||||
return Ok(None);
|
||||
|
@ -679,15 +679,11 @@ impl WebGLRenderingContext {
|
|||
|
||||
match (format, data_type) {
|
||||
(TexFormat::RGBA, TexDataType::UnsignedByte) => {
|
||||
for rgba in pixels.chunks_mut(4) {
|
||||
rgba[0] = multiply_u8_pixel(rgba[0], rgba[3]);
|
||||
rgba[1] = multiply_u8_pixel(rgba[1], rgba[3]);
|
||||
rgba[2] = multiply_u8_pixel(rgba[2], rgba[3]);
|
||||
}
|
||||
pixels::premultiply_inplace(pixels);
|
||||
},
|
||||
(TexFormat::LuminanceAlpha, TexDataType::UnsignedByte) => {
|
||||
for la in pixels.chunks_mut(2) {
|
||||
la[0] = multiply_u8_pixel(la[0], la[1]);
|
||||
la[0] = pixels::multiply_u8_color(la[0], la[1]);
|
||||
}
|
||||
},
|
||||
(TexFormat::RGBA, TexDataType::UnsignedShort5551) => {
|
||||
|
@ -707,9 +703,9 @@ impl WebGLRenderingContext {
|
|||
let a = extend_to_8_bits(pix & 0x0f);
|
||||
NativeEndian::write_u16(
|
||||
rgba,
|
||||
((multiply_u8_pixel(r, a) & 0xf0) as u16) << 8 |
|
||||
((multiply_u8_pixel(g, a) & 0xf0) as u16) << 4 |
|
||||
((multiply_u8_pixel(b, a) & 0xf0) as u16) |
|
||||
((pixels::multiply_u8_color(r, a) & 0xf0) as u16) << 8 |
|
||||
((pixels::multiply_u8_color(g, a) & 0xf0) as u16) << 4 |
|
||||
((pixels::multiply_u8_color(b, a) & 0xf0) as u16) |
|
||||
((a & 0x0f) as u16),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ extern crate num_traits;
|
|||
extern crate offscreen_gl_context;
|
||||
extern crate parking_lot;
|
||||
extern crate phf;
|
||||
extern crate pixels;
|
||||
#[macro_use]
|
||||
extern crate profile_traits;
|
||||
extern crate ref_filter_map;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue