Browse Source

Merge pull request #343 from SixLabors/tocsoft/cleanup-frame-metadata

Remove IFrameMetaData and frame properties from ImageMataData
af/merge-core
James Jackson-South 9 years ago
committed by GitHub
parent
commit
606d34411a
  1. 4
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  2. 2
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  3. 29
      src/ImageSharp/MetaData/IFrameMetaData.cs
  4. 15
      src/ImageSharp/MetaData/ImageFrameMetaData.cs
  5. 10
      src/ImageSharp/MetaData/ImageMetaData.cs
  6. 4
      tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs

4
src/ImageSharp/Formats/Gif/GifDecoderCore.cs

@ -376,7 +376,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
// This initializes the image to become fully transparent because the alpha channel is zero.
this.image = new Image<TPixel>(this.configuration, imageWidth, imageHeight, this.metaData);
this.SetFrameMetaData(this.metaData);
this.SetFrameMetaData(this.image.Frames.RootFrame.MetaData);
image = this.image.Frames.RootFrame;
}
@ -522,7 +522,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// </summary>
/// <param name="metaData">The meta data.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetFrameMetaData(IFrameMetaData metaData)
private void SetFrameMetaData(ImageFrameMetaData metaData)
{
if (this.graphicsControlExtension != null)
{

2
src/ImageSharp/Formats/Gif/GifEncoderCore.cs

@ -287,7 +287,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <param name="metaData">The metadata of the image or frame.</param>
/// <param name="writer">The stream to write to.</param>
/// <param name="transparencyIndex">The index of the color in the color palette to make transparent.</param>
private void WriteGraphicalControlExtension(IFrameMetaData metaData, EndianBinaryWriter writer, int transparencyIndex)
private void WriteGraphicalControlExtension(ImageFrameMetaData metaData, EndianBinaryWriter writer, int transparencyIndex)
{
var extension = new GifGraphicsControlExtension
{

29
src/ImageSharp/MetaData/IFrameMetaData.cs

@ -1,29 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Gif;
namespace SixLabors.ImageSharp.MetaData
{
/// <summary>
/// Encapsulates the metadata of an image frame.
/// </summary>
internal interface IFrameMetaData
{
/// <summary>
/// Gets or sets the frame delay for animated images.
/// If not 0, when utilized in Gif animation, this field specifies the number of hundredths (1/100) of a second to
/// wait before continuing with the processing of the Data Stream.
/// The clock starts ticking immediately after the graphic is rendered.
/// </summary>
int FrameDelay { get; set; }
/// <summary>
/// Gets or sets the disposal method for animated images.
/// Primarily used in Gif animation, this field indicates the way in which the graphic is to
/// be treated after being displayed.
/// </summary>
DisposalMethod DisposalMethod { get; set; }
}
}

15
src/ImageSharp/MetaData/ImageFrameMetaData.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.MetaData
/// <summary>
/// Encapsulates the metadata of an image frame.
/// </summary>
public sealed class ImageFrameMetaData : IFrameMetaData
public sealed class ImageFrameMetaData
{
/// <summary>
/// Initializes a new instance of the <see cref="ImageFrameMetaData"/> class.
@ -33,10 +33,19 @@ namespace SixLabors.ImageSharp.MetaData
this.DisposalMethod = other.DisposalMethod;
}
/// <inheritdoc/>
/// <summary>
/// Gets or sets the frame delay for animated images.
/// If not 0, when utilized in Gif animation, this field specifies the number of hundredths (1/100) of a second to
/// wait before continuing with the processing of the Data Stream.
/// The clock starts ticking immediately after the graphic is rendered.
/// </summary>
public int FrameDelay { get; set; }
/// <inheritdoc/>
/// <summary>
/// Gets or sets the disposal method for animated images.
/// Primarily used in Gif animation, this field indicates the way in which the graphic is to
/// be treated after being displayed.
/// </summary>
public DisposalMethod DisposalMethod { get; set; }
/// <summary>

10
src/ImageSharp/MetaData/ImageMetaData.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.MetaData
/// <summary>
/// Encapsulates the metadata of an image.
/// </summary>
public sealed class ImageMetaData : IFrameMetaData
public sealed class ImageMetaData
{
/// <summary>
/// The default horizontal resolution value (dots per inch) in x direction.
@ -51,8 +51,6 @@ namespace SixLabors.ImageSharp.MetaData
this.HorizontalResolution = other.HorizontalResolution;
this.VerticalResolution = other.VerticalResolution;
this.FrameDelay = other.FrameDelay;
this.DisposalMethod = other.DisposalMethod;
this.RepeatCount = other.RepeatCount;
foreach (ImageProperty property in other.Properties)
@ -115,12 +113,6 @@ namespace SixLabors.ImageSharp.MetaData
/// </summary>
public IccProfile IccProfile { get; set; }
/// <inheritdoc/>
public int FrameDelay { get; set; }
/// <inheritdoc/>
public DisposalMethod DisposalMethod { get; set; }
/// <summary>
/// Gets the list of properties for storing meta information about this image.
/// </summary>

4
tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs

@ -24,22 +24,18 @@ namespace SixLabors.ImageSharp.Tests
ImageProperty imageProperty = new ImageProperty("name", "value");
metaData.ExifProfile = exifProfile;
metaData.FrameDelay = 42;
metaData.HorizontalResolution = 4;
metaData.VerticalResolution = 2;
metaData.Properties.Add(imageProperty);
metaData.RepeatCount = 1;
metaData.DisposalMethod = DisposalMethod.RestoreToBackground;
ImageMetaData clone = new ImageMetaData(metaData);
Assert.Equal(exifProfile.ToByteArray(), clone.ExifProfile.ToByteArray());
Assert.Equal(42, clone.FrameDelay);
Assert.Equal(4, clone.HorizontalResolution);
Assert.Equal(2, clone.VerticalResolution);
Assert.Equal(imageProperty, clone.Properties[0]);
Assert.Equal(1, clone.RepeatCount);
Assert.Equal(DisposalMethod.RestoreToBackground, clone.DisposalMethod);
}
[Fact]

Loading…
Cancel
Save