mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
parent
3bd5ef3384
commit
a3465d2962
7 changed files with 44 additions and 2 deletions
|
@ -27,6 +27,20 @@ fn byte_swap(data: &mut [u8]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(pcwalton): Speed up with SIMD, or better yet, find some way to not do this.
|
||||||
|
fn byte_swap_and_premultiply(data: &mut [u8]) {
|
||||||
|
let length = data.len();
|
||||||
|
for i in range_step(0, length, 4) {
|
||||||
|
let r = data[i + 2];
|
||||||
|
let g = data[i + 1];
|
||||||
|
let b = data[i + 0];
|
||||||
|
let a = data[i + 3];
|
||||||
|
data[i + 0] = ((r as u32) * (a as u32) / 255) as u8;
|
||||||
|
data[i + 1] = ((g as u32) * (a as u32) / 255) as u8;
|
||||||
|
data[i + 2] = ((b as u32) * (a as u32) / 255) as u8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
|
pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
|
||||||
if buffer.len() == 0 {
|
if buffer.len() == 0 {
|
||||||
return None;
|
return None;
|
||||||
|
@ -36,8 +50,9 @@ pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
|
||||||
match png::load_png_from_memory(buffer) {
|
match png::load_png_from_memory(buffer) {
|
||||||
Ok(mut png_image) => {
|
Ok(mut png_image) => {
|
||||||
match png_image.pixels {
|
match png_image.pixels {
|
||||||
png::RGB8(ref mut data) | png::RGBA8(ref mut data) => {
|
png::RGB8(ref mut data) => byte_swap(data.as_mut_slice()),
|
||||||
byte_swap(data.as_mut_slice());
|
png::RGBA8(ref mut data) => {
|
||||||
|
byte_swap_and_premultiply(data.as_mut_slice())
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 1.9 KiB |
13
tests/ref/alpha_png_a.html
Normal file
13
tests/ref/alpha_png_a.html
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Kaboom</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background: #00ff00;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body><img src=alpha_png_a.png></body>
|
||||||
|
</html>
|
||||||
|
|
BIN
tests/ref/alpha_png_a.png
Normal file
BIN
tests/ref/alpha_png_a.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
13
tests/ref/alpha_png_b.html
Normal file
13
tests/ref/alpha_png_b.html
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Kaboom</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background: #00ff00;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body><img src=alpha_png_b.png></body>
|
||||||
|
</html>
|
||||||
|
|
BIN
tests/ref/alpha_png_b.png
Normal file
BIN
tests/ref/alpha_png_b.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
|
@ -111,3 +111,4 @@ flaky_gpu,flaky_linux == acid2_noscroll.html acid2_ref_broken.html
|
||||||
== float_right_intrinsic_width_a.html float_right_intrinsic_width_ref.html
|
== float_right_intrinsic_width_a.html float_right_intrinsic_width_ref.html
|
||||||
== fixed_width_overrides_child_intrinsic_width_a.html fixed_width_overrides_child_intrinsic_width_ref.html
|
== fixed_width_overrides_child_intrinsic_width_a.html fixed_width_overrides_child_intrinsic_width_ref.html
|
||||||
== abs_float_pref_width_a.html abs_float_pref_width_ref.html
|
== abs_float_pref_width_a.html abs_float_pref_width_ref.html
|
||||||
|
== alpha_png_a.html alpha_png_b.html
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue