LibGfx: Correctly handle OS/2 BMPs with 3-byte color entries

We now properly handle OS/2 format BMPs that use 3 bytes per color
entry instead of 4. While OS/2 2.x officially specified 4 bytes per
color, some tools still produce files with 3-byte entries. We can
identify such files by checking the available color table space.
This commit is contained in:
aplefull 2025-05-06 21:32:35 +02:00 committed by Jelle Raaijmakers
commit e5944a4d9e
Notes: github-actions[bot] 2025-05-09 19:49:19 +00:00
3 changed files with 33 additions and 3 deletions

View file

@ -94,6 +94,17 @@ TEST_CASE(test_bmp_v4)
EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::Red);
}
TEST_CASE(test_bmp_os2_3bit)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("bmp/os2_3bpc.bmp"sv)));
EXPECT(Gfx::BMPImageDecoderPlugin::sniff(file->bytes()));
auto plugin_decoder = TRY_OR_FAIL(Gfx::BMPImageDecoderPlugin::create(file->bytes()));
auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 300, 200 }));
EXPECT_EQ(frame.image->get_pixel(150, 100), Gfx::Color::NamedColor::Black);
EXPECT_EQ(frame.image->get_pixel(152, 100), Gfx::Color::NamedColor::White);
}
TEST_CASE(test_ico_malformed_frame)
{
Array test_inputs = {