Skip to content

Commit 22a06d6

Browse files
Merge pull request #2916 from SixLabors/js/fix-2909
V4 - Use BPP from Color Writer for Compressor
2 parents cbd8ada + 0a8902b commit 22a06d6

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
@@ -222,15 +222,6 @@ private long WriteFrame<TPixel>(
222222
height = Math.Min(height, frame.Height);
223223
Size encodingSize = new(width, height);
224224

225-
using TiffBaseCompressor compressor = TiffCompressorFactory.Create(
226-
compression,
227-
writer.BaseStream,
228-
this.memoryAllocator,
229-
width,
230-
(int)bitsPerPixel,
231-
this.compressionLevel,
232-
this.HorizontalPredictor == TiffPredictor.Horizontal ? this.HorizontalPredictor.Value : TiffPredictor.None);
233-
234225
TiffEncoderEntriesCollector entriesCollector = new();
235226
using TiffBaseColorWriter<TPixel> colorWriter = TiffColorWriterFactory.Create(
236227
this.PhotometricInterpretation,
@@ -243,6 +234,15 @@ private long WriteFrame<TPixel>(
243234
entriesCollector,
244235
(int)bitsPerPixel);
245236

237+
using TiffBaseCompressor compressor = TiffCompressorFactory.Create(
238+
compression,
239+
writer.BaseStream,
240+
this.memoryAllocator,
241+
width,
242+
colorWriter.BitsPerPixel,
243+
this.compressionLevel,
244+
this.HorizontalPredictor == TiffPredictor.Horizontal ? this.HorizontalPredictor.Value : TiffPredictor.None);
245+
246246
int rowsPerStrip = CalcRowsPerStrip(height, colorWriter.BytesPerRow, this.CompressionType);
247247

248248
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
@@ -579,6 +579,16 @@ public void TiffEncoder_EncodeBiColor_WithModifiedHuffmanCompression_WhiteIsZero
579579
public void TiffEncoder_EncodeBiColor_WithModifiedHuffmanCompression_BlackIsZero_Works<TPixel>(TestImageProvider<TPixel> provider)
580580
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit1, TiffPhotometricInterpretation.BlackIsZero, TiffCompression.Ccitt1D);
581581

582+
[Theory]
583+
[WithFile(Issue2909, PixelTypes.Rgba32)]
584+
public void TiffEncoder_WithLzwCompression_Works<TPixel>(TestImageProvider<TPixel> provider)
585+
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit24, null, TiffCompression.Lzw, imageDecoder: TiffDecoder.Instance);
586+
587+
[Theory]
588+
[WithFile(Issue2909, PixelTypes.Rgba32)]
589+
public void TiffEncoder_WithDeflateCompression_Works<TPixel>(TestImageProvider<TPixel> provider)
590+
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit24, null, TiffCompression.Deflate, imageDecoder: TiffDecoder.Instance);
591+
582592
[Theory]
583593
[WithFile(GrayscaleUncompressed, PixelTypes.L8, TiffPhotometricInterpretation.BlackIsZero, TiffCompression.PackBits)]
584594
[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
@@ -1107,6 +1107,8 @@ public static class Tiff
11071107
public const string InvalidIptcData = "Tiff/7324fcaff3aad96f27899da51c1bb5d9.tiff";
11081108
public const string IptcData = "Tiff/iptc.tiff";
11091109

1110+
public const string Issue2909 = "Tiff/Issues/Issue2909.tiff";
1111+
11101112
public static readonly string[] Multiframes = { MultiframeDeflateWithPreview, MultiframeLzwPredictor /*, MultiFrameDifferentSize, MultiframeDifferentSizeTiled, MultiFrameDifferentVariants,*/ };
11111113

11121114
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)