Browse Source

Add Tiff EncodeAsync

pull/1457/head
Brian Popow 6 years ago
parent
commit
1e8916dc5d
  1. 26
      src/ImageSharp/Formats/Tiff/README.md
  2. 3
      src/ImageSharp/Formats/Tiff/TiffEncoder.cs
  3. 17
      src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs

26
src/ImageSharp/Formats/Tiff/README.md

@ -40,7 +40,7 @@
| |Encoder|Decoder|Comments | | |Encoder|Decoder|Comments |
|---------------------------|:-----:|:-----:|--------------------------| |---------------------------|:-----:|:-----:|--------------------------|
|None | | Y | | |None | Y | Y | encoding only rgb so far |
|Ccitt1D | | Y | | |Ccitt1D | | Y | |
|PackBits | | Y | | |PackBits | | Y | |
|CcittGroup3Fax | | Y | | |CcittGroup3Fax | | Y | |
@ -58,7 +58,7 @@
|WhiteIsZero | | Y | General + 1/4/8-bit optimised implementations | |WhiteIsZero | | Y | General + 1/4/8-bit optimised implementations |
|BlackIsZero | | Y | General + 1/4/8-bit optimised implementations | |BlackIsZero | | Y | General + 1/4/8-bit optimised implementations |
|Rgb (Chunky) | | Y | General + Rgb888 optimised implementation | |Rgb (Chunky) | | Y | General + Rgb888 optimised implementation |
|Rgb (Planar) | | Y | General implementation only | |Rgb (Planar) | Y | Y | General implementation only |
|PaletteColor | | Y | General implementation only | |PaletteColor | | Y | General implementation only |
|TransparencyMask | | | | |TransparencyMask | | | |
|Separated (TIFF Extension) | | | | |Separated (TIFF Extension) | | | |
@ -72,34 +72,34 @@
|---------------------------|:-----:|:-----:|--------------------------| |---------------------------|:-----:|:-----:|--------------------------|
|NewSubfileType | | | | |NewSubfileType | | | |
|SubfileType | | | | |SubfileType | | | |
|ImageWidth | | Y | | |ImageWidth | Y | Y | |
|ImageLength | | Y | | |ImageLength | Y | Y | |
|BitsPerSample | | Y | | |BitsPerSample | Y | Y | |
|Compression | | Y | | |Compression | | Y | |
|PhotometricInterpretation | | Y | | |PhotometricInterpretation | Y | Y | |
|Threshholding | | | | |Thresholding | | | |
|CellWidth | | | | |CellWidth | | | |
|CellLength | | | | |CellLength | | | |
|FillOrder | | - | Ignore. In practice is very uncommon, and is not recommended. | |FillOrder | | - | Ignore. In practice is very uncommon, and is not recommended. |
|ImageDescription | | Y | | |ImageDescription | | Y | |
|Make | | Y | | |Make | | Y | |
|Model | | Y | | |Model | | Y | |
|StripOffsets | | Y | | |StripOffsets | Y | Y | |
|Orientation | | - | Ignore. Many readers ignore this tag. | |Orientation | | - | Ignore. Many readers ignore this tag. |
|SamplesPerPixel | | - | Currently ignored, as can be inferred from count of BitsPerSample | |SamplesPerPixel | Y | - | Currently ignored, as can be inferred from count of BitsPerSample |
|RowsPerStrip | | Y | | |RowsPerStrip | | Y | |
|StripByteCounts | | Y | | |StripByteCounts | Y | Y | |
|MinSampleValue | | | | |MinSampleValue | | | |
|MaxSampleValue | | | | |MaxSampleValue | | | |
|XResolution | | Y | | |XResolution | Y | Y | |
|YResolution | | Y | | |YResolution | Y | Y | |
|PlanarConfiguration | | Y | | |PlanarConfiguration | | Y | |
|FreeOffsets | | | | |FreeOffsets | | | |
|FreeByteCounts | | | | |FreeByteCounts | | | |
|GrayResponseUnit | | | | |GrayResponseUnit | | | |
|GrayResponseCurve | | | | |GrayResponseCurve | | | |
|ResolutionUnit | | Y | | |ResolutionUnit | | Y | |
|Software | | Y | | |Software | Y | Y | |
|DateTime | | Y | | |DateTime | | Y | |
|Artist | | Y | | |Artist | | Y | |
|HostComputer | | Y | | |HostComputer | | Y | |

