1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

LibGfx: Fix incorrect colors in ICO-embedded BMPs

This commit is contained in:
aplefull 2025-04-23 21:40:41 +02:00 committed by Sam Atkins
parent 9bae24cc4a
commit e0ceb66580
Notes: github-actions[bot] 2025-04-24 12:47:55 +00:00
3 changed files with 22 additions and 5 deletions

View file

@ -1379,12 +1379,18 @@ static ErrorOr<void> decode_bmp_pixel_data(BMPLoadingContext& context)
return Error::from_string_literal("Cannot read 24 bits");
u32 pixel = streamer.read_u24();
u8 b = (pixel & 0xFF0000) >> 16;
u8 g = (pixel & 0x00FF00) >> 8;
u8 r = (pixel & 0x0000FF);
u32 rgbx_pixel = (r << 16) | (g << 8) | b;
context.bitmap->scanline(row)[column++] = rgbx_pixel;
if (context.is_included_in_ico) {
// 24-bit ICO files already use BGRA8888 format
context.bitmap->scanline(row)[column++] = pixel;
} else {
u8 b = (pixel & 0x0000FF);
u8 g = (pixel & 0x00FF00) >> 8;
u8 r = (pixel & 0xFF0000) >> 16;
context.bitmap->scanline(row)[column++] = (b << 16) | (g << 8) | r;
}
break;
}
case 32:

View file

@ -192,6 +192,17 @@ TEST_CASE(test_bmp_embedded_in_ico)
EXPECT_EQ(frame.image->get_pixel(7, 4), Gfx::Color(161, 0, 0));
}
TEST_CASE(test_24bit_bmp_embedded_in_ico)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("ico/yt-favicon.ico"sv)));
EXPECT(Gfx::ICOImageDecoderPlugin::sniff(file->bytes()));
auto plugin_decoder = TRY_OR_FAIL(Gfx::ICOImageDecoderPlugin::create(file->bytes()));
auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 16, 16 }));
EXPECT_EQ(frame.image->get_pixel(14, 14), Gfx::Color(234, 0, 0));
EXPECT_EQ(frame.image->get_pixel(13, 15), Gfx::Color(255, 10, 15));
}
TEST_CASE(test_malformed_maskless_ico)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("ico/malformed_maskless.ico"sv)));

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 B