From c1c4f528c7d2dc4ef99b5c8fa7762a0e7e68508b Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sat, 21 May 2022 21:09:10 +0200 Subject: [PATCH] If component Id's are 1-3 for a 3-channel image, then the image is assumed to be YCbCr --- src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index a07db1c95..7247f1648 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -520,11 +520,18 @@ namespace SixLabors.ImageSharp.Formats.Jpeg } // If the component Id's are R, G, B in ASCII the colorspace is RGB and not YCbCr. + // See: https://docs.oracle.com/javase/7/docs/api/javax/imageio/metadata/doc-files/jpeg_metadata.html#color if (this.Components[2].Id == 66 && this.Components[1].Id == 71 && this.Components[0].Id == 82) { return JpegColorSpace.RGB; } + // If these values are 1-3 for a 3-channel image, then the image is assumed to be YCbCr. + if (this.Components[2].Id == 3 && this.Components[1].Id == 2 && this.Components[0].Id == 1) + { + return JpegColorSpace.YCbCr; + } + // Some images are poorly encoded and contain incorrect colorspace transform metadata. // We ignore that and always fall back to the default colorspace. return JpegColorSpace.YCbCr;