From: Niels K. B. J. <nk...@us...> - 2007-03-20 05:20:13
|
Update of /cvsroot/ufraw/ufraw In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv20354 Modified Files: README dcraw_api.cc dcraw_indi.c Log Message: Update UFRaw to use new, faster AHD interpolation. Index: README =================================================================== RCS file: /cvsroot/ufraw/ufraw/README,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** README 11 Mar 2007 15:07:06 -0000 1.34 --- README 20 Mar 2007 05:20:09 -0000 1.35 *************** *** 189,199 **** version (7.86 in the example) and revision (1.304 in the example) numbers. ! This update procedure is not full proof. First there can be conflict that have to be resolved. But even if there are no conflicts, one should check ! if there are new global variable or functions and add them to dcraw.h. ! also if there where changes in scale_colors(), border_interpolate(), ! lin_interpolate(), vng_interpolate(), cam_to_cielab(), ahd_interpolate(), ! convert_to_rgb(), fuji_rotate(), flip_image(), main(). Such a change could ! effect dcraw_indi.c or dcraw_api.cc. Development version --- 189,199 ---- version (7.86 in the example) and revision (1.304 in the example) numbers. ! This update procedure is not foolproof. First there can be conflicts that have to be resolved. But even if there are no conflicts, one should check ! if there are new global variables or functions and add them to dcraw.h. ! One should also check if there where changes to the functions scale_colors(), ! pre_interpolate(), border_interpolate(), lin_interpolate(), vng_interpolate(), ! ahd_interpolate(), convert_to_rgb(), fuji_rotate(), or main(). Such changes ! could affect dcraw_indi.c or dcraw_api.cc. Development version Index: dcraw_api.cc =================================================================== RCS file: /cvsroot/ufraw/ufraw/dcraw_api.cc,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dcraw_api.cc 17 Mar 2007 07:48:21 -0000 1.12 --- dcraw_api.cc 20 Mar 2007 05:20:09 -0000 1.13 *************** *** 42,47 **** const int width, const int height, const int colors, const int rgb_max, void *dcraw); - void cam_to_cielab_INDI (gushort cam[4], float lab[3], - const int colors, float rgb_cam[3][4]); void ahd_interpolate_INDI(gushort (*image)[4], const unsigned filters, const int width, const int height, const int colors, float rgb_cam[3][4], --- 42,45 ---- *************** *** 180,184 **** d->dcraw_message(DCRAW_VERBOSE,_("Black: %d, Maximum: %d\n"), d->black, d->maximum); - cam_to_cielab_INDI(NULL, NULL, h->colors, d->rgb_cam); dmin = DBL_MAX; for (i=0; i<h->colors; i++) if (dmin > d->pre_mul[i]) dmin = d->pre_mul[i]; --- 178,181 ---- Index: dcraw_indi.c =================================================================== RCS file: /cvsroot/ufraw/ufraw/dcraw_indi.c,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** dcraw_indi.c 17 Mar 2007 07:48:21 -0000 1.34 --- dcraw_indi.c 20 Mar 2007 05:20:09 -0000 1.35 *************** *** 371,406 **** } - void CLASS cam_to_cielab_INDI (ushort cam[4], float lab[3], - const int colors, const float rgb_cam[3][4]) - { - 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 = i / 65535.0; - 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_white[i]; - } else { - xyz[0] = xyz[1] = xyz[2] = 0.5; - FORCC { - xyz[0] += xyz_cam[0][c] * cam[c]; - xyz[1] += xyz_cam[1][c] * cam[c]; - xyz[2] += xyz_cam[2][c] * cam[c]; - } - xyz[0] = cbrt[CLIP((int) xyz[0])]; - xyz[1] = cbrt[CLIP((int) xyz[1])]; - xyz[2] = cbrt[CLIP((int) xyz[2])]; - lab[0] = 116 * xyz[1] - 16; - lab[1] = 500 * (xyz[0] - xyz[1]); - lab[2] = 200 * (xyz[1] - xyz[2]); - } - } - /* Adaptive Homogeneity-Directed interpolation is based on --- 371,374 ---- *************** *** 413,428 **** const float rgb_cam[3][4], void *dcraw) { ! int i, j, top, left, row, col, tr, tc, fc, c, d, val, hm[2]; ushort (*pix)[4], (*rix)[3]; 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; dcraw_message (dcraw, DCRAW_VERBOSE,_("AHD interpolation...\n")); /*UF*/ ! border_interpolate_INDI (height, width, image, filters, colors, 3); buffer = (char *) malloc (26*TS*TS); /* 1664 kB */ merror (buffer, "ahd_interpolate()"); --- 381,405 ---- const float rgb_cam[3][4], void *dcraw) { ! int i, j, k, top, left, row, col, tr, tc, c, d, val, hm[2]; ushort (*pix)[4], (*rix)[3]; static const int dir[4] = { -1, 1, -TS, TS }; unsigned ldiff[2][4], abdiff[2][4], leps, abeps; ! float r, cbrt[0x10000], xyz[3], xyz_cam[3][4]; ushort (*rgb)[TS][TS][3]; ! short (*lab)[TS][TS][3], (*lix)[3]; char (*homo)[TS][TS], *buffer; dcraw_message (dcraw, DCRAW_VERBOSE,_("AHD interpolation...\n")); /*UF*/ ! for (i=0; i < 0x10000; i++) { ! r = i / 65535.0; ! 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_white[i]; ! ! border_interpolate_INDI (height, width, image, filters, colors, 5); buffer = (char *) malloc (26*TS*TS); /* 1664 kB */ merror (buffer, "ahd_interpolate()"); *************** *** 431,449 **** homo = (char (*)[TS][TS]) (buffer + 24*TS*TS); ! for (top=0; top < height; top += TS-6) ! for (left=0; left < width; left += TS-6) { ! memset (rgb, 0, 12*TS*TS); ! /* Interpolate green horizontally and vertically: */ ! for (row = top < 2 ? 2:top; row < top+TS && row < height-2; row++) { ! col = left + (FC(row,left) == 1); ! if (col < 2) col += 2; ! for (fc = FC(row,col); col < left+TS && col < width-2; col+=2) { ! pix = image + row*width+col; ! val = ((pix[-1][1] + pix[0][fc] + pix[1][1]) * 2 ! - pix[-2][fc] - pix[2][fc]) >> 2; ! rgb[0][row-top][col-left][1] = ULIM(val,pix[-1][1],pix[1][1]); ! val = ((pix[-width][1] + pix[0][fc] + pix[width][1]) * 2 ! - pix[-2*width][fc] - pix[2*width][fc]) >> 2; rgb[1][row-top][col-left][1] = ULIM(val,pix[-width][1],pix[width][1]); } --- 408,424 ---- homo = (char (*)[TS][TS]) (buffer + 24*TS*TS); ! for (top=2; top < height-5; top += TS-6) ! for (left=2; left < width-5; left += TS-6) { ! /* Interpolate green horizontally and vertically: */ ! for (row = top; row < top+TS && row < height-2; row++) { ! col = left + (FC(row,left) & 1); ! for (c = FC(row,col); col < left+TS && col < width-2; col+=2) { ! pix = image + row*width+col; ! val = ((pix[-1][1] + pix[0][c] + pix[1][1]) * 2 ! - pix[-2][c] - pix[2][c]) >> 2; ! rgb[0][row-top][col-left][1] = ULIM(val,pix[-1][1],pix[1][1]); ! val = ((pix[-width][1] + pix[0][c] + pix[width][1]) * 2 ! - pix[-2*width][c] - pix[2*width][c]) >> 2; rgb[1][row-top][col-left][1] = ULIM(val,pix[-width][1],pix[width][1]); } *************** *** 451,458 **** /* Interpolate red and blue, and convert to CIELab: */ for (d=0; d < 2; d++) ! for (row=top+1; row < top+TS-1 && row < height-1; row++) ! for (col=left+1; col < left+TS-1 && col < width-1; col++) { pix = image + row*width+col; rix = &rgb[d][row-top][col-left]; if ((c = 2 - FC(row,col)) == 1) { c = FC(row+1,col); --- 426,434 ---- /* Interpolate red and blue, and convert to CIELab: */ for (d=0; d < 2; d++) ! for (row=top+1; row < top+TS-1 && row < height-3; row++) ! for (col=left+1; col < left+TS-1 && col < width-3; col++) { pix = image + row*width+col; rix = &rgb[d][row-top][col-left]; + lix = &lab[d][row-top][col-left]; if ((c = 2 - FC(row,col)) == 1) { c = FC(row+1,col); *************** *** 470,492 **** c = FC(row,col); rix[0][c] = pix[0][c]; ! cam_to_cielab_INDI (rix[0], flab, colors, rgb_cam); ! FORC3 lab[d][row-top][col-left][c] = 64*flab[c]; } /* Build homogeneity maps from the CIELab images: */ memset (homo, 0, 2*TS*TS); ! for (row=top+2; row < top+TS-2 && row < height; row++) { ! tr = row-top; ! for (col=left+2; col < left+TS-2 && col < width; col++) { ! tc = col-left; ! for (d=0; d < 2; d++) ! for (i=0; i < 4; i++) ! ldiff[d][i] = ABS(lab[d][tr][tc][0]-lab[d][tr][tc+dir[i]][0]); leps = MIN(MAX(ldiff[0][0],ldiff[0][1]), MAX(ldiff[1][2],ldiff[1][3])); - for (d=0; d < 2; d++) - for (i=0; i < 4; i++) - if (i >> 1 == d || ldiff[d][i] <= leps) - abdiff[d][i] = SQR(lab[d][tr][tc][1]-lab[d][tr][tc+dir[i]][1]) - + SQR(lab[d][tr][tc][2]-lab[d][tr][tc+dir[i]][2]); abeps = MIN(MAX(abdiff[0][0],abdiff[0][1]), MAX(abdiff[1][2],abdiff[1][3])); --- 446,478 ---- c = FC(row,col); rix[0][c] = pix[0][c]; ! xyz[0] = xyz[1] = xyz[2] = 0.5; ! FORCC { ! xyz[0] += xyz_cam[0][c] * rix[0][c]; ! xyz[1] += xyz_cam[1][c] * rix[0][c]; ! xyz[2] += xyz_cam[2][c] * rix[0][c]; ! } ! xyz[0] = cbrt[CLIP((int) xyz[0])]; ! xyz[1] = cbrt[CLIP((int) xyz[1])]; ! xyz[2] = cbrt[CLIP((int) xyz[2])]; ! lix[0][0] = (short)(64 * (116 * xyz[1] - 16)); ! lix[0][1] = (short)(64 * 500 * (xyz[0] - xyz[1])); ! lix[0][2] = (short)(64 * 200 * (xyz[1] - xyz[2])); } /* Build homogeneity maps from the CIELab images: */ memset (homo, 0, 2*TS*TS); ! for (row=top+2; row < top+TS-2 && row < height-4; row++) { ! tr = row-top; ! for (col=left+2; col < left+TS-2 && col < width-4; col++) { ! tc = col-left; ! for (d=0; d < 2; d++) { ! lix = &lab[d][tr][tc]; ! for (i=0; i < 4; i++) { ! ldiff[d][i] = ABS(lix[0][0]-lix[dir[i]][0]); ! abdiff[d][i] = SQR(lix[0][1]-lix[dir[i]][1]) ! + SQR(lix[0][2]-lix[dir[i]][2]); ! } ! } leps = MIN(MAX(ldiff[0][0],ldiff[0][1]), MAX(ldiff[1][2],ldiff[1][3])); abeps = MIN(MAX(abdiff[0][0],abdiff[0][1]), MAX(abdiff[1][2],abdiff[1][3])); *************** *** 498,504 **** } /* Combine the most homogenous pixels for the final result: */ ! for (row=top+3; row < top+TS-3 && row < height-3; row++) { ! tr = row-top; ! for (col=left+3; col < left+TS-3 && col < width-3; col++) { tc = col-left; for (d=0; d < 2; d++) --- 484,490 ---- } /* Combine the most homogenous pixels for the final result: */ ! for (row=top+3; row < top+TS-3 && row < height-5; row++) { ! tr = row-top; ! for (col=left+3; col < left+TS-3 && col < width-5; col++) { tc = col-left; for (d=0; d < 2; d++) |