diff --git a/libs/pigment/compositeops/KoCompositeOpAlphaDarken.h b/libs/pigment/compositeops/KoCompositeOpAlphaDarken.h index e51e1a6..c05668e 100644 --- a/libs/pigment/compositeops/KoCompositeOpAlphaDarken.h +++ b/libs/pigment/compositeops/KoCompositeOpAlphaDarken.h @@ -91,7 +91,24 @@ public: channels_type fullFlowAlpha; channels_type averageOpacity = scale(*params.lastOpacity); + /** + * Here we calculate fullFlowAlpha, which shuold strive either to + * averageOpacity or opacity (whichever is the greater) or just keep old dstAlpha + * value, if both opacity values are not bit enough + */ if (averageOpacity > opacity) { + /** + * This crypty code is basically an optimized version of the folowing: + * fullFlowAlpha = averageOpacity * + * unionShapeOpacity(srcAlpha / averageOpacity, + * dstAlpha / averageOpacity); + * + * The main idea is: fullFlowAlpha should be as near to averageOpacity as + * maximum of srcAlpha and dstAlpha and a bit more. So that in consequent + * applications of the blending operation alpha channel would aim to + * averageOpacity. + */ + channels_type reverseBlend = KoColorSpaceMaths::divide(dstAlpha, averageOpacity); fullFlowAlpha = averageOpacity > dstAlpha ? lerp(srcAlpha, averageOpacity, reverseBlend) : dstAlpha; } else { @@ -103,8 +120,6 @@ public: } else { channels_type zeroFlowAlpha = dstAlpha; dstAlpha = lerp(zeroFlowAlpha, fullFlowAlpha, flow); - - } dst[alpha_pos] = dstAlpha;