Skip to content

Commit

Permalink
Avoid colors tending toward black when smudging
Browse files Browse the repository at this point in the history
By adding a fudge factor. Not too sure why it happens in the first
place, since we round things properly, but this seems to be a fix for
anything going wrong in that regard. Maybe just an artifact of the
algorithm or caused by the inaccuracy of the 8 bit protocol that we have
to compensate for.
  • Loading branch information
askmeaboutlo0m committed Jul 29, 2023
1 parent 81ca8b1 commit 2912d78
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions extern/drawdance/libengine/dpengine/layer_content.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,12 @@ static DP_UPixelFloat sample_dab_color(DP_LayerContent *lc, DP_BrushStamp stamp)
alpha /= weight;

// Unpremultiply, clamp against rounding error.
red = CLAMP(red / alpha, 0.0f, 1.0f);
green = CLAMP(green / alpha, 0.0f, 1.0f);
blue = CLAMP(blue / alpha, 0.0f, 1.0f);
// The fudge factor avoids smudging causing the color to tend toward black.
// Not entirely sure why that happens, but fudging fixes it, so whatever.
float fudge = 0.005f;
red = CLAMP(red / alpha + fudge, 0.0f, 1.0f);
green = CLAMP(green / alpha + fudge, 0.0f, 1.0f);
blue = CLAMP(blue / alpha + fudge, 0.0f, 1.0f);

return (DP_UPixelFloat){
.b = blue,
Expand Down

0 comments on commit 2912d78

Please sign in to comment.