diff --git a/hicolor.h b/hicolor.h index 76959dc..41e3678 100644 --- a/hicolor.h +++ b/hicolor.h @@ -337,6 +337,7 @@ hicolor_result hicolor_write_header( } /* "a dither" is a public-domain dithering algorithm by Øyvind Kolås. + * This function implements pattern 3. * https://pippin.gimp.org/a_dither/ */ uint8_t hicolor_a_dither_channel( uint8_t intensity, @@ -347,7 +348,7 @@ uint8_t hicolor_a_dither_channel( { double mask = (double) ((x + y * 237) * 119 & 255) / 255.0; double normalized = (double) intensity / 255.0; - double dithered_normalized = floor(levels * normalized + mask) / levels; + double dithered_normalized = fmin(1.0, floor(levels * normalized + mask) / levels); return (uint8_t) (dithered_normalized * 255); }