LibGfx/ILBMLoader: Don't decode bits once full row has been decoded

We were potentially decoding more bits than needed: this could
trash the next lines if decoder didn't zero the extra bits.
This commit is contained in:
Nicolas Ramz 2024-01-12 18:26:52 +01:00 committed by Jelle Raaijmakers
parent d545fb2b60
commit a1255cb6c9
3 changed files with 14 additions and 1 deletions

View file

@ -254,6 +254,17 @@ TEST_CASE(test_brush_transparent_color)
EXPECT_EQ(frame.image->get_pixel(114, 103), Gfx::Color::NamedColor::Black);
}
TEST_CASE(test_small_24bit)
{
auto file = MUST(Core::MappedFile::map(TEST_INPUT("ilbm/small-24bit.iff"sv)));
EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes()));
auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes()));
auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 10, 10 }));
EXPECT_EQ(frame.image->get_pixel(0, 4), Gfx::Color(1, 0, 1, 255));
}
TEST_CASE(test_ilbm_malformed_header)
{
Array test_inputs = {

Binary file not shown.

View file

@ -220,7 +220,9 @@ static ErrorOr<ByteBuffer> planar_to_chunky(ReadonlyBytes bitplanes, ILBMLoading
u8 bit = bitplanes[offset_base + i];
u8 rgb_shift = p / 8;
for (u8 b = 0; b < 8; b++) {
// Some encoders don't pad bytes rows with 0: make sure we stop
// when enough data for current bitplane row has been read
for (u8 b = 0; b < 8 && (i * 8) + b < width; b++) {
u8 mask = 1 << (7 - b);
// get current plane
if (bit & mask) {