Skip to content

Commit

Permalink
Don't truncate color sampling mask to 8 bits
Browse files Browse the repository at this point in the history
It's a 15 bit mask, so this was nonsense. Fixes the issues with smudge
colors going lighter or darker that required a fudge factor to be
applied.
  • Loading branch information
askmeaboutlo0m committed Aug 1, 2023
1 parent b4a28ec commit cb2fc7e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
9 changes: 3 additions & 6 deletions extern/drawdance/libengine/dpengine/layer_content.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,9 @@ static DP_UPixelFloat sample_dab_color(DP_LayerContent *lc, DP_BrushStamp stamp,
alpha /= weight;

// Unpremultiply, clamp against rounding error.
// 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);
red = CLAMP(red / alpha, 0.0f, 1.0f);
green = CLAMP(green / alpha, 0.0f, 1.0f);
blue = CLAMP(blue / alpha, 0.0f, 1.0f);

return (DP_UPixelFloat){
.b = blue,
Expand Down
5 changes: 3 additions & 2 deletions extern/drawdance/libengine/dpengine/paint.c
Original file line number Diff line number Diff line change
Expand Up @@ -1059,8 +1059,9 @@ DP_BrushStamp DP_paint_color_sampling_stamp_make(uint16_t *data, int diameter,
for (int x = 0; x < diameter; ++x) {
double dist = (DP_square_double(x - radius) + yy) * lut_scale;
int i = DP_double_to_int(dist);
*d = i < CLASSIC_LUT_SIZE ? DP_float_to_uint8(DP_BIT15 * lut[i])
: 0;
*d = i < CLASSIC_LUT_SIZE
? DP_float_to_uint16(DP_BIT15 * lut[i])
: 0;
++d;
}
}
Expand Down

0 comments on commit cb2fc7e

Please sign in to comment.