Browse Source

Clone => DeepClone

af/merge-core
James Jackson-South 7 years ago
parent
commit
b36a58bcde
  1. 2
      src/ImageSharp/Formats/Bmp/BmpMetaData.cs
  2. 2
      src/ImageSharp/Formats/Gif/GifFrameMetaData.cs
  3. 2
      src/ImageSharp/Formats/Gif/GifMetaData.cs
  4. 2
      src/ImageSharp/Formats/Jpeg/JpegMetaData.cs
  5. 2
      src/ImageSharp/Formats/Png/PngMetaData.cs
  6. 4
      src/ImageSharp/IDeepCloneable.cs
  7. 18
      src/ImageSharp/ImageFrameCollection.cs
  8. 4
      src/ImageSharp/ImageFrame{TPixel}.cs
  9. 4
      src/ImageSharp/Image{TPixel}.cs
  10. 4
      src/ImageSharp/MetaData/ImageFrameMetaData.cs
  11. 8
      src/ImageSharp/MetaData/ImageMetaData.cs
  12. 4
      src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs
  13. 2
      src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs
  14. 2
      src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs
  15. 4
      src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs
  16. 4
      src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs
  17. 4
      src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs
  18. 4
      src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs
  19. 2
      tests/ImageSharp.Tests/Formats/Bmp/BmpMetaDataTests.cs
  20. 2
      tests/ImageSharp.Tests/Formats/Gif/GifFrameMetaDataTests.cs
  21. 2
      tests/ImageSharp.Tests/Formats/Gif/GifMetaDataTests.cs
  22. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegMetaDataTests.cs
  23. 2
      tests/ImageSharp.Tests/Formats/Png/PngMetaDataTests.cs
  24. 2
      tests/ImageSharp.Tests/MetaData/ImageFrameMetaDataTests.cs
  25. 4
      tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs
  26. 6
      tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs

2
src/ImageSharp/Formats/Bmp/BmpMetaData.cs

@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
public BmpBitsPerPixel BitsPerPixel { get; set; } = BmpBitsPerPixel.Pixel24;
/// <inheritdoc/>
public IDeepCloneable Clone() => new BmpMetaData(this);
public IDeepCloneable DeepClone() => new BmpMetaData(this);
// TODO: Colors used once we support encoding palette bmps.
}

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

@ -49,6 +49,6 @@ namespace SixLabors.ImageSharp.Formats.Gif
public GifDisposalMethod DisposalMethod { get; set; }
/// <inheritdoc/>
public IDeepCloneable Clone() => new GifFrameMetaData(this);
public IDeepCloneable DeepClone() => new GifFrameMetaData(this);
}
}

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

@ -45,6 +45,6 @@ namespace SixLabors.ImageSharp.Formats.Gif
public int GlobalColorTableLength { get; set; }
/// <inheritdoc/>
public IDeepCloneable Clone() => new GifMetaData(this);
public IDeepCloneable DeepClone() => new GifMetaData(this);
}
}

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

@ -27,6 +27,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
public int Quality { get; set; } = 75;
/// <inheritdoc/>
public IDeepCloneable Clone() => new JpegMetaData(this);
public IDeepCloneable DeepClone() => new JpegMetaData(this);
}
}

2
src/ImageSharp/Formats/Png/PngMetaData.cs

@ -43,6 +43,6 @@ namespace SixLabors.ImageSharp.Formats.Png
public float Gamma { get; set; }
/// <inheritdoc/>
public IDeepCloneable Clone() => new PngMetaData(this);
public IDeepCloneable DeepClone() => new PngMetaData(this);
}
}

4
src/ImageSharp/IDeepCloneable.cs

@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp
/// Creates a new <typeparamref name="T"/> that is a deep copy of the current instance.
/// </summary>
/// <returns>The <typeparamref name="T"/>.</returns>
T Clone();
T DeepClone();
}
/// <summary>
@ -26,6 +26,6 @@ namespace SixLabors.ImageSharp
/// Creates a new object that is a deep copy of the current instance.
/// </summary>
/// <returns>The <see cref="IDeepCloneable"/>.</returns>
IDeepCloneable Clone();
IDeepCloneable DeepClone();
}
}

18
src/ImageSharp/ImageFrameCollection.cs

