Browse Source

- Seal tiff writer

- TiffStreamWriter Write byte uses WriteByte method from base stream
- Deflate compress strip: remove duplicate Dispose
pull/1570/head
Brian Popow 5 years ago
parent
commit
b0e965fdf9
  1. 2
      src/ImageSharp/Common/ByteOrder.cs
  2. 17
      src/ImageSharp/Formats/Tiff/Compression/Compressors/DeflateCompressor.cs
  3. 2
      src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs
  4. 3
      src/ImageSharp/Formats/Tiff/Writers/TiffBiColorWriter.cs
  5. 2
      src/ImageSharp/Formats/Tiff/Writers/TiffGrayWriter.cs
  6. 2
      src/ImageSharp/Formats/Tiff/Writers/TiffPaletteWriter.cs
  7. 2
      src/ImageSharp/Formats/Tiff/Writers/TiffRgbWriter.cs
  8. 2
      src/ImageSharp/Formats/Tiff/Writers/TiffStreamWriter.cs

2
src/ImageSharp/Common/ByteOrder.cs

@ -4,7 +4,7 @@
namespace SixLabors.ImageSharp
{
/// <summary>
/// The tiff data stream byte order enum.
/// The byte order of the data stream.
/// </summary>
public enum ByteOrder
{

17
src/ImageSharp/Formats/Tiff/Compression/Compressors/DeflateCompressor.cs

@ -31,17 +31,16 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Compression.Compressors
public override void CompressStrip(Span<byte> rows, int height)
{
this.memoryStream.Seek(0, SeekOrigin.Begin);
using var stream = new ZlibDeflateStream(this.Allocator, this.memoryStream, this.compressionLevel);
if (this.Predictor == TiffPredictor.Horizontal)
using (var stream = new ZlibDeflateStream(this.Allocator, this.memoryStream, this.compressionLevel))
{
HorizontalPredictor.ApplyHorizontalPrediction(rows, this.BytesPerRow, this.BitsPerPixel);
}
if (this.Predictor == TiffPredictor.Horizontal)
{
HorizontalPredictor.ApplyHorizontalPrediction(rows, this.BytesPerRow, this.BitsPerPixel);
}
stream.Write(rows);
stream.Flush();
stream.Dispose();
stream.Write(rows);
stream.Flush();
}
int size = (int)this.memoryStream.Position;

2
src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs

@ -26,8 +26,6 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff
{
public const int DefaultStripSize = 8 * 1024;
public static readonly ByteOrder ByteOrder = BitConverter.IsLittleEndian ? ByteOrder.LittleEndian : ByteOrder.BigEndian;
private static readonly ushort ByteOrderMarker = BitConverter.IsLittleEndian
? TiffConstants.ByteOrderLittleEndianShort
: TiffConstants.ByteOrderBigEndianShort;

3
src/ImageSharp/Formats/Tiff/Writers/TiffBiColorWriter.cs

@ -12,7 +12,7 @@ using SixLabors.ImageSharp.Processing;
namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Writers
{
internal class TiffBiColorWriter<TPixel> : TiffBaseColorWriter<TPixel>
internal sealed class TiffBiColorWriter<TPixel> : TiffBaseColorWriter<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
{
private readonly Image<TPixel> imageBlackWhite;
@ -25,7 +25,6 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Writers
: base(image, memoryAllocator, configuration, entriesCollector)
{
// Convert image to black and white.
// TODO: Should we allow to skip this by the user, if its known to be black and white already?
this.imageBlackWhite = new Image<TPixel>(configuration, new ImageMetadata(), new[] { image.Clone() });
this.imageBlackWhite.Mutate(img => img.BinaryDither(KnownDitherings.FloydSteinberg));
}

2
src/ImageSharp/Formats/Tiff/Writers/TiffGrayWriter.cs

@ -7,7 +7,7 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Writers
{
internal class TiffGrayWriter<TPixel> : TiffCompositeColorWriter<TPixel>
internal sealed class TiffGrayWriter<TPixel> : TiffCompositeColorWriter<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
{
public TiffGrayWriter(ImageFrame<TPixel> image, MemoryAllocator memoryAllocator, Configuration configuration, TiffEncoderEntriesCollector entriesCollector)

2
src/ImageSharp/Formats/Tiff/Writers/TiffPaletteWriter.cs

@ -13,7 +13,7 @@ using SixLabors.ImageSharp.Processing.Processors.Quantization;
namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Writers
{
internal class TiffPaletteWriter<TPixel> : TiffBaseColorWriter<TPixel>
internal sealed class TiffPaletteWriter<TPixel> : TiffBaseColorWriter<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
{
private const int ColorsPerChannel = 256;

2
src/ImageSharp/Formats/Tiff/Writers/TiffRgbWriter.cs

@ -7,7 +7,7 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Writers
{
internal class TiffRgbWriter<TPixel> : TiffCompositeColorWriter<TPixel>
internal sealed class TiffRgbWriter<TPixel> : TiffCompositeColorWriter<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
{
public TiffRgbWriter(ImageFrame<TPixel> image, MemoryAllocator memoryAllocator, Configuration configuration, TiffEncoderEntriesCollector entriesCollector)

2
src/ImageSharp/Formats/Tiff/Writers/TiffStreamWriter.cs

@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Writers
/// Writes a byte to the current stream.
/// </summary>
/// <param name="value">The byte to write.</param>
public void Write(byte value) => this.BaseStream.Write(new byte[] { value }, 0, 1);
public void Write(byte value) => this.BaseStream.WriteByte(value);
/// <summary>
/// Writes a two-byte unsigned integer to the current stream.

Loading…
Cancel
Save