|
|
@ -13,6 +13,8 @@ namespace ImageProcessor.Processors |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Drawing; |
|
|
using System.Drawing; |
|
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
|
using ImageProcessor.Common.Exceptions; |
|
|
using ImageProcessor.Common.Exceptions; |
|
|
using ImageProcessor.Common.Extensions; |
|
|
using ImageProcessor.Common.Extensions; |
|
|
using ImageProcessor.Imaging; |
|
|
using ImageProcessor.Imaging; |
|
|
@ -72,7 +74,7 @@ namespace ImageProcessor.Processors |
|
|
byte originalB = original.B; |
|
|
byte originalB = original.B; |
|
|
|
|
|
|
|
|
Color replacement = parameters.Item2; |
|
|
Color replacement = parameters.Item2; |
|
|
byte replacementR = original.R; |
|
|
byte replacementR = replacement.R; |
|
|
byte replacementG = replacement.G; |
|
|
byte replacementG = replacement.G; |
|
|
byte replacementB = replacement.B; |
|
|
byte replacementB = replacement.B; |
|
|
byte replacementA = replacement.A; |
|
|
byte replacementA = replacement.A; |
|
|
@ -85,14 +87,18 @@ namespace ImageProcessor.Processors |
|
|
|
|
|
|
|
|
using (FastBitmap fastBitmap = new FastBitmap(newImage)) |
|
|
using (FastBitmap fastBitmap = new FastBitmap(newImage)) |
|
|
{ |
|
|
{ |
|
|
for (int y = 0; y < height; y++) |
|
|
Parallel.For( |
|
|
|
|
|
0, |
|
|
|
|
|
height, |
|
|
|
|
|
y => |
|
|
{ |
|
|
{ |
|
|
for (int x = 0; x < width; x++) |
|
|
for (int x = 0; x < width; x++) |
|
|
{ |
|
|
{ |
|
|
// Get the pixel color.
|
|
|
// Get the pixel color.
|
|
|
|
|
|
// ReSharper disable once AccessToDisposedClosure
|
|
|
Color currentColor = fastBitmap.GetPixel(x, y); |
|
|
Color currentColor = fastBitmap.GetPixel(x, y); |
|
|
byte currentR = currentColor.R; |
|
|
byte currentR = currentColor.R; |
|
|
byte currentG = currentColor.B; |
|
|
byte currentG = currentColor.G; |
|
|
byte currentB = currentColor.B; |
|
|
byte currentB = currentColor.B; |
|
|
byte currentA = currentColor.A; |
|
|
byte currentA = currentColor.A; |
|
|
|
|
|
|
|
|
@ -112,12 +118,13 @@ namespace ImageProcessor.Processors |
|
|
// Allow replacement with transparent color.
|
|
|
// Allow replacement with transparent color.
|
|
|
byte a = currentA != replacementA ? replacementA : currentA; |
|
|
byte a = currentA != replacementA ? replacementA : currentA; |
|
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once AccessToDisposedClosure
|
|
|
fastBitmap.SetPixel(x, y, Color.FromArgb(a, r, g, b)); |
|
|
fastBitmap.SetPixel(x, y, Color.FromArgb(a, r, g, b)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
image.Dispose(); |
|
|
image.Dispose(); |
|
|
|