Skip to content

Commit

Permalink
gamut_mapping: safety clamp on desat_bounded()
Browse files Browse the repository at this point in the history
Prevents infinite loop here.
  • Loading branch information
haasn committed Aug 2, 2023
1 parent 9affb27 commit d56e295
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/gamut_mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@ static const float maxDelta = 5e-5f;
static inline struct ICh
desat_bounded(float I, float h, float Cmin, float Cmax, struct gamut gamut)
{
if (I <= gamut.min_luma)
return (struct ICh) { .I = gamut.min_luma, .C = 0, .h = h };
if (I >= gamut.max_luma)
return (struct ICh) { .I = gamut.max_luma, .C = 0, .h = h };

const float maxDI = I * maxDelta;
struct ICh res = { .I = I, .C = (Cmin + Cmax) / 2, .h = h };
do {
Expand Down

0 comments on commit d56e295

Please sign in to comment.