mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 10:22:05 -05:00
LibGfx/TIFF: Add support for grayscale images
Images with a single sample per pixel should be interpreted as grayscale.
This commit is contained in:
parent
923d9e834f
commit
da134f6867
3 changed files with 22 additions and 1 deletions
|
@ -408,6 +408,18 @@ TEST_CASE(test_tiff_packed_bits)
|
|||
EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
|
||||
}
|
||||
|
||||
TEST_CASE(test_tiff_grayscale)
|
||||
{
|
||||
auto file = MUST(Core::MappedFile::map(TEST_INPUT("tiff/grayscale.tiff"sv)));
|
||||
EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
|
||||
auto plugin_decoder = MUST(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
|
||||
|
||||
auto frame = expect_single_frame_of_size(*plugin_decoder, { 400, 300 });
|
||||
|
||||
EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
|
||||
EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color(130, 130, 130));
|
||||
}
|
||||
|
||||
TEST_CASE(test_webp_simple_lossy)
|
||||
{
|
||||
auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/simple-vp8.webp"sv)));
|
||||
|
|
BIN
Tests/LibGfx/test-inputs/tiff/grayscale.tiff
Normal file
BIN
Tests/LibGfx/test-inputs/tiff/grayscale.tiff
Normal file
Binary file not shown.
|
@ -96,7 +96,16 @@ private:
|
|||
Optional<Color> last_color {};
|
||||
|
||||
for (u32 column = 0; column < *m_metadata.image_width(); ++column) {
|
||||
auto color = Color { TRY(decoded_strip->template read_value<u8>()), TRY(decoded_strip->template read_value<u8>()), TRY(decoded_strip->template read_value<u8>()) };
|
||||
Color color {};
|
||||
|
||||
if (m_metadata.samples_per_pixel().value_or(3) == 3) {
|
||||
color = Color { TRY(decoded_strip->template read_value<u8>()), TRY(decoded_strip->template read_value<u8>()), TRY(decoded_strip->template read_value<u8>()) };
|
||||
} else if (*m_metadata.samples_per_pixel() == 1) {
|
||||
auto luminosity = TRY(decoded_strip->template read_value<u8>());
|
||||
color = Color { luminosity, luminosity, luminosity };
|
||||
} else {
|
||||
return Error::from_string_literal("Unsupported number of sample per pixel");
|
||||
}
|
||||
|
||||
if (m_metadata.predictor() == Predictor::HorizontalDifferencing && last_color.has_value()) {
|
||||
color.set_red(last_color->red() + color.red());
|
||||
|
|
Loading…
Add table
Reference in a new issue