ImageSharp icon indicating copy to clipboard operation
ImageSharp copied to clipboard

Can't open some TIFs files (System.NotSupportedException: The specified TIFF compression format 'OldJpeg' is not supported)

Open joaovsoares opened this issue 1 year ago • 3 comments

Prerequisites

  • [ ] I have bought a Commercial License
  • [X] I have written a descriptive issue title
  • [X] I have verified that I am running the latest version of ImageSharp
  • [X] I have verified if the problem exist in both DEBUG and RELEASE mode
  • [X] I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

2.1.3

Other ImageSharp packages and versions

Environment (Operating system, version and so on)

Linux

.NET Framework version

.NET 6

Description

Can't open/load some TIFs files.

We are conducting a technical feasibility study here at the company to choose our component to use with TIFF images. ImageSharp is one of the main candidates for us to acquire the license, however ImageSharp throws the below error message. For our company and needs, it would be a serious problem. Do you have any estimate of when you will be able to resolve this issue? I provided a sample image.

BTW: we have not yet acquired a Commercial License because of this issue. Being able to load all variety of TIF files is critical to the project.

System.NotSupportedException: The specified TIFF compression format 'OldJpeg' is not supported at SixLabors.ImageSharp.Formats.Tiff.TiffThrowHelper.ThrowNotSupported(String message) at SixLabors.ImageSharp.Formats.Tiff.TiffDecoderOptionsParser.ParseCompression(TiffDecoderCore options, Nullable1 compression, ExifProfile exifProfile) at SixLabors.ImageSharp.Formats.Tiff.TiffDecoderOptionsParser.VerifyAndParse(TiffDecoderCore options, ExifProfile exifProfile, TiffFrameMetadata frameMetadata) at SixLabors.ImageSharp.Formats.Tiff.TiffDecoderCore.DecodeFrame[TPixel](ExifProfile tags, CancellationToken cancellationToken) at SixLabors.ImageSharp.Formats.Tiff.TiffDecoderCore.Decode[TPixel](BufferedReadStream stream, CancellationToken cancellationToken) at SixLabors.ImageSharp.Formats.ImageDecoderUtilities.Decode[TPixel](IImageDecoderInternals decoder, Configuration configuration, Stream stream, Func3 largeImageExceptionFactory, CancellationToken cancellationToken) at SixLabors.ImageSharp.Formats.Tiff.TiffDecoder.Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken) at SixLabors.ImageSharp.Image.Decode(Stream stream, Configuration config, CancellationToken cancellationToken) at SixLabors.ImageSharp.Image.<>c__DisplayClass134_0.<Load>b__0(Stream s) at SixLabors.ImageSharp.Image.Load(Configuration configuration, Stream stream, IImageFormat& format)

Steps to Reproduce

The code below:


            using (MemoryStream outStream = new MemoryStream())
            {
                inStream.Position = 0;
                var qualidade = 70;

                var image = Image.Load(inStream);     //<<---- ERROR
                var jpegEncoder = new JpegEncoder() { Quality = qualidade, ColorType = JpegColorType.Luminance };

                image.SaveAsJpeg(outStream, jpegEncoder);

                return outStream;
            }

Images

06062022154217.zip

joaovsoares avatar Sep 19 '22 21:09 joaovsoares

I always hesitated to add support for decoding tiff's with "old jpeg" compression, because of ambiguity of the specification. This ambiguity will make it hard to add support for this, since there can be multiple interpretations of the spec and this will lead to many special case and headache's.

This "old jpeg" compression was ultimately dropped from the spec, because of the ambiguity. See this link for more detail: http://libtiff.maptools.org/TIFFTechNote2.html

@SixLabors/core what do you guy's think about this?

P.S. out of curiosity: which software produced this "old jpeg" tiff files?

brianpopow avatar Sep 20 '22 10:09 brianpopow

I’ll be honest here and say that I’m pretty unhappy with the approach taken here by the OP. Software development takes time and such time should not be given on the pretext that a software license may be bought. The demands are, to put it mildly, unreasonable.