@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp
public ImageFrame<TPixel> InsertFrame(int index, ImageFrame<TPixel> source)
{
this.ValidateFrame(source);
ImageFrame<TPixel> clonedFrame = source.Clone();
ImageFrame<TPixel> clonedFrame = source.Clone(this.parent.GetConfiguration());
this.frames.Insert(index, clonedFrame);
return clonedFrame;
}
@ -107,7 +107,7 @@ namespace SixLabors.ImageSharp
public ImageFrame<TPixel> AddFrame(ImageFrame<TPixel> source)
{
this.ValidateFrame(source);
ImageFrame<TPixel> clonedFrame = source.Clone();
ImageFrame<TPixel> clonedFrame = source.Clone(this.parent.GetConfiguration());
this.frames.Add(clonedFrame);
return clonedFrame;
}
@ -155,10 +155,7 @@ namespace SixLabors.ImageSharp
/// <returns>
/// <c>true</c> if the <seealso cref="ImageFrameCollection{TPixel}"/> contains the specified frame; otherwise, <c>false</c>.
/// </returns>
public bool Contains(ImageFrame<TPixel> frame)
{
return this.frames.Contains(frame);
}
public bool Contains(ImageFrame<TPixel> frame) => this.frames.Contains(frame);
/// <summary>
/// Moves an <seealso cref="ImageFrame{TPixel}"/> from <paramref name="sourceIndex"/> to <paramref name="destinationIndex"/>.
@ -195,7 +192,7 @@ namespace SixLabors.ImageSharp
this.frames.Remove(frame);
return new Image<TPixel>(this.parent.GetConfiguration(), this.parent.MetaData.Clone(), new[] { frame });
return new Image<TPixel>(this.parent.GetConfiguration(), this.parent.MetaData.DeepClone(), new[] { frame });
}
/// <summary>
@ -208,7 +205,7 @@ namespace SixLabors.ImageSharp
{
ImageFrame<TPixel> frame = this[index];
ImageFrame<TPixel> clonedFrame = frame.Clone();
return new Image<TPixel>(this.parent.GetConfiguration(), this.parent.MetaData.Clone(), new[] { clonedFrame });
return new Image<TPixel>(this.parent.GetConfiguration(), this.parent.MetaData.DeepClone(), new[] { clonedFrame });
}
/// <summary>
@ -217,10 +214,7 @@ namespace SixLabors.ImageSharp
/// <returns>
/// The new <see cref="ImageFrame{TPixel}" />.
/// </returns>
public ImageFrame<TPixel> CreateFrame()
{
return this.CreateFrame(default);
}
public ImageFrame<TPixel> CreateFrame() => this.CreateFrame(default);
/// <summary>
/// Creates a new <seealso cref="ImageFrame{TPixel}" /> and appends it to the end of the collection.

4
src/ImageSharp/ImageFrame{TPixel}.cs

@ -139,7 +139,7 @@ namespace SixLabors.ImageSharp
this.MemoryAllocator = configuration.MemoryAllocator;
this.PixelBuffer = this.MemoryAllocator.Allocate2D<TPixel>(source.PixelBuffer.Width, source.PixelBuffer.Height);
source.PixelBuffer.GetSpan().CopyTo(this.PixelBuffer.GetSpan());
this.MetaData = source.MetaData.Clone();
this.MetaData = source.MetaData.DeepClone();
}
/// <summary>
@ -286,7 +286,7 @@ namespace SixLabors.ImageSharp
return this.Clone(configuration) as ImageFrame<TPixel2>;
}
var target = new ImageFrame<TPixel2>(configuration, this.Width, this.Height, this.MetaData.Clone());
var target = new ImageFrame<TPixel2>(configuration, this.Width, this.Height, this.MetaData.DeepClone());
ParallelFor.WithTemporaryBuffer(
0,

4
src/ImageSharp/Image{TPixel}.cs

@ -193,7 +193,7 @@ namespace SixLabors.ImageSharp
public Image<TPixel> Clone(Configuration configuration)
{
IEnumerable<ImageFrame<TPixel>> clonedFrames = this.Frames.Select(x => x.Clone(configuration));
return new Image<TPixel>(configuration, this.MetaData.Clone(), clonedFrames);
return new Image<TPixel>(configuration, this.MetaData.DeepClone(), clonedFrames);
}
/// <summary>
@ -214,7 +214,7 @@ namespace SixLabors.ImageSharp
where TPixel2 : struct, IPixel<TPixel2>
{
IEnumerable<ImageFrame<TPixel2>> clonedFrames = this.Frames.Select(x => x.CloneAs<TPixel2>(configuration));
return new Image<TPixel2>(configuration, this.MetaData.Clone(), clonedFrames);
return new Image<TPixel2>(configuration, this.MetaData.DeepClone(), clonedFrames);
}
/// <inheritdoc/>

4
src/ImageSharp/MetaData/ImageFrameMetaData.cs

@ -33,12 +33,12 @@ namespace SixLabors.ImageSharp.MetaData
foreach (KeyValuePair<IImageFormat, IDeepCloneable> meta in other.formatMetaData)
{
this.formatMetaData.Add(meta.Key, meta.Value.Clone());
this.formatMetaData.Add(meta.Key, meta.Value.DeepClone());
}
}
/// <inheritdoc/>
public ImageFrameMetaData Clone() => new ImageFrameMetaData(this);
public ImageFrameMetaData DeepClone() => new ImageFrameMetaData(this);
/// <summary>
/// Gets the metadata value associated with the specified key.

