File tree Expand file tree Collapse file tree 4 files changed +23
-0
lines changed
src/ImageSharp/Formats/Jpeg Expand file tree Collapse file tree 4 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -556,6 +556,12 @@ private JpegColorSpace DeduceJpegColorSpace(byte componentCount)
556556 return JpegColorSpace . RGB ;
557557 }
558558
559+ // If these values are 1-3 for a 3-channel image, then the image is assumed to be YCbCr.
560+ if ( this . Components [ 2 ] . Id == 3 && this . Components [ 1 ] . Id == 2 && this . Components [ 0 ] . Id == 1 )
561+ {
562+ return JpegColorSpace . YCbCr ;
563+ }
564+
559565 // 3-channel non-subsampled images are assumed to be RGB.
560566 if ( this . Components [ 2 ] . VerticalSamplingFactor == 1 && this . Components [ 1 ] . VerticalSamplingFactor == 1 && this . Components [ 0 ] . VerticalSamplingFactor == 1 &&
561567 this . Components [ 2 ] . HorizontalSamplingFactor == 1 && this . Components [ 1 ] . HorizontalSamplingFactor == 1 && this . Components [ 0 ] . HorizontalSamplingFactor == 1 )
Original file line number Diff line number Diff line change @@ -218,6 +218,19 @@ public void Issue2057_DecodeWorks<TPixel>(TestImageProvider<TPixel> provider)
218218 }
219219 }
220220
221+ // https://github.com/SixLabors/ImageSharp/issues/2133
222+ [ Theory ]
223+ [ WithFile ( TestImages . Jpeg . Issues . Issue2133DeduceColorSpace , PixelTypes . Rgba32 ) ]
224+ public void Issue2133_DeduceColorSpace < TPixel > ( TestImageProvider < TPixel > provider )
225+ where TPixel : unmanaged, IPixel < TPixel >
226+ {
227+ using ( Image < TPixel > image = provider . GetImage ( JpegDecoder ) )
228+ {
229+ image . DebugSave ( provider ) ;
230+ image . CompareToOriginal ( provider ) ;
231+ }
232+ }
233+
221234 // DEBUG ONLY!
222235 // The PDF.js output should be saved by "tests\ImageSharp.Tests\Formats\Jpg\pdfjs\jpeg-converter.htm"
223236 // into "\tests\Images\ActualOutput\JpegDecoderTests\"
Original file line number Diff line number Diff line change @@ -272,6 +272,7 @@ public static class Issues
272272 public const string Issue2057App1Parsing = "Jpg/issues/Issue2057-App1Parsing.jpg" ;
273273 public const string ExifNullArrayTag = "Jpg/issues/issue-2056-exif-null-array.jpg" ;
274274 public const string ValidExifArgumentNullExceptionOnEncode = "Jpg/issues/Issue2087-exif-null-reference-on-encode.jpg" ;
275+ public const string Issue2133DeduceColorSpace = "Jpg/issues/Issue2133.jpg" ;
275276
276277 public static class Fuzz
277278 {
You can’t perform that action at this time.
0 commit comments