mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:07:35 +00:00
LibGfx: Fix color alfa for transparent color in GIFLoader
This commit is contained in:
parent
ccb0d00020
commit
49c801f7fd
1 changed files with 17 additions and 7 deletions
|
@ -294,6 +294,11 @@ bool decode_frames_up_to_index(GIFLoadingContext& context, size_t frame_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
int pixel_index = 0;
|
int pixel_index = 0;
|
||||||
|
RGB transparent_color { 0, 0, 0 };
|
||||||
|
if (image.transparent) {
|
||||||
|
transparent_color = context.logical_screen.color_map[image.transparency_index];
|
||||||
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
Optional<u16> code = decoder.next_code();
|
Optional<u16> code = decoder.next_code();
|
||||||
if (!code.has_value()) {
|
if (!code.has_value()) {
|
||||||
|
@ -311,15 +316,20 @@ bool decode_frames_up_to_index(GIFLoadingContext& context, size_t frame_index)
|
||||||
auto colors = decoder.get_output();
|
auto colors = decoder.get_output();
|
||||||
|
|
||||||
for (const auto& color : colors) {
|
for (const auto& color : colors) {
|
||||||
if (!image.transparent || color != image.transparency_index) {
|
|
||||||
auto rgb = context.logical_screen.color_map[color];
|
auto rgb = context.logical_screen.color_map[color];
|
||||||
|
|
||||||
int x = pixel_index % image.width + image.x;
|
int x = pixel_index % image.width + image.x;
|
||||||
int y = pixel_index / image.width + image.y;
|
int y = pixel_index / image.width + image.y;
|
||||||
|
|
||||||
Color c = Color(rgb.r, rgb.g, rgb.b);
|
Color c = Color(rgb.r, rgb.g, rgb.b);
|
||||||
image.bitmap->set_pixel(x, y, c);
|
|
||||||
|
if (image.transparent) {
|
||||||
|
if (rgb.r == transparent_color.r && rgb.g == transparent_color.g && rgb.b == transparent_color.b) {
|
||||||
|
c.set_alpha(0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
image.bitmap->set_pixel(x, y, c);
|
||||||
++pixel_index;
|
++pixel_index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -536,7 +546,7 @@ GIFImageDecoderPlugin::GIFImageDecoderPlugin(const u8* data, size_t size)
|
||||||
m_context->data_size = size;
|
m_context->data_size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
GIFImageDecoderPlugin::~GIFImageDecoderPlugin() { }
|
GIFImageDecoderPlugin::~GIFImageDecoderPlugin() {}
|
||||||
|
|
||||||
IntSize GIFImageDecoderPlugin::size()
|
IntSize GIFImageDecoderPlugin::size()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue