From 68c3b9347884ba86e49e01a3e539ac07a83a8d87 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Tue, 19 Sep 2017 18:05:28 +0100 Subject: [PATCH 1/2] remove IFrameMetaData and frame properties from ImageMataData --- src/ImageSharp/Formats/Gif/GifEncoderCore.cs | 2 +- src/ImageSharp/MetaData/IFrameMetaData.cs | 29 ------------------- src/ImageSharp/MetaData/ImageFrameMetaData.cs | 15 ++++++++-- src/ImageSharp/MetaData/ImageMetaData.cs | 10 +------ 4 files changed, 14 insertions(+), 42 deletions(-) delete mode 100644 src/ImageSharp/MetaData/IFrameMetaData.cs diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index d143cd531..1b25fd1f1 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -287,7 +287,7 @@ namespace SixLabors.ImageSharp.Formats.Gif /// The metadata of the image or frame. /// The stream to write to. /// The index of the color in the color palette to make transparent. - private void WriteGraphicalControlExtension(IFrameMetaData metaData, EndianBinaryWriter writer, int transparencyIndex) + private void WriteGraphicalControlExtension(ImageFrameMetaData metaData, EndianBinaryWriter writer, int transparencyIndex) { var extension = new GifGraphicsControlExtension { diff --git a/src/ImageSharp/MetaData/IFrameMetaData.cs b/src/ImageSharp/MetaData/IFrameMetaData.cs deleted file mode 100644 index 168b7802c..000000000 --- a/src/ImageSharp/MetaData/IFrameMetaData.cs +++ /dev/null @@ -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 -{ - /// - /// Encapsulates the metadata of an image frame. - /// - internal interface IFrameMetaData - { - /// - /// 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. - /// - int FrameDelay { get; set; } - - /// - /// 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. - /// - DisposalMethod DisposalMethod { get; set; } - } -} diff --git a/src/ImageSharp/MetaData/ImageFrameMetaData.cs b/src/ImageSharp/MetaData/ImageFrameMetaData.cs index e5c2afa87..ca3012f4a 100644 --- a/src/ImageSharp/MetaData/ImageFrameMetaData.cs +++ b/src/ImageSharp/MetaData/ImageFrameMetaData.cs @@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.MetaData /// /// Encapsulates the metadata of an image frame. /// - public sealed class ImageFrameMetaData : IFrameMetaData + public sealed class ImageFrameMetaData { /// /// Initializes a new instance of the class. @@ -33,10 +33,19 @@ namespace SixLabors.ImageSharp.MetaData this.DisposalMethod = other.DisposalMethod; } - /// + /// + /// 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. + /// public int FrameDelay { get; set; } - /// + /// + /// 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. + /// public DisposalMethod DisposalMethod { get; set; } /// diff --git a/src/ImageSharp/MetaData/ImageMetaData.cs b/src/ImageSharp/MetaData/ImageMetaData.cs index 72af56945..e36f2a69f 100644 --- a/src/ImageSharp/MetaData/ImageMetaData.cs +++ b/src/ImageSharp/MetaData/ImageMetaData.cs @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.MetaData /// /// Encapsulates the metadata of an image. /// - public sealed class ImageMetaData : IFrameMetaData + public sealed class ImageMetaData { /// /// 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 /// public IccProfile IccProfile { get; set; } - /// - public int FrameDelay { get; set; } - - /// - public DisposalMethod DisposalMethod { get; set; } - /// /// Gets the list of properties for storing meta information about this image. /// From 19ed95c09c0779cd9feb497b741b6a19b25839ca Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Tue, 19 Sep 2017 18:45:46 +0100 Subject: [PATCH 2/2] fix missed IFrameMetaData method --- src/ImageSharp/Formats/Gif/GifDecoderCore.cs | 4 ++-- tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index c3c395e85..6c7beded7 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/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(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 /// /// The meta data. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void SetFrameMetaData(IFrameMetaData metaData) + private void SetFrameMetaData(ImageFrameMetaData metaData) { if (this.graphicsControlExtension != null) { diff --git a/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs b/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs index ee7faeca5..1cb35596c 100644 --- a/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs +++ b/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]