Browse Source

Add Tiff EncodeAsync

pull/1570/head
Brian Popow 6 years ago
parent
commit
ae34c3ceca
  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 |
|---------------------------|:-----:|:-----:|--------------------------|
|None | | Y | |
|None | Y | Y | encoding only rgb so far |
|Ccitt1D | | Y | |
|PackBits | | Y | |
|CcittGroup3Fax | | Y | |
@ -58,7 +58,7 @@
|WhiteIsZero | | 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 (Planar) | | Y | General implementation only |
|Rgb (Planar) | Y | Y | General implementation only |
|PaletteColor | | Y | General implementation only |
|TransparencyMask | | | |
|Separated (TIFF Extension) | | | |
@ -72,34 +72,34 @@
|---------------------------|:-----:|:-----:|--------------------------|
|NewSubfileType | | | |
|SubfileType | | | |
|ImageWidth | | Y | |
|ImageLength | | Y | |
|BitsPerSample | | Y | |
|ImageWidth | Y | Y | |
|ImageLength | Y | Y | |
|BitsPerSample | Y | Y | |
|Compression | | Y | |
|PhotometricInterpretation | | Y | |
|Threshholding | | | |
|PhotometricInterpretation | Y | Y | |
|Thresholding | | | |
|CellWidth | | | |
|CellLength | | | |
|FillOrder | | - | Ignore. In practice is very uncommon, and is not recommended. |
|ImageDescription | | Y | |
|Make | | Y | |
|Model | | Y | |
|StripOffsets | | Y | |
|StripOffsets | Y | Y | |
|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 | |
|StripByteCounts | | Y | |
|StripByteCounts | Y | Y | |
|MinSampleValue | | | |
|MaxSampleValue | | | |
|XResolution | | Y | |
|YResolution | | Y | |
|XResolution | Y | Y | |
|YResolution | Y | Y | |
|PlanarConfiguration | | Y | |
|FreeOffsets | | | |
|FreeByteCounts | | | |
|GrayResponseUnit | | | |
|GrayResponseCurve | | | |
|ResolutionUnit | | Y | |
|Software | | Y | |
|Software | Y | Y | |
|DateTime | | Y | |
|Artist | | 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)
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.Collections.Generic;
using System.IO;
using System.Threading;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
@ -14,7 +15,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
/// <summary>
/// Performs the TIFF encoding operation.
/// </summary>
internal sealed class TiffEncoderCore
internal sealed class TiffEncoderCore : IImageEncoderInternals
{
/// <summary>
/// The amount to pad each row by in bytes.
@ -39,7 +40,6 @@ namespace SixLabors.ImageSharp.Formats.Tiff
public TiffEncoderCore(ITiffEncoderOptions options, MemoryAllocator memoryAllocator)
{
this.memoryAllocator = memoryAllocator;
options = options ?? new TiffEncoder();
}
/// <summary>
@ -58,7 +58,8 @@ namespace SixLabors.ImageSharp.Formats.Tiff
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <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>
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>
{
Guard.NotNull(image, nameof(image));
@ -221,7 +222,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
var stripOffsets = new ExifLongArray(ExifTagValue.StripOffsets)
{
// TODO: we only write one image strip for the start.
Value = new uint[] { imageDataStartOffset }
Value = new[] { imageDataStartOffset }
};
var samplesPerPixel = new ExifLong(ExifTagValue.SamplesPerPixel)
@ -237,7 +238,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
var stripByteCounts = new ExifLongArray(ExifTagValue.StripByteCounts)
{
Value = new[] { (uint)(imageDataBytes) }
Value = new[] { (uint)imageDataBytes }
};
var xResolution = new ExifRational(ExifTagValue.XResolution)
@ -258,6 +259,11 @@ namespace SixLabors.ImageSharp.Formats.Tiff
Value = 0
};
var software = new ExifString(ExifTagValue.Software)
{
Value = "ImageSharp"
};
ifdEntries.Add(width);
ifdEntries.Add(height);
ifdEntries.Add(bitPerSample);
@ -270,6 +276,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
ifdEntries.Add(xResolution);
ifdEntries.Add(yResolution);
ifdEntries.Add(resolutionUnit);
ifdEntries.Add(software);
}
}
}

Loading…
Cancel
Save