diff --git a/build/Build.ImageProcessor.Plugins.Cair.proj b/build/Build.ImageProcessor.Plugins.Cair.proj
new file mode 100644
index 0000000000..d4668467da
--- /dev/null
+++ b/build/Build.ImageProcessor.Plugins.Cair.proj
@@ -0,0 +1,54 @@
+
+
+ .\
+
+
+
+
+
+
+
+ Release
+ _BuildOutput\
+ False
+ $(MSBuildProjectDirectory)\$(BuildFolder)
+ $(BuildFolderAbsolutePath)ImageProcessor.Plugins.Cair\lib\net45
+ ..\src\Plugins\ImageProcessor\ImageProcessor.Plugins.Cair\
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/Build.bat b/build/Build.bat
index f5ec6373b6..deb60032ff 100644
--- a/build/Build.bat
+++ b/build/Build.bat
@@ -4,8 +4,11 @@ SET version=2.0.1.0
SET webversion=4.0.0.0
SET webconfigversion=2.0.0.0
SET webppluginversion=1.0.1.0
+SET cairpluginversion=1.0.0.0
-ECHO Building ImageProcessor %version%, ImageProcessor.Web %webversion%, ImageProcessor.Web.Config %webconfigversion%, and ImageProcessor.Plugins.WebP %webppluginversion%
+ECHO Building ImageProcessor %version%, ImageProcessor.Web %webversion%, ImageProcessor.Web.Config %webconfigversion%
+
+ECHO Building ImageProcessor.Plugins.WebP %webppluginversion%, ImageProcessor.Plugins.Cair %cairpluginversion%
ECHO Removing _BuildOutput directory so everything is nice and clean
RD _BuildOutput /q /s
@@ -13,12 +16,14 @@ RD _BuildOutput /q /s
%windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe "Build.ImageProcessor.proj" /p:BUILD_RELEASE=%version% /p:BUILD_COMMENT=%comment%
%windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe "Build.ImageProcessor.Web.proj" /p:BUILD_RELEASE=%webversion% /p:BUILD_COMMENT=%comment%
%windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe "Build.ImageProcessor.Plugins.WebP.proj" /p:BUILD_RELEASE=%webppluginversion% /p:BUILD_COMMENT=%comment%
+%windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe "Build.ImageProcessor.Plugins.Cair.proj" /p:BUILD_RELEASE=%cairpluginversion% /p:BUILD_COMMENT=%comment%
ECHO Packing the NuGet release files
..\src\.nuget\NuGet.exe pack NuSpecs\ImageProcessor.nuspec -Version %version%
..\src\.nuget\NuGet.exe pack NuSpecs\ImageProcessor.Web.nuspec -Version %webversion%
..\src\.nuget\NuGet.exe pack NuSpecs\ImageProcessor.Web.Config.nuspec -Version %webconfigversion%
..\src\.nuget\NuGet.exe pack NuSpecs\ImageProcessor.Plugins.WebP.nuspec -Version %webppluginversion%
+..\src\.nuget\NuGet.exe pack NuSpecs\ImageProcessor.Plugins.Cair.nuspec -Version %cairpluginversion%
PAUSE
IF ERRORLEVEL 1 GOTO :showerror
diff --git a/build/NuSpecs/ImageProcessor.Plugins.Cair.nuspec b/build/NuSpecs/ImageProcessor.Plugins.Cair.nuspec
new file mode 100644
index 0000000000..3560ec1544
--- /dev/null
+++ b/build/NuSpecs/ImageProcessor.Plugins.Cair.nuspec
@@ -0,0 +1,37 @@
+
+
+
+ ImageProcessor.Plugins.Cair
+ 1.0.0.0
+ ImageProcessor.Plugins.Cair
+ James South
+ James South
+ http://imageprocessor.org
+ http://raw.githubusercontent.com/JimBobSquarePants/ImageProcessor/master/build/content/imageprocessor.128.png
+ false
+
+ Adds support to ImageProcessor for Content Aware Image Resizing.
+
+ If you use ImageProcessor please get in touch via my twitter @james_m_south
+
+ Feedback is always welcome
+
+ Adds support to ImageProcessor for Content Aware Image Resizing.
+
+ James South
+ en-GB
+
+ Image Imaging ASP Performance Processing HttpModule Cache Resize AutoRotate Rotate RoundedCorners
+ Flip Crop Filter Effects Quality Watermark Alpha Vignette Saturation Brightness Contrast Gif Jpg Jpeg
+ Bitmap Png WebP Tiff Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated EXIF Cair SeamCarving
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/NuSpecs/ImageProcessor.Plugins.WebP.nuspec b/build/NuSpecs/ImageProcessor.Plugins.WebP.nuspec
index 2b73746c52..98826898d2 100644
--- a/build/NuSpecs/ImageProcessor.Plugins.WebP.nuspec
+++ b/build/NuSpecs/ImageProcessor.Plugins.WebP.nuspec
@@ -1,32 +1,38 @@
-
- ImageProcessor.Plugins.WebP
- 1.0.0.0
- ImageProcessor.Plugins.WebP
- James South
- James South
- http://imageprocessor.org
- http://raw.githubusercontent.com/JimBobSquarePants/ImageProcessor/master/build/content/imageprocessor.128.png
- false
- Adds support to ImageProcessor for the WebP image format.
+
+ ImageProcessor.Plugins.WebP
+ 1.0.0.0
+ ImageProcessor.Plugins.WebP
+ James South
+ James South
+ http://imageprocessor.org
+ http://raw.githubusercontent.com/JimBobSquarePants/ImageProcessor/master/build/content/imageprocessor.128.png
+ false
+
+ Adds support to ImageProcessor for the WebP image format.
-If you use ImageProcessor please get in touch via my twitter @james_m_south
+ If you use ImageProcessor please get in touch via my twitter @james_m_south
-Feedback is always welcome
- Adds support to ImageProcessor for the WebP image format.
-
- James South
- en-GB
- Image Imaging ASP Performance Processing HttpModule Cache Resize Rotate RoundedCorners Flip Crop Filter Effects Quality Watermark Alpha Vignette Saturation Brightness Contrast Gif Jpg Jpeg Bitmap Png WebP Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated
-
-
-
-
-
-
-
-
-
-
+ Feedback is always welcome
+
+ Adds support to ImageProcessor for the WebP image format.
+
+ James South
+ en-GB
+
+ Image Imaging ASP Performance Processing HttpModule Cache Resize AutoRotate Rotate RoundedCorners
+ Flip Crop Filter Effects Quality Watermark Alpha Vignette Saturation Brightness Contrast Gif Jpg Jpeg
+ Bitmap Png WebP Tiff Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated EXIF Cair SeamCarving
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/NuSpecs/ImageProcessor.Web.Config.nuspec b/build/NuSpecs/ImageProcessor.Web.Config.nuspec
index 45786ebd55..0b66945dfd 100644
--- a/build/NuSpecs/ImageProcessor.Web.Config.nuspec
+++ b/build/NuSpecs/ImageProcessor.Web.Config.nuspec
@@ -1,35 +1,41 @@
-
- ImageProcessor.Web.Config
- 1.1.0.0
- ImageProcessor.Web.Config
- James South
- James South
- http://imageprocessor.org
- http://raw.githubusercontent.com/JimBobSquarePants/ImageProcessor/master/build/content/imageprocessor.128.png
- false
- Adds configuration to your ImageProcessor.Web solution to allow you to override the default settings.
+
+ ImageProcessor.Web.Config
+ 1.1.0.0
+ ImageProcessor.Web.Config
+ James South
+ James South
+ http://imageprocessor.org
+ http://raw.githubusercontent.com/JimBobSquarePants/ImageProcessor/master/build/content/imageprocessor.128.png
+ false
+
+ Adds configuration to your ImageProcessor.Web solution to allow you to override the default settings.
-If you use ImageProcessor please get in touch via my twitter @james_m_south
+ If you use ImageProcessor please get in touch via my twitter @james_m_south
-Feedback is always welcome
- ImageProcessor.Web configuration settings for ASP.NET websites.
-
- James South
- en-GB
- Image Imaging ASP Performance Processing HttpModule Cache Resize Rotate RoundedCorners Flip Crop Filter Effects Quality Watermark Alpha Vignette Saturation Brightness Contrast Gif Jpg Jpeg Bitmap Png WebP Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated
-
-
-
-
-
-
-
-
-
-
-
-
-
+ Feedback is always welcome
+
+ ImageProcessor.Web configuration settings for ASP.NET websites.
+
+ James South
+ en-GB
+
+ Image Imaging ASP Performance Processing HttpModule Cache Resize AutoRotate Rotate RoundedCorners
+ Flip Crop Filter Effects Quality Watermark Alpha Vignette Saturation Brightness Contrast Gif Jpg Jpeg
+ Bitmap Png WebP Tiff Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated EXIF Cair SeamCarving
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/NuSpecs/ImageProcessor.Web.nuspec b/build/NuSpecs/ImageProcessor.Web.nuspec
index 9f765206e3..ddcc68c942 100644
--- a/build/NuSpecs/ImageProcessor.Web.nuspec
+++ b/build/NuSpecs/ImageProcessor.Web.nuspec
@@ -1,34 +1,40 @@
-
- ImageProcessor.Web
- 3.2.0.0
- ImageProcessor.Web
- James South
- James South
- http://imageprocessor.org
- http://raw.githubusercontent.com/JimBobSquarePants/ImageProcessor/master/build/content/imageprocessor.128.png
- false
- ImageProcessor.Web adds a configurable HttpModule to your website which allows on-the-fly processing of image files. The module also comes with a file and browser based cache that can handle millions of images, increasing your processing output and saving precious server memory.
+
+ ImageProcessor.Web
+ 3.2.0.0
+ ImageProcessor.Web
+ James South
+ James South
+ http://imageprocessor.org
+ http://raw.githubusercontent.com/JimBobSquarePants/ImageProcessor/master/build/content/imageprocessor.128.png
+ false
+
+ ImageProcessor.Web adds a configurable HttpModule to your website which allows on-the-fly processing of image files. The module also comes with a file and browser based cache that can handle millions of images, increasing your processing output and saving precious server memory.
-Methods include: Resize, Rotate, Rounded Corners, Flip, Crop, Watermark, Filter, Saturation, Brightness, Contrast, Quality, Format, Vignette, Gaussian Blur, Gaussian Sharpen, and Transparency.
+ Methods include: Resize, Rotate, Rounded Corners, Flip, Crop, Watermark, Filter, Saturation, Brightness, Contrast, Quality, Format, Vignette, Gaussian Blur, Gaussian Sharpen, and Transparency.
-If you use ImageProcessor please get in touch via my twitter @james_m_south
+ If you use ImageProcessor please get in touch via my twitter @james_m_south
-Feedback is always welcome
- An extension to ImageProcessor that allows on-the-fly processing of image files in an ASP.NET website
-
- James South
- en-GB
- Image Imaging ASP Performance Processing HttpModule Cache Resize AutoRotate Rotate RoundedCorners Flip Crop Filter Effects Quality Watermark Alpha Vignette Saturation Brightness Contrast Gif Jpg Jpeg Bitmap Png WebP Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated EXIF
-
-
-
-
-
-
-
-
-
-
+ Feedback is always welcome
+
+ An extension to ImageProcessor that allows on-the-fly processing of image files in an ASP.NET website
+
+ James South
+ en-GB
+
+ Image Imaging ASP Performance Processing HttpModule Cache Resize AutoRotate Rotate RoundedCorners
+ Flip Crop Filter Effects Quality Watermark Alpha Vignette Saturation Brightness Contrast Gif Jpg Jpeg
+ Bitmap Png WebP Tiff Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated EXIF Cair SeamCarving
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/NuSpecs/ImageProcessor.nuspec b/build/NuSpecs/ImageProcessor.nuspec
index 2b9c8af53b..2e5f84fdfa 100644
--- a/build/NuSpecs/ImageProcessor.nuspec
+++ b/build/NuSpecs/ImageProcessor.nuspec
@@ -1,28 +1,34 @@
-
- ImageProcessor
- 1.9.0.0
- ImageProcessor
- James South
- James South
- http://imageprocessor.org
- http://raw.githubusercontent.com/JimBobSquarePants/ImageProcessor/master/build/content/imageprocessor.128.png
- false
- Image Processor is an easy to use and extend processing library written in C#. Its fluent API makes common imaging tasks very simple to perform.
+
+ ImageProcessor
+ 1.9.0.0
+ ImageProcessor
+ James South
+ James South
+ http://imageprocessor.org
+ http://raw.githubusercontent.com/JimBobSquarePants/ImageProcessor/master/build/content/imageprocessor.128.png
+ false
+
+ Image Processor is an easy to use and extend processing library written in C#. Its fluent API makes common imaging tasks very simple to perform.
-Methods include; Resize, Rotate, Rounded Corners, Flip, Crop, Watermark, Filter, Saturation, Brightness, Contrast, Quality, Format, Vignette, Gaussian Blur, Gaussian Sharpen, and Transparency.
+ Methods include; Resize, Rotate, Rounded Corners, Flip, Crop, Watermark, Filter, Saturation, Brightness, Contrast, Quality, Format, Vignette, Gaussian Blur, Gaussian Sharpen, and Transparency.
-If you use ImageProcessor please get in touch on my twitter @james_m_south.
+ If you use ImageProcessor please get in touch on my twitter @james_m_south.
-Feedback is always welcome.
- A library for manipulating image files written in C#.
-
- James South
- en-GB
- Image Imaging ASP Performance Processing Resize AutoRotate Rotate RoundedCorners Flip Crop Filter Effects Quality Watermark Alpha Vignette Saturation Brightness Contrast Gif Jpg Jpeg Bitmap Png WebP Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated EXIF
-
-
-
-
+ Feedback is always welcome.
+
+ A library for manipulating image files written in C#.
+
+ James South
+ en-GB
+
+ Image Imaging ASP Performance Processing HttpModule Cache Resize AutoRotate Rotate RoundedCorners
+ Flip Crop Filter Effects Quality Watermark Alpha Vignette Saturation Brightness Contrast Gif Jpg Jpeg
+ Bitmap Png WebP Tiff Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated EXIF Cair SeamCarving
+
+
+
+
+
diff --git a/src/ImageProcessorConsole/Program.cs b/src/ImageProcessorConsole/Program.cs
index 6293a3edce..f7658b7d1f 100644
--- a/src/ImageProcessorConsole/Program.cs
+++ b/src/ImageProcessorConsole/Program.cs
@@ -12,11 +12,13 @@ namespace ImageProcessorConsole
{
using System;
using System.Collections.Generic;
+ using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using ImageProcessor;
using ImageProcessor.Plugins.Cair;
+ using ImageProcessor.Plugins.Cair.Imaging;
///
/// The program.
@@ -48,6 +50,11 @@ public static void Main(string[] args)
{
byte[] photoBytes = File.ReadAllBytes(fileInfo.FullName);
+ Console.WriteLine("Processing: " + fileInfo.Name);
+
+ Stopwatch stopwatch = new Stopwatch();
+ stopwatch.Start();
+
// ImageProcessor
using (MemoryStream inStream = new MemoryStream(photoBytes))
{
@@ -55,15 +62,24 @@ public static void Main(string[] args)
{
Size size = new Size(800, 0);
+ ContentAwareResizeLayer layer = new ContentAwareResizeLayer(size)
+ {
+ ConvolutionType = ConvolutionType.Sobel
+ };
+
// Load, resize, set the format and quality and save an image.
imageFactory.Load(inStream)
//.BackgroundColor(Color.White)
//.Resize(new Size((int)(size.Width * 1.1), 0))
- .ContentAwareResize(size)
+ .ContentAwareResize(layer)
//.Constrain(size)
.Save(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path), @"..\..\images\output", fileInfo.Name)));
+
+ stopwatch.Stop();
}
}
+
+ Console.WriteLine("Processed: " + fileInfo.Name + " in " + stopwatch.ElapsedMilliseconds + "ms");
}
}
diff --git a/src/ImageProcessorConsole/images/input/night-bridge.jpg.REMOVED.git-id b/src/ImageProcessorConsole/images/input/night-bridge.png.REMOVED.git-id
similarity index 100%
rename from src/ImageProcessorConsole/images/input/night-bridge.jpg.REMOVED.git-id
rename to src/ImageProcessorConsole/images/input/night-bridge.png.REMOVED.git-id
diff --git a/src/ImageProcessorConsole/images/output/2006-citybus.jpg.REMOVED.git-id b/src/ImageProcessorConsole/images/output/2006-citybus.jpg.REMOVED.git-id
index 5fe88ad754..233b2595f7 100644
--- a/src/ImageProcessorConsole/images/output/2006-citybus.jpg.REMOVED.git-id
+++ b/src/ImageProcessorConsole/images/output/2006-citybus.jpg.REMOVED.git-id
@@ -1 +1 @@
-33f7e25da5675197f18bb2fa2c9fe5fa366e84ec
\ No newline at end of file
+c6cb11afaf9fdb9181772246e5c873d8f7d1b99c
\ No newline at end of file
diff --git a/src/ImageProcessorConsole/images/output/2008.jpg.REMOVED.git-id b/src/ImageProcessorConsole/images/output/2008.jpg.REMOVED.git-id
index fcb030451d..01ba573540 100644
--- a/src/ImageProcessorConsole/images/output/2008.jpg.REMOVED.git-id
+++ b/src/ImageProcessorConsole/images/output/2008.jpg.REMOVED.git-id
@@ -1 +1 @@
-f24f17627804b11d823240d49c91ec17fb7fd55d
\ No newline at end of file
+10b48cac44776a023df7585ba2c68c3f51b0f803
\ No newline at end of file
diff --git a/src/ImageProcessorConsole/images/output/2012-citybus.jpg.REMOVED.git-id b/src/ImageProcessorConsole/images/output/2012-citybus.jpg.REMOVED.git-id
index 3ade52d600..731a81b1ac 100644
--- a/src/ImageProcessorConsole/images/output/2012-citybus.jpg.REMOVED.git-id
+++ b/src/ImageProcessorConsole/images/output/2012-citybus.jpg.REMOVED.git-id
@@ -1 +1 @@
-def19dd7469cf2eba1f595e7263d9d48fda85825
\ No newline at end of file
+e631eb3491496bb83f99cd41a752f79c9d7f6830
\ No newline at end of file
diff --git a/src/ImageProcessorConsole/images/output/Arc-de-Triomphe-France.jpg.REMOVED.git-id b/src/ImageProcessorConsole/images/output/Arc-de-Triomphe-France.jpg.REMOVED.git-id
index 83ecfe0323..437ecbc461 100644
--- a/src/ImageProcessorConsole/images/output/Arc-de-Triomphe-France.jpg.REMOVED.git-id
+++ b/src/ImageProcessorConsole/images/output/Arc-de-Triomphe-France.jpg.REMOVED.git-id
@@ -1 +1 @@
-8cf61b55acca1a3d1a69177ddc439685ee0ba192
\ No newline at end of file
+782056919992bb7e453eeee5d9c0034e03b57506
\ No newline at end of file
diff --git a/src/ImageProcessorConsole/images/output/Image with gaps.jpg.REMOVED.git-id b/src/ImageProcessorConsole/images/output/Image with gaps.jpg.REMOVED.git-id
index 7ea6903419..99c38fa2f1 100644
--- a/src/ImageProcessorConsole/images/output/Image with gaps.jpg.REMOVED.git-id
+++ b/src/ImageProcessorConsole/images/output/Image with gaps.jpg.REMOVED.git-id
@@ -1 +1 @@
-629284a6f834f5d1cf185e3603a50c484dd9121a
\ No newline at end of file
+1d9ded0201edcd248140b4ec02f69ccdb4b539e5
\ No newline at end of file
diff --git a/src/ImageProcessorConsole/images/output/arc_de_triomphe_paris_france.jpg.REMOVED.git-id b/src/ImageProcessorConsole/images/output/arc_de_triomphe_paris_france.jpg.REMOVED.git-id
index e3f15eac73..b55932abb8 100644
--- a/src/ImageProcessorConsole/images/output/arc_de_triomphe_paris_france.jpg.REMOVED.git-id
+++ b/src/ImageProcessorConsole/images/output/arc_de_triomphe_paris_france.jpg.REMOVED.git-id
@@ -1 +1 @@
-3d652e0628f2042e7aca0751384ba21f1182ef5f
\ No newline at end of file
+2880457cc09cd2897b5f9f377807ec22f8f83013
\ No newline at end of file
diff --git a/src/ImageProcessorConsole/images/output/mountain.jpg.REMOVED.git-id b/src/ImageProcessorConsole/images/output/mountain.jpg.REMOVED.git-id
index 05e668428c..aba0ec52f1 100644
--- a/src/ImageProcessorConsole/images/output/mountain.jpg.REMOVED.git-id
+++ b/src/ImageProcessorConsole/images/output/mountain.jpg.REMOVED.git-id
@@ -1 +1 @@
-1c48519b2675b9dd90e8e95d6421148b25b8c317
\ No newline at end of file
+34dcced6c7c3e4dd6fae239eba8eddef6234028d
\ No newline at end of file
diff --git a/src/ImageProcessorConsole/images/output/rotate.jpg.REMOVED.git-id b/src/ImageProcessorConsole/images/output/rotate.jpg.REMOVED.git-id
index 5ebfcd78d6..ec3d83b76b 100644
--- a/src/ImageProcessorConsole/images/output/rotate.jpg.REMOVED.git-id
+++ b/src/ImageProcessorConsole/images/output/rotate.jpg.REMOVED.git-id
@@ -1 +1 @@
-a0aa8338f74f3539c2531f43fa9027a3ce0a39fb
\ No newline at end of file
+de6754762f7705f9109ea364f42ca128e454e853
\ No newline at end of file
diff --git a/src/ImageProcessorConsole/images/output/shutterstock_19173982_Arc_de_triomphe-square1.jpg.REMOVED.git-id b/src/ImageProcessorConsole/images/output/shutterstock_19173982_Arc_de_triomphe-square1.jpg.REMOVED.git-id
index 6f31ad7d11..481fa6aaad 100644
--- a/src/ImageProcessorConsole/images/output/shutterstock_19173982_Arc_de_triomphe-square1.jpg.REMOVED.git-id
+++ b/src/ImageProcessorConsole/images/output/shutterstock_19173982_Arc_de_triomphe-square1.jpg.REMOVED.git-id
@@ -1 +1 @@
-04f6093d3345a4c8b48333c32972753dd0949730
\ No newline at end of file
+24db72130626e81b9a4262c891dd28e6d97e5a96
\ No newline at end of file
diff --git a/src/ImageProcessorConsole/images/output/test.jpg.REMOVED.git-id b/src/ImageProcessorConsole/images/output/test.jpg.REMOVED.git-id
index 8f920f20c2..65ec37fb75 100644
--- a/src/ImageProcessorConsole/images/output/test.jpg.REMOVED.git-id
+++ b/src/ImageProcessorConsole/images/output/test.jpg.REMOVED.git-id
@@ -1 +1 @@
-f7b1543810ada7598773d6ee31bc7c0c20afaa9f
\ No newline at end of file
+4885438f0b97e3aae59d6e214b5ec455358ae225
\ No newline at end of file
diff --git a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/CairBootstrapper.cs b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/CairBootstrapper.cs
index 60a9eb0ce6..2baf4fa70f 100644
--- a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/CairBootstrapper.cs
+++ b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/CairBootstrapper.cs
@@ -32,12 +32,12 @@ static CairBootstrapper()
///
/// Gets the cair path.
///
- public static string CairPath { get; private set; }
+ public static string CairExecutablePath { get; private set; }
///
- /// Gets the cair image path.
+ /// Gets the cair base path.
///
- public static string CairImagePath { get; private set; }
+ public static string CairPath { get; private set; }
///
/// Registers the embedded CAIR executable.
@@ -47,12 +47,17 @@ public static void RegisterCairExecutable()
// None of the tools used here are called using dllimport so we don't go through the normal registration channel.
string folder = ImageProcessorBootstrapper.Instance.NativeBinaryFactory.Is64BitEnvironment ? "x64" : "x86";
Assembly assembly = Assembly.GetExecutingAssembly();
- string targetBasePath = new Uri(assembly.Location).LocalPath;
- string multithreaderTargetPath = Path.GetFullPath(Path.Combine(targetBasePath, "..\\" + folder + "\\" + "pthreadVSE2.dll"));
+ CairPath = Path.GetFullPath(Path.Combine(new Uri(assembly.Location).LocalPath, "..\\" + folder + "\\imageprocessor.cair\\"));
+ CairExecutablePath = Path.Combine(CairPath, "CAIR.exe");
+ string multithreaderTargetPath = Path.Combine(CairPath, "pthreadVSE2.dll");
- // Set the global variable.
- CairPath = Path.GetFullPath(Path.Combine(targetBasePath, "..\\" + folder + "\\" + "CAIR.exe"));
- CairImagePath = Path.GetFullPath(Path.Combine(targetBasePath, "..\\" + folder + "\\" + "cairimages\\"));
+ // Create the folder for storing temporary images.
+ // ReSharper disable once AssignNullToNotNullAttribute
+ DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(CairPath));
+ if (!directoryInfo.Exists)
+ {
+ directoryInfo.Create();
+ }
// Get the resources and copy them across.
const string CairResourcePath = "ImageProcessor.Plugins.Cair.Resources.Unmanaged.x86.CAIR.exe";
@@ -64,13 +69,6 @@ public static void RegisterCairExecutable()
{
if (resourceStream != null)
{
- // ReSharper disable once AssignNullToNotNullAttribute
- DirectoryInfo threaderDirectoryInfo = new DirectoryInfo(Path.GetDirectoryName(multithreaderTargetPath));
- if (!threaderDirectoryInfo.Exists)
- {
- threaderDirectoryInfo.Create();
- }
-
using (FileStream fileStream = File.OpenWrite(multithreaderTargetPath))
{
resourceStream.CopyTo(fileStream);
@@ -83,27 +81,12 @@ public static void RegisterCairExecutable()
{
if (resourceStream != null)
{
- // ReSharper disable once AssignNullToNotNullAttribute
- DirectoryInfo cairDirectoryInfo = new DirectoryInfo(Path.GetDirectoryName(CairPath));
- if (!cairDirectoryInfo.Exists)
- {
- cairDirectoryInfo.Create();
- }
-
- using (FileStream fileStream = File.OpenWrite(CairPath))
+ using (FileStream fileStream = File.OpenWrite(CairExecutablePath))
{
resourceStream.CopyTo(fileStream);
}
}
}
-
- // Lastly create the image folder for storing temporary images.
- // ReSharper disable once AssignNullToNotNullAttribute
- DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(CairImagePath));
- if (!directoryInfo.Exists)
- {
- directoryInfo.Create();
- }
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/ImageProcessor.Plugins.Cair.csproj b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/ImageProcessor.Plugins.Cair.csproj
index 75ba8715e6..45c0d70a3d 100644
--- a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/ImageProcessor.Plugins.Cair.csproj
+++ b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/ImageProcessor.Plugins.Cair.csproj
@@ -45,9 +45,10 @@
-
+
+
diff --git a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeConvolutionType.cs b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeConvolutionType.cs
deleted file mode 100644
index 143b0fd3cf..0000000000
--- a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeConvolutionType.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------
-//
-// Copyright (c) James South.
-// Licensed under the Apache License, Version 2.0.
-//
-//
-// Provides enumeration of the content aware resize convolution types.
-//
-// --------------------------------------------------------------------------------------------------------------------
-
-namespace ImageProcessor.Plugins.Cair.Imaging
-{
- ///
- /// Provides enumeration of the content aware resize convolution types.
- ///
- public enum ContentAwareResizeConvolutionType
- {
- ///
- /// The Prewitt kernel convolution type.
- ///
- Prewitt = 0,
-
- ///
- /// The V1 kernel convolution type.
- ///
- V1 = 1,
-
- ///
- /// The VSquare kernel convolution type.
- ///
- VSquare = 2,
-
- ///
- /// The Sobel kernel convolution type.
- ///
- Sobel = 3,
-
- ///
- /// The Laplacian kernel convolution type.
- ///
- Laplacian = 4
- }
-}
\ No newline at end of file
diff --git a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeLayer.cs b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeLayer.cs
index d81b299072..c8b5dc02fe 100644
--- a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeLayer.cs
+++ b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeLayer.cs
@@ -20,7 +20,7 @@ public class ContentAwareResizeLayer
///
/// The convolution type to apply to the layer.
///
- private ContentAwareResizeConvolutionType convolutionType = ContentAwareResizeConvolutionType.Prewitt;
+ private ConvolutionType convolutionType = ConvolutionType.Prewitt;
///
/// The energy function to apply to the layer.
@@ -28,14 +28,14 @@ public class ContentAwareResizeLayer
private EnergyFunction energyFunction = EnergyFunction.Forward;
///
- /// Whether to assign multiple threads to the resizing method.
+ /// The expected output type.
///
- private bool parallelize = true;
+ private OutputType outputType = OutputType.Cair;
///
- /// Whether to pre-scale the image to reduce errors in the output.
+ /// Whether to assign multiple threads to the resizing method.
///
- private bool prescale = true;
+ private bool parallelize = true;
///
/// The timeout in milliseconds to attempt to resize for.
@@ -53,15 +53,10 @@ public ContentAwareResizeLayer(Size size)
this.Size = size;
}
- ///
- /// Gets or sets the size.
- ///
- public Size Size { get; set; }
-
///
/// Gets or sets the content aware resize convolution type (Default ContentAwareResizeConvolutionType.Prewitt).
///
- public ContentAwareResizeConvolutionType ConvolutionType
+ public ConvolutionType ConvolutionType
{
get
{
@@ -91,36 +86,52 @@ public EnergyFunction EnergyFunction
}
///
- /// Gets or sets a value indicating whether to assign multiple threads to the resizing method.
- /// (Default true)
+ /// Gets or sets the expected output type.
///
- public bool Parallelize
+ public OutputType OutputType
{
get
{
- return this.parallelize;
+ return this.outputType;
}
set
{
- this.parallelize = value;
+ this.outputType = value;
}
}
///
- /// Gets or sets a value indicating whether to pre-scale the image to reduce errors in the output.
+ /// Gets or sets the size.
+ ///
+ public Size Size { get; set; }
+
+ ///
+ /// Gets or sets the the file path to a bitmap file that provides weight indicators specified using
+ /// color to guide preservation of image portions during carving.
+ ///
+ /// The following colors define weight guidance.
+ ///
- Protect the weight.
+ ///
- Remove the weight.
+ ///
- No weight.
+ ///
+ ///
+ public string WeightPath { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether to assign multiple threads to the resizing method.
/// (Default true)
///
- public bool PreScale
+ public bool Parallelize
{
get
{
- return this.prescale;
+ return this.parallelize;
}
set
{
- this.prescale = value;
+ this.parallelize = value;
}
}
@@ -162,7 +173,12 @@ public override bool Equals(object obj)
}
return this.Size == resizeLayer.Size
- && this.ConvolutionType == resizeLayer.ConvolutionType;
+ && this.ConvolutionType == resizeLayer.ConvolutionType
+ && this.EnergyFunction == resizeLayer.EnergyFunction
+ && this.OutputType == resizeLayer.OutputType
+ && this.Parallelize == resizeLayer.Parallelize
+ && this.Timeout == resizeLayer.Timeout
+ && this.WeightPath == resizeLayer.WeightPath;
}
///
@@ -173,7 +189,13 @@ public override bool Equals(object obj)
///
public override int GetHashCode()
{
- return this.Size.GetHashCode() + this.ConvolutionType.GetHashCode();
+ return this.Size.GetHashCode() +
+ this.ConvolutionType.GetHashCode() +
+ this.EnergyFunction.GetHashCode() +
+ this.OutputType.GetHashCode() +
+ this.Parallelize.GetHashCode() +
+ this.Timeout.GetHashCode() +
+ this.WeightPath.GetHashCode();
}
}
}
diff --git a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/OutputType.cs b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/OutputType.cs
new file mode 100644
index 0000000000..168776c6f6
--- /dev/null
+++ b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/OutputType.cs
@@ -0,0 +1,53 @@
+// --------------------------------------------------------------------------------------------------------------------
+//
+// Copyright (c) James South.
+// Licensed under the Apache License, Version 2.0.
+//
+//
+// Enumerates the output type to produce.
+//
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace ImageProcessor.Plugins.Cair.Imaging
+{
+ ///
+ /// Enumerates the output type to produce.
+ ///
+ public enum OutputType
+ {
+ ///
+ /// Output the result as a carved image. The default action.
+ ///
+ Cair = 0,
+
+ ///
+ /// Output the result as a greyscale image.
+ ///
+ Grayscale = 1,
+
+ ///
+ /// Output the result highlighting the detected edges.
+ ///
+ Edge = 2,
+
+ ///
+ /// Output the result highlighting the vertical energy patterns.
+ ///
+ VerticalEnergy = 3,
+
+ ///
+ /// Output the result highlighting the vertical energy patterns.
+ ///
+ HorizontalEnergy = 4,
+
+ ///
+ /// Appears to do nothing.
+ ///
+ Removal = 5,
+
+ ///
+ /// Output the result as a carved image with the focus on high quality output over speed.
+ ///
+ CairHighDefinition = 6
+ }
+}
diff --git a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Processors/ContentAwareResize.cs b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Processors/ContentAwareResize.cs
index c85f5b6608..aca83388be 100644
--- a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Processors/ContentAwareResize.cs
+++ b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Processors/ContentAwareResize.cs
@@ -19,7 +19,6 @@ namespace ImageProcessor.Plugins.Cair.Processors
using System.IO;
using ImageProcessor.Common.Exceptions;
- using ImageProcessor.Imaging;
using ImageProcessor.Plugins.Cair.Imaging;
using ImageProcessor.Processors;
@@ -69,17 +68,14 @@ public System.Drawing.Image ProcessImage(ImageFactory factory)
string fileName = Guid.NewGuid().ToString();
// Use bmp's as the temporary files since they are lossless and support transparency.
- string sourcePath = Path.Combine(CairBootstrapper.CairImagePath, fileName + ".bmp");
- string resizedPath = Path.Combine(CairBootstrapper.CairImagePath, fileName + "-r.bmp");
+ string sourcePath = Path.Combine(CairBootstrapper.CairPath, fileName + ".bmp");
+ string resizedPath = Path.Combine(CairBootstrapper.CairPath, fileName + "-r.bmp");
// Gather the parameters.
- int width = this.DynamicParameter.Size.Width ?? 0;
- int height = this.DynamicParameter.Size.Height ?? 0;
- ContentAwareResizeConvolutionType convolutionType = this.DynamicParameter.ConvolutionType;
- EnergyFunction energyFunction = this.DynamicParameter.EnergyFunction;
- bool prescale = this.DynamicParameter.PreScale;
- bool parallelize = this.DynamicParameter.Parallelize;
- int timeout = this.DynamicParameter.Timeout ?? 60000;
+ ContentAwareResizeLayer layer = (ContentAwareResizeLayer)this.DynamicParameter;
+ int width = layer.Size.Width;
+ int height = layer.Size.Height;
+ int timeout = layer.Timeout > 0 ? layer.Timeout : 60000;
int defaultMaxWidth;
int defaultMaxHeight;
@@ -115,48 +111,28 @@ public System.Drawing.Image ProcessImage(ImageFactory factory)
if (width > 0 && height > 0 && width <= maxWidth && height <= maxHeight)
{
- if (prescale)
- {
- if (width < image.Width || height < image.Height)
- {
- int preWidth = Math.Min(image.Width, width + 50); //(int)Math.Ceiling(width * 1.25));
- ResizeLayer layer = new ResizeLayer(new Size(preWidth, 0));
- Dictionary resizeSettings = new Dictionary
- {
- {
- "MaxWidth", image.Width.ToString("G")
- },
- {
- "MaxHeight", image.Height.ToString("G")
- }
- };
- Resize resize = new Resize { DynamicParameter = layer, Settings = resizeSettings };
- image = resize.ProcessImage(factory);
- }
- }
-
// Save the temporary bitmap.
image.Save(sourcePath, ImageFormat.Bmp);
// Process the image using the CAIR executable.
string arguments = string.Format(
- " -I \"{0}\" -O \"{1}\" -C {2} -X {3} -Y {4} -E {5} -T {6}",
+ " -I \"{0}\" -O \"{1}\" -C {2} -X {3} -Y {4} -E {5} -T {6} -R {7}",
sourcePath,
resizedPath,
- (int)convolutionType,
+ (int)layer.ConvolutionType,
width,
height,
- (int)energyFunction,
- parallelize ? Math.Min(4, Environment.ProcessorCount) : 1);
-
- bool success = this.ProcessCairImage(arguments, timeout);
+ (int)layer.EnergyFunction,
+ layer.Parallelize ? Math.Min(4, Environment.ProcessorCount) : 1,
+ (int)layer.OutputType);
- if (!success)
+ if (!string.IsNullOrWhiteSpace(layer.WeightPath))
{
- throw new ImageProcessingException(
- "Error processing image with " + this.GetType().Name + " due to timeout.");
+ arguments = string.Format("{0} -W {1}", arguments, layer.WeightPath);
}
+ this.ProcessCairImage(arguments, timeout);
+
// Assign the new image.
newImage = new Bitmap(resizedPath);
newImage.MakeTransparent();
@@ -202,13 +178,10 @@ public System.Drawing.Image ProcessImage(ImageFactory factory)
///
/// The time in milliseconds to attempt to resize the image for.
///
- ///
- /// The .
- ///
- private bool ProcessCairImage(string arguments, int timeout)
+ private void ProcessCairImage(string arguments, int timeout)
{
// Set up and start a new process to resize the image.
- ProcessStartInfo start = new ProcessStartInfo(CairBootstrapper.CairPath, arguments)
+ ProcessStartInfo start = new ProcessStartInfo(CairBootstrapper.CairExecutablePath, arguments)
{
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false,
@@ -222,18 +195,21 @@ private bool ProcessCairImage(string arguments, int timeout)
{
if (process != null)
{
- bool result = process.WaitForExit(timeout);
-
- if (!result)
+ if (!process.WaitForExit(timeout))
{
process.Kill();
+
+ throw new ImageProcessingException("Error processing image with " + this.GetType().Name + " due to timeout.");
}
- return result;
+ string output = string.Format(" {0} {1}", process.StandardError.ReadToEnd(), process.StandardOutput.ReadToEnd());
+
+ if (process.ExitCode != 0)
+ {
+ throw new ImageProcessingException("Error processing image with " + this.GetType().Name + output);
+ }
}
}
-
- return false;
}
}
}
diff --git a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Resources/Unmanaged/x86/Usage.txt b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Resources/Unmanaged/x86/Usage.txt
new file mode 100644
index 0000000000..a6b19bcef8
--- /dev/null
+++ b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Resources/Unmanaged/x86/Usage.txt
@@ -0,0 +1,41 @@
+CAIR CLI Usage:
+
+cair -I
+
+Other options:
+ -O
+ Default: Dependent on operation
+ -W
+ Bitmap with: Black- no weight
+ Green- Protect weight
+ Red- Remove weight
+ Default: Weights are all zero
+ -S
+ Default: 100,000
+ -X
+ Default: Source image width
+ -Y
+ Default: Source image height
+ -R
+ CAIR: 0
+ Grayscale: 1
+ Edge: 2
+ Vertical Energy: 3
+ Horizontal Energy: 4
+ Removal: 5
+ CAIR_HD: 6
+ Default: CAIR
+ -C
+ Prewitt: 0
+ V1: 1
+ V_SQUARE: 2
+ Sobel: 3
+ Laplacian: 4
+ Default: Prewitt
+
+ -E
+ Backward: 0
+ Forward: 1
+ Default: Backward
+ -T
+ Default : CAIR_NUM_THREADS (4)