{"record":{"id":"54295ad8b7f75177","repo":"SixLabors/ImageSharp","slug":"invalid-tiff-photometric-interpretation-for-jpeg-encoding","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/TiffJpegSpectralConverter{TPixel}.cs","lineNumber":58,"sourceCode":"    /// The color conversion will be done after the decompression. For Separated/CMYK/YCCK, the jpeg color converter will handle the color conversion,\n    /// since the jpeg color converter needs to return RGB data and cannot return 4 component data.\n    /// For grayscale images <see cref=\"GrayJpegSpectralConverter{TPixel}\"/> must be used.\n    /// </summary>\n    /// <param name=\"interpretation\">\n    /// The <see cref=\"TiffPhotometricInterpretation\"/> to convert to a <see cref=\"JpegColorSpace\"/>.\n    /// </param>\n    /// <param name=\"data\">\n    /// The <see cref=\"IRawJpegData\"/> containing the color space information.\n    /// </param>\n    /// <exception cref=\"InvalidImageContentException\">\n    /// Thrown when the <paramref name=\"interpretation\"/> is not supported for JPEG encoding.\n    /// </exception>\n    private static JpegColorSpace GetJpegColorSpace(TiffPhotometricInterpretation interpretation, IRawJpegData data) => interpretation switch\n    {\n        TiffPhotometricInterpretation.Rgb => JpegColorSpace.RGB,\n        TiffPhotometricInterpretation.Separated => data.ColorSpace == JpegColorSpace.Ycck ? JpegColorSpace.TiffYccK : JpegColorSpace.TiffCmyk,\n        TiffPhotometricInterpretation.YCbCr => JpegColorSpace.RGB, // TODO: Why doesn't this use the YCbCr color space?\n        _ => throw new InvalidImageContentException($\"Invalid TIFF photometric interpretation for JPEG encoding: {interpretation}\"),\n    };\n}\n","sourceCodeStart":40,"sourceCodeEnd":61,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Tiff/Compression/Decompressors/TiffJpegSpectralConverter{TPixel}.cs#L40-L61","documentation":"When decoding a JPEG-compressed TIFF, TiffJpegSpectralConverter maps the TIFF photometric interpretation tag to a JpegColorSpace. Only RGB, Separated (CMYK/Ycck), and YCbCr are handled; any other interpretation (e.g. WhiteIsZero, BlackIsZero, Palette, TransparencyMask) is invalid for JPEG-in-TIFF and throws InvalidImageContentException.","triggerScenarios":"Image.Load/opening of a TIFF with Compression=JPEG whose PhotometricInterpretation tag is one of the unsupported values (WhiteIsZero, BlackIsZero, Palette, Mask).","commonSituations":"Hand-edited or buggy encoder output where the JPEG-compressed TIFF carries a mismatched photometric tag; corrupted tag values in legacy files.","solutions":["Fix the source file's photometric interpretation tag to match its JPEG data (usually YCbCr or RGB) using tiffset.","Re-save the TIFF with a conforming encoder (libtiff, ImageMagick) using JPEG compression.","Catch InvalidImageContentException and fall back to another decoder that tolerates the tag mismatch."],"exampleFix":"// before\n// file has Compression=JPEG but PhotometricInterpretation=MinIsWhite\n// after (shell): tiffset -s 262 1 broken.tif   # set photometric to BlackIsZero-compatible/YCbCr\n// or re-encode:\n// magick broken.tif -compress jpeg fixed.tif","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { using var img = Image.Load(path); }\ncatch (InvalidImageContentException ex)\n{\n    // photometric tag incompatible with JPEG compression; repair with tiffset -s 262 <n>\n}","preventionTips":["Inspect photometric tag (tiffinfo) for JPEG-compressed TIFFs before ingesting","Re-save files from non-conforming encoders with libtiff/ImageMagick","Treat tag mismatches as source-file bugs — fix at the producer"],"tags":["tiff","jpeg","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"}