diff --git a/src/ImageSharp/Formats/Tiff/Constants/TiffPredictor.cs b/src/ImageSharp/Formats/Tiff/Constants/TiffPredictor.cs index 092bb7aa5..5eaa9f1d1 100644 --- a/src/ImageSharp/Formats/Tiff/Constants/TiffPredictor.cs +++ b/src/ImageSharp/Formats/Tiff/Constants/TiffPredictor.cs @@ -20,6 +20,8 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Constants /// /// Floating point horizontal differencing. + /// + /// Note: The Tiff Encoder does not yet support this. If this is chosen, the encoder will fallback to none. /// FloatingPoint = 3 } diff --git a/src/ImageSharp/Formats/Tiff/ITiffEncoderOptions.cs b/src/ImageSharp/Formats/Tiff/ITiffEncoderOptions.cs index 44c53c857..9ebf2f025 100644 --- a/src/ImageSharp/Formats/Tiff/ITiffEncoderOptions.cs +++ b/src/ImageSharp/Formats/Tiff/ITiffEncoderOptions.cs @@ -35,9 +35,9 @@ namespace SixLabors.ImageSharp.Formats.Tiff TiffEncodingMode Mode { get; } /// - /// Gets a value indicating whether to use horizontal prediction. This can improve the compression ratio with deflate or lzw compression. + /// Gets a value indicating which horizontal prediction to use. This can improve the compression ratio with deflate or lzw compression. /// - bool UseHorizontalPredictor { get; } + TiffPredictor HorizontalPredictor { get; } /// /// Gets the quantizer for creating a color palette image. diff --git a/src/ImageSharp/Formats/Tiff/TiffEncoder.cs b/src/ImageSharp/Formats/Tiff/TiffEncoder.cs index 5bca172b5..bf943a995 100644 --- a/src/ImageSharp/Formats/Tiff/TiffEncoder.cs +++ b/src/ImageSharp/Formats/Tiff/TiffEncoder.cs @@ -31,7 +31,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff public TiffEncodingMode Mode { get; set; } /// - public bool UseHorizontalPredictor { get; set; } + public TiffPredictor HorizontalPredictor { get; set; } /// public IQuantizer Quantizer { get; set; } diff --git a/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs b/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs index 8f68e192f..42300969b 100644 --- a/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs +++ b/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs @@ -72,7 +72,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff this.Mode = options.Mode; this.quantizer = options.Quantizer ?? KnownQuantizers.Octree; this.BitsPerPixel = options.BitsPerPixel; - this.UseHorizontalPredictor = options.UseHorizontalPredictor; + this.HorizontalPredictor = options.HorizontalPredictor; this.CompressionType = options.Compression; this.compressionLevel = options.CompressionLevel; this.maxStripBytes = options.MaxStripBytes; @@ -95,9 +95,9 @@ namespace SixLabors.ImageSharp.Formats.Tiff internal TiffEncodingMode Mode { get; private set; } /// - /// Gets a value indicating whether to use horizontal prediction. This can improve the compression ratio with deflate compression. + /// Gets a value indicating which horizontal predictor to use. This can improve the compression ratio with deflate compression. /// - internal bool UseHorizontalPredictor { get; } + internal TiffPredictor HorizontalPredictor { get; } /// /// Gets the bits per pixel. @@ -164,7 +164,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff var entriesCollector = new TiffEncoderEntriesCollector(); // Write the image bytes to the steam. - var imageDataStart = (uint)writer.Position; + uint imageDataStart = (uint)writer.Position; TiffBitsPerPixel? tiffBitsPerPixel = this.BitsPerPixel; if (tiffBitsPerPixel != null) @@ -176,7 +176,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff image.Width, (int)tiffBitsPerPixel, this.compressionLevel, - this.UseHorizontalPredictor ? TiffPredictor.Horizontal : TiffPredictor.None); + this.HorizontalPredictor != TiffPredictor.FloatingPoint ? this.HorizontalPredictor : TiffPredictor.None); using TiffBaseColorWriter colorWriter = TiffColorWriterFactory.Create( this.Mode, diff --git a/src/ImageSharp/Formats/Tiff/TiffEncoderEntriesCollector.cs b/src/ImageSharp/Formats/Tiff/TiffEncoderEntriesCollector.cs index 4d059aa67..c0ad474b2 100644 --- a/src/ImageSharp/Formats/Tiff/TiffEncoderEntriesCollector.cs +++ b/src/ImageSharp/Formats/Tiff/TiffEncoderEntriesCollector.cs @@ -264,7 +264,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff this.collector.AddOrReplace(compression); this.collector.AddOrReplace(photometricInterpretation); - if (encoder.UseHorizontalPredictor) + if (encoder.HorizontalPredictor == TiffPredictor.Horizontal) { if (encoder.Mode == TiffEncodingMode.Rgb || encoder.Mode == TiffEncodingMode.Gray || encoder.Mode == TiffEncodingMode.ColorPalette) { diff --git a/tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs index 21a976620..20eb49376 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs @@ -194,7 +194,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff [Theory] [WithFile(Calliphora_RgbUncompressed, PixelTypes.Rgba32)] public void TiffEncoder_EncodeRgb_WithDeflateCompressionAndPredictor_Works(TestImageProvider provider) - where TPixel : unmanaged, IPixel => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit24, TiffEncodingMode.Rgb, TiffCompression.Deflate, usePredictor: true); + where TPixel : unmanaged, IPixel => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit24, TiffEncodingMode.Rgb, TiffCompression.Deflate, TiffPredictor.Horizontal); [Theory] [WithFile(Calliphora_RgbUncompressed, PixelTypes.Rgba32)] @@ -204,7 +204,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff [Theory] [WithFile(Calliphora_RgbUncompressed, PixelTypes.Rgba32)] public void TiffEncoder_EncodeRgb_WithLzwCompressionAndPredictor_Works(TestImageProvider provider) - where TPixel : unmanaged, IPixel => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit24, TiffEncodingMode.Rgb, TiffCompression.Lzw, usePredictor: true); + where TPixel : unmanaged, IPixel => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit24, TiffEncodingMode.Rgb, TiffCompression.Lzw, TiffPredictor.Horizontal); [Theory] [WithFile(Calliphora_RgbUncompressed, PixelTypes.Rgba32)] @@ -224,7 +224,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff [Theory] [WithFile(Calliphora_GrayscaleUncompressed, PixelTypes.Rgba32)] public void TiffEncoder_EncodeGray_WithDeflateCompressionAndPredictor_Works(TestImageProvider provider) - where TPixel : unmanaged, IPixel => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit8, TiffEncodingMode.Gray, TiffCompression.Deflate, usePredictor: true); + where TPixel : unmanaged, IPixel => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit8, TiffEncodingMode.Gray, TiffCompression.Deflate, TiffPredictor.Horizontal); [Theory] [WithFile(Calliphora_GrayscaleUncompressed, PixelTypes.Rgba32)] @@ -234,7 +234,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff [Theory] [WithFile(Calliphora_GrayscaleUncompressed, PixelTypes.Rgba32)] public void TiffEncoder_EncodeGray_WithLzwCompressionAndPredictor_Works(TestImageProvider provider) - where TPixel : unmanaged, IPixel => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit8, TiffEncodingMode.Gray, TiffCompression.Lzw, usePredictor: true); + where TPixel : unmanaged, IPixel => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit8, TiffEncodingMode.Gray, TiffCompression.Lzw, TiffPredictor.Horizontal); [Theory] [WithFile(Calliphora_GrayscaleUncompressed, PixelTypes.Rgba32)] @@ -269,7 +269,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff [WithFile(Calliphora_PaletteUncompressed, PixelTypes.Rgba32)] public void TiffEncoder_EncodeColorPalette_WithDeflateCompressionAndPredictor_Works(TestImageProvider provider) where TPixel : unmanaged, IPixel => - TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit8, TiffEncodingMode.ColorPalette, TiffCompression.Deflate, usePredictor: true, useExactComparer: false, compareTolerance: 0.001f); + TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit8, TiffEncodingMode.ColorPalette, TiffCompression.Deflate, TiffPredictor.Horizontal, useExactComparer: false, compareTolerance: 0.001f); [Theory] [WithFile(Calliphora_PaletteUncompressed, PixelTypes.Rgba32)] @@ -281,7 +281,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff [WithFile(Calliphora_PaletteUncompressed, PixelTypes.Rgba32)] public void TiffEncoder_EncodeColorPalette_WithLzwCompressionAndPredictor_Works(TestImageProvider provider) where TPixel : unmanaged, IPixel => - TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit8, TiffEncodingMode.ColorPalette, TiffCompression.Lzw, usePredictor: true, useExactComparer: false, compareTolerance: 0.001f); + TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit8, TiffEncodingMode.ColorPalette, TiffCompression.Lzw, TiffPredictor.Horizontal, useExactComparer: false, compareTolerance: 0.001f); [Theory] [WithFile(Calliphora_BiColorUncompressed, PixelTypes.Rgba32)] @@ -379,7 +379,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff TiffBitsPerPixel bitsPerPixel, TiffEncodingMode mode, TiffCompression compression = TiffCompression.None, - bool usePredictor = false, + TiffPredictor predictor = TiffPredictor.None, bool useExactComparer = true, int maxStripSize = 0, float compareTolerance = 0.01f) @@ -391,7 +391,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff Mode = mode, BitsPerPixel = bitsPerPixel, Compression = compression, - UseHorizontalPredictor = usePredictor, + HorizontalPredictor = predictor, MaxStripBytes = maxStripSize };