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

CR2: System.NotSupportedException: Missing SOI marker offset for tiff with old jpeg compression #2665

Open
4 tasks done
am11 opened this issue Feb 14, 2024 · 2 comments
Open
4 tasks done

Comments

@am11
Copy link

am11 commented Feb 14, 2024

Prerequisites

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

ImageSharp version

3.1.2

Other ImageSharp packages and versions

Environment (Operating system, version and so on)

Windows 11 amd64

.NET Framework version

.NET 8.0

Description

In a project, I have test assets with a CR2 image

Berries.CR2.zip

which windows file explorer provides the preview for:

image

However, loading this image with ImageSharp fails:

      System.NotSupportedException: Missing SOI marker offset for tiff with old jpeg compression
         at SixLabors.ImageSharp.Formats.Tiff.TiffThrowHelper.ThrowNotSupported(String message)
         at SixLabors.ImageSharp.Formats.Tiff.TiffDecoderOptionsParser.ParseCompression(TiffDecoderCore options, Nullable`1 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, Func`3 largeImageExceptionFactory, CancellationToken cancellationToken)
         at SixLabors.ImageSharp.Formats.ImageDecoderUtilities.Decode[TPixel](IImageDecoderInternals decoder, Configuration configuration, Stream stream, CancellationToken cancellationToken)
         at SixLabors.ImageSharp.Formats.Tiff.TiffDecoder.Decode[TPixel](DecoderOptions options, Stream stream, CancellationToken cancellationToken)
         at SixLabors.ImageSharp.Formats.Tiff.TiffDecoder.Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
         at SixLabors.ImageSharp.Formats.ImageDecoder.<>c__DisplayClass3_0.<DecodeAsync>b__0(Stream s, CancellationToken ct)
         at SixLabors.ImageSharp.Formats.ImageDecoder.<>c__DisplayClass12_0`1.<WithSeekableMemoryStreamAsync>g__PeformActionAndResetPosition|0(Stream s, Int64 position, CancellationToken ct)
      --- End of stack trace from previous location ---
         at SixLabors.ImageSharp.Formats.ImageDecoder.DecodeAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
         at SixLabors.ImageSharp.Image.WithSeekableStreamAsync[T](DecoderOptions options, Stream stream, Func`3 action, CancellationToken cancellationToken)

I couldn't find much information whether or not Canon's CR2 support is deliberately left out.

suggests it might not be intentional. Opening this issue just in case. :)

Steps to Reproduce

using Image berries = await Image.LoadAsync(@"C:\temp\Berries.CR2");

Images

Berries.CR2.zip

@JimBobSquarePants
Copy link
Member

As I'm sure you are aware. CR2 files are raw files that use the Tiff format internally.

The reference you highlighted is just some metadata in the jpg file indicating the raw file it originated from. We don't have dedicated CR2 decoders nor encoders.

However.... We can actually open the file if we remove the sanitation check and treat the default SOI offset as zero. However, we parse the dimensions of the file as defined in the IFD0 marker as 5184x3456 (The image is rotated 90degrees CW for display) not as described by Windows as 5202x3464

I think we are doing the correct thing here by only decoding the valid pixels but that's open to interpretation. Would that behaviour be expected by you?

image

@am11
Copy link
Author

am11 commented Feb 24, 2024

@JimBobSquarePants, thank you for the update. I think having the CR2 encoder/decoder (derived from TIFF?) would be a good fit for ImageSharp library. Compliance with standard, instead of Windows behavior, makes sense to me as well. File explorer example was just a reference point where this format is supported.

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

No branches or pull requests

2 participants