Browse Source
Merge pull request #2916 from SixLabors/js/fix-2909
V4 - Use BPP from Color Writer for Compressor
pull/2854/merge
James Jackson-South
10 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with
24 additions and
9 deletions
-
src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs
-
tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs
-
tests/ImageSharp.Tests/TestImages.cs
-
tests/Images/Input/Tiff/Issues/Issue2909.tiff
|
|
|
@ -222,15 +222,6 @@ internal sealed class TiffEncoderCore |
|
|
|
height = Math.Min(height, frame.Height); |
|
|
|
Size encodingSize = new(width, height); |
|
|
|
|
|
|
|
using TiffBaseCompressor compressor = TiffCompressorFactory.Create( |
|
|
|
compression, |
|
|
|
writer.BaseStream, |
|
|
|
this.memoryAllocator, |
|
|
|
width, |
|
|
|
(int)bitsPerPixel, |
|
|
|
this.compressionLevel, |
|
|
|
this.HorizontalPredictor == TiffPredictor.Horizontal ? this.HorizontalPredictor.Value : TiffPredictor.None); |
|
|
|
|
|
|
|
TiffEncoderEntriesCollector entriesCollector = new(); |
|
|
|
using TiffBaseColorWriter<TPixel> colorWriter = TiffColorWriterFactory.Create( |
|
|
|
this.PhotometricInterpretation, |
|
|
|
@ -243,6 +234,15 @@ internal sealed class TiffEncoderCore |
|
|
|
entriesCollector, |
|
|
|
(int)bitsPerPixel); |
|
|
|
|
|
|
|
using TiffBaseCompressor compressor = TiffCompressorFactory.Create( |
|
|
|
compression, |
|
|
|
writer.BaseStream, |
|
|
|
this.memoryAllocator, |
|
|
|
width, |
|
|
|
colorWriter.BitsPerPixel, |
|
|
|
this.compressionLevel, |
|
|
|
this.HorizontalPredictor == TiffPredictor.Horizontal ? this.HorizontalPredictor.Value : TiffPredictor.None); |
|
|
|
|
|
|
|
int rowsPerStrip = CalcRowsPerStrip(height, colorWriter.BytesPerRow, this.CompressionType); |
|
|
|
|
|
|
|
colorWriter.Write(compressor, rowsPerStrip); |
|
|
|
|
|
|
|
@ -579,6 +579,16 @@ public class TiffEncoderTests : TiffEncoderBaseTester |
|
|
|
public void TiffEncoder_EncodeBiColor_WithModifiedHuffmanCompression_BlackIsZero_Works<TPixel>(TestImageProvider<TPixel> provider) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit1, TiffPhotometricInterpretation.BlackIsZero, TiffCompression.Ccitt1D); |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFile(Issue2909, PixelTypes.Rgba32)] |
|
|
|
public void TiffEncoder_WithLzwCompression_Works<TPixel>(TestImageProvider<TPixel> provider) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit24, null, TiffCompression.Lzw, imageDecoder: TiffDecoder.Instance); |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFile(Issue2909, PixelTypes.Rgba32)] |
|
|
|
public void TiffEncoder_WithDeflateCompression_Works<TPixel>(TestImageProvider<TPixel> provider) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit24, null, TiffCompression.Deflate, imageDecoder: TiffDecoder.Instance); |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFile(GrayscaleUncompressed, PixelTypes.L8, TiffPhotometricInterpretation.BlackIsZero, TiffCompression.PackBits)] |
|
|
|
[WithFile(GrayscaleUncompressed16Bit, PixelTypes.L16, TiffPhotometricInterpretation.BlackIsZero, TiffCompression.PackBits)] |
|
|
|
|
|
|
|
@ -1107,6 +1107,8 @@ public static class TestImages |
|
|
|
public const string InvalidIptcData = "Tiff/7324fcaff3aad96f27899da51c1bb5d9.tiff"; |
|
|
|
public const string IptcData = "Tiff/iptc.tiff"; |
|
|
|
|
|
|
|
public const string Issue2909 = "Tiff/Issues/Issue2909.tiff"; |
|
|
|
|
|
|
|
public static readonly string[] Multiframes = { MultiframeDeflateWithPreview, MultiframeLzwPredictor /*, MultiFrameDifferentSize, MultiframeDifferentSizeTiled, MultiFrameDifferentVariants,*/ }; |
|
|
|
|
|
|
|
public static readonly string[] Metadata = { SampleMetadata }; |
|
|
|
|
|
|
|
@ -0,0 +1,3 @@ |
|
|
|
version https://git-lfs.github.com/spec/v1 |
|
|
|
oid sha256:3c69a7e7c7920766e98fccd273424a34e9094550e2176a7b4757ab2c0756d084 |
|
|
|
size 1272 |