mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
auto merge of #5194 : hirschenberger/servo/gif_alpha_background, r=larsbergstrom
This is GIF specific. It's also done when the image is PNG but PNG is handled separately with the PNG crate, whereas GIFs are handled by the stb-image crate and the distinction between alpha and non-alpha-supporting images was missing.
This commit is contained in:
commit
6593cf9ec4
6 changed files with 40 additions and 1 deletions
|
@ -59,7 +59,12 @@ pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
|
|||
match stb_image::load_from_memory_with_depth(buffer, FORCE_DEPTH, true) {
|
||||
stb_image::LoadResult::ImageU8(mut image) => {
|
||||
assert!(image.depth == 4);
|
||||
byte_swap(image.data.as_mut_slice());
|
||||
// handle gif separately because the alpha-channel has to be premultiplied
|
||||
if is_gif(buffer) {
|
||||
byte_swap_and_premultiply(image.data.as_mut_slice());
|
||||
} else {
|
||||
byte_swap(image.data.as_mut_slice());
|
||||
}
|
||||
Some(png::Image {
|
||||
width: image.width as u32,
|
||||
height: image.height as u32,
|
||||
|
@ -77,3 +82,10 @@ pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_gif(buffer: &[u8]) -> bool {
|
||||
match buffer {
|
||||
[b'G',b'I',b'F',b'8', n, b'a', ..] if n == b'7' || n == b'9' => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
|
BIN
tests/ref/alpha_gif_a.gif
Normal file
BIN
tests/ref/alpha_gif_a.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 562 B |
13
tests/ref/alpha_gif_a.html
Normal file
13
tests/ref/alpha_gif_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_gif_a.gif></body>
|
||||
</html>
|
||||
|
BIN
tests/ref/alpha_gif_b.gif
Normal file
BIN
tests/ref/alpha_gif_b.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 589 B |
13
tests/ref/alpha_gif_b.html
Normal file
13
tests/ref/alpha_gif_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_gif_b.gif></body>
|
||||
</html>
|
||||
|
|
@ -13,6 +13,7 @@ fragment=top != ../html/acid2.html acid2_ref.html
|
|||
== acid1_a.html acid1_b.html
|
||||
== acid2_noscroll.html acid2_ref_broken.html
|
||||
== after_block_iteration.html after_block_iteration_ref.html
|
||||
== alpha_gif_a.html alpha_gif_b.html
|
||||
== alpha_png_a.html alpha_png_b.html
|
||||
== anon_block_inherit_a.html anon_block_inherit_b.html
|
||||
flaky_cpu == append_style_a.html append_style_b.html
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue