diff options
author | Jeff Muizelaar <jmuizelaar@mozilla.com> | 2009-06-11 10:55:46 -0400 |
---|---|---|
committer | Jeff Muizelaar <jmuizelaar@mozilla.com> | 2009-06-11 10:55:46 -0400 |
commit | 8887035d81af8a57f6120e69217193146943b114 (patch) | |
tree | aa50972fa0973a71595ce3fb09f57f441d91d8e5 /transform.c | |
parent | ca138f8fba4f6c4b06c7b8679696a886e31da6e0 (diff) |
Make number of output entries produced by invert_lut() a parameter
The callers of invert_lut() have been changed to pass the lut length as the
output length for now. There should be no behaviour change.
Diffstat (limited to 'transform.c')
-rw-r--r-- | transform.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/transform.c b/transform.c index 784cd28..146f9e4 100644 --- a/transform.c +++ b/transform.c @@ -547,17 +547,30 @@ qcms_bool set_rgb_colorants(qcms_profile *profile, qcms_CIE_xyY white_point, qcm return true; } -static uint16_t *invert_lut(uint16_t *table, int length) +/* + The number of entries needed to invert a lookup table should not + necessarily be the same as the original number of entries. This is + especially true of lookup tables that have a small number of entries. + + For example: + Using a table like: + {0, 3104, 14263, 34802, 65535} + invert_lut will produce an inverse of: + {3, 34459, 47529, 56801, 65535} + which has an maximum error of about 9855 (pixel difference of ~38.346) + + For now, we punt the decision of output size to the caller. */ +static uint16_t *invert_lut(uint16_t *table, int length, int out_length) { int i; - /* for now we invert the lut by creating a lut of the same size + /* for now we invert the lut by creating a lut of size out_length * and attempting to lookup a value for each entry using lut_inverse_interp16 */ - uint16_t *output = malloc(sizeof(uint16_t)*length); + uint16_t *output = malloc(sizeof(uint16_t)*out_length); if (!output) return NULL; - for (i = 0; i < length; i++) { - double x = ((double) i * 65535.) / (double) (length - 1); + for (i = 0; i < out_length; i++) { + double x = ((double) i * 65535.) / (double) (out_length - 1); uint16_fract_t input = floor(x + .5); output[i] = lut_inverse_interp16(input, table, length); } @@ -1351,7 +1364,7 @@ qcms_bool compute_precache(struct curveType *trc, uint8_t *output) } else if (trc->count == 1) { compute_precache_pow(output, 1./u8Fixed8Number_to_float(trc->data[0])); } else { - uint16_t *inverted = invert_lut(trc->data, trc->count); + uint16_t *inverted = invert_lut(trc->data, trc->count, trc->count); if (!inverted) return false; compute_precache_lut(output, inverted, trc->count); @@ -1441,7 +1454,7 @@ void build_output_lut(struct curveType *trc, *output_gamma_lut = build_pow_table(gamma, 4096); *output_gamma_lut_length = 4096; } else { - *output_gamma_lut = invert_lut(trc->data, trc->count); + *output_gamma_lut = invert_lut(trc->data, trc->count, trc->count); *output_gamma_lut_length = trc->count; } |