Browse Source

Fix alpha in blur/sharpen

Former-commit-id: 84890eb08e6efb88ba6afa03aae3d7a1901f183c
Former-commit-id: 0e5514d691a608c5a28f5dc697a19dbf2efcaaf1
Former-commit-id: 8c7585826eaaec3a703fa6ef65f5b7f758b517ab
af/merge-core
James Jackson-South 10 years ago
parent
commit
49efa26822
  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