Skip to content

Commit

Permalink
fix(a_dither): limit maximum value
Browse files Browse the repository at this point in the history
  • Loading branch information
dbohdan committed Oct 1, 2023
1 parent 2a5c525 commit 6b44e60
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hicolor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}

Expand Down

0 comments on commit 6b44e60

Please sign in to comment.