8
src/ImageSharp/MetaData/ImageMetaData.cs

@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.MetaData
foreach (KeyValuePair<IImageFormat, IDeepCloneable> meta in other.formatMetaData)
{
this.formatMetaData.Add(meta.Key, meta.Value.Clone());
this.formatMetaData.Add(meta.Key, meta.Value.DeepClone());
}
foreach (ImageProperty property in other.Properties)
@ -68,8 +68,8 @@ namespace SixLabors.ImageSharp.MetaData
this.Properties.Add(property);
}
this.ExifProfile = other.ExifProfile?.Clone();
this.IccProfile = other.IccProfile?.Clone();
this.ExifProfile = other.ExifProfile?.DeepClone();
this.IccProfile = other.IccProfile?.DeepClone();
}
/// <summary>
@ -154,7 +154,7 @@ namespace SixLabors.ImageSharp.MetaData
}
/// <inheritdoc/>
public ImageMetaData Clone() => new ImageMetaData(this);
public ImageMetaData DeepClone() => new ImageMetaData(this);
/// <summary>
/// Looks up a property with the provided name.

4
src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs

@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
foreach (ExifValue value in other.Values)
{
this.values.Add(value.Clone());
this.values.Add(value.DeepClone());
}
}
@ -242,7 +242,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
}
/// <inheritdoc/>
public ExifProfile Clone() => new ExifProfile(this);
public ExifProfile DeepClone() => new ExifProfile(this);
/// <summary>
/// Synchronizes the profiles with the specified meta data.

2
src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs

@ -229,7 +229,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
}
/// <inheritdoc/>
public ExifValue Clone() => new ExifValue(this);
public ExifValue DeepClone() => new ExifValue(this);
/// <summary>
/// Creates a new <see cref="ExifValue"/>

2
src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs

@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
}
/// <inheritdoc/>
public IccProfile Clone() => new IccProfile(this);
public IccProfile DeepClone() => new IccProfile(this);
#if !NETSTANDARD1_1

4
src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs

@ -51,10 +51,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{
// We will always be creating the clone even for mutate because we may need to resize the canvas
IEnumerable<ImageFrame<TPixel>> frames =
source.Frames.Select(x => new ImageFrame<TPixel>(source.GetConfiguration(), this.TargetDimensions, x.MetaData.Clone()));
source.Frames.Select(x => new ImageFrame<TPixel>(source.GetConfiguration(), this.TargetDimensions, x.MetaData.DeepClone()));
// Use the overload to prevent an extra frame being added
return new Image<TPixel>(source.GetConfiguration(), source.MetaData.Clone(), frames);
return new Image<TPixel>(source.GetConfiguration(), source.MetaData.DeepClone(), frames);
}
/// <inheritdoc/>

4
src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs

@ -36,10 +36,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
protected override Image<TPixel> CreateDestination(Image<TPixel> source, Rectangle sourceRectangle)
{
// We will always be creating the clone even for mutate because we may need to resize the canvas
IEnumerable<ImageFrame<TPixel>> frames = source.Frames.Select(x => new ImageFrame<TPixel>(source.GetConfiguration(), this.CropRectangle.Width, this.CropRectangle.Height, x.MetaData.Clone()));
IEnumerable<ImageFrame<TPixel>> frames = source.Frames.Select(x => new ImageFrame<TPixel>(source.GetConfiguration(), this.CropRectangle.Width, this.CropRectangle.Height, x.MetaData.DeepClone()));
// Use the overload to prevent an extra frame being added
return new Image<TPixel>(source.GetConfiguration(), source.MetaData.Clone(), frames);
return new Image<TPixel>(source.GetConfiguration(), source.MetaData.DeepClone(), frames);
}
/// <inheritdoc/>

4
src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs

