diff --git a/src/ImageSharp.Formats.Tiff/ITiffEncoderOptions.cs b/src/ImageSharp.Formats.Tiff/ITiffEncoderOptions.cs new file mode 100644 index 0000000000..df2ad77709 --- /dev/null +++ b/src/ImageSharp.Formats.Tiff/ITiffEncoderOptions.cs @@ -0,0 +1,14 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Formats +{ + /// + /// Encapsulates the options for the . + /// + public interface ITiffEncoderOptions : IEncoderOptions + { + } +} diff --git a/src/ImageSharp.Formats.Tiff/TiffDecoder.cs b/src/ImageSharp.Formats.Tiff/TiffDecoder.cs new file mode 100644 index 0000000000..4b99c1cb66 --- /dev/null +++ b/src/ImageSharp.Formats.Tiff/TiffDecoder.cs @@ -0,0 +1,29 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Formats +{ + using System; + using System.IO; + + /// + /// Image decoder for generating an image out of a TIFF stream. + /// + public class TiffDecoder : IImageDecoder + { + /// + public void Decode(Image image, Stream stream, IDecoderOptions options) + where TColor : struct, IPixel + { + Guard.NotNull(image, "image"); + Guard.NotNull(stream, "stream"); + + using (TiffDecoderCore decoder = new TiffDecoderCore(options)) + { + decoder.Decode(image, stream, false); + } + } + } +} diff --git a/src/ImageSharp.Formats.Tiff/TiffDecoderCore.cs b/src/ImageSharp.Formats.Tiff/TiffDecoderCore.cs new file mode 100644 index 0000000000..e9bbb650b7 --- /dev/null +++ b/src/ImageSharp.Formats.Tiff/TiffDecoderCore.cs @@ -0,0 +1,58 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Formats +{ + using System; + using System.IO; + using System.Runtime.CompilerServices; + using System.Threading.Tasks; + + /// + /// Performs the tiff decoding operation. + /// + internal class TiffDecoderCore : IDisposable + { + /// + /// The decoder options. + /// + private readonly IDecoderOptions options; + + /// + /// Initializes a new instance of the class. + /// + /// The decoder options. + public TiffDecoderCore(IDecoderOptions options) + { + this.options = options ?? new DecoderOptions(); + } + + /// + /// Gets the input stream. + /// + public Stream InputStream { get; private set; } + + /// + /// Decodes the image from the specified and sets + /// the data to image. + /// + /// The pixel format. + /// The image, where the data should be set to. + /// The stream, where the image should be. + /// Whether to decode metadata only. + public void Decode(Image image, Stream stream, bool metadataOnly) + where TColor : struct, IPixel + { + this.InputStream = stream; + } + + /// + /// Dispose + /// + public void Dispose() + { + } + } +} diff --git a/src/ImageSharp.Formats.Tiff/TiffEncoder.cs b/src/ImageSharp.Formats.Tiff/TiffEncoder.cs new file mode 100644 index 0000000000..7193c1a765 --- /dev/null +++ b/src/ImageSharp.Formats.Tiff/TiffEncoder.cs @@ -0,0 +1,40 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Formats +{ + using System; + using System.IO; + + /// + /// Encoder for writing the data image to a stream in TIFF format. + /// + public class TiffEncoder : IImageEncoder + { + /// + public void Encode(Image image, Stream stream, IEncoderOptions options) + where TColor : struct, IPixel + { + ITiffEncoderOptions tiffOptions = TiffEncoderOptions.Create(options); + + this.Encode(image, stream, tiffOptions); + } + + /// + /// Encodes the image to the specified stream from the . + /// + /// The pixel format. + /// The to encode from. + /// The to encode the image data to. + /// The options for the encoder. + public void Encode(Image image, Stream stream, ITiffEncoderOptions options) + where TColor : struct, IPixel + { + throw new NotImplementedException(); + // TiffEncoderCore encode = new TiffEncoderCore(options); + // encode.Encode(image, stream); + } + } +} diff --git a/src/ImageSharp.Formats.Tiff/TiffEncoderOptions.cs b/src/ImageSharp.Formats.Tiff/TiffEncoderOptions.cs new file mode 100644 index 0000000000..ed72bbb920 --- /dev/null +++ b/src/ImageSharp.Formats.Tiff/TiffEncoderOptions.cs @@ -0,0 +1,40 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Formats +{ + /// + /// Encapsulates the options for the . + /// + public sealed class TiffEncoderOptions : EncoderOptions, ITiffEncoderOptions + { + /// + /// Initializes a new instance of the class. + /// + public TiffEncoderOptions() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The options for the encoder. + private TiffEncoderOptions(IEncoderOptions options) + : base(options) + { + } + + /// + /// Converts the options to a instance with a + /// cast or by creating a new instance with the specfied options. + /// + /// The options for the encoder. + /// The options for the . + internal static ITiffEncoderOptions Create(IEncoderOptions options) + { + return options as ITiffEncoderOptions ?? new TiffEncoderOptions(options); + } + } +} diff --git a/src/ImageSharp.Formats.Tiff/TiffFormat.cs b/src/ImageSharp.Formats.Tiff/TiffFormat.cs index 805eef87b3..6f09d49099 100644 --- a/src/ImageSharp.Formats.Tiff/TiffFormat.cs +++ b/src/ImageSharp.Formats.Tiff/TiffFormat.cs @@ -25,7 +25,7 @@ namespace ImageSharp.Formats public IImageDecoder Decoder => new TiffDecoder(); /// - public IImageEncoder Encoder => throw new System.NotImplementedException(); + public IImageEncoder Encoder => new TiffEncoder(); /// public int HeaderSize => 4; diff --git a/tests/ImageSharp.Formats.Tiff.Tests/Formats/Tiff/TiffFormatTests.cs b/tests/ImageSharp.Formats.Tiff.Tests/Formats/Tiff/TiffFormatTests.cs index e0f8fd41b8..2657875469 100644 --- a/tests/ImageSharp.Formats.Tiff.Tests/Formats/Tiff/TiffFormatTests.cs +++ b/tests/ImageSharp.Formats.Tiff.Tests/Formats/Tiff/TiffFormatTests.cs @@ -106,5 +106,16 @@ namespace ImageSharp.Tests Assert.NotNull(decoder); Assert.IsType(decoder); } + + [Fact] + public void Encoder_ReturnsTiffEncoder() + { + TiffFormat tiffFormat = new TiffFormat(); + + var encoder = tiffFormat.Encoder; + + Assert.NotNull(encoder); + Assert.IsType(encoder); + } } }