-
-
Notifications
You must be signed in to change notification settings - Fork 851
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
Jpeg compressed tiff with photometric interpretation Separated is not supported #2454
Comments
Added another image where ImageSharp complains about Separated. |
We actually support photometric interpretation Separated, see CmykTests. The issue here comes from the combination of JPEG compression and separated. I am not sure how to decode those image, that's why it's disabled and throws an exception with that message. If I map the colorspace for separated to CMYK in You can help figuring out what needs to be done to decode this image. Even better would be to provide a PR with a fix, but figuring out what needs to be done to decode this would already be very helpful. |
I am no expert in image formats and their underlying algorithms. I did some digging (not sure if it is helpful or you are already aware of this): From the file:
So 7, JPEG Compression (new format), PhotometricInterpretation 5 equals CMYK. From https://www.kronometric.org/phot/processing/DNG/dng_spec_1.4.0.0.pdf p. 19:
So, I guess we are looking at 'a lossless Huffman JPEG'? Is this helpful (or am I out of my depth)? |
@shapeh: Thanks for looking into this, any help is always welcome! Just to give some context how tiff decoding works (a bit simplified):
What makes decoding image data compressed as jpeg a bit complicated, is that usually the Jpeg decoding process also involves converting the data from internal representation (YCbCr, CMYK) to RGB. That's why my initial thought was to map the colorspace for separated to CMYK in TiffJpegSpectralConverter.cs. I believe now that was not the right call. I think we should map it to RGB, so no conversion is done when decoding the jpeg stream and leave the color conversion to I believe the first step (decompress jpeg data) is working correctly. I think the second step is what we need to look into and is not working as intended. |
@brianpopow - I am glad it is helpful. I looks like the decompression works (because you can identify some of artifacts (window frame, funky chair etc) in your conversion that resembles the correct image). Re no. 2 - Okay with the conversion to RGB from CMYK. Please let me know if there is anything I can help with/investigate further. |
@brianpopow TiffLibrary seems to have this covered. Is this useful to you? https://github.com/yigolden/TiffLibrary/blob/cec3a858de270a74965abe5b57a19b12c7a0e8d0/src/TiffLibrary/ImageDecoder/TiffD |
@JimBobSquarePants I was looking a bit further into this. I still think we should map the colorspace to RGB in I have compared the decompressed data from TiffLibrary with ours. The decompressed data is not the same. It seems that the jpeg has 4 channels. Our Jpeg decompression only expecteds 3 channels with colorspace RGB. I am not sure what the right steps are now to be able to decompress this. To me it seems:
Any opinions? Here is simpler version to test with with just 4 colors: |
Thanks for looking into this @brianpopow Is it really Rgba? It does seem that there are rgba jpegs out there. https://stackoverflow.com/questions/6212897/can-i-use-libjpeg-to-read-jpegs-with-an-alpha-channel Are you absolutely sure that the test CMYK image is the same as the sample? I was able to open the CMYK image with Windows Photo Viewer and Paint.NET but not LC-Snow_snow |
I was not able to get those jpeg files from the stackoverflow post. The links seem to be broken.
Both images have Compression Scheme: JPEG and Photometric Interpretation: separated, so I thought they should be similar enough. The CMYK image has no color profile and only 4 colors, so I thought it would make debugging easier.
Other then that I am not sure what the problem is. The only viewer I found which can display the LC-Snow image correctly is XnView (besides photoshop, which the OP has mentioned can open the files correctly): |
Just a minor comment: I think this image from XnView is showing some weird greens/blues - it looks different from the image from Photoshop, i.e. less warm color tones. |
@brianpopow @shapeh LibTiff.NET produces the same output as Paint. LibTiff.NET does not recognize a known jpeg colorspace and makes no attempt at color conversion. However if I hardcode the input and output colorspaces from YCCK to CMYK... ...then I get the following conversion. I don't have an understanding yet of how jpeg compression in tiff works so I cannot tell you whether your plan is sound. |
Usually the Photometric interpretation determines which Tiff ColorConverter we need to use. With tiff images its more complicated. Remember we usually do 1. Decompress, 2. Color Conversion. Take for example If we would call So if we set Some more context from the PR, which introduced this: #2177
So the question would be, how can we achieve the same here? |
All my hack does (I think) is trick the decoder into actually doing something which allows following decoders to read the color space type. I think we should try your plan but maybe with a different name for the colorspace, Rgba seems inaccurate. |
@JimBobSquarePants: My plan did not work out. Jpeg Color converters always convert to / return RGB data. There seems to be no way to return 4 components data (at least I dont see any way of doing it). So I tried another approach:
So the color conversion is done on the jpeg side not tiff. I would have preferred it to be handled by the tiff side, but I could not figure out how to do so. The branch is called Now the Cmyk-jpeg.tiff from above works, but the Snow jpeg has still wrong colors. This seems to be a Adobe tiff quirk. As discovered above we need to convert to YCCK -> CMYK -> RGB. There is also a comment in libtif.net in |
Well done making progress on this!
I was actually surprised it was done in the Tiff side. I always assumed it was supposed to happen in jpeg/gif etc... Regarding identification. My guess is that there is actually additional AppN markers in the jpeg stream (App14) that would allow us to identify that the image is encoded using YccK color. The below link states that those markers found in the stream should be ignored though. If we open the file in the same manner as almost everything else, I think we should just stick with that for now. P.S. While I was searching for answers this seemed relevant. |
@brianpopow Do you have your code stub for this online? |
I have started to work on this in the branch |
Hi all, I'm checking about using tiff. Thanks for any info! |
This thread is about decoding specific tiff files using joeg compression that do not appear to work outside of photoshop. Encoding multiframe tiff files is entirely supported. |
Pfew! Thanks. |
Prerequisites
DEBUG
andRELEASE
modeImageSharp version
3.0.1
Other ImageSharp packages and versions
None
Environment (Operating system, version and so on)
Windows 11 and Windows Server 2022
.NET Framework version
.NET 7.0.5
Description
Hi,
I am getting this error when trying to resize a tiff image:
Jpeg compressed tiff with photometric interpretation Separated is not supported
I looked at this: #12 and maybe it is still relevant, despite edited 2021?
"Photometric Interpretation Formats: Separated (TIFF Extension color spaces)" - not ticked.
Update: https://github.com/SixLabors/ImageSharp/blob/main/src/ImageSharp/Formats/Tiff/README.md - Separated seems to be supported?
Is there a plan for support at a later stage?
Thanks for a great library.
Steps to Reproduce
The code is simple like this (image is coming from Azure Blob Storage but that is not the issue):
Images
LC-Snow_Snow.zip
Aeros.zip
The text was updated successfully, but these errors were encountered: