diff --git a/rtengine/hilite_recon.cc b/rtengine/hilite_recon.cc index d28545d2b..d5937cfdf 100644 --- a/rtengine/hilite_recon.cc +++ b/rtengine/hilite_recon.cc @@ -29,6 +29,8 @@ #include #include #include +//#include "stack1.h" + #ifdef _OPENMP #include @@ -244,13 +246,16 @@ void RawImageSource :: HLRecovery_inpaint (float** red, float** green, float** b for (int c=0; c<4; c++) camwb[c]=ri->get_cam_mul(c); float min = MIN(MIN(camwb[0],camwb[1]),camwb[2]); + multi_array2D channelblur(width,height,ARRAY2D_CLEAR_DATA); multi_array2D hilite_full(width,height,ARRAY2D_CLEAR_DATA); - - multi_array2D hilite(hfw,hfh,ARRAY2D_CLEAR_DATA); - - multi_array2D hilite_dir(hfw,hfh,ARRAY2D_CLEAR_DATA); + // blur RGB channels + boxblur2(red ,channelblur[0],height,width,4); + boxblur2(green,channelblur[1],height,width,4); + boxblur2(blue ,channelblur[2],height,width,4); + + float hipass_sum=0, hipass_norm=0.01; // set up which pixels are clipped or near clipping #ifdef _OPENMP @@ -263,18 +268,24 @@ void RawImageSource :: HLRecovery_inpaint (float** red, float** green, float** b if ((red[i][j]>thresh[0] || green[i][j]>thresh[1] || blue[i][j]>thresh[2]) && \ (red[i][j]setProgress(0.25); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -286,6 +297,14 @@ void RawImageSource :: HLRecovery_inpaint (float** red, float** green, float** b #endif for (int i=0; i 2*hipass_ave) { + //too much variation + hilite_full[0][i][j] = hilite_full[1][i][j] = hilite_full[2][i][j] = hilite_full[3][i][j] = 0; + continue; + } if (hilite_full[4][i][j]>0.00001 && hilite_full[4][i][j]<0.95) { //too near an edge, could risk using CA affected pixels, therefore omit @@ -294,11 +313,19 @@ void RawImageSource :: HLRecovery_inpaint (float** red, float** green, float** b } } + for (int c=0; c<3; c++) channelblur[c](1,1);//free up some memory + + multi_array2D hilite(hfw,hfh,ARRAY2D_CLEAR_DATA); + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // blur and resample highlight data; range=size of blur, pitch=sample spacing for (int m=0; m<4; m++) boxblur_resamp(hilite_full[m],hilite[m],chmaxalt[m],height,width,range,pitch); + for (int c=0; c<5; c++) hilite_full[c](1,1);//free up some memory + + multi_array2D hilite_dir(hfw,hfh,ARRAY2D_CLEAR_DATA); + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //blur highlights @@ -440,8 +467,8 @@ void RawImageSource :: HLRecovery_inpaint (float** red, float** green, float** b //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // now reconstruct clipped channels using color ratios - //const float Yclip = (0.299*max[0] + 0.587*max[0] + 0.114*max[0]); - const float Yclip = 0.3333*(max[0] + max[1] + max[2]); + const float Yclip = (0.299*max[0] + 0.587*max[1] + 0.114*max[2]); + //const float Yclip = 0.3333*(max[0] + max[1] + max[2]); #ifdef _OPENMP #pragma omp parallel for @@ -455,17 +482,19 @@ void RawImageSource :: HLRecovery_inpaint (float** red, float** green, float** b if (pixel[0]0.5) { - dirwt = invfn[65535*(SQR(hfsize[0][i1][j1]/Y-hilite_dir[dir*4+0][i1][j1]/Yhi) + \ - SQR(hfsize[1][i1][j1]/Y-hilite_dir[dir*4+1][i1][j1]/Yhi) + \ - SQR(hfsize[2][i1][j1]/Y-hilite_dir[dir*4+2][i1][j1]/Yhi))]; + dirwt = invfn[65535*(SQR(pixref[0]/Y-hilite_dir[dir*4+0][i1][j1]/Yhi) + \ + SQR(pixref[1]/Y-hilite_dir[dir*4+1][i1][j1]/Yhi) + \ + SQR(pixref[2]/Y-hilite_dir[dir*4+2][i1][j1]/Yhi))]; totwt += dirwt; clipfix[0] += dirwt*hilite_dir[dir*4+0][i1][j1]/(hilite_dir[dir*4+3][i1][j1]+0.00001); clipfix[1] += dirwt*hilite_dir[dir*4+1][i1][j1]/(hilite_dir[dir*4+3][i1][j1]+0.00001); @@ -536,21 +565,25 @@ void RawImageSource :: HLRecovery_inpaint (float** red, float** green, float** b // diagnostic output /*for (int i=0; i