Browse Source

Fix broken tests and cleanup.

Former-commit-id: 8ffd61fd16ba32d300ae6cb0bd4a1f4d40915097
Former-commit-id: 2d3f52bf43aaaf8dec769b5f8d537523ad27769f
Former-commit-id: 91c3011b36fc412d8a17ec6102357e7108160813
af/merge-core
James Jackson-South 10 years ago
parent
commit
8a79e364cf
  1. 4
      src/ImageProcessor/Common/Helpers/ImageMaths.cs
  2. 21
      src/ImageProcessor/Image.cs
  3. 6
      src/ImageProcessor/ParallelImageProcessor.cs
  4. 16
      src/ImageProcessor/Samplers/EntropyCrop.cs
  5. 6
      src/ImageProcessor/Samplers/Resampler.cs
  6. 2
      src/ImageProcessor/project.json
  7. 56
      tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs
  8. 23
      tests/ImageProcessor.Tests/Processors/ProcessorTestBase.cs
  9. 1
      tests/ImageProcessor.Tests/TestImages/Formats/Gif/ani2.gif.REMOVED.git-id
  10. 3
      tests/ImageProcessor.Tests/TestImages/Formats/Gif/ben2.gif
  11. 1
      tests/ImageProcessor.Tests/TestImages/Formats/Gif/leaf.gif.REMOVED.git-id
  12. 3
      tests/ImageProcessor.Tests/TestImages/Formats/Jpg/Backdrop.jpg
  13. 1
      tests/ImageProcessor.Tests/TestImages/Formats/Jpg/ant.jpg.REMOVED.git-id
  14. 1
      tests/ImageProcessor.Tests/TestImages/Formats/Jpg/china.jpg.REMOVED.git-id
  15. 1
      tests/ImageProcessor.Tests/TestImages/Formats/Jpg/greyscale.jpg.REMOVED.git-id
  16. 3
      tests/ImageProcessor.Tests/TestImages/Formats/Jpg/lomo.jpg
  17. 3
      tests/ImageProcessor.Tests/TestImages/Formats/Jpg/parachute.jpg
  18. 1
      tests/ImageProcessor.Tests/TestImages/Formats/Jpg/shaftesbury.jpg.REMOVED.git-id
  19. 1
      tests/ImageProcessor.Tests/TestImages/Formats/Png/cballs.png.REMOVED.git-id
  20. 3
      tests/ImageProcessor.Tests/TestImages/Formats/Png/cmyk.png
  21. 3
      tests/ImageProcessor.Tests/TestImages/Formats/Png/gamma-1.0-or-2.2.png

4
src/ImageProcessor/Common/Helpers/ImageMaths.cs

@ -298,8 +298,8 @@ namespace ImageProcessor
topLeft.Y = getMinY(bitmap);
topLeft.X = getMinX(bitmap);
bottomRight.Y = getMaxY(bitmap) + 1;
bottomRight.X = getMaxX(bitmap) + 1;
bottomRight.Y = (getMaxY(bitmap) + 1).Clamp(0, height);
bottomRight.X = (getMaxX(bitmap) + 1).Clamp(0, width);
return GetBoundingRectangle(topLeft, bottomRight);
}

21
src/ImageProcessor/Image.cs

@ -81,8 +81,6 @@ namespace ImageProcessor
public Image(Image other)
: base(other)
{
Guard.NotNull(other, nameof(other), "Other image cannot be null.");
foreach (ImageFrame frame in other.Frames)
{
if (frame != null)
@ -96,6 +94,25 @@ namespace ImageProcessor
this.CurrentImageFormat = other.CurrentImageFormat;
}
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class.
/// </summary>
/// <param name="other">
/// The other <see cref="ImageFrame"/> to create this instance from.
/// </param>
/// <exception cref="ArgumentNullException">
/// Thrown if the given <see cref="ImageFrame"/> is null.
/// </exception>
public Image(ImageFrame other)
: base(other)
{
this.HorizontalResolution = DefaultHorizontalResolution;
this.VerticalResolution = DefaultVerticalResolution;
// Most likely a gif
this.CurrentImageFormat = DefaultFormats.Value.First(f => f.GetType() == typeof(GifFormat));
}
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class.
/// </summary>

6
src/ImageProcessor/ParallelImageProcessor.cs

@ -22,7 +22,8 @@ namespace ImageProcessor
public void Apply(ImageBase target, ImageBase source, Rectangle sourceRectangle)
{
// We don't want to affect the original source pixels so we make clone here.
Image temp = new Image((Image)source);
ImageFrame frame = source as ImageFrame;
Image temp = frame != null ? new Image(frame) : new Image((Image)source);
this.OnApply(temp, target, target.Bounds, sourceRectangle);
if (this.Parallelism > 1)
@ -64,7 +65,8 @@ namespace ImageProcessor
}
// We don't want to affect the original source pixels so we make clone here.
Image temp = new Image((Image)source);
ImageFrame frame = source as ImageFrame;
Image temp = frame != null ? new Image(frame) : new Image((Image)source);
this.OnApply(temp, target, target.Bounds, sourceRectangle);
targetRectangle = target.Bounds;

16
src/ImageProcessor/Samplers/EntropyCrop.cs

@ -58,10 +58,18 @@ namespace ImageProcessor.Samplers
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
if (source.Bounds == target.Bounds)
{
target.SetPixels(target.Width, target.Height, source.Pixels);
return;
}
int targetY = this.cropRectangle.Y;
int startX = targetRectangle.X;
int targetX = this.cropRectangle.X;
int endX = this.cropRectangle.Width;
int maxX = endX - 1;
int maxY = this.cropRectangle.Bottom - 1;
Parallel.For(
startY,
@ -70,7 +78,13 @@ namespace ImageProcessor.Samplers
{
for (int x = startX; x < endX; x++)
{
target[x, y] = source[x + targetX, y + targetY];
int offsetY = y + targetY;
offsetY = offsetY.Clamp(0, maxY);
int offsetX = x + targetX;
offsetX = offsetX.Clamp(0, maxX);
target[x, y] = source[offsetX, offsetY];
}
});
}

