diff --git a/src/ImageProcessor/Common/Helpers/ImageMaths.cs b/src/ImageProcessor/Common/Helpers/ImageMaths.cs
index 6722d1dc1..d3e85a703 100644
--- a/src/ImageProcessor/Common/Helpers/ImageMaths.cs
+++ b/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);
}
diff --git a/src/ImageProcessor/Image.cs b/src/ImageProcessor/Image.cs
index f07a35a9d..75483d753 100644
--- a/src/ImageProcessor/Image.cs
+++ b/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;
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The other to create this instance from.
+ ///
+ ///
+ /// Thrown if the given is null.
+ ///
+ 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));
+ }
+
///
/// Initializes a new instance of the class.
///
diff --git a/src/ImageProcessor/ParallelImageProcessor.cs b/src/ImageProcessor/ParallelImageProcessor.cs
index e005054d3..610d60c0c 100644
--- a/src/ImageProcessor/ParallelImageProcessor.cs
+++ b/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;
diff --git a/src/ImageProcessor/Samplers/EntropyCrop.cs b/src/ImageProcessor/Samplers/EntropyCrop.cs
index e97be9b2c..0f1ce9067 100644
--- a/src/ImageProcessor/Samplers/EntropyCrop.cs
+++ b/src/ImageProcessor/Samplers/EntropyCrop.cs
@@ -58,10 +58,18 @@ namespace ImageProcessor.Samplers
///
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];
}
});
}
diff --git a/src/ImageProcessor/Samplers/Resampler.cs b/src/ImageProcessor/Samplers/Resampler.cs
index c18843c25..ba14fb3ea 100644
--- a/src/ImageProcessor/Samplers/Resampler.cs
+++ b/src/ImageProcessor/Samplers/Resampler.cs
@@ -115,6 +115,12 @@ namespace ImageProcessor.Samplers
///
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;
diff --git a/src/ImageProcessor/project.json b/src/ImageProcessor/project.json
index 22e1e36a4..1c7c0bda3 100644
--- a/src/ImageProcessor/project.json
+++ b/src/ImageProcessor/project.json
@@ -24,6 +24,6 @@
"Microsoft.NETCore.Platforms": "1.0.1-beta-23516"
},
"frameworks": {
- "dotnet5.4": { }
+ "dnxcore50": { }
}
}
\ No newline at end of file
diff --git a/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs b/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs
index f985ca4d0..f8daec2cf 100644
--- a/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs
+++ b/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs
@@ -13,35 +13,35 @@ namespace ImageProcessor.Tests
{
public static readonly TheoryData Filters = new TheoryData
{
- //{ "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]
diff --git a/tests/ImageProcessor.Tests/Processors/ProcessorTestBase.cs b/tests/ImageProcessor.Tests/Processors/ProcessorTestBase.cs
index d4d968f34..3b96507e7 100644
--- a/tests/ImageProcessor.Tests/Processors/ProcessorTestBase.cs
+++ b/tests/ImageProcessor.Tests/Processors/ProcessorTestBase.cs
@@ -19,26 +19,13 @@ namespace ImageProcessor.Tests
///
public static readonly List Files = new List
{
- //"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"
};
}
}
diff --git a/tests/ImageProcessor.Tests/TestImages/Formats/Gif/ani2.gif.REMOVED.git-id b/tests/ImageProcessor.Tests/TestImages/Formats/Gif/ani2.gif.REMOVED.git-id
deleted file mode 100644
index c8fe9de52..000000000
--- a/tests/ImageProcessor.Tests/TestImages/Formats/Gif/ani2.gif.REMOVED.git-id
+++ /dev/null
@@ -1 +0,0 @@
-c2c7a5fcc0f00cdef39dacd7df0816137b3d63a3
\ No newline at end of file
diff --git a/tests/ImageProcessor.Tests/TestImages/Formats/Gif/ben2.gif b/tests/ImageProcessor.Tests/TestImages/Formats/Gif/ben2.gif
deleted file mode 100644
index a91ea4a8e..000000000
--- a/tests/ImageProcessor.Tests/TestImages/Formats/Gif/ben2.gif
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:e69e47e78320e848efd07d83e265328a749cafde65291c0d7e7bdba90ba658c3
-size 50960
diff --git a/tests/ImageProcessor.Tests/TestImages/Formats/Gif/leaf.gif.REMOVED.git-id b/tests/ImageProcessor.Tests/TestImages/Formats/Gif/leaf.gif.REMOVED.git-id
deleted file mode 100644
index e62f10ab5..000000000
--- a/tests/ImageProcessor.Tests/TestImages/Formats/Gif/leaf.gif.REMOVED.git-id
+++ /dev/null
@@ -1 +0,0 @@
-98e8f0bd9cd631e784bcc356a589d87989d43176
\ No newline at end of file
diff --git a/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/Backdrop.jpg b/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/Backdrop.jpg
deleted file mode 100644
index 94c60daf3..000000000
--- a/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/Backdrop.jpg
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:048c66eb1d5257d36319da28ca24837429e0604682e4ebb74778175fbbb18db9
-size 49595
diff --git a/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/ant.jpg.REMOVED.git-id b/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/ant.jpg.REMOVED.git-id
deleted file mode 100644
index 1485b2316..000000000
--- a/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/ant.jpg.REMOVED.git-id
+++ /dev/null
@@ -1 +0,0 @@
-1da0ed59ed220f32d72b01e6cbb9c73a7f3b9b35
\ No newline at end of file
diff --git a/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/china.jpg.REMOVED.git-id b/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/china.jpg.REMOVED.git-id
deleted file mode 100644
index b8a8b4908..000000000
--- a/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/china.jpg.REMOVED.git-id
+++ /dev/null
@@ -1 +0,0 @@
-8cee90e94f9f09e04697bee0477bb5059b85c63f
\ No newline at end of file
diff --git a/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/greyscale.jpg.REMOVED.git-id b/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/greyscale.jpg.REMOVED.git-id
deleted file mode 100644
index bd909a4b1..000000000
--- a/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/greyscale.jpg.REMOVED.git-id
+++ /dev/null
@@ -1 +0,0 @@
-aca934c81771312563d8db52eedd95bb01164048
\ No newline at end of file
diff --git a/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/lomo.jpg b/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/lomo.jpg
deleted file mode 100644
index 23f75c72e..000000000
--- a/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/lomo.jpg
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:bdfad9ce367629518c374b27b8ce311d1f0326f61b9a0ed113b5b966dd3dd1bc
-size 45508
diff --git a/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/parachute.jpg b/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/parachute.jpg
deleted file mode 100644
index 0b155b75f..000000000
--- a/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/parachute.jpg
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:88f4e06fb00ecdcc663a8ba4227dc89be2e3b000bd39246d6bc4adb6450520b3
-size 28324
diff --git a/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/shaftesbury.jpg.REMOVED.git-id b/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/shaftesbury.jpg.REMOVED.git-id
deleted file mode 100644
index 59372951b..000000000
--- a/tests/ImageProcessor.Tests/TestImages/Formats/Jpg/shaftesbury.jpg.REMOVED.git-id
+++ /dev/null
@@ -1 +0,0 @@
-2eabac96326130ba423b3fecb5a163b734278370
\ No newline at end of file
diff --git a/tests/ImageProcessor.Tests/TestImages/Formats/Png/cballs.png.REMOVED.git-id b/tests/ImageProcessor.Tests/TestImages/Formats/Png/cballs.png.REMOVED.git-id
deleted file mode 100644
index 55cb73356..000000000
--- a/tests/ImageProcessor.Tests/TestImages/Formats/Png/cballs.png.REMOVED.git-id
+++ /dev/null
@@ -1 +0,0 @@
-58c3318271250961bfac9fe6e9c8b0053e1b8e28
\ No newline at end of file
diff --git a/tests/ImageProcessor.Tests/TestImages/Formats/Png/cmyk.png b/tests/ImageProcessor.Tests/TestImages/Formats/Png/cmyk.png
deleted file mode 100644
index 380f5e386..000000000
--- a/tests/ImageProcessor.Tests/TestImages/Formats/Png/cmyk.png
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:2e17ba8fac1fd6247ff839ab7e21d715c96b3588d5f4fdb835dbe8c937dbf79d
-size 37678
diff --git a/tests/ImageProcessor.Tests/TestImages/Formats/Png/gamma-1.0-or-2.2.png b/tests/ImageProcessor.Tests/TestImages/Formats/Png/gamma-1.0-or-2.2.png
deleted file mode 100644
index 953689f45..000000000
--- a/tests/ImageProcessor.Tests/TestImages/Formats/Png/gamma-1.0-or-2.2.png
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:01a558cd936c4972954baaa163d4cb584fbf52133e5287fff5f8d74402107b46
-size 4195