app: gimpoperationgradient keep achromatic colors under dither

Use the same amount of dithering on R,G and B if they initially were all equal.
This allows us to keep achromatic gradients achromatic, while providing the
same amount of dither as before for colored gradients. Discrepancy uncovered in
issue #10756.
This commit is contained in:
Øyvind Kolås 2024-02-16 18:50:00 +01:00 committed by Øyvind "pippin" Kolås
parent 8e63ef91f5
commit 597c52b92e
1 changed files with 16 additions and 3 deletions

View File

@ -1060,9 +1060,22 @@ gradient_dither_pixel (GimpRGB *color,
i = g_rand_int (dither_rand);
r = color->r + (gdouble) (i & 0xff) / 256.0 / 256.0 - 0.5 / 256.0; i >>= 8;
g = color->g + (gdouble) (i & 0xff) / 256.0 / 256.0 - 0.5 / 256.0; i >>= 8;
b = color->b + (gdouble) (i & 0xff) / 256.0 / 256.0 - 0.5 / 256.0; i >>= 8;
if ((color->r == color->g) && (color->r == color->b))
{
gdouble dither = (gdouble) (i & 0xff) / 256.0 / 256.0 - 0.5 / 256.0;
r = color->r + dither;
g = color->g + dither;
b = color->b + dither;
}
else
{
r = color->r + (gdouble) (i & 0xff) / 256.0 / 256.0 - 0.5 / 256.0;
i >>= 8;
g = color->g + (gdouble) (i & 0xff) / 256.0 / 256.0 - 0.5 / 256.0;
i >>= 8;
b = color->b + (gdouble) (i & 0xff) / 256.0 / 256.0 - 0.5 / 256.0;
i >>= 8;
}
if (color->a > 0.0 && color->a < 1.0)
a = color->a + (gdouble) (i & 0xff) / 256.0 / 256.0 - 0.5 / 256.0;