Skip to content

Commit 5d8c199

Browse files
Merge pull request #2915 from SixLabors/js/v3-fix-2909
V3 - Use BPP from Color Writer for Compressor
2 parents 850e878 + de566af commit 5d8c199

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,6 @@ private long WriteFrame<TPixel>(
210210
long ifdOffset)
211211
where TPixel : unmanaged, IPixel<TPixel>
212212
{
213-
using TiffBaseCompressor compressor = TiffCompressorFactory.Create(
214-
this.CompressionType ?? TiffCompression.None,
215-
writer.BaseStream,
216-
this.memoryAllocator,
217-
frame.Width,
218-
(int)this.BitsPerPixel,
219-
this.compressionLevel,
220-
this.HorizontalPredictor == TiffPredictor.Horizontal ? this.HorizontalPredictor.Value : TiffPredictor.None);
221-
222213
TiffEncoderEntriesCollector entriesCollector = new();
223214
using TiffBaseColorWriter<TPixel> colorWriter = TiffColorWriterFactory.Create(
224215
this.PhotometricInterpretation,
@@ -230,6 +221,15 @@ private long WriteFrame<TPixel>(
230221
entriesCollector,
231222
(int)this.BitsPerPixel);
232223

224+
using TiffBaseCompressor compressor = TiffCompressorFactory.Create(
225+
this.CompressionType ?? TiffCompression.None,
226+
writer.BaseStream,
227+
this.memoryAllocator,
228+
frame.Width,
229+
colorWriter.BitsPerPixel,
230+
this.compressionLevel,
231+
this.HorizontalPredictor == TiffPredictor.Horizontal ? this.HorizontalPredictor.Value : TiffPredictor.None);
232+
233233
int rowsPerStrip = CalcRowsPerStrip(frame.Height, colorWriter.BytesPerRow, this.CompressionType);
234234

235235
colorWriter.Write(compressor, rowsPerStrip);

tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,16 @@ public void TiffEncoder_EncodeBiColor_WithModifiedHuffmanCompression_WhiteIsZero
518518
public void TiffEncoder_EncodeBiColor_WithModifiedHuffmanCompression_BlackIsZero_Works<TPixel>(TestImageProvider<TPixel> provider)
519519
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit1, TiffPhotometricInterpretation.BlackIsZero, TiffCompression.Ccitt1D);
520520

521+
[Theory]
522+
[WithFile(Issue2909, PixelTypes.Rgba32)]
523+
public void TiffEncoder_WithLzwCompression_Works<TPixel>(TestImageProvider<TPixel> provider)
524+
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit24, null, TiffCompression.Lzw, imageDecoder: TiffDecoder.Instance);
525+
526+
[Theory]
527+
[WithFile(Issue2909, PixelTypes.Rgba32)]
528+
public void TiffEncoder_WithDeflateCompression_Works<TPixel>(TestImageProvider<TPixel> provider)
529+
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit24, null, TiffCompression.Deflate, imageDecoder: TiffDecoder.Instance);
530+
521531
[Theory]
522532
[WithFile(GrayscaleUncompressed, PixelTypes.L8, TiffPhotometricInterpretation.BlackIsZero, TiffCompression.PackBits)]
523533
[WithFile(GrayscaleUncompressed16Bit, PixelTypes.L16, TiffPhotometricInterpretation.BlackIsZero, TiffCompression.PackBits)]

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,8 @@ public static class Tiff
11311131
public const string InvalidIptcData = "Tiff/7324fcaff3aad96f27899da51c1bb5d9.tiff";
11321132
public const string IptcData = "Tiff/iptc.tiff";
11331133

1134+
public const string Issue2909 = "Tiff/Issues/Issue2909.tiff";
1135+
11341136
public static readonly string[] Multiframes = { MultiframeDeflateWithPreview, MultiframeLzwPredictor /*, MultiFrameDifferentSize, MultiframeDifferentSizeTiled, MultiFrameDifferentVariants,*/ };
11351137

11361138
public static readonly string[] Metadata = { SampleMetadata };
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:3c69a7e7c7920766e98fccd273424a34e9094550e2176a7b4757ab2c0756d084
3+
size 1272

0 commit comments

Comments
 (0)