From c755ac602e4d39f997b6d4584949777ce146a636 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 4 Nov 2015 18:09:59 +1100 Subject: [PATCH] Use Lerp silly! Former-commit-id: eaf0f42e5396ade62ae183cebf6e5184497d4080 Former-commit-id: 549126e52b96fa9964cd784d4b9d77d49a144406 Former-commit-id: ab690f14924de2ae267ffc189dd741c6281b10bc --- src/ImageProcessor/Filters/Blend.cs | 8 ++------ .../Processors/Filters/FilterTests.cs | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/ImageProcessor/Filters/Blend.cs b/src/ImageProcessor/Filters/Blend.cs index 2bc6ace25c..858ed56028 100644 --- a/src/ImageProcessor/Filters/Blend.cs +++ b/src/ImageProcessor/Filters/Blend.cs @@ -59,13 +59,9 @@ namespace ImageProcessor.Filters { Color blendedColor = this.toBlend[x, y]; - // Combining colors is dependent on the alpha of the blended color + // Lerping colors is dependent on the alpha of the blended color float alphaFactor = alpha > 0 ? alpha : blendedColor.A; - float invertedAlphaFactor = 1 - alphaFactor; - - color.R = (color.R * invertedAlphaFactor) + (blendedColor.R * alphaFactor); - color.G = (color.G * invertedAlphaFactor) + (blendedColor.G * alphaFactor); - color.B = (color.B * invertedAlphaFactor) + (blendedColor.B * alphaFactor); + color = Color.Lerp(color, blendedColor, alphaFactor); } target[x, y] = color; diff --git a/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs b/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs index 96824e2641..aba96ddddf 100644 --- a/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs +++ b/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs @@ -16,7 +16,7 @@ namespace ImageProcessor.Tests //{ "Brightness--50", new Brightness(-50) }, //{ "Contrast-50", new Contrast(50) }, //{ "Contrast--50", new Contrast(-50) }, - { "Blend", new Blend(new Image(File.OpenRead("../../TestImages/Formats/Bmp/Car.bmp")),50)}, + { "Blend", new Blend(new Image(File.OpenRead("../../TestImages/Formats/Bmp/Car.bmp")),75)}, //{ "Saturation-50", new Saturation(50) }, //{ "Saturation--50", new Saturation(-50) }, //{ "Alpha--50", new Alpha(50) },