@ -51,10 +51,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{
// We will always be creating the clone even for mutate because we may need to resize the canvas
IEnumerable<ImageFrame<TPixel>> frames =
source.Frames.Select(x => new ImageFrame<TPixel>(source.GetConfiguration(), this.TargetDimensions.Width, this.TargetDimensions.Height, x.MetaData.Clone()));
source.Frames.Select(x => new ImageFrame<TPixel>(source.GetConfiguration(), this.TargetDimensions.Width, this.TargetDimensions.Height, x.MetaData.DeepClone()));
// Use the overload to prevent an extra frame being added
return new Image<TPixel>(source.GetConfiguration(), source.MetaData.Clone(), frames);
return new Image<TPixel>(source.GetConfiguration(), source.MetaData.DeepClone(), frames);
}
/// <inheritdoc/>

4
src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs

@ -215,10 +215,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
protected override Image<TPixel> CreateDestination(Image<TPixel> source, Rectangle sourceRectangle)
{
// We will always be creating the clone even for mutate because we may need to resize the canvas
IEnumerable<ImageFrame<TPixel>> frames = source.Frames.Select(x => new ImageFrame<TPixel>(source.GetConfiguration(), this.Width, this.Height, x.MetaData.Clone()));
IEnumerable<ImageFrame<TPixel>> frames = source.Frames.Select(x => new ImageFrame<TPixel>(source.GetConfiguration(), this.Width, this.Height, x.MetaData.DeepClone()));
// Use the overload to prevent an extra frame being added
return new Image<TPixel>(source.GetConfiguration(), source.MetaData.Clone(), frames);
return new Image<TPixel>(source.GetConfiguration(), source.MetaData.DeepClone(), frames);
}
/// <inheritdoc/>

2
tests/ImageSharp.Tests/Formats/Bmp/BmpMetaDataTests.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
public void CloneIsDeep()
{
var meta = new BmpMetaData() { BitsPerPixel = BmpBitsPerPixel.Pixel24 };
var clone = (BmpMetaData)meta.Clone();
var clone = (BmpMetaData)meta.DeepClone();
clone.BitsPerPixel = BmpBitsPerPixel.Pixel32;

2
tests/ImageSharp.Tests/Formats/Gif/GifFrameMetaDataTests.cs

@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
ColorTableLength = 2
};
var clone = (GifFrameMetaData)meta.Clone();
var clone = (GifFrameMetaData)meta.DeepClone();
clone.FrameDelay = 2;
clone.DisposalMethod = GifDisposalMethod.RestoreToPrevious;

2
tests/ImageSharp.Tests/Formats/Gif/GifMetaDataTests.cs

@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
GlobalColorTableLength = 2
};
var clone = (GifMetaData)meta.Clone();
var clone = (GifMetaData)meta.DeepClone();
clone.RepeatCount = 2;
clone.ColorTableMode = GifColorTableMode.Local;

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

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void CloneIsDeep()
{
var meta = new JpegMetaData() { Quality = 50 };
var clone = (JpegMetaData)meta.Clone();
var clone = (JpegMetaData)meta.DeepClone();
clone.Quality = 99;

2
tests/ImageSharp.Tests/Formats/Png/PngMetaDataTests.cs

@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
ColorType = PngColorType.GrayscaleWithAlpha,
Gamma = 2
};
var clone = (PngMetaData)meta.Clone();
var clone = (PngMetaData)meta.DeepClone();
clone.BitDepth = PngBitDepth.Bit2;
clone.ColorType = PngColorType.Palette;

2
tests/ImageSharp.Tests/MetaData/ImageFrameMetaDataTests.cs

@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Tests
public void CloneIsDeep()
{
var metaData = new ImageFrameMetaData();
ImageFrameMetaData clone = metaData.Clone();
ImageFrameMetaData clone = metaData.DeepClone();
Assert.False(metaData.GetFormatMetaData(GifFormat.Instance).Equals(clone.GetFormatMetaData(GifFormat.Instance)));
}
}

4
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);
@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests
metaData.VerticalResolution = 2;
metaData.Properties.Add(imageProperty);
ImageMetaData clone = metaData.Clone();
ImageMetaData clone = metaData.DeepClone();
clone.HorizontalResolution = 2;
clone.VerticalResolution = 4;

6
tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs

@ -67,16 +67,16 @@ namespace SixLabors.ImageSharp.Tests
[Fact]
public void ConstructorCopy()
{
Assert.Throws<NullReferenceException>(() => ((ExifProfile)null).Clone());
Assert.Throws<NullReferenceException>(() => ((ExifProfile)null).DeepClone());
ExifProfile profile = GetExifProfile();
ExifProfile clone = profile.Clone();
ExifProfile clone = profile.DeepClone();
TestProfile(clone);
profile.SetValue(ExifTag.ColorSpace, (ushort)2);
clone = profile.Clone();
clone = profile.DeepClone();
TestProfile(clone);
}

Loading…
Cancel
Save