Browse Source

Fix resizer

Former-commit-id: a30925b4f90f25bd8cbda4d71e43d45198a52d53
Former-commit-id: eb5b8f040d476372cfd3407a39fe9b6accfa659b
Former-commit-id: 83f1e75b1e63c585c83ea2ad836815c4cf0e5c10
pull/17/head
James Jackson-South 11 years ago
parent
commit
99a296efb4
  1. 6
      src/ImageProcessor/Samplers/ImageSampleExtensions.cs
  2. 19
      src/ImageProcessor/Samplers/Resize.cs
  3. 4
      tests/ImageProcessor.Tests/Filters/FilterTests.cs

6
src/ImageProcessor/Samplers/ImageSampleExtensions.cs

@ -12,17 +12,17 @@ namespace ImageProcessor.Samplers
{ {
public static Image Resize(this Image source, int width, int height) public static Image Resize(this Image source, int width, int height)
{ {
return source.Process(width, height, default(Rectangle), default(Rectangle), new Resize(new BicubicResampler(), width, height)); return source.Process(width, height, default(Rectangle), default(Rectangle), new Resize(new BicubicResampler()));
} }
public static Image Resize(this Image source, int width, int height, IResampler sampler) public static Image Resize(this Image source, int width, int height, IResampler sampler)
{ {
return source.Process(width, height, default(Rectangle), default(Rectangle), new Resize(sampler, width, height)); return source.Process(width, height, default(Rectangle), default(Rectangle), new Resize(sampler));
} }
public static Image Resize(this Image source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle) public static Image Resize(this Image source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle)
{ {
return source.Process(width, height, sourceRectangle, targetRectangle, new Resize(sampler, width, height)); return source.Process(width, height, sourceRectangle, targetRectangle, new Resize(sampler));
} }
} }
} }

19
src/ImageProcessor/Samplers/Resize.cs

@ -10,15 +10,11 @@ namespace ImageProcessor.Samplers
/// <param name="sampler"> /// <param name="sampler">
/// The sampler to perform the resize operation. /// The sampler to perform the resize operation.
/// </param> /// </param>
public Resize(IResampler sampler, int width, int height) public Resize(IResampler sampler)
{ {
Guard.NotNull(sampler, nameof(sampler)); Guard.NotNull(sampler, nameof(sampler));
Guard.MustBeGreaterThan(width, 0, nameof(width));
Guard.MustBeGreaterThan(height, 0, nameof(height));
this.Sampler = sampler; this.Sampler = sampler;
this.Width = width;
this.Height = height;
} }
/// <summary> /// <summary>
@ -26,16 +22,6 @@ namespace ImageProcessor.Samplers
/// </summary> /// </summary>
public IResampler Sampler { get; } public IResampler Sampler { get; }
/// <summary>
/// Gets the width.
/// </summary>
public int Width { get; }
/// <summary>
/// Gets the height.
/// </summary>
public int Height { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void Apply( protected override void Apply(
ImageBase target, ImageBase target,
@ -51,6 +37,7 @@ namespace ImageProcessor.Samplers
int width = target.Width; int width = target.Width;
int height = target.Height; int height = target.Height;
int targetY = targetRectangle.Y;
int startX = targetRectangle.X; int startX = targetRectangle.X;
int endX = targetRectangle.Right; int endX = targetRectangle.Right;
int right = (int)(this.Sampler.Radius + .5); int right = (int)(this.Sampler.Radius + .5);
@ -69,7 +56,7 @@ namespace ImageProcessor.Samplers
if (y >= 0 && y < height) if (y >= 0 && y < height)
{ {
// Y coordinates of source points. // Y coordinates of source points.
double originY = ((startY - targetRectangle.Y) * heightFactor) - 0.5; double originY = ((y - targetY) * heightFactor) - 0.5;
int originY1 = (int)originY; int originY1 = (int)originY;
double dy = originY - originY1; double dy = originY - originY1;

4
tests/ImageProcessor.Tests/Filters/FilterTests.cs

@ -14,12 +14,12 @@ namespace ImageProcessor.Tests.Filters
{ {
public static readonly List<string> Files = new List<string> public static readonly List<string> Files = new List<string>
{ {
//{ "../../TestImages/Formats/Jpg/Backdrop.jpg"}, { "../../TestImages/Formats/Jpg/Backdrop.jpg"},
//{ "../../TestImages/Formats/Bmp/Car.bmp" }, //{ "../../TestImages/Formats/Bmp/Car.bmp" },
//{ "../../TestImages/Formats/Png/cmyk.png" }, //{ "../../TestImages/Formats/Png/cmyk.png" },
//{ "../../TestImages/Formats/Gif/a.gif" }, //{ "../../TestImages/Formats/Gif/a.gif" },
//{ "../../TestImages/Formats/Gif/leaf.gif" }, //{ "../../TestImages/Formats/Gif/leaf.gif" },
{ "../../TestImages/Formats/Gif/ani.gif" }, //{ "../../TestImages/Formats/Gif/ani.gif" },
//{ "../../TestImages/Formats/Gif/ani2.gif" }, //{ "../../TestImages/Formats/Gif/ani2.gif" },
//{ "../../TestImages/Formats/Gif/giphy.gif" }, //{ "../../TestImages/Formats/Gif/giphy.gif" },
}; };

Loading…
Cancel
Save