Browse Source

Add stub Tiff encoders/decoders

pull/1570/head
Andrew Wilkinson 9 years ago
parent
commit
9848245df3
  1. 14
      src/ImageSharp.Formats.Tiff/ITiffEncoderOptions.cs
  2. 29
      src/ImageSharp.Formats.Tiff/TiffDecoder.cs
  3. 58
      src/ImageSharp.Formats.Tiff/TiffDecoderCore.cs
  4. 40
      src/ImageSharp.Formats.Tiff/TiffEncoder.cs
  5. 40
      src/ImageSharp.Formats.Tiff/TiffEncoderOptions.cs
  6. 2
      src/ImageSharp.Formats.Tiff/TiffFormat.cs
  7. 11
      tests/ImageSharp.Formats.Tiff.Tests/Formats/Tiff/TiffFormatTests.cs

14
src/ImageSharp.Formats.Tiff/ITiffEncoderOptions.cs

@ -0,0 +1,14 @@
// <copyright file="ITiffEncoderOptions.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats
{
/// <summary>
/// Encapsulates the options for the <see cref="TiffEncoder"/>.
/// </summary>
public interface ITiffEncoderOptions : IEncoderOptions
{
}
}

29
src/ImageSharp.Formats.Tiff/TiffDecoder.cs

@ -0,0 +1,29 @@
// <copyright file="TiffDecoder.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats
{
using System;
using System.IO;
/// <summary>
/// Image decoder for generating an image out of a TIFF stream.
/// </summary>
public class TiffDecoder : IImageDecoder
{
/// <inheritdoc/>
public void Decode<TColor>(Image<TColor> image, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor>
{
Guard.NotNull(image, "image");
Guard.NotNull(stream, "stream");
using (TiffDecoderCore decoder = new TiffDecoderCore(options))
{
decoder.Decode(image, stream, false);
}
}
}
}

58
src/ImageSharp.Formats.Tiff/TiffDecoderCore.cs

@ -0,0 +1,58 @@
// <copyright file="TiffDecoderCore.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats
{
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
/// <summary>
/// Performs the tiff decoding operation.
/// </summary>
internal class TiffDecoderCore : IDisposable
{
/// <summary>
/// The decoder options.
/// </summary>
private readonly IDecoderOptions options;
/// <summary>
/// Initializes a new instance of the <see cref="TiffDecoderCore" /> class.
/// </summary>
/// <param name="options">The decoder options.</param>
public TiffDecoderCore(IDecoderOptions options)
{
this.options = options ?? new DecoderOptions();
}
/// <summary>
/// Gets the input stream.
/// </summary>
public Stream InputStream { get; private set; }
/// <summary>
/// Decodes the image from the specified <see cref="Stream"/> and sets
/// the data to image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="image">The image, where the data should be set to.</param>
/// <param name="stream">The stream, where the image should be.</param>
/// <param name="metadataOnly">Whether to decode metadata only.</param>
public void Decode<TColor>(Image<TColor> image, Stream stream, bool metadataOnly)
where TColor : struct, IPixel<TColor>
{
this.InputStream = stream;
}
/// <summary>
/// Dispose
/// </summary>
public void Dispose()
{
}
}
}

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

@ -0,0 +1,40 @@
// <copyright file="TiffEncoder.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats
{
using System;
using System.IO;
/// <summary>
/// Encoder for writing the data image to a stream in TIFF format.
/// </summary>
public class TiffEncoder : IImageEncoder
{
/// <inheritdoc/>
public void Encode<TColor>(Image<TColor> image, Stream stream, IEncoderOptions options)
where TColor : struct, IPixel<TColor>
{
ITiffEncoderOptions tiffOptions = TiffEncoderOptions.Create(options);
this.Encode(image, stream, tiffOptions);
}
/// <summary>
/// Encodes the image to the specified stream from the <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="image">The <see cref="Image{TColor}"/> to encode from.</param>
/// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
/// <param name="options">The options for the encoder.</param>
public void Encode<TColor>(Image<TColor> image, Stream stream, ITiffEncoderOptions options)
where TColor : struct, IPixel<TColor>
{
throw new NotImplementedException();
// TiffEncoderCore encode = new TiffEncoderCore(options);
// encode.Encode(image, stream);
}
}
}

40
src/ImageSharp.Formats.Tiff/TiffEncoderOptions.cs

@ -0,0 +1,40 @@
// <copyright file="TiffEncoderOptions.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats
{
/// <summary>
/// Encapsulates the options for the <see cref="JTiffEncoder"/>.
/// </summary>
public sealed class TiffEncoderOptions : EncoderOptions, ITiffEncoderOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="TiffEncoderOptions"/> class.
/// </summary>
public TiffEncoderOptions()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="TiffEncoderOptions"/> class.
/// </summary>
/// <param name="options">The options for the encoder.</param>
private TiffEncoderOptions(IEncoderOptions options)
: base(options)
{
}
/// <summary>
/// Converts the options to a <see cref="ITiffEncoderOptions"/> instance with a
/// cast or by creating a new instance with the specfied options.
/// </summary>
/// <param name="options">The options for the encoder.</param>
/// <returns>The options for the <see cref="TiffEncoder"/>.</returns>
internal static ITiffEncoderOptions Create(IEncoderOptions options)
{
return options as ITiffEncoderOptions ?? new TiffEncoderOptions(options);
}
}
}

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

@ -25,7 +25,7 @@ namespace ImageSharp.Formats
public IImageDecoder Decoder => new TiffDecoder();
/// <inheritdoc/>
public IImageEncoder Encoder => throw new System.NotImplementedException();
public IImageEncoder Encoder => new TiffEncoder();
/// <inheritdoc/>
public int HeaderSize => 4;

11
tests/ImageSharp.Formats.Tiff.Tests/Formats/Tiff/TiffFormatTests.cs

@ -106,5 +106,16 @@ namespace ImageSharp.Tests
Assert.NotNull(decoder);
Assert.IsType<TiffDecoder>(decoder);
}
[Fact]
public void Encoder_ReturnsTiffEncoder()
{
TiffFormat tiffFormat = new TiffFormat();
var encoder = tiffFormat.Encoder;
Assert.NotNull(encoder);
Assert.IsType<TiffEncoder>(encoder);
}
}
}

Loading…
Cancel
Save