public override BitmapSource ExecuteFilter(BitmapSource inputImage) { byte[] sourceBytes = new byte[inputImage.PixelWidth * inputImage.PixelHeight * 4]; byte[] destBytes = new byte[inputImage.PixelWidth * inputImage.PixelHeight * 4]; inputImage.CopyPixels(sourceBytes, inputImage.PixelWidth * 4, 0); float redAdjust = 1.0f + (this.Warmth / 100.0f); float blueAdjust = 1.0f - (this.Warmth / 100.0f); GaussianBlurFilter blur = new GaussianBlurFilter(3 * Softness); BrightnessContrastFilter bc = new BrightnessContrastFilter(Lighting, -Lighting / 2); DesaturateFilter desat = new DesaturateFilter(); inputImage = blur.ExecuteFilter(inputImage); inputImage.CopyPixels(destBytes, inputImage.PixelWidth * 4, 0); int width = inputImage.PixelWidth; int height = inputImage.PixelHeight; for (int i = 0; i < sourceBytes.Length; i += 4) { byte b = sourceBytes[i]; byte g = sourceBytes[i + 1]; byte r = sourceBytes[i + 2]; byte a = sourceBytes[i + 3]; bc.PerformOperation(ref b, ref g, ref r, ref a); desat.PerformOperation(ref b, ref g, ref r, ref a); double rD = r * redAdjust; double bD = r * blueAdjust; if (rD > 255) { rD = 255; } else if (rD < 0) { rD = 0; } if (bD > 255) { bD = 255; } else if (bD < 0) { bD = 0; } destBytes[i] = PixelBlend.BlendOverlay(b, destBytes[i]); destBytes[i + 1] = PixelBlend.BlendOverlay(g, destBytes[i + 1]); destBytes[i + 2] = PixelBlend.BlendOverlay(r, destBytes[i + 2]); destBytes[i + 3] = PixelBlend.BlendOverlay(a, destBytes[i + 3]); } return(BitmapSource.Create(inputImage.PixelWidth, inputImage.PixelHeight, 96, 96, inputImage.Format, null, destBytes, inputImage.PixelWidth * 4)); }
public override BitmapSource ExecuteFilter(BitmapSource inputImage) { byte[] srcBytes = new byte[inputImage.PixelWidth * inputImage.PixelHeight * 4]; byte[] finalBytes = new byte[inputImage.PixelWidth * inputImage.PixelHeight * 4]; inputImage.CopyPixels(srcBytes, inputImage.PixelWidth * 4, 0); BrightnessContrastFilter bcFilter = new BrightnessContrastFilter(Brightness, Contrast); GaussianBlurFilter blurFilter = new GaussianBlurFilter(Radius); BitmapSource glow = blurFilter.ExecuteFilter(inputImage); byte[] glowBytes = new byte[glow.PixelWidth * glow.PixelHeight * 4]; glow.CopyPixels(glowBytes, glow.PixelWidth * 4, 0); for (int i = 0; i < glowBytes.Length; i += 4) { byte b = glowBytes[i]; byte g = glowBytes[i + 1]; byte r = glowBytes[i + 2]; byte a = glowBytes[i + 3]; bcFilter.PerformOperation(ref b, ref g, ref r, ref a); finalBytes[i] = PixelBlend.BlendScreen(srcBytes[i], b); finalBytes[i + 1] = PixelBlend.BlendScreen(srcBytes[i + 1], g); finalBytes[i + 2] = PixelBlend.BlendScreen(srcBytes[i + 2], r); finalBytes[i + 3] = 255; } return(BitmapSource.Create(inputImage.PixelWidth, inputImage.PixelHeight, 96, 96, inputImage.Format, null, finalBytes, inputImage.PixelWidth * 4)); }