Browse Source

Fix alpha in blur/sharpen

Former-commit-id: 61655d3efbe0f50634494d8fb60fb1f31c19c630
Former-commit-id: 34f12510e1d229b557ac0c8e4cbff14ea675e1ad
Former-commit-id: 0b27a97895bbeeca43d9ff8d3569e321b5e34896
af/merge-core
James Jackson-South 11 years ago
parent
commit
42f388283c
  1. 28
      src/ImageProcessor/Filters/Convolution/Convolution2PassFilter.cs
  2. 4
      tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs
  3. 2
      tests/ImageProcessor.Tests/Processors/ProcessorTestBase.cs

28
src/ImageProcessor/Filters/Convolution/Convolution2PassFilter.cs

@ -80,12 +80,13 @@ namespace ImageProcessor.Filters
{
for (int x = startX; x < endX; x++)
{
float rX = 0;
float gX = 0;
float bX = 0;
float red = 0;
float green = 0;
float blue = 0;
float alpha = 0;
// Apply each matrix multiplier to the color components for each pixel.
for (int fy = 0; fy < kernelHeight; fy++)
// Apply each matrix multiplier to the color components for each pixel.
for (int fy = 0; fy < kernelHeight; fy++)
{
int fyr = fy - radiusY;
int offsetY = y + fyr;
@ -100,22 +101,15 @@ namespace ImageProcessor.Filters
offsetX = offsetX.Clamp(0, maxX);
Color currentColor = source[offsetX, offsetY];
float r = currentColor.R;
float g = currentColor.G;
float b = currentColor.B;
rX += kernel[fy, fx] * r;
gX += kernel[fy, fx] * g;
bX += kernel[fy, fx] * b;
red += kernel[fy, fx] * currentColor.R;
green += kernel[fy, fx] * currentColor.G;
blue += kernel[fy, fx] * currentColor.B;
alpha += kernel[fy, fx] * currentColor.A;
}
}
float red = rX;
float green = gX;
float blue = bX;
Color targetColor = target[x, y];
target[x, y] = new Color(red, green, blue, targetColor.A);
target[x, y] = new Color(red, green, blue, alpha);
}
}
});

4
tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs

@ -38,8 +38,8 @@ namespace ImageProcessor.Tests
//{ "RobertsCross", new RobertsCross() },
//{ "Scharr", new Scharr() },
//{ "Sobel", new Sobel() },
//{ "GuassianBlur", new GuassianBlur() },
{ "GuassianSharpen", new GuassianSharpen() }
{ "GuassianBlur", new GuassianBlur(10) },
{ "GuassianSharpen", new GuassianSharpen(10) }
};
[Theory]

2
tests/ImageProcessor.Tests/Processors/ProcessorTestBase.cs

@ -32,7 +32,7 @@ namespace ImageProcessor.Tests
"../../TestImages/Formats/Png/cballs.png",
//"../../TestImages/Formats/Png/cmyk.png",
//"../../TestImages/Formats/Png/gamma-1.0-or-2.2.png",
//"../../TestImages/Formats/Png/splash.png",
"../../TestImages/Formats/Png/splash.png",
//"../../TestImages/Formats/Gif/leaf.gif",
//"../../TestImages/Formats/Gif/ben2.gif",
//"../../TestImages/Formats/Gif/rings.gif",

Loading…
Cancel
Save