3
src/ImageSharp/Formats/Tiff/TiffEncoder.cs

@ -26,7 +26,8 @@ namespace SixLabors.ImageSharp.Formats.Tiff
public Task EncodeAsync<TPixel>(Image<TPixel> image, Stream stream, CancellationToken cancellationToken) public Task EncodeAsync<TPixel>(Image<TPixel> image, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
throw new System.NotImplementedException(); var encoder = new TiffEncoderCore(this, image.GetMemoryAllocator());
return encoder.EncodeAsync(image, stream, cancellationToken);
} }
} }
} }

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

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata.Profiles.Exif; using SixLabors.ImageSharp.Metadata.Profiles.Exif;
@ -14,7 +15,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
/// <summary> /// <summary>
/// Performs the TIFF encoding operation. /// Performs the TIFF encoding operation.
/// </summary> /// </summary>
internal sealed class TiffEncoderCore internal sealed class TiffEncoderCore : IImageEncoderInternals
{ {
/// <summary> /// <summary>
/// The amount to pad each row by in bytes. /// The amount to pad each row by in bytes.
@ -39,7 +40,6 @@ namespace SixLabors.ImageSharp.Formats.Tiff
public TiffEncoderCore(ITiffEncoderOptions options, MemoryAllocator memoryAllocator) public TiffEncoderCore(ITiffEncoderOptions options, MemoryAllocator memoryAllocator)
{ {
this.memoryAllocator = memoryAllocator; this.memoryAllocator = memoryAllocator;
options = options ?? new TiffEncoder();
} }
/// <summary> /// <summary>
@ -58,7 +58,8 @@ namespace SixLabors.ImageSharp.Formats.Tiff
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="Image{TPixel}"/> to encode from.</param> /// <param name="image">The <see cref="Image{TPixel}"/> to encode from.</param>
/// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param> /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
public void Encode<TPixel>(Image<TPixel> image, Stream stream) /// <param name="cancellationToken">The token to request cancellation.</param>
public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
Guard.NotNull(image, nameof(image)); Guard.NotNull(image, nameof(image));
@ -221,7 +222,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
var stripOffsets = new ExifLongArray(ExifTagValue.StripOffsets) var stripOffsets = new ExifLongArray(ExifTagValue.StripOffsets)
{ {
// TODO: we only write one image strip for the start. // TODO: we only write one image strip for the start.
Value = new uint[] { imageDataStartOffset } Value = new[] { imageDataStartOffset }
}; };
var samplesPerPixel = new ExifLong(ExifTagValue.SamplesPerPixel) var samplesPerPixel = new ExifLong(ExifTagValue.SamplesPerPixel)
@ -237,7 +238,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
var stripByteCounts = new ExifLongArray(ExifTagValue.StripByteCounts) var stripByteCounts = new ExifLongArray(ExifTagValue.StripByteCounts)
{ {
Value = new[] { (uint)(imageDataBytes) } Value = new[] { (uint)imageDataBytes }
}; };
var xResolution = new ExifRational(ExifTagValue.XResolution) var xResolution = new ExifRational(ExifTagValue.XResolution)
@ -258,6 +259,11 @@ namespace SixLabors.ImageSharp.Formats.Tiff
Value = 0 Value = 0
}; };
var software = new ExifString(ExifTagValue.Software)
{
Value = "ImageSharp"
};
ifdEntries.Add(width); ifdEntries.Add(width);
ifdEntries.Add(height); ifdEntries.Add(height);
ifdEntries.Add(bitPerSample); ifdEntries.Add(bitPerSample);
@ -270,6 +276,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
ifdEntries.Add(xResolution); ifdEntries.Add(xResolution);
ifdEntries.Add(yResolution); ifdEntries.Add(yResolution);
ifdEntries.Add(resolutionUnit); ifdEntries.Add(resolutionUnit);
ifdEntries.Add(software);
} }
} }
} }

Loading…
Cancel
Save