SixLabors/ImageSharp · error · InvalidImageContentException

Invalid tiff photometric interpretation for jpeg encoding

Error message

Invalid tiff photometric interpretation for jpeg encoding: {interpretation}

What it means

For old-style JPEG-in-TIFF (Compression = OJPEG, TIFF tag 6), the spectral converter derives the JPEG color space from the photometric interpretation, treating even RGB-tagged data as YCbCr (libtiff behavior). Any interpretation other than Rgb, Separated, or YCbCr throws InvalidImageContentException.

Solutions

  1. Convert the OJPEG file to a modern TIFF: tiffcp -c jpeg old.tif new.tif (recompresses as new-style JPEG).
  2. Correct the photometric tag with tiffset so it matches the embedded JPEG data.
  3. Catch InvalidImageContentException and fall back to a decoder with full OJPEG support (e.g. libtiff-based tools).
Defensive patterns

Strategy: fallback

Try / catch

try { using var img = Image.Load(path); }
catch (InvalidImageContentException)
{
    // OJPEG legacy file: convert via tiffcp -c jpeg old.tif new.tif and retry
}

Prevention

When it happens

Trigger: Loading a TIFF with Compression.OldJpeg whose photometric interpretation is not Rgb/Separated/YCbCr (e.g. Palette or MinIsWhite/MinIsBlack tags).

Common situations: Very old scanner/fax TIFFs using OJPEG with inconsistent tags; files produced by legacy Windows encoders; OJPEG is notoriously non-conformant, so tag mismatches are common.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13). Data as JSON: /api/errors/1b8fda511c423b8c. Report an issue: GitHub.

Appendix: source

Thrown at src/ImageSharp/Formats/Tiff/Compression/Decompressors/TiffOldJpegSpectralConverter{TPixel}.cs:44

    public TiffOldJpegSpectralConverter(Configuration configuration, TiffPhotometricInterpretation photometricInterpretation)
        : base(configuration)
        => this.photometricInterpretation = photometricInterpretation;

    /// <inheritdoc/>
    protected override JpegColorConverterBase GetColorConverter(JpegFrame frame, IRawJpegData jpegData)
    {
        JpegColorSpace colorSpace = GetJpegColorSpaceFromPhotometricInterpretation(this.photometricInterpretation, jpegData);
        return JpegColorConverterBase.GetConverter(colorSpace, frame.Precision);
    }

    private static JpegColorSpace GetJpegColorSpaceFromPhotometricInterpretation(TiffPhotometricInterpretation interpretation, IRawJpegData data)
        => interpretation switch
        {
            // Like libtiff: Always treat the pixel data as YCbCr when the data is compressed with old jpeg compression.
            TiffPhotometricInterpretation.Rgb => JpegColorSpace.YCbCr,
            TiffPhotometricInterpretation.Separated => data.ColorSpace == JpegColorSpace.Ycck ? JpegColorSpace.TiffYccK : JpegColorSpace.TiffCmyk,
            TiffPhotometricInterpretation.YCbCr => JpegColorSpace.YCbCr,
            _ => throw new InvalidImageContentException($"Invalid tiff photometric interpretation for jpeg encoding: {interpretation}"),
        };
}

View on GitHub (pinned to 59ce6af6fc)