Browse Source

Implemented the IDecoderOptions inside the jpeg decoder.

af/merge-core
Dirk Lemstra 9 years ago
committed by Dirk Lemstra
parent
commit
c7ced5bcdf
  1. 2
      src/ImageSharp.Formats.Jpeg/JpegDecoder.cs
  2. 11
      src/ImageSharp.Formats.Jpeg/JpegDecoderCore.cs
  3. 44
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderCoreTests.cs
  4. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

2
src/ImageSharp.Formats.Jpeg/JpegDecoder.cs

@ -20,7 +20,7 @@ namespace ImageSharp.Formats
Guard.NotNull(image, "image");
Guard.NotNull(stream, "stream");
using (JpegDecoderCore decoder = new JpegDecoderCore())
using (JpegDecoderCore decoder = new JpegDecoderCore(options))
{
decoder.Decode(image, stream, false);
}

11
src/ImageSharp.Formats.Jpeg/JpegDecoderCore.cs

@ -37,6 +37,11 @@ namespace ImageSharp.Formats
public InputProcessor InputProcessor;
#pragma warning restore SA401
/// <summary>
/// The decoder options.
/// </summary>
private readonly IDecoderOptions options;
/// <summary>
/// The App14 marker color-space
/// </summary>
@ -85,8 +90,10 @@ namespace ImageSharp.Formats
/// <summary>
/// Initializes a new instance of the <see cref="JpegDecoderCore" /> class.
/// </summary>
public JpegDecoderCore()
/// <param name="options">The decoder options.</param>
public JpegDecoderCore(IDecoderOptions options)
{
this.options = options ?? DecoderOptions.Default;
this.HuffmanTrees = HuffmanTree.CreateHuffmanTrees();
this.QuantizationTables = new Block8x8F[MaxTq + 1];
this.Temp = new byte[2 * Block8x8F.ScalarCount];
@ -958,7 +965,7 @@ namespace ImageSharp.Formats
private void ProcessApp1Marker<TColor>(int remaining, Image<TColor> image)
where TColor : struct, IPixel<TColor>
{
if (remaining < 6)
if (remaining < 6 || this.options.IgnoreMetadata)
{
this.InputProcessor.Skip(remaining);
return;

44
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderCoreTests.cs

@ -0,0 +1,44 @@
// <copyright file="JpegDecoderCoreTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
{
using Xunit;
public class JpegDecoderCoreTests
{
[Fact]
public void Decode_IgnoreMetadataIsFalse_ExifProfileIsRead()
{
var options = new DecoderOptions()
{
IgnoreMetadata = false
};
TestFile testFile = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan);
using (Image image = new Image(testFile.FilePath, options))
{
Assert.NotNull(image.MetaData.ExifProfile);
}
}
[Fact]
public void Decode_IgnoreMetadataIsTrue_ExifProfileIgnored()
{
var options = new DecoderOptions()
{
IgnoreMetadata = true
};
TestFile testFile = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan);
using (Image image = new Image(testFile.FilePath, options))
{
Assert.Null(image.MetaData.ExifProfile);
}
}
}
}

2
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -90,7 +90,7 @@ namespace ImageSharp.Tests
ms.Seek(0, SeekOrigin.Begin);
Image<TColor> mirror = provider.Factory.CreateImage(1, 1);
using (JpegDecoderCore decoder = new JpegDecoderCore())
using (JpegDecoderCore decoder = new JpegDecoderCore(null))
{
decoder.Decode(mirror, ms, true);

Loading…
Cancel
Save