Browse Source

v2.2.4

Former-commit-id: 04c60e2a80b2cadf870ee13f03d8a97f8126e951
Former-commit-id: 0d456022ccb52a1a5247e1ed8ccb2dba22f184ee
Former-commit-id: 23efb4c9b9005835b8f685ae3f17bb147b9ff4c1
pull/17/head
James South 11 years ago
parent
commit
9eccb38ef1
  1. 2
      build/build.xml
  2. 12
      src/ImageProcessor.Playground/Program.cs
  3. 62
      src/ImageProcessor/Imaging/FastBitmap.cs
  4. 41
      src/ImageProcessor/Imaging/Helpers/Adjustments.cs
  5. 4
      src/ImageProcessor/Properties/AssemblyInfo.cs

2
build/build.xml

@ -1,7 +1,7 @@
<projects>
<project>
<name>ImageProcessor</name>
<version>2.2.3.0</version>
<version>2.2.4.0</version>
<folder>..\src\ImageProcessor</folder>
<projfile>ImageProcessor.csproj</projfile>
<outputs>

12
src/ImageProcessor.Playground/Program.cs

@ -72,8 +72,8 @@ namespace ImageProcessor.PlayGround
//FileInfo fileInfo = new FileInfo(Path.Combine(resolvedPath, "cmyk.png"));
//IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".gif");
//IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".png", ".jpg", ".jpeg");
IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".jpg", ".jpeg", ".jfif");
//IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".png");
// IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".jpg", ".jpeg", ".jfif");
IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".png");
//IEnumerable<FileInfo> 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)

62
src/ImageProcessor/Imaging/FastBitmap.cs

@ -66,6 +66,11 @@ namespace ImageProcessor.Imaging
/// </summary>
private readonly int channel;
/// <summary>
/// Whether to compute integral rectangles.
/// </summary>
private readonly bool computeIntegrals;
/// <summary>
/// Whether to compute tilted integral rectangles.
/// </summary>
@ -172,10 +177,25 @@ namespace ImageProcessor.Imaging
/// Initializes a new instance of the <see cref="FastBitmap"/> class.
/// </summary>
/// <param name="bitmap">The input bitmap.</param>
/// <param name="computeIntegrals">
/// Whether to compute integral rectangles.
/// </param>
public FastBitmap(Image bitmap, bool computeIntegrals)
: this(bitmap, computeIntegrals, false)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FastBitmap"/> class.
/// </summary>
/// <param name="bitmap">The input bitmap.</param>
/// <param name="computeIntegrals">
/// Whether to compute integral rectangles.
/// </param>
/// <param name="computeTilted">
/// Whether to compute tilted integral rectangles.
/// </param>
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();
}
}
/// <summary>

41
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;
}

4
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")]

Loading…
Cancel
Save