LibGfx/TIFF: Apply the HorizontalDifferencing on the alpha channel

When present, the alpha channel is also affected by the horizontal
differencing predictor.

The test case was generated with GIMP with the following steps:
 - Open an RGB image
 - Add a transparency layer
 - Export as TIFF with the LZW compression scheme
This commit is contained in:
Lucas CHOLLET 2024-01-22 21:19:42 -05:00 committed by Andrew Kaster
parent 0e6d87fe83
commit 1faf9bb44f
Notes: sideshowbarker 2024-07-16 18:03:21 +09:00
3 changed files with 14 additions and 0 deletions

View File

@ -676,6 +676,18 @@ TEST_CASE(test_tiff_palette_alpha)
EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
}
TEST_CASE(test_tiff_alpha_predictor)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/alpha_predictor.tiff"sv)));
EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
EXPECT_EQ(frame.image->get_pixel(0, 0).alpha(), 255);
EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
}
TEST_CASE(test_tiff_16_bits)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/16_bits.tiff"sv)));

Binary file not shown.

View File

@ -267,6 +267,8 @@ private:
color.set_red(last_color->red() + color.red());
color.set_green(last_color->green() + color.green());
color.set_blue(last_color->blue() + color.blue());
if (alpha_channel_index().has_value())
color.set_alpha(last_color->alpha() + color.alpha());
}
last_color = color;