diff --git a/src/ImageSharp/Formats/Bmp/BmpMetaData.cs b/src/ImageSharp/Formats/Bmp/BmpMetaData.cs
index 3d678c13e..8b33e30fa 100644
--- a/src/ImageSharp/Formats/Bmp/BmpMetaData.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpMetaData.cs
@@ -6,13 +6,29 @@ namespace SixLabors.ImageSharp.Formats.Bmp
///
/// Provides Bmp specific metadata information for the image.
///
- public class BmpMetaData
+ public class BmpMetaData : IDeepCloneable
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public BmpMetaData()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The metadata to create an instance from.
+ private BmpMetaData(BmpMetaData other) => this.BitsPerPixel = other.BitsPerPixel;
+
///
/// Gets or sets the number of bits per pixel.
///
public BmpBitsPerPixel BitsPerPixel { get; set; } = BmpBitsPerPixel.Pixel24;
+ ///
+ public IDeepCloneable DeepClone() => new BmpMetaData(this);
+
// TODO: Colors used once we support encoding palette bmps.
}
-}
+}
\ No newline at end of file
diff --git a/src/ImageSharp/Formats/Gif/GifFrameMetaData.cs b/src/ImageSharp/Formats/Gif/GifFrameMetaData.cs
index 5b4023f0f..0042c6a10 100644
--- a/src/ImageSharp/Formats/Gif/GifFrameMetaData.cs
+++ b/src/ImageSharp/Formats/Gif/GifFrameMetaData.cs
@@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// Initializes a new instance of the class.
///
/// The metadata to create an instance from.
- internal GifFrameMetaData(GifFrameMetaData other)
+ private GifFrameMetaData(GifFrameMetaData other)
{
this.ColorTableLength = other.ColorTableLength;
this.FrameDelay = other.FrameDelay;
diff --git a/src/ImageSharp/Formats/Gif/GifMetaData.cs b/src/ImageSharp/Formats/Gif/GifMetaData.cs
index f58f5dff3..bb7fb5051 100644
--- a/src/ImageSharp/Formats/Gif/GifMetaData.cs
+++ b/src/ImageSharp/Formats/Gif/GifMetaData.cs
@@ -6,8 +6,26 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
/// Provides Gif specific metadata information for the image.
///
- public class GifMetaData
+ public class GifMetaData : IDeepCloneable
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public GifMetaData()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The metadata to create an instance from.
+ private GifMetaData(GifMetaData other)
+ {
+ this.RepeatCount = other.RepeatCount;
+ this.ColorTableMode = other.ColorTableMode;
+ this.GlobalColorTableLength = other.GlobalColorTableLength;
+ }
+
///
/// Gets or sets the number of times any animation is repeated.
///
@@ -25,5 +43,8 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// Gets or sets the length of the global color table if present.
///
public int GlobalColorTableLength { get; set; }
+
+ ///
+ public IDeepCloneable DeepClone() => new GifMetaData(this);
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Formats/Jpeg/JpegMetaData.cs b/src/ImageSharp/Formats/Jpeg/JpegMetaData.cs
index bd7232e60..fcad29e5d 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegMetaData.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegMetaData.cs
@@ -6,11 +6,27 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
///
/// Provides Jpeg specific metadata information for the image.
///
- public class JpegMetaData
+ public class JpegMetaData : IDeepCloneable
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public JpegMetaData()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The metadata to create an instance from.
+ private JpegMetaData(JpegMetaData other) => this.Quality = other.Quality;
+
///
/// Gets or sets the encoded quality.
///
public int Quality { get; set; } = 75;
+
+ ///
+ public IDeepCloneable DeepClone() => new JpegMetaData(this);
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Formats/Png/PngMetaData.cs b/src/ImageSharp/Formats/Png/PngMetaData.cs
index 1eb3cdad6..9c7676514 100644
--- a/src/ImageSharp/Formats/Png/PngMetaData.cs
+++ b/src/ImageSharp/Formats/Png/PngMetaData.cs
@@ -6,8 +6,26 @@ namespace SixLabors.ImageSharp.Formats.Png
///
/// Provides Png specific metadata information for the image.
///
- public class PngMetaData
+ public class PngMetaData : IDeepCloneable
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public PngMetaData()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The metadata to create an instance from.
+ private PngMetaData(PngMetaData other)
+ {
+ this.BitDepth = other.BitDepth;
+ this.ColorType = other.ColorType;
+ this.Gamma = other.Gamma;
+ }
+
///
/// Gets or sets the number of bits per sample or per palette index (not per pixel).
/// Not all values are allowed for all values.
@@ -23,5 +41,8 @@ namespace SixLabors.ImageSharp.Formats.Png
/// Gets or sets the gamma value for the image.
///
public float Gamma { get; set; }
+
+ ///
+ public IDeepCloneable DeepClone() => new PngMetaData(this);
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/ImageFrameCollection.cs b/src/ImageSharp/ImageFrameCollection.cs
index 59571ce92..c55d63627 100644
--- a/src/ImageSharp/ImageFrameCollection.cs
+++ b/src/ImageSharp/ImageFrameCollection.cs
@@ -195,7 +195,7 @@ namespace SixLabors.ImageSharp
this.frames.Remove(frame);
- return new Image(this.parent.GetConfiguration(), this.parent.MetaData.Clone(), new[] { frame });
+ return new Image(this.parent.GetConfiguration(), this.parent.MetaData.DeepClone(), new[] { frame });
}
///
@@ -208,7 +208,7 @@ namespace SixLabors.ImageSharp
{
ImageFrame frame = this[index];
ImageFrame clonedFrame = frame.Clone();
- return new Image(this.parent.GetConfiguration(), this.parent.MetaData.Clone(), new[] { clonedFrame });
+ return new Image(this.parent.GetConfiguration(), this.parent.MetaData.DeepClone(), new[] { clonedFrame });
}
///
diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs
index 8bc5a40bd..bdb1447f2 100644
--- a/src/ImageSharp/Image{TPixel}.cs
+++ b/src/ImageSharp/Image{TPixel}.cs
@@ -190,7 +190,7 @@ namespace SixLabors.ImageSharp
public Image Clone()
{
IEnumerable> clonedFrames = this.frames.Select(x => x.Clone());
- return new Image(this.configuration, this.MetaData.Clone(), clonedFrames);
+ return new Image(this.configuration, this.MetaData.DeepClone(), clonedFrames);
}
///
@@ -208,7 +208,7 @@ namespace SixLabors.ImageSharp
where TPixel2 : struct, IPixel
{
IEnumerable> clonedFrames = this.frames.Select(x => x.CloneAs());
- var target = new Image(this.configuration, this.MetaData.Clone(), clonedFrames);
+ var target = new Image(this.configuration, this.MetaData.DeepClone(), clonedFrames);
return target;
}
diff --git a/src/ImageSharp/MetaData/ImageMetaData.cs b/src/ImageSharp/MetaData/ImageMetaData.cs
index 7e74157e7..73549d98a 100644
--- a/src/ImageSharp/MetaData/ImageMetaData.cs
+++ b/src/ImageSharp/MetaData/ImageMetaData.cs
@@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using System;
using System.Collections.Generic;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.MetaData.Profiles.Exif;
@@ -12,7 +11,7 @@ namespace SixLabors.ImageSharp.MetaData
///
/// Encapsulates the metadata of an image.
///
- public sealed class ImageMetaData
+ public sealed class ImageMetaData : IDeepCloneable
{
///
/// The default horizontal resolution value (dots per inch) in x direction.
@@ -26,7 +25,13 @@ namespace SixLabors.ImageSharp.MetaData
///
public const double DefaultVerticalResolution = 96;
- private readonly Dictionary formatMetaData = new Dictionary();
+ ///
+ /// The default pixel resolution units.
+ /// The default value is .
+ ///
+ public const PixelResolutionUnit DefaultPixelResolutionUnits = PixelResolutionUnit.PixelsPerInch;
+
+ private readonly Dictionary formatMetaData = new Dictionary();
private double horizontalResolution;
private double verticalResolution;
@@ -37,6 +42,7 @@ namespace SixLabors.ImageSharp.MetaData
{
this.horizontalResolution = DefaultHorizontalResolution;
this.verticalResolution = DefaultVerticalResolution;
+ this.ResolutionUnits = DefaultPixelResolutionUnits;
}
///
@@ -52,9 +58,9 @@ namespace SixLabors.ImageSharp.MetaData
this.VerticalResolution = other.VerticalResolution;
this.ResolutionUnits = other.ResolutionUnits;
- foreach (KeyValuePair meta in other.formatMetaData)
+ foreach (KeyValuePair meta in other.formatMetaData)
{
- this.formatMetaData.Add(meta.Key, meta.Value);
+ this.formatMetaData.Add(meta.Key, meta.Value.DeepClone());
}
foreach (ImageProperty property in other.Properties)
@@ -62,13 +68,8 @@ namespace SixLabors.ImageSharp.MetaData
this.Properties.Add(property);
}
- this.ExifProfile = other.ExifProfile != null
- ? new ExifProfile(other.ExifProfile)
- : null;
-
- this.IccProfile = other.IccProfile != null
- ? new IccProfile(other.IccProfile)
- : null;
+ this.ExifProfile = other.ExifProfile?.DeepClone();
+ this.IccProfile = other.IccProfile?.DeepClone();
}
///
@@ -114,7 +115,7 @@ namespace SixLabors.ImageSharp.MetaData
/// 02 : Pixels per centimeter
/// 03 : Pixels per meter
///
- public PixelResolutionUnit ResolutionUnits { get; set; } = PixelResolutionUnit.PixelsPerInch;
+ public PixelResolutionUnit ResolutionUnits { get; set; }
///
/// Gets or sets the Exif profile.
@@ -140,9 +141,9 @@ namespace SixLabors.ImageSharp.MetaData
/// The .
///
public TFormatMetaData GetFormatMetaData(IImageFormat key)
- where TFormatMetaData : class
+ where TFormatMetaData : class, IDeepCloneable
{
- if (this.formatMetaData.TryGetValue(key, out object meta))
+ if (this.formatMetaData.TryGetValue(key, out IDeepCloneable meta))
{
return (TFormatMetaData)meta;
}
@@ -152,11 +153,8 @@ namespace SixLabors.ImageSharp.MetaData
return newMeta;
}
- ///
- /// Clones this into a new instance
- ///
- /// The cloned metadata instance
- public ImageMetaData Clone() => new ImageMetaData(this);
+ ///
+ public ImageMetaData DeepClone() => new ImageMetaData(this);
///
/// Looks up a property with the provided name.
diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs
index 1dd885721..b48b146f1 100644
--- a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs
+++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs
@@ -12,23 +12,18 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
///
/// Represents an EXIF profile providing access to the collection of values.
///
- public sealed class ExifProfile
+ public sealed class ExifProfile : IDeepCloneable
{
///
/// The byte array to read the EXIF profile from.
///
- private byte[] data;
+ private readonly byte[] data;
///
/// The collection of EXIF values
///
private List values;
- ///
- /// The list of invalid EXIF tags
- ///
- private IReadOnlyList invalidTags;
-
///
/// The thumbnail offset position in the byte stream
///
@@ -55,7 +50,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
{
this.Parts = ExifParts.All;
this.data = data;
- this.invalidTags = new List();
+ this.InvalidTags = new List();
}
///
@@ -63,22 +58,19 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
/// by making a copy from another EXIF profile.
///
/// The other EXIF profile, where the clone should be made from.
- /// is null.
- public ExifProfile(ExifProfile other)
+ private ExifProfile(ExifProfile other)
{
- Guard.NotNull(other, nameof(other));
-
this.Parts = other.Parts;
this.thumbnailLength = other.thumbnailLength;
this.thumbnailOffset = other.thumbnailOffset;
- this.invalidTags = new List(other.invalidTags);
+ this.InvalidTags = new List(other.InvalidTags);
if (other.values != null)
{
this.values = new List(other.Values.Count);
foreach (ExifValue value in other.Values)
{
- this.values.Add(new ExifValue(value));
+ this.values.Add(value.DeepClone());
}
}
@@ -97,7 +89,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
///
/// Gets the tags that where found but contained an invalid value.
///
- public IReadOnlyList InvalidTags => this.invalidTags;
+ public IReadOnlyList InvalidTags { get; private set; }
///
/// Gets the values of this EXIF profile.
@@ -249,6 +241,9 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
return writer.GetData();
}
+ ///
+ public ExifProfile DeepClone() => new ExifProfile(this);
+
///
/// Synchronizes the profiles with the specified meta data.
///
@@ -294,7 +289,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
this.values = reader.ReadValues();
- this.invalidTags = new List(reader.InvalidTags);
+ this.InvalidTags = new List(reader.InvalidTags);
this.thumbnailOffset = (int)reader.ThumbnailOffset;
this.thumbnailLength = (int)reader.ThumbnailLength;
}
diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs
index e6da9b7d1..ccacfd0bf 100644
--- a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs
+++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs
@@ -11,15 +11,30 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
///
/// Represent the value of the EXIF profile.
///
- public sealed class ExifValue : IEquatable
+ public sealed class ExifValue : IEquatable, IDeepCloneable
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The tag.
+ /// The data type.
+ /// The value.
+ /// Whether the value is an array.
+ internal ExifValue(ExifTag tag, ExifDataType dataType, object value, bool isArray)
+ {
+ this.Tag = tag;
+ this.DataType = dataType;
+ this.IsArray = isArray && dataType != ExifDataType.Ascii;
+ this.Value = value;
+ }
+
///
/// Initializes a new instance of the class
/// by making a copy from another exif value.
///
/// The other exif value, where the clone should be made from.
- /// is null.
- public ExifValue(ExifValue other)
+ /// is null.
+ private ExifValue(ExifValue other)
{
Guard.NotNull(other, nameof(other));
@@ -29,30 +44,17 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
if (!other.IsArray)
{
+ // All types are value types except for string which is immutable so safe to simply assign.
this.Value = other.Value;
}
else
{
+ // All array types are value types so Clone() is sufficient here.
var array = (Array)other.Value;
this.Value = array.Clone();
}
}
- ///
- /// Initializes a new instance of the class.
- ///
- /// The tag.
- /// The data type.
- /// The value.
- /// Whether the value is an array.
- internal ExifValue(ExifTag tag, ExifDataType dataType, object value, bool isArray)
- {
- this.Tag = tag;
- this.DataType = dataType;
- this.IsArray = isArray && dataType != ExifDataType.Ascii;
- this.Value = value;
- }
-
///
/// Gets the data type of the exif value.
///
@@ -145,10 +147,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
///
/// True if the parameter is equal to the parameter; otherwise, false.
///
- public static bool operator ==(ExifValue left, ExifValue right)
- {
- return ReferenceEquals(left, right) || left.Equals(right);
- }
+ public static bool operator ==(ExifValue left, ExifValue right) => ReferenceEquals(left, right) || left.Equals(right);
///
/// Compares two objects for equality.
@@ -162,16 +161,10 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
///
/// True if the parameter is not equal to the parameter; otherwise, false.
///
- public static bool operator !=(ExifValue left, ExifValue right)
- {
- return !(left == right);
- }
+ public static bool operator !=(ExifValue left, ExifValue right) => !(left == right);
///
- public override bool Equals(object obj)
- {
- return obj is ExifValue other && this.Equals(other);
- }
+ public override bool Equals(object obj) => obj is ExifValue other && this.Equals(other);
///
public bool Equals(ExifValue other)
@@ -187,9 +180,9 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
}
return
- this.Tag == other.Tag &&
- this.DataType == other.DataType &&
- object.Equals(this.Value, other.Value);
+ this.Tag == other.Tag
+ && this.DataType == other.DataType
+ && object.Equals(this.Value, other.Value);
}
///
@@ -205,10 +198,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
}
///
- public override int GetHashCode()
- {
- return this.GetHashCode(this);
- }
+ public override int GetHashCode() => this.GetHashCode(this);
///
public override string ToString()
@@ -238,6 +228,9 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
return sb.ToString();
}
+ ///
+ public ExifValue DeepClone() => new ExifValue(this);
+
///
/// Creates a new
///
@@ -584,7 +577,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
private static ExifValue CreateNumber(ExifTag tag, object value, bool isArray)
{
Type type = value?.GetType();
- if (type != null && type.IsArray)
+ if (type?.IsArray == true)
{
type = type.GetElementType();
}
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs
index dac56c608..44990b7ec 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs
@@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
///
/// Represents an ICC profile
///
- public sealed class IccProfile
+ public sealed class IccProfile : IDeepCloneable
{
///
/// The byte array to read the ICC profile from
@@ -42,23 +42,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// Initializes a new instance of the class.
///
/// The raw ICC profile data
- public IccProfile(byte[] data)
- {
- this.data = data;
- }
-
- ///
- /// Initializes a new instance of the class
- /// by making a copy from another ICC profile.
- ///
- /// The other ICC profile, where the clone should be made from.
- /// is null.>
- public IccProfile(IccProfile other)
- {
- Guard.NotNull(other, nameof(other));
-
- this.data = other.ToByteArray();
- }
+ public IccProfile(byte[] data) => this.data = data;
///
/// Initializes a new instance of the class.
@@ -74,6 +58,19 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
this.entries = new List(entries);
}
+ ///
+ /// Initializes a new instance of the class
+ /// by making a copy from another ICC profile.
+ ///
+ /// The other ICC profile, where the clone should be made from.
+ /// is null.>
+ private IccProfile(IccProfile other)
+ {
+ Guard.NotNull(other, nameof(other));
+
+ this.data = other.ToByteArray();
+ }
+
///
/// Gets or sets the profile header
///
@@ -100,6 +97,9 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
}
}
+ ///
+ public IccProfile DeepClone() => new IccProfile(this);
+
#if !NETSTANDARD1_1
///
diff --git a/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs
index a7cbb0337..a7e158925 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs
@@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
source.Frames.Select(x => new ImageFrame(source.GetConfiguration(), this.TargetDimensions, x.MetaData.DeepClone()));
// Use the overload to prevent an extra frame being added
- return new Image(source.GetConfiguration(), source.MetaData.Clone(), frames);
+ return new Image(source.GetConfiguration(), source.MetaData.DeepClone(), frames);
}
///
diff --git a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs
index ab1044df3..df1ac3274 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs
@@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
IEnumerable> frames = source.Frames.Select(x => new ImageFrame(source.GetConfiguration(), this.CropRectangle.Width, this.CropRectangle.Height, x.MetaData.DeepClone()));
// Use the overload to prevent an extra frame being added
- return new Image(source.GetConfiguration(), source.MetaData.Clone(), frames);
+ return new Image(source.GetConfiguration(), source.MetaData.DeepClone(), frames);
}
///
diff --git a/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs
index 680ce679e..15816cb4d 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs
@@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
source.Frames.Select(x => new ImageFrame(source.GetConfiguration(), this.TargetDimensions.Width, this.TargetDimensions.Height, x.MetaData.DeepClone()));
// Use the overload to prevent an extra frame being added
- return new Image(source.GetConfiguration(), source.MetaData.Clone(), frames);
+ return new Image(source.GetConfiguration(), source.MetaData.DeepClone(), frames);
}
///
diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs
index c3d766622..b1c0632c6 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs
@@ -218,7 +218,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
IEnumerable> frames = source.Frames.Select(x => new ImageFrame(source.GetConfiguration(), this.Width, this.Height, x.MetaData.DeepClone()));
// Use the overload to prevent an extra frame being added
- return new Image(source.GetConfiguration(), source.MetaData.Clone(), frames);
+ return new Image(source.GetConfiguration(), source.MetaData.DeepClone(), frames);
}
///
diff --git a/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs b/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs
index d681c90ba..8a6c51661 100644
--- a/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs
+++ b/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs
@@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Tests
metaData.VerticalResolution = 2;
metaData.Properties.Add(imageProperty);
- ImageMetaData clone = metaData.Clone();
+ ImageMetaData clone = metaData.DeepClone();
Assert.Equal(exifProfile.ToByteArray(), clone.ExifProfile.ToByteArray());
Assert.Equal(4, clone.HorizontalResolution);
diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs
index 3deb382ea..c10ffb6c8 100644
--- a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs
+++ b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs
@@ -67,16 +67,16 @@ namespace SixLabors.ImageSharp.Tests
[Fact]
public void ConstructorCopy()
{
- Assert.Throws(() => { new ExifProfile((ExifProfile)null); });
+ Assert.Throws(() => ((ExifProfile)null).DeepClone());
ExifProfile profile = GetExifProfile();
- var clone = new ExifProfile(profile);
+ ExifProfile clone = profile.DeepClone();
TestProfile(clone);
profile.SetValue(ExifTag.ColorSpace, (ushort)2);
- clone = new ExifProfile(profile);
+ clone = profile.DeepClone();
TestProfile(clone);
}
@@ -234,10 +234,12 @@ namespace SixLabors.ImageSharp.Tests
exifProfile.SetValue(ExifTag.XResolution, new Rational(200));
exifProfile.SetValue(ExifTag.YResolution, new Rational(300));
- var metaData = new ImageMetaData();
- metaData.ExifProfile = exifProfile;
- metaData.HorizontalResolution = 200;
- metaData.VerticalResolution = 300;
+ var metaData = new ImageMetaData
+ {
+ ExifProfile = exifProfile,
+ HorizontalResolution = 200,
+ VerticalResolution = 300
+ };
metaData.HorizontalResolution = 100;
@@ -355,11 +357,11 @@ namespace SixLabors.ImageSharp.Tests
// act
Image reloadedImage = WriteAndRead(image, imageFormat);
-
+
// assert
ExifProfile actual = reloadedImage.MetaData.ExifProfile;
Assert.NotNull(actual);
- foreach(KeyValuePair expectedProfileValue in TestProfileValues)
+ foreach (KeyValuePair expectedProfileValue in TestProfileValues)
{
ExifValue actualProfileValue = actual.GetValue(expectedProfileValue.Key);
Assert.NotNull(actualProfileValue);
@@ -371,7 +373,7 @@ namespace SixLabors.ImageSharp.Tests
public void ProfileToByteArray()
{
// arrange
- byte[] exifBytesWithExifCode = ProfileResolver.ExifMarker.Concat(ExifConstants.LittleEndianByteOrderMarker).ToArray();
+ byte[] exifBytesWithExifCode = ProfileResolver.ExifMarker.Concat(ExifConstants.LittleEndianByteOrderMarker).ToArray();
byte[] exifBytesWithoutExifCode = ExifConstants.LittleEndianByteOrderMarker;
ExifProfile expectedProfile = CreateExifProfile();
var expectedProfileTags = expectedProfile.Values.Select(x => x.Tag).ToList();
@@ -384,7 +386,7 @@ namespace SixLabors.ImageSharp.Tests
Assert.NotNull(actualBytes);
Assert.NotEmpty(actualBytes);
Assert.Equal(exifBytesWithoutExifCode, actualBytes.Take(exifBytesWithoutExifCode.Length).ToArray());
- foreach(ExifTag expectedProfileTag in expectedProfileTags)
+ foreach (ExifTag expectedProfileTag in expectedProfileTags)
{
ExifValue actualProfileValue = actualProfile.GetValue(expectedProfileTag);
ExifValue expectedProfileValue = expectedProfile.GetValue(expectedProfileTag);
@@ -396,7 +398,7 @@ namespace SixLabors.ImageSharp.Tests
{
var profile = new ExifProfile();
- foreach(KeyValuePair exifProfileValue in TestProfileValues)
+ foreach (KeyValuePair exifProfileValue in TestProfileValues)
{
profile.SetValue(exifProfileValue.Key, exifProfileValue.Value);
}
@@ -416,7 +418,7 @@ namespace SixLabors.ImageSharp.Tests
private static Image WriteAndRead(Image image, TestImageWriteFormat imageFormat)
{
- switch(imageFormat)
+ switch (imageFormat)
{
case TestImageWriteFormat.Jpeg:
return WriteAndReadJpeg(image);