Our issue tracker should also not be abused. Given that the OP does not hold a license they should not have opened a commercial issue.

Decoding this obsolete compression format is a complex task which will likely lead to extra future work to handle specification ambiguity. The only implementation we should attempt would be a carbon copy of the libtiff implementation.

I would much prefer that someone external to the core team attempted to implement it. We have more important issues to attend to. The source is open and available to all to contribute to.

JimBobSquarePants avatar Sep 20 '22 10:09 JimBobSquarePants

@brianpopow thanks for the answer.

P.S. out of curiosity: which software produced this "old jpeg" tiff files?

Old scanner software... :/ To put it simple, our company has many "special" scanners that scan with high speed. It is an expensive component to replace and they are scattered across the country.

@JimBobSquarePants thanks for the answer.

I’ll be honest here and say that I’m pretty unhappy with the approach taken here by the OP. Software development takes time and such time should not be given on the pretext that a software license may be bought. The demands are, to put it mildly, unreasonable.

I'm very sorry about the start approach. And I'll agree at some point with you, but still at this moment, we need a component that cover the most scenarios. We really have commercial intentions (ImageSharp is one of the main candidates), but I see your point and again: I'm sorry.

Decoding this obsolete compression format is a complex task which will likely lead to extra future work to handle specification ambiguity. The only implementation we should attempt would be a carbon copy of the libtiff implementation.

I would much prefer that someone external to the core team attempted to implement it. We have more important issues to attend to. The source is open and available to all to contribute to.

I see. Thanks for the answer.

joaovsoares avatar Sep 20 '22 12:09 joaovsoares

@brianpopow and @JimBobSquarePants Update: As I said before, we had commercial intentions. Last Monday we bought an ImageSharp license. \o/

By the way, I've noticed from the commits that you're putting effort into this implementation, and we really appreciate it. Thank you very much. If you need, I can provide more example files. I don't know if just the one I provided helped...

joaovsoares avatar Sep 28 '22 16:09 joaovsoares

@joaovsoares Thanks for buying a license and yes I have started working on this. Decoding the provided image works so far.

Having more example images maybe from different scanner vendors would help, because there are different variations of this compression.

By the way: Can I use the image you have provided here in a unit test or is that confidential?

brianpopow avatar Sep 28 '22 17:09 brianpopow

Having more example images maybe from different scanner vendors would help, because there are different variations of this compression.

@brianpopow I'll look for more examples. But maybe I can't guarantee they are from different vendors.

By the way: Can I use the image you have provided here in a unit test or is that confidential?

It's some sort of confidential. BUT, if you can hide the "Aluno" field (first field), it's OK.

joaovsoares avatar Sep 28 '22 19:09 joaovsoares

It's some sort of confidential. BUT, if you can hide the "Aluno" field (first field), it's OK.

Cannot do that without re-encoding. Maybe you can provide another black and white example, which can be used for unit tests? Maybe from the same scanner? I dont have a black and white example besides the one you have provided here.

brianpopow avatar Sep 28 '22 19:09 brianpopow

Cannot do that without re-encoding. Maybe you can provide another black and white example, which can be used for unit tests? Maybe from the same scanner? I dont have a black and white example besides the one you have provided here.

I'm going to ask them to scan a blank form. But as I said, they are spread across the country, so it might take a while.

joaovsoares avatar Sep 28 '22 19:09 joaovsoares

@brianpopow , I just attached examples of images from 2 different scanners models. I'm looking for more exemples, but we can start with this. You can use this images in your tests.

Scanner1.zip Scanner2.zip

joaovsoares avatar Oct 10 '22 14:10 joaovsoares

@joaovsoares: Thanks, good news, we can decode all of those. I have added now a test for this.

brianpopow avatar Oct 12 '22 11:10 brianpopow

Fixed via #2266

JimBobSquarePants avatar Oct 13 '22 01:10 JimBobSquarePants