mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:47:35 +00:00
LibGfx/TIFF: Add support for RGBPalette images
TIFF images with the PhotometricInterpretation tag set to RGBPalette are based on indexed colors instead of explicitly describing the color for each pixel. Let's add support for them. The test case was generated with GIMP using the Indexed image mode after adding an alpha layer. Not all decoders are able to open this image, but GIMP can.
This commit is contained in:
parent
d8759d9656
commit
67522fab2e
4 changed files with 37 additions and 0 deletions
|
@ -92,6 +92,7 @@ private:
|
|||
switch (*m_metadata.photometric_interpretation()) {
|
||||
case PhotometricInterpretation::WhiteIsZero:
|
||||
case PhotometricInterpretation::BlackIsZero:
|
||||
case PhotometricInterpretation::RGBPalette:
|
||||
return 1;
|
||||
case PhotometricInterpretation::RGB:
|
||||
return 3;
|
||||
|
@ -147,6 +148,29 @@ private:
|
|||
return Color(first_component, second_component, third_component, alpha);
|
||||
}
|
||||
|
||||
if (m_metadata.photometric_interpretation() == PhotometricInterpretation::RGBPalette) {
|
||||
auto const index = TRY(stream.read_bits<u16>(bits_per_sample[0]));
|
||||
auto const alpha = TRY(manage_extra_channels());
|
||||
|
||||
// SamplesPerPixel == 1 is a requirement for RGBPalette
|
||||
// From description of PhotometricInterpretation in Section 8: Baseline Field Reference Guide
|
||||
// "In a TIFF ColorMap, all the Red values come first, followed by the Green values,
|
||||
// then the Blue values."
|
||||
auto const size = 1 << (*m_metadata.bits_per_sample())[0];
|
||||
auto const red_offset = 0 * size;
|
||||
auto const green_offset = 1 * size;
|
||||
auto const blue_offset = 2 * size;
|
||||
|
||||
auto const color_map = *m_metadata.color_map();
|
||||
|
||||
// FIXME: ColorMap's values are always 16-bits, stop truncating them when we support 16 bits bitmaps
|
||||
return Color(
|
||||
color_map[red_offset + index] >> 8,
|
||||
color_map[green_offset + index] >> 8,
|
||||
color_map[blue_offset + index] >> 8,
|
||||
alpha);
|
||||
}
|
||||
|
||||
if (*m_metadata.photometric_interpretation() == PhotometricInterpretation::WhiteIsZero
|
||||
|| *m_metadata.photometric_interpretation() == PhotometricInterpretation::BlackIsZero) {
|
||||
auto luminosity = TRY(read_component(stream, bits_per_sample[0]));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue