Browse Source

Set PhotometricInterpretation to RGB, let jpeg decoder handle color conversion

pull/2266/head
Brian Popow 4 years ago
parent
commit
08f9063229
  1. 5
      src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs
  2. 1
      tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs
  3. 1
      tests/ImageSharp.Tests/TestImages.cs
  4. 3
      tests/Images/Input/Tiff/YCbCrOldJpegCompressed.tiff

5
src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs

@ -478,8 +478,9 @@ internal static class TiffDecoderOptionsParser
{
options.CompressionType = TiffDecoderCompressionType.OldJpeg;
// Like libtiff: always assume PhotometricInterpretation to be YCbCr, if the compression is old jpeg.
options.PhotometricInterpretation = TiffPhotometricInterpretation.YCbCr;
// Note: Setting PhotometricInterpretation and color type to RGB here, since the jpeg decoder will handle the conversion of the pixel data.
options.PhotometricInterpretation = TiffPhotometricInterpretation.Rgb;
options.ColorType = TiffColorType.Rgb;
if (!options.OldJpegCompressionStartOfImageMarker.HasValue)
{

1
tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs

@ -666,6 +666,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
[Theory]
[WithFile(RgbOldJpegCompressed, PixelTypes.Rgba32)]
[WithFile(YCbCrOldJpegCompressed, PixelTypes.Rgba32)]
public void TiffDecoder_CanDecode_OldJpegCompressed<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel> => TestTiffDecoder(provider, useExactComparer: false);

1
tests/ImageSharp.Tests/TestImages.cs

@ -796,6 +796,7 @@ public static class TestImages
public const string RgbJpegCompressed = "Tiff/rgb_jpegcompression.tiff";
public const string RgbJpegCompressed2 = "Tiff/twain-rgb-jpeg-with-bogus-ycbcr-subsampling.tiff";
public const string RgbOldJpegCompressed = "Tiff/OldJpegCompression.tiff";
public const string YCbCrOldJpegCompressed = "Tiff/YCbCrOldJpegCompressed.tiff";
public const string RgbWithStripsJpegCompressed = "Tiff/rgb_jpegcompressed_stripped.tiff";
public const string RgbJpegCompressedNoJpegTable = "Tiff/rgb_jpegcompressed_nojpegtable.tiff";
public const string RgbLzwPredictor = "Tiff/rgb_lzw_predictor.tiff";

3
tests/Images/Input/Tiff/YCbCrOldJpegCompressed.tiff

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b6527e69a3cce3e6d425c35695319711ad36d939f934902faa47f6ee1f1c7e08
size 10076700
Loading…
Cancel
Save