Browse Source

Use Lerp silly!

Former-commit-id: a686fee5731eb4d4ec47cd0d4c1a16706b6a727d
Former-commit-id: 6ee7a568923863ffe39c68da3c9559d537eb129e
Former-commit-id: cf008a8c2b8178d6791d7da027956c8a4f6ad22e
pull/17/head
James Jackson-South 10 years ago
parent
commit
762bd235e8
  1. 8
      src/ImageProcessor/Filters/Blend.cs
  2. 2
      tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs

8
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;

2
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) },

Loading…
Cancel
Save