--- /tmp/dcraw_orig.c 2006-01-17 22:09:18.000000000 -0600 +++ Desktop/dcraw.c 2006-01-17 22:40:38.000000000 -0600 @@ -3010,39 +3010,49 @@ free (brow[4]); } -void CLASS cam_to_cielab (ushort cam[4], float lab[3]) -{ + +#define cbrt cam_to_cielab__cbrt +#define xyz_cam cam_to_cielab__xyz_cam +static float cbrt[0x10000]; +static float xyz_cam[3][4]; + +void init_cam_to_cielab(void) { int c, i, j, k; float r, xyz[3]; static const float d65[3] = { 0.950456, 1, 1.088754 }; + for (i=0; i < 0x10000; i++) { + r = (float) i / maximum; + cbrt[i] = r > 0.008856 ? pow(r,1/3.0) : 7.787*r + 16/116.0; + } + for (i=0; i < 3; i++) + for (j=0; j < colors; j++) + for (xyz_cam[i][j] = k=0; k < 3; k++) + xyz_cam[i][j] += xyz_rgb[i][k] * rgb_cam[k][j] / d65[i]; +} + +inline void CLASS cam_to_cielab (ushort cam[4], float lab[3]) +{ + int c, i, j, k; + float r, xyz[3]; static float cbrt[0x10000], xyz_cam[3][4]; - if (cam == NULL) { - for (i=0; i < 0x10000; i++) { - r = (float) i / maximum; - cbrt[i] = r > 0.008856 ? pow(r,1/3.0) : 7.787*r + 16/116.0; - } - for (i=0; i < 3; i++) - for (j=0; j < colors; j++) - for (xyz_cam[i][j] = k=0; k < 3; k++) - xyz_cam[i][j] += xyz_rgb[i][k] * rgb_cam[k][j] / d65[i]; - } else { - for (i=0; i < 3; i++) { - for (xyz[i]=0.5, c=0; c < colors; c++) + for (i=0; i < 3; i++) { + for (xyz[i]=0.5, c=0; c < 3; c++) xyz[i] += xyz_cam[i][c] * cam[c]; - xyz[i] = cbrt[CLIP((int) xyz[i])]; - } - lab[0] = 116 * xyz[1] - 16; - lab[1] = 500 * (xyz[0] - xyz[1]); - lab[2] = 200 * (xyz[1] - xyz[2]); + xyz[i] = cbrt[CLIP((int) xyz[i])]; } + lab[0] = 116 * xyz[1] - 16; + lab[1] = 500 * (xyz[0] - xyz[1]); + lab[2] = 200 * (xyz[1] - xyz[2]); } +#undef cbrt +#undef xyz_cam /* Adaptive Homogeneity-Directed interpolation is based on the work of Keigo Hirakawa, Thomas Parks, and Paul Lee. */ -#define TS 256 /* Tile Size */ +#define TS 128 /* Tile Size */ void CLASS ahd_interpolate() { @@ -3051,18 +3061,13 @@ static const int dir[4] = { -1, 1, -TS, TS }; unsigned ldiff[2][4], abdiff[2][4], leps, abeps; float flab[3]; - ushort (*rgb)[TS][TS][3]; - short (*lab)[TS][TS][3]; - char (*homo)[TS][TS], *buffer; + ushort rgb[2][TS][TS][3]; + short lab[2][TS][TS][3]; + char homo[2][TS][TS]; if (verbose) fprintf (stderr, "AHD interpolation...\n"); border_interpolate(3); - buffer = malloc (26*TS*TS); /* 1664 kB */ - merror (buffer, "ahd_interpolate()"); - rgb = (void *) buffer; - lab = (void *) (buffer + 12*TS*TS); - homo = (void *) (buffer + 24*TS*TS); for (top=0; top < height; top += TS-6) for (left=0; left < width; left += TS-6) { @@ -3147,7 +3152,6 @@ } } } - free (buffer); } #undef TS @@ -6031,7 +6035,7 @@ if (is_foveon) foveon_interpolate(); else scale_colors(); if (shrink) filters = 0; - cam_to_cielab (NULL,NULL); + init_cam_to_cielab(); if (filters && !document_mode) { if (quality == 0) lin_interpolate();