Update of /cvsroot/ufraw/ufraw In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv29386
Modified Files: dcraw.cc dcraw.h dcraw_api.cc Log Message: Recommit fixed version of new Canon black point code. Index: dcraw.cc =================================================================== RCS file: /cvsroot/ufraw/ufraw/dcraw.cc,v retrieving revision 1.212 retrieving revision 1.213 diff -u -d -r1.212 -r1.213 --- dcraw.cc 15 Mar 2010 15:00:26 -0000 1.212 +++ dcraw.cc 15 Mar 2010 16:05:11 -0000 1.213 @@ -418,20 +418,6 @@ swab ((const char *)pixel, (char *)pixel, count*2); /*mingw support UF*/ } -void CLASS canon_black (double dark[2], int nblack) -{ - int c, diff, row, col; - - if (!nblack) return; - FORC(2) dark[c] /= nblack >> 1; - if ((diff = dark[0] - dark[1])) - for (row=0; row < height; row++) - for (col=1; col < width; col+=2) - BAYER(row,col) += diff; - dark[1] += diff; - black = (dark[0] + dark[1] + 1) / 2; -} - void CLASS canon_600_fixed_wb (int temp) { static const short mul[4][5] = { @@ -785,10 +771,9 @@ void CLASS canon_compressed_load_raw() { ushort *pixel, *prow, *huff[2]; - int nblocks, lowbits, i, c, row, r, col, save, val, nblack=0; + int nblocks, lowbits, i, c, row, r, col, save, val; unsigned irow, icol; int block, diffbuf[64], leaf, len, diff, carry=0, pnum=0, base[2]; - double dark[2] = { 0,0 }; crw_init_tables (tiff_compress, huff); pixel = (ushort *) calloc (raw_width*8, sizeof *pixel); @@ -841,17 +826,18 @@ if (irow >= height) continue; for (col=0; col < raw_width; col++) { icol = col - left_margin; + c = FC(irow,icol); if (icol < width) BAYER(irow,icol) = pixel[r*raw_width+col]; else if (col > 1 && (unsigned) (col-left_margin+2) > (unsigned) (width+3)) - dark[icol & 1] += (nblack++,pixel[r*raw_width+col]); + cblack[c] += (cblack[4+c]++,pixel[r*raw_width+col]); } } } free (pixel); FORC(2) free (huff[c]); - canon_black (dark, nblack); + FORC4 if (cblack[4+c]) cblack[c] /= cblack[4+c]; } /* @@ -974,8 +960,7 @@ void CLASS lossless_jpeg_load_raw() { - int jwide, jrow, jcol, val, jidx, i, j, row=0, col=0, nblack=0; - double dark[2] = { 0,0 }; + int jwide, jrow, jcol, val, jidx, c, i, j, row=0, col=0; struct jhead jh; int min=INT_MAX; ushort *rp; @@ -1001,19 +986,20 @@ if (raw_width == 3984 && (col -= 2) < 0) col += (row--,raw_width); if ((unsigned) (row-top_margin) < height) { + c = FC(row-top_margin,col-left_margin); if ((unsigned) (col-left_margin) < width) { BAYER(row-top_margin,col-left_margin) = val; if (min > val) min = val; } else if (col > 1 && (unsigned) (col-left_margin+2) > (unsigned) (width+3)) - dark[(col-left_margin) & 1] += (nblack++,val); + cblack[c] += (cblack[4+c]++,val); } if (++col >= raw_width) col = (row++,0); } } ljpeg_end (&jh); - canon_black (dark, nblack); + FORC4 if (cblack[4+c]) cblack[c] /= cblack[4+c]; if (!strcasecmp(make,"KODAK")) black = min; } @@ -3471,6 +3457,8 @@ BAYER(row,col) = MAX (BAYER(row,col) - ntohs(pixel[col]), 0); } free (pixel); + fclose (fp); + memset (cblack, 0, sizeof cblack); black = 0; } @@ -3646,7 +3634,7 @@ void CLASS wavelet_denoise() { float *fimg=0, *temp, thold, mul[2], avg, diff; - int scale=1, size, lev, hpass, lpass, row, col, nc, c, i, wlast; + int scale=1, size, lev, hpass, lpass, row, col, nc, c, i, wlast, blk[2]; ushort *window[4]; static const float noise[] = { 0.8002,0.2735,0.1202,0.0585,0.0291,0.0152,0.0080,0.0044 }; @@ -3655,7 +3643,7 @@ while (maximum << scale < 0x10000) scale++; maximum <<= --scale; - black <<= scale; + FORC4 cblack[c] <<= scale; if ((size = iheight*iwidth) < 0x15550000) fimg = (float *) malloc ((size*3 + iheight + iwidth) * sizeof *fimg); merror (fimg, "wavelet_denoise()"); @@ -3690,8 +3678,10 @@ image[i][c] = CLIP(SQR(fimg[i]+fimg[lpass+i])/0x10000); } if (filters && colors == 3) { /* pull G1 and G3 closer together */ - for (row=0; row < 2; row++) + for (row=0; row < 2; row++) { mul[row] = 0.125 * pre_mul[FC(row+1,0) | 1] / pre_mul[FC(row,0) | 1]; + blk[row] = cblack[FC(row,0) | 1]; + } for (i=0; i < 4; i++) window[i] = (ushort *) fimg + width*i; for (wlast=-1, row=1; row < height-1; row++) { @@ -3704,8 +3694,8 @@ thold = threshold/512; for (col = (FC(row,0) & 1)+1; col < width-1; col+=2) { avg = ( window[0][col-1] + window[0][col+1] + - window[2][col-1] + window[2][col+1] - black*4 ) - * mul[row & 1] + (window[1][col] - black) * 0.5 + black; + window[2][col-1] + window[2][col+1] - blk[~row & 1]*4 ) + * mul[row & 1] + (window[1][col] + blk[row & 1]) * 0.5; avg = avg < 0 ? 0 : sqrt(avg); diff = sqrt(BAYER(row,col)) - avg; if (diff < -thold) diff += thold; @@ -3726,6 +3716,7 @@ float scale_mul[4], fr, fc; ushort *img=0, *pix; + FORC4 cblack[c] += black; if (user_mul[0]) memcpy (pre_mul, user_mul, sizeof pre_mul); if (use_auto_wb || (use_camera_wb && cam_mul[0] == -1)) { @@ -3744,7 +3735,7 @@ } else val = image[y*width+x][c]; if (val > (int)(maximum-25)) goto skip_block; - if ((val -= black) < 0) val = 0; + if ((val -= cblack[c]) < 0) val = 0; sum[c] += val; sum[c+4]++; if (filters) break; @@ -3759,7 +3750,7 @@ for (row=0; row < 8; row++) for (col=0; col < 8; col++) { c = FC(row,col); - if ((val = white[row][col] - black) > 0) + if ((val = white[row][col] - cblack[c]) > 0) sum[c] += val; sum[c+4]++; } @@ -3791,7 +3782,7 @@ for (i=0; i < size*4; i++) { val = image[0][i]; if (!val) continue; - val -= black; + val -= cblack[i & 3]; val *= scale_mul[i & 3]; image[0][i] = CLIP(val); } @@ -4621,14 +4612,13 @@ if (tag == 0x200 && len == 3) shot_order = (get4(),get4()); if (tag == 0x200 && len == 4) - black = (get2()+get2()+get2()+get2())/4; + FORC4 cblack[c ^ c >> 1] = get2(); if (tag == 0x201 && len == 4) goto get2_rggb; if (tag == 0x220 && len == 53) meta_offset = ftell(ifp) + 14; - if (tag == 0x401 && type == 4 && len == 4) { - black = (get4()+get4()+get4()+get4())/4; - } + if (tag == 0x401 && type == 4 && len == 4) + FORC4 cblack[c ^ c >> 1] = get4(); if (tag == 0xe01) { /* Nikon Capture Note */ type = order; order = 0x4949; @@ -4659,8 +4649,7 @@ for (i=0; i < 3; i++) FORC3 cmatrix[i][c] = ((short) get2()) / 256.0; if ((tag == 0x1012 || tag == 0x20400600) && len == 4) - for (black = i=0; i < 4; i++) - black += get2() << 2; + FORC4 cblack[c ^ c >> 1] = get2() << 4; if (tag == 0x1017 || tag == 0x20400100) cam_mul[0] = get2() / 256.0; if (tag == 0x1018 || tag == 0x20400100) @@ -6756,6 +6745,7 @@ cdesc[0] = desc[0] = artist[0] = make[0] = model[0] = model2[0] = 0; iso_speed = shutter = aperture = focal_len = unique_id = 0; memset (gpsdata, 0, sizeof gpsdata); + memset (cblack, 0, sizeof cblack); memset (white, 0, sizeof white); thumb_offset = thumb_length = thumb_width = thumb_height = 0; load_raw = thumb_load_raw = 0; @@ -8844,6 +8834,10 @@ if (dark_frame) subtract (dark_frame); quality = 2 + !fuji_width; if (user_qual >= 0) quality = user_qual; + i = cblack[3]; + FORC3 if ((unsigned)i > cblack[c]) i = cblack[c]; + FORC4 cblack[c] -= i; + black += i; if (user_black >= 0) black = user_black; if (user_sat > 0) maximum = user_sat; #ifdef COLORCHECK Index: dcraw.h =================================================================== RCS file: /cvsroot/ufraw/ufraw/dcraw.h,v retrieving revision 1.59 retrieving revision 1.60 diff -u -d -r1.59 -r1.60 --- dcraw.h 15 Mar 2010 15:00:28 -0000 1.59 +++ dcraw.h 15 Mar 2010 16:05:11 -0000 1.60 @@ -49,7 +49,7 @@ unsigned thumb_length, meta_length, profile_length; unsigned thumb_misc, *oprof, fuji_layout, shot_select, multi_out; unsigned tiff_nifds, tiff_samples, tiff_bps, tiff_compress; -unsigned black, maximum, mix_green, raw_color, zero_is_bad; +unsigned black, cblack[8], maximum, mix_green, raw_color, zero_is_bad; unsigned zero_after_ff, is_raw, dng_version, is_foveon, data_error; unsigned tile_width, tile_length, gpsdata[32], load_flags; ushort raw_height, raw_width, height, width, top_margin, left_margin; @@ -121,7 +121,6 @@ float int_to_float (int i); double getreal (int type); void read_shorts (ushort *pixel, unsigned count); -void canon_black (double dark[2], int nblack); void canon_600_fixed_wb (int temp); int canon_600_color (int ratio[2], int mar); void canon_600_auto_wb(); Index: dcraw_api.cc =================================================================== RCS file: /cvsroot/ufraw/ufraw/dcraw_api.cc,v retrieving revision 1.67 retrieving revision 1.68 diff -u -d -r1.67 -r1.68 --- dcraw_api.cc 23 Feb 2010 19:36:43 -0000 1.67 +++ dcraw_api.cc 15 Mar 2010 16:05:11 -0000 1.68 @@ -30,7 +30,10 @@ #include "dcraw_api.h" #include "dcraw.h" -#define FORCC for (c=0; c < colors; c++) +#define FORC(cnt) for (c=0; c < cnt; c++) +#define FORC3 FORC(3) +#define FORC4 FORC(4) +#define FORCC FORC(colors) #define FC(filters,row,col) \ (filters >> ((((row) << 1 & 14) + ((col) & 1)) << 1) & 3) extern "C" { @@ -63,6 +66,7 @@ int dcraw_open(dcraw_data *h, char *filename) { DCRaw *d = new DCRaw; + int c, i; #ifndef LOCALTIME putenv (const_cast<char *>("TZ=UTC")); @@ -131,6 +135,10 @@ // camera-wb. If they'll change we will recalculate the camera-wb. h->rgbMax = d->maximum; h->black = d->black; + i = d->cblack[3]; + FORC3 if ((unsigned)i > d->cblack[c]) i = d->cblack[c]; + FORC4 d->cblack[c] -= i; + h->black += i; h->shrink = d->shrink = (h->filters!=0); h->pixel_aspect = d->pixel_aspect; /* copied from dcraw's main() */ @@ -186,7 +194,7 @@ int dcraw_load_raw(dcraw_data *h) { DCRaw *d = (DCRaw *)h->dcraw; - int i, j; + int c, i, j; double dmin; g_free(d->messageBuffer); @@ -233,6 +241,10 @@ // load_raw. If they change, document where. If not, move to dcraw_open(). h->rgbMax = d->maximum; h->black = d->black; + i = d->cblack[3]; + FORC3 if ((unsigned)i > d->cblack[c]) i = d->cblack[c]; + FORC4 d->cblack[c] -= i; + h->black += i; d->dcraw_message(DCRAW_VERBOSE,_("Black: %d, Maximum: %d\n"), d->black, d->maximum); dmin = DBL_MAX; ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ ufraw-cvs mailing list ufraw-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ufraw-cvs