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.
diff --git a/transform.c b/transform.c
index 784cd28..146f9e4 100644
--- a/transform.c
+++ b/transform.c
@@ -547,17 +547,30 @@
 	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 @@
 	} 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 @@
 		*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;
 	}