Commit a34e151b authored by noel's avatar noel Committed by Commit bot

lut_inverse_interp16: better handle degenerate TRC curves

Degenerate TRC have runs of 0's / 1's from the left / right edge of
the TRC curve (a curve we want to invert), but the inverse curve is
not well-defined in those regions. Return 0 or 1 for the inverse in
those regions. Also ensure the binary search parameters are bounded
to a valid search range.

BUG=458024

Review URL: https://codereview.chromium.org/1016213002

Cr-Commit-Position: refs/heads/master@{#321930}
parent 7d5426fd
......@@ -59,5 +59,7 @@ google.patch contains the following modifications. Apply with
- https://bugzilla.mozilla.org/show_bug.cgi?id=1132468
- lut_inverse_interp16: remove odd whitespace formatting
- https://code.google.com/p/chromium/issues/detail?id=458024
- lut_inverse_interp16: better handle degenerate TRC curves
- https://code.google.com/p/chromium/issues/detail?id=458024
To regenerate google.patch:
git diff b8456f38 src > google.patch
......@@ -328,11 +328,16 @@ uint16_fract_t lut_inverse_interp16(uint16_t Value, uint16_t LutTable[], int len
// Does the curve belong to this case?
if (NumZeroes > 1 || NumPoles > 1)
{
int a, b;
int a, b, sample;
// Identify if value fall downto 0 or FFFF zone
if (Value == 0) return 0;
// if (Value == 0xFFFF) return 0xFFFF;
// if (Value == 0xFFFF) return 0xFFFF;
sample = (length-1) * ((double) Value * (1./65535.));
if (LutTable[sample] == 0)
return 0;
if (LutTable[sample] == 0xffff)
return 0xffff;
// else restrict to valid zone
......@@ -341,8 +346,14 @@ uint16_fract_t lut_inverse_interp16(uint16_t Value, uint16_t LutTable[], int len
l = a - 1;
r = b + 1;
}
// Ensure a valid binary search range
if (l < 1)
l = 1;
if (r > 0x10000)
r = 0x10000;
}
// Seems not a degenerated case... apply binary search
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment