diff --git a/build/NuSpecs/ImageProcessor.Web.Config.nuspec b/build/NuSpecs/ImageProcessor.Web.Config.nuspec index eb605f2b8f..f2c7f84128 100644 --- a/build/NuSpecs/ImageProcessor.Web.Config.nuspec +++ b/build/NuSpecs/ImageProcessor.Web.Config.nuspec @@ -18,7 +18,7 @@ Feedback is always welcome 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 Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated + 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 diff --git a/build/NuSpecs/ImageProcessor.Web.nuspec b/build/NuSpecs/ImageProcessor.Web.nuspec index 840d438a25..f9421c49fc 100644 --- a/build/NuSpecs/ImageProcessor.Web.nuspec +++ b/build/NuSpecs/ImageProcessor.Web.nuspec @@ -22,7 +22,7 @@ Feedback is always welcome 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 Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated EXIF + 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 diff --git a/build/NuSpecs/ImageProcessor.nuspec b/build/NuSpecs/ImageProcessor.nuspec index f12daba8f2..8fd1644794 100644 --- a/build/NuSpecs/ImageProcessor.nuspec +++ b/build/NuSpecs/ImageProcessor.nuspec @@ -21,12 +21,9 @@ Feedback is always welcome. 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 Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated EXIF + 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 - - - \ No newline at end of file diff --git a/build/content/ImageProcessor.Web/web.config.transform b/build/content/ImageProcessor.Web/web.config.transform index 5c3edb9677..7d02ee4623 100644 --- a/build/content/ImageProcessor.Web/web.config.transform +++ b/build/content/ImageProcessor.Web/web.config.transform @@ -3,7 +3,6 @@ - @@ -14,7 +13,6 @@ - \ No newline at end of file diff --git a/build/content/ImageProcessor/imageprocessor.targets b/build/content/ImageProcessor/imageprocessor.targets deleted file mode 100644 index f8de1a74b5..0000000000 --- a/build/content/ImageProcessor/imageprocessor.targets +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - $(PrepareForRunDependsOn); - CopyNativeBinaries - - - - - - - - \ No newline at end of file diff --git a/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj b/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj index 12c43700b0..82d3986a71 100644 --- a/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj +++ b/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj @@ -116,9 +116,6 @@ - - ImageProcessorNativeBinaryModule.cs - Alpha.cs diff --git a/src/ImageProcessor.Web/NET45/Configuration/ImageProcessorConfiguration.cs b/src/ImageProcessor.Web/NET45/Configuration/ImageProcessorConfiguration.cs index 95c3123e26..a9684c9c52 100644 --- a/src/ImageProcessor.Web/NET45/Configuration/ImageProcessorConfiguration.cs +++ b/src/ImageProcessor.Web/NET45/Configuration/ImageProcessorConfiguration.cs @@ -13,17 +13,12 @@ namespace ImageProcessor.Web.Configuration using System; using System.Collections.Concurrent; using System.Collections.Generic; - using System.Diagnostics; - using System.IO; using System.Linq; using System.Reflection; - using System.Web; using System.Web.Compilation; using ImageProcessor.Common.Extensions; using ImageProcessor.Processors; - using ImageProcessor.Web.Helpers; - using ImageProcessor.Web.HttpModules; using ImageProcessor.Web.Processors; /// @@ -33,12 +28,6 @@ namespace ImageProcessor.Web.Configuration public sealed class ImageProcessorConfiguration { #region Fields - /// - /// Whether the process is running in 64bit mode. Used for calling the correct dllimport method. - /// Clunky I know but I couldn't get dynamic methods to work. - /// - private static readonly bool Is64Bit = Environment.Is64BitProcess; - /// /// A new instance Initializes a new instance of the class. /// with lazy initialization. @@ -82,7 +71,6 @@ namespace ImageProcessor.Web.Configuration /// private ImageProcessorConfiguration() { - this.EnsureNativeBinariesLoaded(); this.LoadGraphicsProcessors(); } #endregion @@ -365,22 +353,6 @@ namespace ImageProcessor.Web.Configuration webProcessor.Processor.Settings = this.GetPluginSettings(webProcessor.GetType().Name); } } - - /// - /// Ensures that the native binaries are loaded. - /// - private void EnsureNativeBinariesLoaded() - { - // Load the correct method from the native binary module. - // We do it here as on init will cause an UnauthorizedAccessException. - HttpModuleCollection modules = HttpContext.Current.ApplicationInstance.Modules; - ImageProcessorNativeBinaryModule nativeBinaryModule = modules.Get("ImageProcessorNativeBinaryModule") as ImageProcessorNativeBinaryModule; - - if (nativeBinaryModule != null) - { - nativeBinaryModule.LoadNativeBinaries(); - } - } #endregion } -} +} \ No newline at end of file diff --git a/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessorNativeBinaryModule.cs b/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessorNativeBinaryModule.cs deleted file mode 100644 index 57f8cfdc08..0000000000 --- a/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessorNativeBinaryModule.cs +++ /dev/null @@ -1,161 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) James South. -// Licensed under the Apache License, Version 2.0. -// -// -// The image processing native binary module. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace ImageProcessor.Web.HttpModules -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Reflection; - using System.Web; - - using ImageProcessor.Web.Helpers; - - /// - /// Controls the loading and unloading of any native binaries required by ImageProcessor.Web. - /// - public sealed class ImageProcessorNativeBinaryModule : IHttpModule - { - /// - /// Whether the process is running in 64bit mode. Used for calling the correct dllimport method. - /// - private static readonly bool Is64Bit = Environment.Is64BitProcess; - - /// - /// The object to lock against. - /// - private static readonly object SyncRoot = new object(); - - /// - /// The native binaries. - /// - private static readonly List NativeBinaries = new List(); - - /// - /// A value indicating whether this instance of the given entity has been disposed. - /// - /// if this instance has been disposed; otherwise, . - /// - /// If the entity is disposed, it must not be disposed a second - /// time. The isDisposed field is set the first time the entity - /// is disposed. If the isDisposed field is true, then the Dispose() - /// method will not dispose again. This help not to prolong the entity's - /// life in the Garbage Collector. - /// - private bool isDisposed; - - /// - /// Disposes of the resources (other than memory) used by the module that implements - /// . - /// - public void Dispose() - { - if (this.isDisposed) - { - return; - } - - // Call the appropriate methods to clean up - // unmanaged resources here. - lock (SyncRoot) - { - this.FreeNativeBinaries(); - } - - // Note disposing is done. - this.isDisposed = true; - } - - /// - /// Initializes a module and prepares it to handle requests. - /// - /// An that provides access to - /// the methods, properties, and events common to all application objects within an ASP.NET application - public void Init(HttpApplication context) - { - } - - /// - /// Loads any native ImageProcessor binaries. - /// - public void LoadNativeBinaries() - { - lock (SyncRoot) - { - this.RegisterNativeBinaries(); - } - } - - /// - /// Registers any native binaries. - /// - /// - /// Thrown when a native binary cannot be loaded. - /// - private void RegisterNativeBinaries() - { - if (NativeBinaries.Any()) - { - return; - } - - string folder = Is64Bit ? "x64" : "x86"; - string sourcePath = HttpContext.Current.Server.MapPath("~/bin/" + folder); - Assembly assembly = Assembly.GetExecutingAssembly(); - string targetBasePath = new Uri(assembly.Location).LocalPath; - - DirectoryInfo directoryInfo = new DirectoryInfo(sourcePath); - if (directoryInfo.Exists) - { - foreach (FileInfo fileInfo in directoryInfo.EnumerateFiles("*.dll")) - { - if (fileInfo.Name.ToUpperInvariant().StartsWith("IMAGEPROCESSOR")) - { - IntPtr pointer; - string targetPath = Path.GetFullPath(Path.Combine(targetBasePath, "..\\" + folder + "\\" + fileInfo.Name)); - - File.Copy(sourcePath, targetPath, true); - - try - { - // Load the binary into memory. - pointer = NativeMethods.LoadLibrary(targetPath); - } - catch (Exception ex) - { - throw new ApplicationException(ex.Message); - } - - if (pointer == IntPtr.Zero) - { - throw new ApplicationException("Cannot load " + fileInfo.Name); - } - - NativeBinaries.Add(pointer); - } - } - } - } - - /// - /// Frees the reference to the native binaries. - /// - private void FreeNativeBinaries() - { - foreach (IntPtr nativeBinary in NativeBinaries) - { - // According to http://stackoverflow.com/a/2445558/427899 you need to call this twice. - NativeMethods.FreeLibrary(nativeBinary); - NativeMethods.FreeLibrary(nativeBinary); - } - } - } -} diff --git a/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj b/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj index 47bd96a171..40bd16bc71 100644 --- a/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj +++ b/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj @@ -62,7 +62,6 @@ - diff --git a/src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs b/src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs index a9d9c5542d..09b7724554 100644 --- a/src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs +++ b/src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs @@ -12,9 +12,7 @@ namespace ImageProcessor.Configuration { using System; using System.Collections.Generic; - using System.IO; using System.Linq; - using System.Reflection; using ImageProcessor.Common.Exceptions; using ImageProcessor.Common.Extensions; @@ -38,6 +36,7 @@ namespace ImageProcessor.Configuration private ImageProcessorBootstrapper() { this.LoadSupportedImageFormats(); + this.NativeBinaryFactory = new NativeBinaryFactory(); } /// @@ -56,6 +55,11 @@ namespace ImageProcessor.Configuration /// public IEnumerable SupportedImageFormats { get; private set; } + /// + /// Gets the native binary factory for registering embedded (unmanaged) binaries. + /// + public NativeBinaryFactory NativeBinaryFactory { get; private set; } + /// /// Creates a list, using reflection, of supported image formats that ImageProcessor can run. /// diff --git a/src/ImageProcessor/Configuration/NativeBinaryFactory.cs b/src/ImageProcessor/Configuration/NativeBinaryFactory.cs new file mode 100644 index 0000000000..5db7a37158 --- /dev/null +++ b/src/ImageProcessor/Configuration/NativeBinaryFactory.cs @@ -0,0 +1,196 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Controls the loading and unloading of any native binaries required by ImageProcessor. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.Configuration +{ + using System; + using System.Collections.Concurrent; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Reflection; + + /// + /// Controls the loading and unloading of any native binaries required by ImageProcessor. + /// + public class NativeBinaryFactory : IDisposable + { + /// + /// Whether the process is running in 64bit mode. Used for calling the correct dllimport method. + /// + private static readonly bool Is64Bit = Environment.Is64BitProcess; + + /// + /// The native binaries. + /// + private static ConcurrentDictionary nativeBinaries; + + /// + /// A value indicating whether this instance of the given entity has been disposed. + /// + /// if this instance has been disposed; otherwise, . + /// + /// If the entity is disposed, it must not be disposed a second + /// time. The isDisposed field is set the first time the entity + /// is disposed. If the isDisposed field is true, then the Dispose() + /// method will not dispose again. This help not to prolong the entity's + /// life in the Garbage Collector. + /// + private bool isDisposed; + + /// + /// Initializes a new instance of the class. + /// + public NativeBinaryFactory() + { + nativeBinaries = new ConcurrentDictionary(); + } + + /// + /// Finalizes an instance of the ImageFactory class. + /// + /// + /// Use C# destructor syntax for finalization code. + /// This destructor will run only if the Dispose method + /// does not get called. + /// It gives your base class the opportunity to finalize. + /// Do not provide destructors in types derived from this class. + /// + ~NativeBinaryFactory() + { + // Do not re-create Dispose clean-up code here. + // Calling Dispose(false) is optimal in terms of + // readability and maintainability. + this.Dispose(false); + } + + /// + /// Registers any embedded native (unmanaged) binaries required by ImageProcessor. + /// + /// + /// The name of the native binary. + /// + /// + /// The resource bytes containing the native binary. + /// + /// + /// Thrown if the binary cannot be registered. + /// + public void RegisterNativeBinary(string name, byte[] resourceBytes) + { + nativeBinaries.GetOrAdd( + name, + b => + { + IntPtr pointer; + string folder = Is64Bit ? "x64" : "x86"; + Assembly assembly = Assembly.GetExecutingAssembly(); + string targetBasePath = new Uri(assembly.Location).LocalPath; + string targetPath = Path.GetFullPath(Path.Combine(targetBasePath, "..\\" + folder + "\\" + name)); + + // Copy the file across if necessary. + FileInfo fileInfo = new FileInfo(targetPath); + bool rewrite = true; + if (fileInfo.Exists) + { + byte[] existing = File.ReadAllBytes(targetPath); + + if (resourceBytes.SequenceEqual(existing)) + { + rewrite = false; + } + } + + if (rewrite) + { + // ReSharper disable once AssignNullToNotNullAttribute + DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(targetPath)); + if (!directoryInfo.Exists) + { + directoryInfo.Create(); + } + + File.WriteAllBytes(targetPath, resourceBytes); + } + + try + { + // Load the binary into memory. + pointer = NativeMethods.LoadLibrary(targetPath); + } + catch (Exception ex) + { + throw new ApplicationException(ex.Message); + } + + if (pointer == IntPtr.Zero) + { + throw new ApplicationException("Cannot load " + name); + } + + return pointer; + }); + } + + /// + /// Disposes the object and frees resources for the Garbage Collector. + /// + public void Dispose() + { + this.Dispose(true); + + // This object will be cleaned up by the Dispose method. + // Therefore, you should call GC.SupressFinalize to + // take this object off the finalization queue + // and prevent finalization code for this object + // from executing a second time. + GC.SuppressFinalize(this); + } + + /// + /// Disposes the object and frees resources for the Garbage Collector. + /// + /// If true, the object gets disposed. + protected virtual void Dispose(bool disposing) + { + if (this.isDisposed) + { + return; + } + + if (disposing) + { + // Dispose of any managed resources here. + } + + // Call the appropriate methods to clean up + // unmanaged resources here. + this.FreeNativeBinaries(); + + // Note disposing is done. + this.isDisposed = true; + } + + /// + /// Frees the reference to the native binaries. + /// + private void FreeNativeBinaries() + { + foreach (KeyValuePair nativeBinary in nativeBinaries) + { + IntPtr pointer = nativeBinary.Value; + + // According to http://stackoverflow.com/a/2445558/427899 you need to call this twice. + NativeMethods.FreeLibrary(pointer); + NativeMethods.FreeLibrary(pointer); + } + } + } +} diff --git a/src/ImageProcessor/Configuration/NativeMethods.cs b/src/ImageProcessor/Configuration/NativeMethods.cs new file mode 100644 index 0000000000..ea2aa1aa91 --- /dev/null +++ b/src/ImageProcessor/Configuration/NativeMethods.cs @@ -0,0 +1,44 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Provides access to unmanaged native methods. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.Configuration +{ + using System; + using System.Runtime.InteropServices; + + /// + /// Provides access to unmanaged native methods. + /// + internal class NativeMethods + { + /// + /// Loads the specified module into the address space of the calling process. + /// The specified module may cause other modules to be loaded. + /// + /// + /// The name of the module. This can be either a library module or + /// an executable module. + /// + /// If the function succeeds, the return value is a handle to the module; otherwise null. + [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern IntPtr LoadLibrary(string libname); + + /// + /// Frees the loaded dynamic-link library (DLL) module and, if necessary, decrements its reference count. + /// When the reference count reaches zero, the module is unloaded from the address space of the calling + /// process and the handle is no longer valid. + /// + /// A handle to the loaded library module. + /// The LoadLibrary, LoadLibraryEx, GetModuleHandle, or GetModuleHandleEx function returns this handle. + /// If the function succeeds, the return value is nonzero; otherwise zero. + [DllImport("kernel32.dll", CharSet = CharSet.Auto)] + public static extern bool FreeLibrary(IntPtr hModule); + } +} diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj index 73ac24ef73..ad69d127b4 100644 --- a/src/ImageProcessor/ImageProcessor.csproj +++ b/src/ImageProcessor/ImageProcessor.csproj @@ -64,6 +64,8 @@ + + @@ -130,12 +132,8 @@ - - PreserveNewest - - - PreserveNewest - + + diff --git a/src/ImageProcessor/Imaging/Formats/NativeMethods.cs b/src/ImageProcessor/Imaging/Formats/NativeMethods.cs index 7b3bc7d268..b6cb764505 100644 --- a/src/ImageProcessor/Imaging/Formats/NativeMethods.cs +++ b/src/ImageProcessor/Imaging/Formats/NativeMethods.cs @@ -11,8 +11,12 @@ namespace ImageProcessor.Imaging.Formats { using System; + using System.IO; + using System.Reflection; using System.Runtime.InteropServices; + using ImageProcessor.Configuration; + /// /// Provides access to unmanaged native methods. /// @@ -24,123 +28,26 @@ namespace ImageProcessor.Imaging.Formats /// private static readonly bool Is64Bit = Environment.Is64BitProcess; - #region WebP /// - /// Validate the WebP image header and retrieve the image height and width. Pointers *width and *height can be passed NULL if deemed irrelevant + /// Initializes static members of the class. /// - /// - /// Pointer to WebP image data - /// - /// - /// This is the size of the memory block pointed to by data containing the image data - /// - /// - /// The width range is limited currently from 1 to 16383 - /// - /// - /// The height range is limited currently from 1 to 16383 - /// - /// - /// 1 if success, otherwise error code returned in the case of (a) formatting error(s). - /// - public static int WebPGetInfo(IntPtr data, uint dataSize, out int width, out int height) + static NativeMethods() { - return Is64Bit ? WebPGetInfo64(data, dataSize, out width, out height) - : WebPGetInfo86(data, dataSize, out width, out height); - } + string folder = Is64Bit ? "x64" : "x86"; + string name = string.Format("ImageProcessor.Resources.Unmanaged.{0}.libwebp.dll", folder); + Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name); - /// - /// Decode WEBP image pointed to by *data and returns BGR samples into a pre-allocated buffer - /// - /// - /// Pointer to WebP image data - /// - /// - /// This is the size of the memory block pointed to by data containing the image data - /// - /// - /// Pointer to decoded WebP image - /// - /// - /// Size of allocated buffer - /// - /// - /// Specifies the distance between scan-lines - /// - /// - /// output_buffer if function succeeds; NULL otherwise - /// - public static IntPtr WebPDecodeBGRAInto(IntPtr data, uint dataSize, IntPtr outputBuffer, int outputBufferSize, int outputStride) - { - return Is64Bit ? WebPDecodeBGRAInto64(data, dataSize, outputBuffer, outputBufferSize, outputStride) - : WebPDecodeBGRAInto86(data, dataSize, outputBuffer, outputBufferSize, outputStride); + using (MemoryStream memoryStream = new MemoryStream()) + { + if (stream != null) + { + stream.CopyTo(memoryStream); + ImageProcessorBootstrapper.Instance.NativeBinaryFactory.RegisterNativeBinary("libwebp.dll", memoryStream.ToArray()); + } + } } - /// - /// Lossy encoding images pointed to by *data in WebP format - /// - /// - /// Pointer to RGB image data - /// - /// - /// The width range is limited currently from 1 to 16383 - /// - /// - /// The height range is limited currently from 1 to 16383 - /// - /// - /// The stride. - /// - /// - /// Ranges from 0 (lower quality) to 100 (highest quality). Controls the loss and quality during compression - /// - /// - /// output_buffer with WebP image - /// - /// - /// Size of WebP Image - /// - public static int WebPEncodeBGRA(IntPtr rgb, int width, int height, int stride, float qualityFactor, out IntPtr output) - { - return Is64Bit ? WebPEncodeBGRA64(rgb, width, height, stride, qualityFactor, out output) - : WebPEncodeBGRA86(rgb, width, height, stride, qualityFactor, out output); - } - - /// - /// Frees the unmanaged memory. - /// - /// - /// The pointer. - /// - /// - /// 1 if success, otherwise error code returned in the case of (a) error(s). - /// - public static int WebPFree(IntPtr pointer) - { - return Is64Bit ? WebPFree64(pointer) : WebPFree86(pointer); - } - - /// - /// Validate the WebP image header and retrieve the image height and width. Pointers *width and *height can be passed NULL if deemed irrelevant - /// - /// - /// Pointer to WebP image data - /// - /// - /// This is the size of the memory block pointed to by data containing the image data - /// - /// - /// The width range is limited currently from 1 to 16383 - /// - /// - /// The height range is limited currently from 1 to 16383 - /// - /// - /// 1 if success, otherwise error code returned in the case of (a) formatting error(s). - /// - [DllImport("x86\\imageprocessor.libwebp.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "WebPGetInfo")] - private static extern int WebPGetInfo86(IntPtr data, uint dataSize, out int width, out int height); - + #region WebP /// /// Validate the WebP image header and retrieve the image height and width. Pointers *width and *height can be passed NULL if deemed irrelevant /// @@ -159,32 +66,8 @@ namespace ImageProcessor.Imaging.Formats /// /// 1 if success, otherwise error code returned in the case of (a) formatting error(s). /// - [DllImport("x64\\imageprocessor.libwebp.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "WebPGetInfo")] - private static extern int WebPGetInfo64(IntPtr data, uint dataSize, out int width, out int height); - - /// - /// Decode WEBP image pointed to by *data and returns BGR samples into a pre-allocated buffer - /// - /// - /// Pointer to WebP image data - /// - /// - /// This is the size of the memory block pointed to by data containing the image data - /// - /// - /// Pointer to decoded WebP image - /// - /// - /// Size of allocated buffer - /// - /// - /// Specifies the distance between scan-lines - /// - /// - /// output_buffer if function succeeds; NULL otherwise - /// - [DllImport("x86\\imageprocessor.libwebp.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "WebPDecodeBGRAInto")] - private static extern IntPtr WebPDecodeBGRAInto86(IntPtr data, uint dataSize, IntPtr outputBuffer, int outputBufferSize, int outputStride); + [DllImport("libwebp.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "WebPGetInfo")] + public static extern int WebPGetInfo(IntPtr data, uint dataSize, out int width, out int height); /// /// Decode WEBP image pointed to by *data and returns BGR samples into a pre-allocated buffer @@ -207,8 +90,8 @@ namespace ImageProcessor.Imaging.Formats /// /// output_buffer if function succeeds; NULL otherwise /// - [DllImport("x64\\imageprocessor.libwebp.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "WebPDecodeBGRAInto")] - private static extern IntPtr WebPDecodeBGRAInto64(IntPtr data, uint dataSize, IntPtr outputBuffer, int outputBufferSize, int outputStride); + [DllImport("libwebp.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "WebPDecodeBGRAInto")] + public static extern IntPtr WebPDecodeBGRAInto(IntPtr data, uint dataSize, IntPtr outputBuffer, int outputBufferSize, int outputStride); /// /// Lossy encoding images pointed to by *data in WebP format @@ -234,47 +117,8 @@ namespace ImageProcessor.Imaging.Formats /// /// Size of WebP Image /// - [DllImport("x86\\imageprocessor.libwebp.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "WebPEncodeBGRA")] - private static extern int WebPEncodeBGRA86(IntPtr rgb, int width, int height, int stride, float qualityFactor, out IntPtr output); - - /// - /// Lossy encoding images pointed to by *data in WebP format - /// - /// - /// Pointer to RGB image data - /// - /// - /// The width range is limited currently from 1 to 16383 - /// - /// - /// The height range is limited currently from 1 to 16383 - /// - /// - /// The stride. - /// - /// - /// Ranges from 0 (lower quality) to 100 (highest quality). Controls the loss and quality during compression - /// - /// - /// output_buffer with WebP image - /// - /// - /// Size of WebP Image - /// - [DllImport("x64\\imageprocessor.libwebp.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "WebPEncodeBGRA")] - private static extern int WebPEncodeBGRA64(IntPtr rgb, int width, int height, int stride, float qualityFactor, out IntPtr output); - - /// - /// Frees the unmanaged memory. - /// - /// - /// The pointer. - /// - /// - /// 1 if success, otherwise error code returned in the case of (a) error(s). - /// - [DllImport("x86\\imageprocessor.libwebp.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "WebPFree")] - private static extern int WebPFree86(IntPtr pointer); + [DllImport("libwebp.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "WebPEncodeBGRA")] + public static extern int WebPEncodeBGRA(IntPtr rgb, int width, int height, int stride, float qualityFactor, out IntPtr output); /// /// Frees the unmanaged memory. @@ -285,8 +129,8 @@ namespace ImageProcessor.Imaging.Formats /// /// 1 if success, otherwise error code returned in the case of (a) error(s). /// - [DllImport("x64\\imageprocessor.libwebp.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "WebPFree")] - private static extern int WebPFree64(IntPtr pointer); + [DllImport("libwebp.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "WebPFree")] + public static extern int WebPFree(IntPtr pointer); #endregion } } diff --git a/src/ImageProcessor/Imaging/Formats/WebPFormat.cs b/src/ImageProcessor/Imaging/Formats/WebPFormat.cs index 9f350c5c0b..49dfdf75a5 100644 --- a/src/ImageProcessor/Imaging/Formats/WebPFormat.cs +++ b/src/ImageProcessor/Imaging/Formats/WebPFormat.cs @@ -22,6 +22,7 @@ namespace ImageProcessor.Imaging.Formats using System.Text; using ImageProcessor.Common.Exceptions; + using ImageProcessor.Configuration; /// /// Provides the necessary information to support webp images. diff --git a/src/ImageProcessor/x64/imageprocessor.libwebp.dll.REMOVED.git-id b/src/ImageProcessor/Resources/Unmanaged/x64/libwebp.dll.REMOVED.git-id similarity index 100% rename from src/ImageProcessor/x64/imageprocessor.libwebp.dll.REMOVED.git-id rename to src/ImageProcessor/Resources/Unmanaged/x64/libwebp.dll.REMOVED.git-id diff --git a/src/ImageProcessor/x86/imageprocessor.libwebp.dll.REMOVED.git-id b/src/ImageProcessor/Resources/Unmanaged/x86/libwebp.dll.REMOVED.git-id similarity index 100% rename from src/ImageProcessor/x86/imageprocessor.libwebp.dll.REMOVED.git-id rename to src/ImageProcessor/Resources/Unmanaged/x86/libwebp.dll.REMOVED.git-id diff --git a/src/ImageProcessorConsole/Program.cs b/src/ImageProcessorConsole/Program.cs index 5bacb50dde..a84e4a5dbd 100644 --- a/src/ImageProcessorConsole/Program.cs +++ b/src/ImageProcessorConsole/Program.cs @@ -40,7 +40,7 @@ namespace ImageProcessorConsole di.Create(); } - IEnumerable files = GetFilesByExtensions(di, ".gif"); + IEnumerable files = GetFilesByExtensions(di, ".webp"); //IEnumerable files = GetFilesByExtensions(di, ".gif", ".webp", ".bmp", ".jpg", ".png"); foreach (FileInfo fileInfo in files) diff --git a/src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id b/src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id deleted file mode 100644 index 4767fd13de..0000000000 --- a/src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -6f3f997e323adb1fce142930d86338efacffc3fd \ No newline at end of file diff --git a/src/ImageProcessorConsole/images/output/Tl4Yb.gif.REMOVED.git-id b/src/ImageProcessorConsole/images/output/Tl4Yb.gif.REMOVED.git-id deleted file mode 100644 index f0f194a2bb..0000000000 --- a/src/ImageProcessorConsole/images/output/Tl4Yb.gif.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -3ab082661fc5d88f88643c47409e196d66e26d4b \ No newline at end of file diff --git a/src/ImageProcessorConsole/images/output/circle.png b/src/ImageProcessorConsole/images/output/circle.png deleted file mode 100644 index 41fdcd72af..0000000000 Binary files a/src/ImageProcessorConsole/images/output/circle.png and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/nLpfllv.gif.REMOVED.git-id b/src/ImageProcessorConsole/images/output/nLpfllv.gif.REMOVED.git-id deleted file mode 100644 index b8684cd602..0000000000 --- a/src/ImageProcessorConsole/images/output/nLpfllv.gif.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -e2c2fbac64987ad26e19f5d2721fcaa60fee843d \ No newline at end of file diff --git a/src/ImageProcessorConsole/images/output/rotate.jpg b/src/ImageProcessorConsole/images/output/rotate.jpg deleted file mode 100644 index 55c97888dc..0000000000 Binary files a/src/ImageProcessorConsole/images/output/rotate.jpg and /dev/null differ diff --git a/src/TestWebsites/NET45/Test_Website_NET45/Web.config b/src/TestWebsites/NET45/Test_Website_NET45/Web.config index 528462e12a..67e3367778 100644 --- a/src/TestWebsites/NET45/Test_Website_NET45/Web.config +++ b/src/TestWebsites/NET45/Test_Website_NET45/Web.config @@ -43,7 +43,6 @@ - @@ -64,7 +63,6 @@ -