Browse Source

Rename Generate -> Clone

pull/275/head
Scott Williams 9 years ago
parent
commit
a61fcc95d9
  1. 6
      samples/AvatarWithRoundedCorner/Program.cs
  2. 2
      src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs
  3. 10
      src/ImageSharp/ApplyProcessors.cs
  4. 9
      src/ImageSharp/Image/Image{TPixel}.cs
  5. 2
      tests/ImageSharp.Tests/ImageComparer.cs

6
samples/AvatarWithRoundedCorner/Program.cs

@ -16,17 +16,17 @@ namespace AvatarWithRoundedCorner
using (var img = Image.Load("fb.jpg")) using (var img = Image.Load("fb.jpg"))
{ {
// as generate returns a new IImage make sure we dispose of it // as generate returns a new IImage make sure we dispose of it
using (Image<Rgba32> dest = img.Generate(x => x.ConvertToAvatar(new Size(200, 200), 20))) using (Image<Rgba32> dest = img.Clone(x => x.ConvertToAvatar(new Size(200, 200), 20)))
{ {
dest.Save("output/fb.png"); dest.Save("output/fb.png");
} }
using (Image<Rgba32> destRound = img.Generate(x => x.ConvertToAvatar(new Size(200, 200), 100))) using (Image<Rgba32> destRound = img.Clone(x => x.ConvertToAvatar(new Size(200, 200), 100)))
{ {
destRound.Save("output/fb-round.png"); destRound.Save("output/fb-round.png");
} }
using (Image<Rgba32> destRound = img.Generate(x => x.ConvertToAvatar(new Size(200, 200), 150))) using (Image<Rgba32> destRound = img.Clone(x => x.ConvertToAvatar(new Size(200, 200), 150)))
{ {
destRound.Save("output/fb-rounder.png"); destRound.Save("output/fb-rounder.png");
} }

2
src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs

@ -70,7 +70,7 @@ namespace ImageSharp.Drawing.Processors
{ {
if (targetImage.Bounds.Size != this.Size) if (targetImage.Bounds.Size != this.Size)
{ {
targetImage = disposableImage = this.Image.Generate(x => x.Resize(this.Size.Width, this.Size.Height)); targetImage = disposableImage = this.Image.Clone(x => x.Resize(this.Size.Width, this.Size.Height));
} }
// Align start/end positions. // Align start/end positions.

10
src/ImageSharp/ApplyProcessors.cs

@ -49,13 +49,13 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Mutates the image by applying the operations to it. /// Clones the current image mutating the clone by applying the operations to it.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to rotate, flip, or both.</param> /// <param name="source">The image to rotate, flip, or both.</param>
/// <param name="operations">The operations to perform on the source.</param> /// <param name="operations">The operations to perform on the source.</param>
/// <returns>Anew Image which has teh data from the <paramref name="source"/> but with the <paramref name="operations"/> applied.</returns> /// <returns>Anew Image which has teh data from the <paramref name="source"/> but with the <paramref name="operations"/> applied.</returns>
public static Image<TPixel> Generate<TPixel>(this Image<TPixel> source, Action<IImageOperations<TPixel>> operations) public static Image<TPixel> Clone<TPixel>(this Image<TPixel> source, Action<IImageOperations<TPixel>> operations)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
Guard.NotNull(operations, nameof(operations)); Guard.NotNull(operations, nameof(operations));
@ -68,13 +68,13 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Mutates the image by applying the operations to it. /// Clones the current image mutating the clone by applying the operations to it.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to rotate, flip, or both.</param> /// <param name="source">The image to rotate, flip, or both.</param>
/// <param name="operations">The operations to perform on the source.</param> /// <param name="operations">The operations to perform on the source.</param>
/// <returns>Anew Image which has teh data from the <paramref name="source"/> but with the <paramref name="operations"/> applied.</returns> /// <returns>Anew Image which has teh data from the <paramref name="source"/> but with the <paramref name="operations"/> applied.</returns>
public static Image<TPixel> Generate<TPixel>(this Image<TPixel> source, params IImageProcessor<TPixel>[] operations) public static Image<TPixel> Clone<TPixel>(this Image<TPixel> source, params IImageProcessor<TPixel>[] operations)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
Guard.NotNull(operations, nameof(operations)); Guard.NotNull(operations, nameof(operations));
@ -87,7 +87,7 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Mutates the image by applying the operations to it. /// Queues up a simple operation that provides access to the mutatable image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to rotate, flip, or both.</param> /// <param name="source">The image to rotate, flip, or both.</param>

9
src/ImageSharp/Image/Image{TPixel}.cs

@ -250,6 +250,15 @@ namespace ImageSharp
} }
#endif #endif
/// <summary>
/// Clones the current image
/// </summary>
/// <returns>Returns a new image with all the same metadata as the original.</returns>
public Image<TPixel> Clone()
{
return new Image<TPixel>(this);
}
/// <inheritdoc/> /// <inheritdoc/>
public override string ToString() public override string ToString()
{ {

2
tests/ImageSharp.Tests/ImageComparer.cs

@ -138,7 +138,7 @@ namespace ImageSharp.Tests
where TPixelA : struct, IPixel<TPixelA> where TPixelA : struct, IPixel<TPixelA>
{ {
byte[] buffer = new byte[3]; byte[] buffer = new byte[3];
using (Image<TPixelA> img = source.Generate(x => x.Resize(scalingFactor, scalingFactor).Grayscale())) using (Image<TPixelA> img = source.Clone(x => x.Resize(scalingFactor, scalingFactor).Grayscale()))
{ {
using (PixelAccessor<TPixelA> pixels = img.Lock()) using (PixelAccessor<TPixelA> pixels = img.Lock())
{ {

Loading…
Cancel
Save