diff --git a/build/build.xml b/build/build.xml index dd40840b8..694c0cada 100644 --- a/build/build.xml +++ b/build/build.xml @@ -1,7 +1,7 @@ ImageProcessor - 2.2.3.0 + 2.2.4.0 ..\src\ImageProcessor ImageProcessor.csproj diff --git a/src/ImageProcessor.Playground/Program.cs b/src/ImageProcessor.Playground/Program.cs index 590ad5989..0ea7594df 100644 --- a/src/ImageProcessor.Playground/Program.cs +++ b/src/ImageProcessor.Playground/Program.cs @@ -72,8 +72,8 @@ namespace ImageProcessor.PlayGround //FileInfo fileInfo = new FileInfo(Path.Combine(resolvedPath, "cmyk.png")); //IEnumerable files = GetFilesByExtensions(di, ".gif"); //IEnumerable files = GetFilesByExtensions(di, ".png", ".jpg", ".jpeg"); - IEnumerable files = GetFilesByExtensions(di, ".jpg", ".jpeg", ".jfif"); - //IEnumerable files = GetFilesByExtensions(di, ".png"); + // IEnumerable files = GetFilesByExtensions(di, ".jpg", ".jpeg", ".jfif"); + IEnumerable files = GetFilesByExtensions(di, ".png"); //IEnumerable files = GetFilesByExtensions(di, ".gif", ".webp", ".bmp", ".jpg", ".png"); foreach (FileInfo fileInfo in files) @@ -94,9 +94,9 @@ namespace ImageProcessor.PlayGround { using (ImageFactory imageFactory = new ImageFactory(true, true)) { - Size size = new Size(600, 0); + Size size = new Size(1920, 1920); //CropLayer cropLayer = new CropLayer(20, 20, 20, 20, ImageProcessor.Imaging.CropMode.Percentage); - //ResizeLayer layer = new ResizeLayer(size, ResizeMode.Max, AnchorPosition.Center, false); + ResizeLayer layer = new ResizeLayer(size, ResizeMode.Max, AnchorPosition.Center, false); // TextLayer textLayer = new TextLayer() //{ // Text = "هناك حقيقة مثبتة منذ زمن", @@ -133,7 +133,7 @@ namespace ImageProcessor.PlayGround //.GaussianSharpen(3) //.Saturation(20) //.Resize(size) - //.Resize(new ResizeLayer(size, ResizeMode.Max)) + .Resize(layer) // .Resize(new ResizeLayer(size, ResizeMode.Stretch)) //.DetectEdges(new SobelEdgeFilter(), true) //.DetectEdges(new LaplacianOfGaussianEdgeFilter()) @@ -147,7 +147,7 @@ namespace ImageProcessor.PlayGround //.Filter(MatrixFilters.Invert) //.Brightness(-5) //.Contrast(50) - .Filter(MatrixFilters.Comic) + //.Filter(MatrixFilters.Comic) //.Flip() //.Filter(MatrixFilters.HiSatch) //.Pixelate(8) diff --git a/src/ImageProcessor/Imaging/FastBitmap.cs b/src/ImageProcessor/Imaging/FastBitmap.cs index 750ccad64..195aa6fd5 100644 --- a/src/ImageProcessor/Imaging/FastBitmap.cs +++ b/src/ImageProcessor/Imaging/FastBitmap.cs @@ -66,6 +66,11 @@ namespace ImageProcessor.Imaging /// private readonly int channel; + /// + /// Whether to compute integral rectangles. + /// + private readonly bool computeIntegrals; + /// /// Whether to compute tilted integral rectangles. /// @@ -172,10 +177,25 @@ namespace ImageProcessor.Imaging /// Initializes a new instance of the class. /// /// The input bitmap. + /// + /// Whether to compute integral rectangles. + /// + public FastBitmap(Image bitmap, bool computeIntegrals) + : this(bitmap, computeIntegrals, false) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The input bitmap. + /// + /// Whether to compute integral rectangles. + /// /// /// Whether to compute tilted integral rectangles. /// - public FastBitmap(Image bitmap, bool computeTilted) + public FastBitmap(Image bitmap, bool computeIntegrals, bool computeTilted) { int pixelFormat = (int)bitmap.PixelFormat; @@ -193,6 +213,7 @@ namespace ImageProcessor.Imaging this.height = this.bitmap.Height; this.channel = pixelFormat == Format8bppIndexed ? 0 : 2; + this.computeIntegrals = computeIntegrals; this.computeTilted = computeTilted; this.LockBitmap(); @@ -515,29 +536,32 @@ namespace ImageProcessor.Imaging // Set the value to the first scan line this.pixelBase = (byte*)this.bitmapData.Scan0.ToPointer(); - // Allocate values for integral image calculation. - this.normalWidth = this.width + 1; - int normalHeight = this.height + 1; + if (this.computeIntegrals) + { + // Allocate values for integral image calculation. + this.normalWidth = this.width + 1; + int normalHeight = this.height + 1; - this.tiltedWidth = this.width + 2; - int tiltedHeight = this.height + 2; + this.tiltedWidth = this.width + 2; + int tiltedHeight = this.height + 2; - this.normalSumImage = new long[normalHeight, this.normalWidth]; - this.normalSumHandle = GCHandle.Alloc(this.normalSumImage, GCHandleType.Pinned); - this.normalSum = (long*)this.normalSumHandle.AddrOfPinnedObject().ToPointer(); + this.normalSumImage = new long[normalHeight, this.normalWidth]; + this.normalSumHandle = GCHandle.Alloc(this.normalSumImage, GCHandleType.Pinned); + this.normalSum = (long*)this.normalSumHandle.AddrOfPinnedObject().ToPointer(); - this.squaredSumImage = new long[normalHeight, this.normalWidth]; - this.squaredSumHandle = GCHandle.Alloc(this.squaredSumImage, GCHandleType.Pinned); - this.squaredSum = (long*)this.squaredSumHandle.AddrOfPinnedObject().ToPointer(); + this.squaredSumImage = new long[normalHeight, this.normalWidth]; + this.squaredSumHandle = GCHandle.Alloc(this.squaredSumImage, GCHandleType.Pinned); + this.squaredSum = (long*)this.squaredSumHandle.AddrOfPinnedObject().ToPointer(); - if (this.computeTilted) - { - this.tiltedSumImage = new long[tiltedHeight, this.tiltedWidth]; - this.tiltedSumHandle = GCHandle.Alloc(this.tiltedSumImage, GCHandleType.Pinned); - this.tiltedSum = (long*)this.tiltedSumHandle.AddrOfPinnedObject().ToPointer(); - } + if (this.computeTilted) + { + this.tiltedSumImage = new long[tiltedHeight, this.tiltedWidth]; + this.tiltedSumHandle = GCHandle.Alloc(this.tiltedSumImage, GCHandleType.Pinned); + this.tiltedSum = (long*)this.tiltedSumHandle.AddrOfPinnedObject().ToPointer(); + } - this.CalculateIntegrals(); + this.CalculateIntegrals(); + } } /// diff --git a/src/ImageProcessor/Imaging/Helpers/Adjustments.cs b/src/ImageProcessor/Imaging/Helpers/Adjustments.cs index cb583bd47..641537399 100644 --- a/src/ImageProcessor/Imaging/Helpers/Adjustments.cs +++ b/src/ImageProcessor/Imaging/Helpers/Adjustments.cs @@ -204,47 +204,16 @@ namespace ImageProcessor.Imaging.Helpers Bitmap destination = new Bitmap(width, height); destination.SetResolution(source.HorizontalResolution, source.VerticalResolution); - byte[] ramp = new byte[256]; - for (int x = 0; x < 256; ++x) + Rectangle rectangle = new Rectangle(0, 0, width, height); + using (Graphics graphics = Graphics.FromImage(destination)) { - byte val = ((255.0 * Math.Pow(x / 255.0, value)) + 0.5).ToByte(); - ramp[x] = val; - } - - using (FastBitmap fastSource = new FastBitmap(source)) - { - using (FastBitmap fastDestination = new FastBitmap(destination)) + using (ImageAttributes attributes = new ImageAttributes()) { - Parallel.For( - 0, - height, - y => - { - for (int x = 0; x < width; x++) - { - // ReSharper disable once AccessToDisposedClosure - Color color = fastSource.GetPixel(x, y); - byte r = ramp[color.R]; - byte g = ramp[color.G]; - byte b = ramp[color.B]; - - // ReSharper disable once AccessToDisposedClosure - fastDestination.SetPixel(x, y, Color.FromArgb(color.A, r, g, b)); - } - }); + attributes.SetGamma(value); + graphics.DrawImage(source, rectangle, 0, 0, width, height, GraphicsUnit.Pixel, attributes); } } - //Rectangle rectangle = new Rectangle(0, 0, width, height); - //using (Graphics graphics = Graphics.FromImage(destination)) - //{ - // using (ImageAttributes attributes = new ImageAttributes()) - // { - // attributes.SetGamma(value); - // graphics.DrawImage(source, rectangle, 0, 0, width, height, GraphicsUnit.Pixel, attributes); - // } - //} - source.Dispose(); return destination; } diff --git a/src/ImageProcessor/Properties/AssemblyInfo.cs b/src/ImageProcessor/Properties/AssemblyInfo.cs index 38bbae15e..c589c6098 100644 --- a/src/ImageProcessor/Properties/AssemblyInfo.cs +++ b/src/ImageProcessor/Properties/AssemblyInfo.cs @@ -41,8 +41,8 @@ using System.Runtime.InteropServices; // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("2.2.3.0")] -[assembly: AssemblyFileVersion("2.2.3.0")] +[assembly: AssemblyVersion("2.2.4.0")] +[assembly: AssemblyFileVersion("2.2.4.0")] [assembly: InternalsVisibleTo("ImageProcessor.UnitTests")] [assembly: InternalsVisibleTo("ImageProcessor.Web")]