6
src/ImageProcessor/Samplers/Resampler.cs

@ -115,6 +115,12 @@ namespace ImageProcessor.Samplers
/// </remarks>
private void ApplyResizeOnly(ImageBase target, ImageBase source, Rectangle targetRectangle, int startY, int endY)
{
if (source.Bounds == target.Bounds)
{
target.SetPixels(target.Width, target.Height, source.Pixels);
return;
}
int targetY = targetRectangle.Y;
int targetBottom = targetRectangle.Bottom;
int startX = targetRectangle.X;

2
src/ImageProcessor/project.json

@ -24,6 +24,6 @@
"Microsoft.NETCore.Platforms": "1.0.1-beta-23516"
},
"frameworks": {
"dotnet5.4": { }
"dnxcore50": { }
}
}

56
tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs

@ -13,35 +13,35 @@ namespace ImageProcessor.Tests
{
public static readonly TheoryData<string, IImageProcessor> Filters = new TheoryData<string, IImageProcessor>
{
//{ "Brightness-50", new Brightness(50) },
//{ "Brightness--50", new Brightness(-50) },
//{ "Contrast-50", new Contrast(50) },
//{ "Contrast--50", new Contrast(-50) },
//{ "BackgroundColor", new BackgroundColor(new Color(243 / 255f, 87 / 255f, 161 / 255f))},
//{ "Blend", new Blend(new Image(File.OpenRead("TestImages/Formats/Bmp/Car.bmp")),50)},
//{ "Saturation-50", new Saturation(50) },
//{ "Saturation--50", new Saturation(-50) },
//{ "Alpha--50", new Alpha(50) },
//{ "Invert", new Invert() },
//{ "Sepia", new Sepia() },
//{ "BlackWhite", new BlackWhite() },
//{ "Lomograph", new Lomograph() },
//{ "Polaroid", new Polaroid() },
//{ "Kodachrome", new Kodachrome() },
//{ "GreyscaleBt709", new GreyscaleBt709() },
//{ "GreyscaleBt601", new GreyscaleBt601() },
//{ "Kayyali", new Kayyali() },
//{ "Kirsch", new Kirsch() },
//{ "Laplacian3X3", new Laplacian3X3() },
//{ "Laplacian5X5", new Laplacian5X5() },
//{ "LaplacianOfGaussian", new LaplacianOfGaussian() },
//{ "Prewitt", new Prewitt() },
//{ "RobertsCross", new RobertsCross() },
//{ "Scharr", new Scharr() },
//{ "Sobel", new Sobel {Greyscale = true} },
{ "Brightness-50", new Brightness(50) },
{ "Brightness--50", new Brightness(-50) },
{ "Contrast-50", new Contrast(50) },
{ "Contrast--50", new Contrast(-50) },
{ "BackgroundColor", new BackgroundColor(new Color(243 / 255f, 87 / 255f, 161 / 255f))},
{ "Blend", new Blend(new Image(File.OpenRead("TestImages/Formats/Bmp/Car.bmp")),50)},
{ "Saturation-50", new Saturation(50) },
{ "Saturation--50", new Saturation(-50) },
{ "Alpha--50", new Alpha(50) },
{ "Invert", new Invert() },
{ "Sepia", new Sepia() },
{ "BlackWhite", new BlackWhite() },
{ "Lomograph", new Lomograph() },
{ "Polaroid", new Polaroid() },
{ "Kodachrome", new Kodachrome() },
{ "GreyscaleBt709", new GreyscaleBt709() },
{ "GreyscaleBt601", new GreyscaleBt601() },
{ "Kayyali", new Kayyali() },
{ "Kirsch", new Kirsch() },
{ "Laplacian3X3", new Laplacian3X3() },
{ "Laplacian5X5", new Laplacian5X5() },
{ "LaplacianOfGaussian", new LaplacianOfGaussian() },
{ "Prewitt", new Prewitt() },
{ "RobertsCross", new RobertsCross() },
{ "Scharr", new Scharr() },
{ "Sobel", new Sobel {Greyscale = true} },
{ "Pixelate", new Pixelate(8) },
//{ "GuassianBlur", new GuassianBlur(10) },
//{ "GuassianSharpen", new GuassianSharpen(10) }
{ "GuassianBlur", new GuassianBlur(10) },
{ "GuassianSharpen", new GuassianSharpen(10) }
};
[Theory]

23
tests/ImageProcessor.Tests/Processors/ProcessorTestBase.cs

@ -19,26 +19,13 @@ namespace ImageProcessor.Tests
/// </summary>
public static readonly List<string> Files = new List<string>
{
//"TestImages/Formats/Jpg/Backdrop.jpg",
"TestImages/Formats/Jpg/Calliphora.jpg",
//"TestImages/Formats/Jpg/china.jpg",
//"TestImages/Formats/Jpg/ant.jpg",
//"TestImages/Formats/Jpg/parachute.jpg",
//"TestImages/Formats/Jpg/lomo.jpg",
//"TestImages/Formats/Jpg/shaftesbury.jpg",
//"TestImages/Formats/Jpg/gamma_dalai_lama_gray.jpg",
//"TestImages/Formats/Jpg/greyscale.jpg",
"TestImages/Formats/Jpg/gamma_dalai_lama_gray.jpg",
"TestImages/Formats/Bmp/Car.bmp",
//"TestImages/Formats/Png/cballs.png",
//"TestImages/Formats/Png/blur.png",
//"TestImages/Formats/Png/cmyk.png",
//"TestImages/Formats/Png/gamma-1.0-or-2.2.png",
//"TestImages/Formats/Png/splash.png",
//"TestImages/Formats/Gif/leaf.gif",
//"TestImages/Formats/Gif/ben2.gif",
//"TestImages/Formats/Gif/rings.gif",
//"TestImages/Formats/Gif/ani2.gif",
//"TestImages/Formats/Gif/giphy.gif"
"TestImages/Formats/Png/blur.png",
"TestImages/Formats/Png/splash.png",
"TestImages/Formats/Gif/rings.gif",
"TestImages/Formats/Gif/giphy.gif"
};
}
}

