{"record":{"id":"1b8fda511c423b8c","repo":"SixLabors/ImageSharp","slug":"invalid-tiff-photometric-interpretation-for-jpeg-encoding-1b8fda","errorCode":null,"errorMessage":"Invalid tiff photometric interpretation for jpeg encoding: {interpretation}","messagePattern":"Invalid tiff photometric interpretation for jpeg encoding: (.+?)","errorType":"exception","errorClass":"InvalidImageContentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Tiff/Compression/Decompressors/TiffOldJpegSpectralConverter{TPixel}.cs","lineNumber":44,"sourceCode":"    public TiffOldJpegSpectralConverter(Configuration configuration, TiffPhotometricInterpretation photometricInterpretation)\n        : base(configuration)\n        => this.photometricInterpretation = photometricInterpretation;\n\n    /// <inheritdoc/>\n    protected override JpegColorConverterBase GetColorConverter(JpegFrame frame, IRawJpegData jpegData)\n    {\n        JpegColorSpace colorSpace = GetJpegColorSpaceFromPhotometricInterpretation(this.photometricInterpretation, jpegData);\n        return JpegColorConverterBase.GetConverter(colorSpace, frame.Precision);\n    }\n\n    private static JpegColorSpace GetJpegColorSpaceFromPhotometricInterpretation(TiffPhotometricInterpretation interpretation, IRawJpegData data)\n        => interpretation switch\n        {\n            // Like libtiff: Always treat the pixel data as YCbCr when the data is compressed with old jpeg compression.\n            TiffPhotometricInterpretation.Rgb => JpegColorSpace.YCbCr,\n            TiffPhotometricInterpretation.Separated => data.ColorSpace == JpegColorSpace.Ycck ? JpegColorSpace.TiffYccK : JpegColorSpace.TiffCmyk,\n            TiffPhotometricInterpretation.YCbCr => JpegColorSpace.YCbCr,\n            _ => throw new InvalidImageContentException($\"Invalid tiff photometric interpretation for jpeg encoding: {interpretation}\"),\n        };\n}\n","sourceCodeStart":26,"sourceCodeEnd":47,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Tiff/Compression/Decompressors/TiffOldJpegSpectralConverter{TPixel}.cs#L26-L47","documentation":"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.","triggerScenarios":"Loading a TIFF with Compression.OldJpeg whose photometric interpretation is not Rgb/Separated/YCbCr (e.g. Palette or MinIsWhite/MinIsBlack tags).","commonSituations":"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.","solutions":["Convert the OJPEG file to a modern TIFF: tiffcp -c jpeg old.tif new.tif (recompresses as new-style JPEG).","Correct the photometric tag with tiffset so it matches the embedded JPEG data.","Catch InvalidImageContentException and fall back to a decoder with full OJPEG support (e.g. libtiff-based tools)."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { using var img = Image.Load(path); }\ncatch (InvalidImageContentException)\n{\n    // OJPEG legacy file: convert via tiffcp -c jpeg old.tif new.tif and retry\n}","preventionTips":["Detect old-JPEG compression (tag 259 == 6) early and convert OJPEG files up front","Normalize legacy scanner TIFFs before ingestion","Keep a libtiff-based conversion step for non-conformant OJPEG files"],"tags":["tiff","ojpeg","decoding","photometric-interpretation"],"backgroundTag":"invalid-enum-value","analyzedSha":"59ce6af6fc29027cda277ef62d4d1694a8acce91","analyzedAt":"2026-09-13T18:34:59.331Z","contentChangedAt":"2026-09-13T18:34:59.331Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}