diff --git a/components/canvas/webgl_thread.rs b/components/canvas/webgl_thread.rs index be9d1d48f86..f1b31d8ba15 100644 --- a/components/canvas/webgl_thread.rs +++ b/components/canvas/webgl_thread.rs @@ -24,7 +24,7 @@ use euclid::default::Size2D; use fnv::FnvHashMap; use half::f16; use log::{debug, error, trace, warn}; -use pixels::{self, PixelFormat}; +use pixels::{self, unmultiply_inplace, PixelFormat}; use sparkle::gl; use sparkle::gl::{GLint, GLuint, Gl}; use surfman::chains::{PreserveBuffer, SwapChains, SwapChainsAPI}; @@ -2838,15 +2838,6 @@ fn premultiply_inplace(format: TexFormat, data_type: TexDataType, pixels: &mut [ } } -fn unmultiply_inplace(pixels: &mut [u8]) { - for rgba in pixels.chunks_mut(4) { - let a = (rgba[3] as f32) / 255.0; - rgba[0] = (rgba[0] as f32 / a) as u8; - rgba[1] = (rgba[1] as f32 / a) as u8; - rgba[2] = (rgba[2] as f32 / a) as u8; - } -} - /// Flips the pixels in the Vec on the Y axis. fn flip_pixels_y( internal_format: TexFormat, diff --git a/components/pixels/lib.rs b/components/pixels/lib.rs index bd2aea5b410..e90df8e32ea 100644 --- a/components/pixels/lib.rs +++ b/components/pixels/lib.rs @@ -197,6 +197,15 @@ pub fn detect_image_format(buffer: &[u8]) -> Result { } } +pub fn unmultiply_inplace(pixels: &mut [u8]) { + for rgba in pixels.chunks_mut(4) { + let a = (rgba[3] as f32) / 255.0; + rgba[0] = (rgba[0] as f32 / a) as u8; + rgba[1] = (rgba[1] as f32 / a) as u8; + rgba[2] = (rgba[2] as f32 / a) as u8; + } +} + fn is_gif(buffer: &[u8]) -> bool { buffer.starts_with(b"GIF87a") || buffer.starts_with(b"GIF89a") }