1
tests/ImageProcessor.Tests/TestImages/Formats/Gif/ani2.gif.REMOVED.git-id

@ -1 +0,0 @@
c2c7a5fcc0f00cdef39dacd7df0816137b3d63a3

3
tests/ImageProcessor.Tests/TestImages/Formats/Gif/ben2.gif

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e69e47e78320e848efd07d83e265328a749cafde65291c0d7e7bdba90ba658c3
size 50960

1
tests/ImageProcessor.Tests/TestImages/Formats/Gif/leaf.gif.REMOVED.git-id

@ -1 +0,0 @@
98e8f0bd9cd631e784bcc356a589d87989d43176

3
tests/ImageProcessor.Tests/TestImages/Formats/Jpg/Backdrop.jpg

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:048c66eb1d5257d36319da28ca24837429e0604682e4ebb74778175fbbb18db9
size 49595

1
tests/ImageProcessor.Tests/TestImages/Formats/Jpg/ant.jpg.REMOVED.git-id

@ -1 +0,0 @@
1da0ed59ed220f32d72b01e6cbb9c73a7f3b9b35

1
tests/ImageProcessor.Tests/TestImages/Formats/Jpg/china.jpg.REMOVED.git-id

@ -1 +0,0 @@
8cee90e94f9f09e04697bee0477bb5059b85c63f

1
tests/ImageProcessor.Tests/TestImages/Formats/Jpg/greyscale.jpg.REMOVED.git-id

@ -1 +0,0 @@
aca934c81771312563d8db52eedd95bb01164048

3
tests/ImageProcessor.Tests/TestImages/Formats/Jpg/lomo.jpg

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:bdfad9ce367629518c374b27b8ce311d1f0326f61b9a0ed113b5b966dd3dd1bc
size 45508

3
tests/ImageProcessor.Tests/TestImages/Formats/Jpg/parachute.jpg

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:88f4e06fb00ecdcc663a8ba4227dc89be2e3b000bd39246d6bc4adb6450520b3
size 28324

1
tests/ImageProcessor.Tests/TestImages/Formats/Jpg/shaftesbury.jpg.REMOVED.git-id

@ -1 +0,0 @@
2eabac96326130ba423b3fecb5a163b734278370

1
tests/ImageProcessor.Tests/TestImages/Formats/Png/cballs.png.REMOVED.git-id

@ -1 +0,0 @@
58c3318271250961bfac9fe6e9c8b0053e1b8e28

3
tests/ImageProcessor.Tests/TestImages/Formats/Png/cmyk.png

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2e17ba8fac1fd6247ff839ab7e21d715c96b3588d5f4fdb835dbe8c937dbf79d
size 37678

3
tests/ImageProcessor.Tests/TestImages/Formats/Png/gamma-1.0-or-2.2.png

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:01a558cd936c4972954baaa163d4cb584fbf52133e5287fff5f8d74402107b46
size 4195
Loading…
Cancel
Save