mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Move unmultiply_inplace to pixels crate (#33553)
Signed-off-by: Taym <haddadi.taym@gmail.com>
This commit is contained in:
parent
fa0521481b
commit
02953d2fb6
2 changed files with 10 additions and 10 deletions
|
@ -24,7 +24,7 @@ use euclid::default::Size2D;
|
||||||
use fnv::FnvHashMap;
|
use fnv::FnvHashMap;
|
||||||
use half::f16;
|
use half::f16;
|
||||||
use log::{debug, error, trace, warn};
|
use log::{debug, error, trace, warn};
|
||||||
use pixels::{self, PixelFormat};
|
use pixels::{self, unmultiply_inplace, PixelFormat};
|
||||||
use sparkle::gl;
|
use sparkle::gl;
|
||||||
use sparkle::gl::{GLint, GLuint, Gl};
|
use sparkle::gl::{GLint, GLuint, Gl};
|
||||||
use surfman::chains::{PreserveBuffer, SwapChains, SwapChainsAPI};
|
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.
|
/// Flips the pixels in the Vec on the Y axis.
|
||||||
fn flip_pixels_y(
|
fn flip_pixels_y(
|
||||||
internal_format: TexFormat,
|
internal_format: TexFormat,
|
||||||
|
|
|
@ -197,6 +197,15 @@ pub fn detect_image_format(buffer: &[u8]) -> Result<ImageFormat, &str> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
fn is_gif(buffer: &[u8]) -> bool {
|
||||||
buffer.starts_with(b"GIF87a") || buffer.starts_with(b"GIF89a")
|
buffer.starts_with(b"GIF87a") || buffer.starts_with(b"GIF89a")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue