From 9a4f8467f8300e885151c531f93ca2beb676a7a2 Mon Sep 17 00:00:00 2001 From: Elias Batek Date: Sat, 25 May 2024 00:58:05 +0200 Subject: [PATCH] Implement "lighten" + "darken" blend-modes --- pixmappaint.d | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pixmappaint.d b/pixmappaint.d index 18e16c3..98e75c9 100644 --- a/pixmappaint.d +++ b/pixmappaint.d @@ -272,6 +272,9 @@ private struct OriginRectangle { // misc private { Point pos(Rectangle r) => r.upperLeft; + + T max(T)(T a, T b) => (a >= b) ? a : b; + T min(T)(T a, T b) => (a <= b) ? a : b; } /++ @@ -491,6 +494,7 @@ void blendPixel(BlendMode mode, BlendAccuracy accuracy = BlendAccuracy.rgba)( ref Pixel target, const Pixel source, ) if (mode == Blend.multiply) { + return alphaBlend!(accuracy, (a, b) => n255thsOf(a, b) )(target, source); @@ -512,7 +516,10 @@ void blendPixel(BlendMode mode, BlendAccuracy accuracy = BlendAccuracy.rgba)( ref Pixel target, const Pixel source, ) if (mode == Blend.darken) { - assert(false, "TODO"); + + return alphaBlend!(accuracy, + (a, b) => min(a, b) + )(target, source); } /// ditto @@ -520,7 +527,10 @@ void blendPixel(BlendMode mode, BlendAccuracy accuracy = BlendAccuracy.rgba)( ref Pixel target, const Pixel source, ) if (mode == Blend.lighten) { - assert(false, "TODO"); + + return alphaBlend!(accuracy, + (a, b) => max(a, b) + )(target, source); } /++