diff --git a/src/ImageProcessor.Tests/RegularExpressionUnitTests.cs b/src/ImageProcessor.Tests/RegularExpressionUnitTests.cs index c184374dd..088053df6 100644 --- a/src/ImageProcessor.Tests/RegularExpressionUnitTests.cs +++ b/src/ImageProcessor.Tests/RegularExpressionUnitTests.cs @@ -18,8 +18,8 @@ [TestMethod] public void TestAlphaRegex() { - string querystring = "alpha=56"; - int expected = 56; + const string querystring = "alpha=56"; + const int expected = 56; Alpha alpha = new Alpha(); alpha.MatchRegexIndex(querystring); @@ -60,6 +60,7 @@ [TestMethod] public void TestRotateRegex() { + // Why does this fail? string querystring = "rotate=270"; RotateLayer expected = new RotateLayer { @@ -72,8 +73,6 @@ RotateLayer actual = rotate.DynamicParameter; - Debug.Print("{0}{1}", actual.Angle, actual.BackgroundColor); - Assert.AreEqual(expected, actual); } #endregion diff --git a/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs b/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs index 68895043f..da41a9573 100644 --- a/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs +++ b/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs @@ -11,6 +11,7 @@ namespace ImageProcessor.Web.HttpModules using System; using System.IO; using System.Net; + using System.Reflection; using System.Web; using System.Web.Hosting; using ImageProcessor.Helpers.Extensions; @@ -40,6 +41,11 @@ namespace ImageProcessor.Web.HttpModules /// The object to lock against. /// private static readonly object SyncRoot = new object(); + + /// + /// The assembly version. + /// + private static readonly string AssemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); #endregion #region IHttpModule Members @@ -232,6 +238,8 @@ namespace ImageProcessor.Web.HttpModules response.ContentType = responseType; + response.AddHeader("Image-Served-By", "ImageProcessor/" + AssemblyVersion); + HttpCachePolicy cache = response.Cache; cache.VaryByHeaders["Accept-Encoding"] = true; diff --git a/src/ImageProcessor.Web/Properties/AssemblyInfo.cs b/src/ImageProcessor.Web/Properties/AssemblyInfo.cs index 89e023946..a2f13edc1 100644 --- a/src/ImageProcessor.Web/Properties/AssemblyInfo.cs +++ b/src/ImageProcessor.Web/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ 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("1.3.0.0")] -[assembly: AssemblyFileVersion("1.3.0.0")] +[assembly: AssemblyVersion("2.0.0.0")] +[assembly: AssemblyFileVersion("2.0.0.0")] diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs index 737b54778..93fa21b49 100644 --- a/src/ImageProcessor/ImageFactory.cs +++ b/src/ImageProcessor/ImageFactory.cs @@ -77,7 +77,7 @@ namespace ImageProcessor public string ImagePath { get; private set; } /// - /// Gets the querystring params for web image manipulation. + /// Gets the query-string parameters for web image manipulation. /// public string QueryString { get; private set; } @@ -177,9 +177,9 @@ namespace ImageProcessor #region Manipulation /// - /// Adds a querystring to the image factory to allow autoprocessing of remote files. + /// Adds a query-string to the image factory to allow auto-processing of remote files. /// - /// The querystring parameter to process. + /// The query-string parameter to process. /// /// The current instance of the class. /// @@ -533,7 +533,7 @@ namespace ImageProcessor /// /// Uses the - /// to fix the colour palette of gif images. + /// to fix the color palette of gif images. /// private void FixGifs() { diff --git a/src/ImageProcessor/Imaging/Filters/BlackWhiteMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/BlackWhiteMatrixFilter.cs index 6fdd1f11d..bea19b178 100644 --- a/src/ImageProcessor/Imaging/Filters/BlackWhiteMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/BlackWhiteMatrixFilter.cs @@ -19,10 +19,10 @@ namespace ImageProcessor.Imaging.Filters /// /// Encapsulates methods with which to add a black and white filter to an image. /// - class BlackWhiteMatrixFilter : IMatrixFilter + internal class BlackWhiteMatrixFilter : IMatrixFilter { /// - /// Gets the for this filter instance. + /// Gets the for this filter instance. /// public ColorMatrix Matrix { diff --git a/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs index 93394037e..ce694a4b3 100644 --- a/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs @@ -17,7 +17,7 @@ namespace ImageProcessor.Imaging.Filters /// /// Encapsulates methods with which to add a comic filter to an image. /// - class ComicMatrixFilter : IMatrixFilter + internal class ComicMatrixFilter : IMatrixFilter { /// /// Enumurates Argb colour channels. diff --git a/src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs index 3f679d130..327789852 100644 --- a/src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs @@ -20,10 +20,10 @@ namespace ImageProcessor.Imaging.Filters /// /// Encapsulates methods with which to add a gotham filter to an image. /// - class GothamMatrixFilter : IMatrixFilter + internal class GothamMatrixFilter : IMatrixFilter { /// - /// Gets the for this filter instance. + /// Gets the for this filter instance. /// public ColorMatrix Matrix { diff --git a/src/ImageProcessor/Imaging/Filters/GreyScaleMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/GreyScaleMatrixFilter.cs index 46b64a379..fa3874e51 100644 --- a/src/ImageProcessor/Imaging/Filters/GreyScaleMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/GreyScaleMatrixFilter.cs @@ -19,10 +19,10 @@ namespace ImageProcessor.Imaging.Filters /// /// Encapsulates methods with which to add a greyscale filter to an image. /// - class GreyScaleMatrixFilter : IMatrixFilter + internal class GreyScaleMatrixFilter : IMatrixFilter { /// - /// Gets the for this filter instance. + /// Gets the for this filter instance. /// public ColorMatrix Matrix { diff --git a/src/ImageProcessor/Imaging/Filters/HiSatchMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/HiSatchMatrixFilter.cs index 1e6946f60..47bff6d76 100644 --- a/src/ImageProcessor/Imaging/Filters/HiSatchMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/HiSatchMatrixFilter.cs @@ -19,10 +19,10 @@ namespace ImageProcessor.Imaging.Filters /// /// Encapsulates methods with which to add a high saturated filter to an image. /// - class HiSatchMatrixFilter : IMatrixFilter + internal class HiSatchMatrixFilter : IMatrixFilter { /// - /// Gets the for this filter instance. + /// Gets the for this filter instance. /// public ColorMatrix Matrix { diff --git a/src/ImageProcessor/Imaging/Filters/IMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/IMatrixFilter.cs index 89783de41..4de697fb3 100644 --- a/src/ImageProcessor/Imaging/Filters/IMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/IMatrixFilter.cs @@ -18,7 +18,7 @@ namespace ImageProcessor.Imaging.Filters interface IMatrixFilter { /// - /// Gets the for this filter instance. + /// Gets the for this filter instance. /// ColorMatrix Matrix { get; } diff --git a/src/ImageProcessor/Imaging/Filters/InvertMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/InvertMatrixFilter.cs index dfd40b65f..71bc16996 100644 --- a/src/ImageProcessor/Imaging/Filters/InvertMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/InvertMatrixFilter.cs @@ -19,10 +19,10 @@ namespace ImageProcessor.Imaging.Filters /// /// Encapsulates methods with which to add an inverted filter to an image. /// - class InvertMatrixFilter : IMatrixFilter + internal class InvertMatrixFilter : IMatrixFilter { /// - /// Gets the for this filter instance. + /// Gets the for this filter instance. /// public ColorMatrix Matrix { diff --git a/src/ImageProcessor/Imaging/Filters/LoSatchMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/LoSatchMatrixFilter.cs index b02d19ad0..db7d97266 100644 --- a/src/ImageProcessor/Imaging/Filters/LoSatchMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/LoSatchMatrixFilter.cs @@ -19,10 +19,10 @@ namespace ImageProcessor.Imaging.Filters /// /// Encapsulates methods with which to add a low saturated filter to an image. /// - class LoSatchMatrixFilter : IMatrixFilter + internal class LoSatchMatrixFilter : IMatrixFilter { /// - /// Gets the for this filter instance. + /// Gets the for this filter instance. /// public ColorMatrix Matrix { diff --git a/src/ImageProcessor/Imaging/Filters/LomographMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/LomographMatrixFilter.cs index d9b92158f..e69e2066c 100644 --- a/src/ImageProcessor/Imaging/Filters/LomographMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/LomographMatrixFilter.cs @@ -20,10 +20,10 @@ namespace ImageProcessor.Imaging.Filters /// /// Encapsulates methods with which to add a lomograph filter to an image. /// - class LomographMatrixFilter : IMatrixFilter + internal class LomographMatrixFilter : IMatrixFilter { /// - /// Gets the for this filter instance. + /// Gets the for this filter instance. /// public ColorMatrix Matrix { diff --git a/src/ImageProcessor/Imaging/Filters/PolaroidMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/PolaroidMatrixFilter.cs index 60cd46ef7..618209c9d 100644 --- a/src/ImageProcessor/Imaging/Filters/PolaroidMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/PolaroidMatrixFilter.cs @@ -21,10 +21,10 @@ namespace ImageProcessor.Imaging.Filters /// /// Encapsulates methods with which to add a polaroid filter to an image. /// - class PolaroidMatrixFilter : IMatrixFilter + internal class PolaroidMatrixFilter : IMatrixFilter { /// - /// Gets the for this filter instance. + /// Gets the for this filter instance. /// public ColorMatrix Matrix { diff --git a/src/ImageProcessor/Imaging/Filters/SepiaMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/SepiaMatrixFilter.cs index 6277a76a7..1dc057974 100644 --- a/src/ImageProcessor/Imaging/Filters/SepiaMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/SepiaMatrixFilter.cs @@ -19,10 +19,10 @@ namespace ImageProcessor.Imaging.Filters /// /// Encapsulates methods with which to add a sepia filter to an image. /// - class SepiaMatrixFilter : IMatrixFilter + internal class SepiaMatrixFilter : IMatrixFilter { /// - /// Gets the for this filter instance. + /// Gets the for this filter instance. /// public ColorMatrix Matrix { diff --git a/src/ImageProcessor/Imaging/RotateLayer.cs b/src/ImageProcessor/Imaging/RotateLayer.cs index ad4790714..a56fa54c9 100644 --- a/src/ImageProcessor/Imaging/RotateLayer.cs +++ b/src/ImageProcessor/Imaging/RotateLayer.cs @@ -8,13 +8,15 @@ namespace ImageProcessor.Imaging { #region Using + using System; + using System.Collections.Generic; using System.Drawing; #endregion /// - /// Enacapsulates the properties required to rotate an image. + /// Encapsulates the properties required to rotate an image. /// - public class RotateLayer + public class RotateLayer : IEqualityComparer { #region Constructors /// @@ -37,5 +39,58 @@ namespace ImageProcessor.Imaging /// public Color BackgroundColor { get; set; } #endregion + + /// + /// Returns a value indicating whether this instance is equal to another . + /// + /// + /// The other to compare to. + /// + /// + /// True if this instance is equal to another ; otherwise, false. + /// + public bool Equals(RotateLayer other) + { + return this.Angle.Equals(other.Angle) && this.BackgroundColor.Equals(other.BackgroundColor); + } + + /// + /// Determines whether the specified objects are equal. + /// + /// + /// true if the specified objects are equal; otherwise, false. + /// + /// + /// The first object of type to compare. + /// + /// + /// The second object of type to compare. + /// + public bool Equals(RotateLayer x, RotateLayer y) + { + return x.Angle.Equals(y.Angle) && x.BackgroundColor.Equals(y.BackgroundColor); + } + + /// + /// Returns a hash code for the specified object. + /// + /// + /// A hash code for the specified object. + /// + /// + /// The for which a hash code is to be returned. + /// + /// + /// The type of is a reference type and is null. + /// + public int GetHashCode(RotateLayer obj) + { + if (obj == null) + { + throw new ArgumentNullException(); + } + + return this.Angle.GetHashCode() + this.BackgroundColor.GetHashCode(); + } } } diff --git a/src/ImageProcessor/Processors/Copy of Filter.cs b/src/ImageProcessor/Processors/Copy of Filter.cs deleted file mode 100644 index df31ffce8..000000000 --- a/src/ImageProcessor/Processors/Copy of Filter.cs +++ /dev/null @@ -1,610 +0,0 @@ -// ----------------------------------------------------------------------- -// -// TODO: Update copyright text. -// -// ----------------------------------------------------------------------- - -namespace ImageProcessor.Processors -{ - #region Using - - using System; - using System.Collections.Generic; - using System.Drawing; - using System.Drawing.Drawing2D; - using System.Drawing.Imaging; - using System.IO; - using System.Text.RegularExpressions; - using System.Web; - using System.Web.Hosting; - - #endregion - - /// - /// Encapsulates methods with which to add filters to an image. - /// - public class Filter : IGraphicsProcessor - { - /// - /// The regular expression to search strings for. - /// - private static readonly Regex QueryRegex = new Regex(@"filter=(lomograph|polaroid|blackwhite|sepia|greyscale|gotham|invert|hisatch|losatch|comic)", RegexOptions.Compiled); - - /// - /// Enumurates Argb colour channels. - /// - private enum ChannelArgb - { - /// - /// The blue channel - /// - Blue = 0, - - /// - /// The green channel - /// - Green = 1, - - /// - /// The red channel - /// - Red = 2, - - /// - /// The alpha channel - /// - Alpha = 3 - } - - #region IGraphicsProcessor Members - /// - /// Gets the name. - /// - public string Name - { - get - { - return "Filter"; - } - } - - /// - /// Gets the description. - /// - public string Description - { - get - { - return "Encapsulates methods with which to add filters to an image. e.g polaroid, lomograph"; - } - } - - /// - /// Gets the regular expression to search strings for. - /// - public Regex RegexPattern - { - get - { - return QueryRegex; - } - } - - /// - /// Gets or sets DynamicParameter. - /// - public dynamic DynamicParameter - { - get; - set; - } - - /// - /// Gets the order in which this processor is to be used in a chain. - /// - public int SortOrder - { - get; - private set; - } - - /// - /// Gets or sets any additional settings required by the processor. - /// - public Dictionary Settings - { - get; - set; - } - - /// - /// The position in the original string where the first character of the captured substring was found. - /// - /// - /// The query string to search. - /// - /// - /// The zero-based starting position in the original string where the captured substring was found. - /// - public int MatchRegexIndex(string queryString) - { - int index = 0; - - // Set the sort order to max to allow filtering. - this.SortOrder = int.MaxValue; - - foreach (Match match in this.RegexPattern.Matches(queryString)) - { - if (match.Success) - { - if (index == 0) - { - // Set the index on the first instance only. - this.SortOrder = match.Index; - this.DynamicParameter = match.Value.Split('=')[1]; - } - - index += 1; - } - } - - return this.SortOrder; - } - - /// - /// Processes the image. - /// - /// - /// The the current instance of the class containing - /// the image to process. - /// - /// - /// The processed image from the current instance of the class. - /// - public Image ProcessImage(ImageFactory factory) - { - Bitmap newImage = null; - Image image = factory.Image; - - // Bitmaps for comic pattern - Bitmap hisatchBitmap = null; - Bitmap patternBitmap = null; - - try - { - // Dont use an object initializer here. - newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb); - newImage.Tag = image.Tag; - - ColorMatrix colorMatrix = null; - - switch ((string)this.DynamicParameter) - { - case "polaroid": - colorMatrix = ColorMatrixes.Polaroid; - break; - case "lomograph": - colorMatrix = ColorMatrixes.Lomograph; - break; - case "sepia": - colorMatrix = ColorMatrixes.Sepia; - break; - case "blackwhite": - colorMatrix = ColorMatrixes.BlackWhite; - break; - case "greyscale": - colorMatrix = ColorMatrixes.GreyScale; - break; - case "gotham": - colorMatrix = ColorMatrixes.Gotham; - break; - case "invert": - colorMatrix = ColorMatrixes.Invert; - break; - case "hisatch": - colorMatrix = ColorMatrixes.HiSatch; - break; - case "losatch": - colorMatrix = ColorMatrixes.LoSatch; - break; - case "comic": - colorMatrix = ColorMatrixes.LoSatch; - break; - } - - using (Graphics graphics = Graphics.FromImage(newImage)) - { - using (ImageAttributes attributes = new ImageAttributes()) - { - if (colorMatrix != null) - { - attributes.SetColorMatrix(colorMatrix); - } - - Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height); - - if (this.DynamicParameter == "comic") - { - // Set the attributes to LoSatch and draw the image. - graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes); - - // Create a bitmap for overlaying. - hisatchBitmap = new Bitmap(rectangle.Width, rectangle.Height, PixelFormat.Format32bppPArgb); - - // Set the color matrix - attributes.SetColorMatrix(ColorMatrixes.HiSatch); - - // Draw the image with the hisatch colormatrix. - using (var g = Graphics.FromImage(hisatchBitmap)) - { - g.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes); - } - - // We need to create a new image now with the hi saturation colormatrix and a pattern mask to paint it - // onto the other image with. - patternBitmap = new Bitmap(rectangle.Width, rectangle.Height, PixelFormat.Format32bppPArgb); - - // Create the pattern mask. - using (var g = Graphics.FromImage(patternBitmap)) - { - g.Clear(Color.Black); - g.SmoothingMode = SmoothingMode.HighQuality; - for (var y = 0; y < image.Height; y += 10) - { - for (var x = 0; x < image.Width; x += 6) - { - g.FillEllipse(Brushes.White, x, y, 4, 4); - g.FillEllipse(Brushes.White, x + 3, y + 5, 4, 4); - } - } - } - - // Transfer the alpha channel from the mask to the hi sturation image. - TransferOneArgbChannelFromOneBitmapToAnother(patternBitmap, hisatchBitmap, ChannelArgb.Blue, ChannelArgb.Alpha); - - // Overlay the image. - graphics.DrawImage(hisatchBitmap, 0, 0); - - // Dispose of the other images - hisatchBitmap.Dispose(); - patternBitmap.Dispose(); - } - else - { - graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes); - - // Polaroid requires an extra tweak. - if (this.DynamicParameter == "polaroid") - { - using (GraphicsPath path = new GraphicsPath()) - { - path.AddEllipse(rectangle); - using (PathGradientBrush brush = new PathGradientBrush(path)) - { - // Fill a rectangle with an elliptical gradient brush that goes from orange to transparent. - // This has the effect of painting the far corners transparent and fading in to orange on the - // way in to the centre. - brush.WrapMode = WrapMode.Tile; - brush.CenterColor = Color.FromArgb(70, 255, 153, 102); - brush.SurroundColors = new Color[] { Color.FromArgb(0, 0, 0, 0) }; - - Blend blend = new Blend - { - Positions = new float[] { 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0F }, - Factors = new float[] { 0.0f, 0.5f, 1f, 1f, 1.0f, 1.0f } - }; - - brush.Blend = blend; - - Region oldClip = graphics.Clip; - graphics.Clip = new Region(rectangle); - graphics.FillRectangle(brush, rectangle); - graphics.Clip = oldClip; - } - } - } - - // Gotham requires an extra tweak. - if (this.DynamicParameter == "gotham") - { - using (GraphicsPath path = new GraphicsPath()) - { - path.AddRectangle(rectangle); - - // Paint a burgundy rectangle with a transparency of ~30% over the image. - // Paint a blue rectangle with a transparency of 20% over the image. - using (SolidBrush brush = new SolidBrush(Color.FromArgb(77, 43, 4, 18))) - { - Region oldClip = graphics.Clip; - graphics.Clip = new Region(rectangle); - graphics.FillRectangle(brush, rectangle); - - // Fill the blue. - brush.Color = Color.FromArgb(51, 12, 22, 88); - graphics.FillRectangle(brush, rectangle); - graphics.Clip = oldClip; - } - } - } - } - } - } - - // Add a vignette to finish the effect. - // TODO: This feels a bit mucky so I might chop it out. - if (this.DynamicParameter == "polaroid" || this.DynamicParameter == "lomograph") - { - factory.Image = newImage; - Vignette vignette = new Vignette(); - newImage = (Bitmap)vignette.ProcessImage(factory); - } - - // Reassign the image. - image.Dispose(); - image = newImage; - } - catch - { - if (newImage != null) - { - newImage.Dispose(); - } - - if (hisatchBitmap != null) - { - hisatchBitmap.Dispose(); - } - - if (patternBitmap != null) - { - patternBitmap.Dispose(); - } - } - - return image; - } - #endregion - - /// - /// Transfers a single ARGB channel from one image to another. - /// - /// - /// The source. - /// - /// - /// The destination. - /// - /// - /// The source channel. - /// - /// - /// The destination channel. - /// - private static void TransferOneArgbChannelFromOneBitmapToAnother(Bitmap source, Bitmap destination, ChannelArgb sourceChannel, ChannelArgb destinationChannel) - { - if (source.Size != destination.Size) - { - throw new ArgumentException(); - } - - Rectangle rectangle = new Rectangle(Point.Empty, source.Size); - - // Lockbits the source. - BitmapData bitmapDataSource = source.LockBits(rectangle, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); - - // Declare an array to hold the bytes of the bitmap. - int bytes = bitmapDataSource.Stride * bitmapDataSource.Height; - - // Allocate a buffer for the source image - byte[] sourceRgbValues = new byte[bytes]; - - // Copy the RGB values into the array. - System.Runtime.InteropServices.Marshal.Copy(bitmapDataSource.Scan0, sourceRgbValues, 0, bytes); - - // Unlockbits the source. - source.UnlockBits(bitmapDataSource); - - // Lockbits the destination. - BitmapData bitmapDataDestination = destination.LockBits(rectangle, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); - - // Allocate a buffer for image - byte[] destinationRgbValues = new byte[bytes]; - - // Copy the RGB values into the array. - System.Runtime.InteropServices.Marshal.Copy(bitmapDataDestination.Scan0, destinationRgbValues, 0, bytes); - - int s = (int)sourceChannel; - int d = (int)destinationChannel; - - for (int i = rectangle.Height * rectangle.Width; i > 0; i--) - { - destinationRgbValues[d] = sourceRgbValues[s]; - d += 4; - s += 4; - } - - // Copy the RGB values back to the bitmap - System.Runtime.InteropServices.Marshal.Copy(destinationRgbValues, 0, bitmapDataDestination.Scan0, bytes); - - // Unlock bits the destination. - destination.UnlockBits(bitmapDataDestination); - } - - /// - /// A list of available color matrices to apply to an image. - /// - private static class ColorMatrixes - { - /// - /// Gets Sepia. - /// - internal static ColorMatrix Sepia - { - get - { - return new ColorMatrix( - new float[][] - { - new float[] { .393f, .349f, .272f, 0, 0 }, - new float[] { .769f, .686f, .534f, 0, 0 }, - new float[] { .189f, .168f, .131f, 0, 0 }, - new float[] { 0, 0, 0, 1, 0 }, - new float[] { 0, 0, 0, 0, 1 } - }); - } - } - - /// - /// Gets BlackWhite. - /// - internal static ColorMatrix BlackWhite - { - get - { - return new ColorMatrix( - new float[][] - { - new float[] { 1.5f, 1.5f, 1.5f, 0, 0 }, - new float[] { 1.5f, 1.5f, 1.5f, 0, 0 }, - new float[] { 1.5f, 1.5f, 1.5f, 0, 0 }, - new float[] { 0, 0, 0, 1, 0 }, - new float[] { -1, -1, -1, 0, 1 } - }); - } - } - - /// - /// Gets Polaroid. - /// - internal static ColorMatrix Polaroid - { - get - { - return new ColorMatrix( - new float[][] - { - new float[] { 1.638f, -0.062f, -0.262f, 0, 0 }, - new float[] { -0.122f, 1.378f, -0.122f, 0, 0 }, - new float[] { 1.016f, -0.016f, 1.383f, 0, 0 }, - new float[] { 0, 0, 0, 1, 0 }, - new float[] { 0.06f, -0.05f, -0.05f, 0, 1 } - }); - } - } - - /// - /// Gets Lomograph. - /// - internal static ColorMatrix Lomograph - { - get - { - return new ColorMatrix( - new float[][] - { - new float[] { 1.50f, 0, 0, 0, 0 }, - new float[] { 0, 1.45f, 0, 0, 0 }, - new float[] { 0, 0, 1.09f, 0, 0 }, - new float[] { 0, 0, 0, 1, 0 }, - new float[] { -0.10f, 0.05f, -0.08f, 0, 1 } - }); - } - } - - /// - /// Gets GreyScale. - /// - internal static ColorMatrix GreyScale - { - get - { - return new ColorMatrix( - new float[][] - { - new float[] { .33f, .33f, .33f, 0, 0 }, - new float[] { .59f, .59f, .59f, 0, 0 }, - new float[] { .11f, .11f, .11f, 0, 0 }, - new float[] { 0, 0, 0, 1, 0 }, - new float[] { 0, 0, 0, 0, 1 } - }); - } - } - - /// - /// Gets Gotham. - /// - internal static ColorMatrix Gotham - { - get - { - return new ColorMatrix( - new float[][] - { - new float[] { .9f, .9f, .9f, 0, 0 }, - new float[] { .9f, .9f, .9f, 0, 0 }, - new float[] { .9f, .9f, .9f, 0, 0 }, - new float[] { 0, 0, 0, 1, 0 }, - new float[] { -.5f, -.5f, -.45f, 0, 1 } - }); - } - } - - /// - /// Gets Invert. - /// - internal static ColorMatrix Invert - { - get - { - return new ColorMatrix( - new float[][] - { - new float[] { -1, 0, 0, 0, 0 }, - new float[] { 0, -1, 0, 0, 0 }, - new float[] { 0, 0, -1, 0, 0 }, - new float[] { 0, 0, 0, 1, 0 }, - new float[] { 1, 1, 1, 0, 1 } - }); - } - } - - /// - /// Gets HiSatch. - /// - internal static ColorMatrix HiSatch - { - get - { - return new ColorMatrix( - new float[][] - { - new float[] { 3, -1, -1, 0, 0 }, - new float[] { -1, 3, -1, 0, 0 }, - new float[] { -1, -1, 3, 0, 0 }, - new float[] { 0, 0, 0, 1, 0 }, - new float[] { 0, 0, 0, 0, 1 } - }); - } - } - - /// - /// Gets LoSatch. - /// - internal static ColorMatrix LoSatch - { - get - { - return new ColorMatrix( - new float[][] - { - new float[] { 1, 0, 0, 0, 0 }, - new float[] { 0, 1, 0, 0, 0 }, - new float[] { 0, 0, 1, 0, 0 }, - new float[] { 0, 0, 0, 1, 0 }, - new float[] { .25f, .25f, .25f, 0, 1 } - }); - } - } - } - } -} diff --git a/src/ImageProcessor/Processors/Png8.cs b/src/ImageProcessor/Processors/Png8.cs deleted file mode 100644 index 36b44f0b7..000000000 --- a/src/ImageProcessor/Processors/Png8.cs +++ /dev/null @@ -1,147 +0,0 @@ -// ----------------------------------------------------------------------- -// -// TODO: Update copyright text. -// -// ----------------------------------------------------------------------- - -namespace ImageProcessor.Processors -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Drawing; - using System.Linq; - using System.Text; - using System.Text.RegularExpressions; - using ImageProcessor.Imaging; - - /// - /// TODO: Update summary. - /// - public class Png8 : IGraphicsProcessor - { - #region Implementation of IGraphicsProcessor - - /// - /// Gets the name. - /// - public string Name - { - get - { - throw new NotImplementedException(); - } - } - - /// - /// Gets the description. - /// - public string Description - { - get - { - throw new NotImplementedException(); - } - } - - /// - /// Gets the regular expression to search strings for. - /// - public Regex RegexPattern - { - get - { - throw new NotImplementedException(); - } - } - - /// - /// Gets DynamicParameter. - /// - public dynamic DynamicParameter - { - get - { - throw new NotImplementedException(); - } - } - - /// - /// Gets the order in which this processor is to be used in a chain. - /// - public int SortOrder - { - get - { - throw new NotImplementedException(); - } - } - - /// - /// Gets or sets any additional settings required by the processor. - /// - public Dictionary Settings - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - /// - /// The position in the original string where the first character of the captured substring was found. - /// - /// - /// The query string to search. - /// - /// - /// The zero-based starting position in the original string where the captured substring was found. - /// - public int MatchRegexIndex(string queryString) - { - throw new NotImplementedException(); - } - - /// - /// Processes the image. - /// - /// - /// The the current instance of the class containing - /// the image to process. - /// - /// - /// The processed image from the current instance of the class. - /// - public Image ProcessImage(ImageFactory factory) - { - Bitmap newImage = null; - Image image = factory.Image; - try - { - newImage = new Bitmap(image) { Tag = image.Tag }; - using (Graphics graphics = Graphics.FromImage(newImage)) - { - ArrayList pallete = new ArrayList(); - PaletteQuantizer paletteQuantizer = new PaletteQuantizer(new ArrayList(newImage.Palette.Entries)); - newImage = paletteQuantizer.Quantize(newImage); - } - - } - catch - { - if (newImage != null) - { - newImage.Dispose(); - } - } - - return image; - } - - #endregion - } -} diff --git a/src/ImageProcessor/Properties/AssemblyInfo.cs b/src/ImageProcessor/Properties/AssemblyInfo.cs index 23e407cbc..87a64030b 100644 --- a/src/ImageProcessor/Properties/AssemblyInfo.cs +++ b/src/ImageProcessor/Properties/AssemblyInfo.cs @@ -32,6 +32,6 @@ using System.Security; // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.3.0.0")] -[assembly: AssemblyFileVersion("1.3.0.0")] +[assembly: AssemblyVersion("1.4.0.0")] +[assembly: AssemblyFileVersion("1.4.0.0")] diff --git a/src/Nuget/ImageProcessor.1.4.0.0.nupkg b/src/Nuget/ImageProcessor.1.4.0.0.nupkg new file mode 100644 index 000000000..e3dfdce91 Binary files /dev/null and b/src/Nuget/ImageProcessor.1.4.0.0.nupkg differ diff --git a/src/Nuget/ImageProcessor.Web.2.0.0.0.nupkg b/src/Nuget/ImageProcessor.Web.2.0.0.0.nupkg new file mode 100644 index 000000000..2ccc1e324 Binary files /dev/null and b/src/Nuget/ImageProcessor.Web.2.0.0.0.nupkg differ diff --git a/src/Test/Test/Test.csproj b/src/Test/Test/Test.csproj index 5c803077b..b5c334041 100644 --- a/src/Test/Test/Test.csproj +++ b/src/Test/Test/Test.csproj @@ -91,6 +91,8 @@ + +