Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIFF files with unassociated extra samples are unsupported. #183

Open
Aerocatia opened this issue Oct 19, 2022 · 5 comments
Open

TIFF files with unassociated extra samples are unsupported. #183

Aerocatia opened this issue Oct 19, 2022 · 5 comments

Comments

@Aerocatia
Copy link

TIFF files with 2 samples per pixel (Luminance + Alpha) are unsupported by this library.
Such TIFF files are the default output of imagemagick if the input is grayscale.

Attached is an example.
example_tiff.zip

@fintelia
Copy link
Contributor

Do you know where specifically the error is coming from? GrayA is listed as a supported color type and I believe that most of the code doesn't care how many samples per pixel there are.

@HeroicKatora
Copy link
Member

HeroicKatora commented Oct 20, 2022

It seems, imagemagick does not encode it as a truly alpha component but as a mask:

$ tiffinfo *
TIFF Directory at offset 0x80008 (524296)
  Image Width: 512 Image Length: 512
  Resolution: 1, 1 (unitless)
  Bits/Sample: 8
  Compression Scheme: None
  Photometric Interpretation: min-is-black
  Extra Samples: 1<unassoc-alpha>
  FillOrder: msb-to-lsb
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 2
  Rows/Strip: 512
  Planar Configuration: single image plane
  Page Number: 0-1
  White Point: 0.3127-0.329
  PrimaryChromaticities: 0.640000,0.330000,0.300000,0.600000,0.150000,0.060000

This is probably intended in this case (pistol_scope_mask.tif) but quite possibly the reason that it's not commonly encountered or reported as such.

The library doesn't guess the meaning of extra channels and unassociated extra samples aren't supported.

@HeroicKatora HeroicKatora changed the title TIFF files with 2 samples per pixel are unsupported. TIFF files with unassociated extra samples are unsupported. Nov 2, 2022
@sophie-h
Copy link

sophie-h commented Aug 5, 2024

I guess this is the same issue?

Format error decoding Tiff: Format error: invalid JPEG format: Invalid number of channels (4) for RGB data

If so, is the solution to change the check to "at least 3 channels" and just use the first 3 channels?

Triggered by Transparency_example.tiff generated via https://www.freeconvert.com

Downstream issue https://gitlab.gnome.org/sophie-h/glycin/-/issues/78

@sophie-h
Copy link

sophie-h commented Aug 5, 2024

$ tiffinfo Transparency_example.tiff 
=== TIFF directory 0 ===
TIFF Directory at offset 0x8 (8)
  Image Width: 194 Image Length: 68
  Bits/Sample: 8
  Compression Scheme: JPEG
  Photometric Interpretation: RGB color
  Extra Samples: 1<unassoc-alpha>
  FillOrder: msb-to-lsb
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 4
  Rows/Strip: 68
  Planar Configuration: single image plane
  Page Number: 0-1
  White Point: 0.3127-0.329
  PrimaryChromaticities: 0.640000,0.330000,0.300000,0.600000,0.150000,0.060000
  JPEG Tables: (289 bytes)

@sophie-h
Copy link

sophie-h commented Aug 5, 2024

Maybe we can just use SamplesPerPixel – ExtraSamples as a default and special-case (1) where the premultiplication has to be undone? (Haven't looked at the code yet.)

0 = Unspecified data

1 = Associated alpha data (with pre-multiplied color)

2 = Unassociated alpha data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants