1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:27:35 +00: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:
Lucas CHOLLET 2023-12-01 19:28:06 -05:00 committed by Sam Atkins
parent 923d9e834f
commit da134f6867
3 changed files with 22 additions and 1 deletions

View file

@ -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());