From 0f38d995ccd126f5fcd1a8a61eea877d1b380478 Mon Sep 17 00:00:00 2001 From: ffsup2 Date: Tue, 29 Jun 2010 00:30:01 +0200 Subject: [PATCH] Some minor optimizations and bug fix --- rtengine/rawimagesource.cc | 114 ++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 51 deletions(-) diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 3693830c6..c4dd09907 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -874,8 +874,6 @@ int RawImageSource::load (Glib::ustring fname) { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if (ri->filters) { - MyTime t1,t2; - t1.set(); // demosaic if (settings->demosaicMethod=="hphd") hphd_demosaic (); @@ -891,8 +889,6 @@ int RawImageSource::load (Glib::ustring fname) { dcb_demosaic(settings->dcb_iterations, settings->dcb_enhance? 1:0); else eahd_demosaic (); - t2.set(); - printf("Totale demosaicing:%d \n",t2.etime(t1)); } @@ -2866,8 +2862,8 @@ inline void RawImageSource::dcb_initTileLimits(int &colMin, int &rowMin, int &co colMax = CACHESIZE-border; if(!y0 ) rowMin = TILEBORDER+border; if(!x0 ) colMin = TILEBORDER+border; - if( y0+TILESIZE > H-border) rowMax = TILEBORDER+H-border-y0; - if( x0+TILESIZE > W-border) colMax = TILEBORDER+W-border-x0; + if( y0+TILESIZE >= H-border) rowMax = TILEBORDER+H-border-y0; + if( x0+TILESIZE >= W-border) colMax = TILEBORDER+W-border-x0; } void RawImageSource::fill_raw( ushort (*cache )[4], int x0, int y0, ushort** rawData) @@ -2876,8 +2872,8 @@ void RawImageSource::fill_raw( ushort (*cache )[4], int x0, int y0, ushort** raw dcb_initTileLimits(colMin,rowMin,colMax,rowMax,x0,y0,0); for (int row=rowMin,y=y0-TILEBORDER+rowMin; row ( image[indx-1][1] + image[indx+1][1] + image[indx-u][1] + image[indx+u][1])/4 ) - image[indx][3] = ((MIN( image[indx-1][1], image[indx+1][1]) + image[indx-1][1] + image[indx+1][1] ) < (MIN( image[indx-u][1], image[indx+u][1]) + image[indx-u][1] + image[indx+u][1])); + ushort *pix = &(image[indx][1]); + if ( *pix > ( pix[-4] + pix[+4] + pix[-u] + pix[+u])/4 ) + image[indx][3] = ((MIN( pix[-4], pix[+4]) + pix[-4] + pix[+4] ) < (MIN( pix[-u], pix[+u]) + pix[-u] + pix[+u])); else - image[indx][3] = ((MAX( image[indx-1][1], image[indx+1][1]) + image[indx-1][1] + image[indx+1][1] ) > (MAX( image[indx-u][1], image[indx+u][1]) + image[indx-u][1] + image[indx+u][1])); + image[indx][3] = ((MAX( pix[-4], pix[+4]) + pix[-4] + pix[+4] ) > (MAX( pix[-u], pix[+u]) + pix[-u] + pix[+u])); } } } @@ -3023,15 +3011,11 @@ void RawImageSource::dcb_correction(ushort (*image)[4], int x0, int y0) dcb_initTileLimits(colMin,rowMin,colMax,rowMax,x0,y0,4); for (int row=rowMin; row < rowMax; row++) { - for (int col=colMin, indx=row*CACHESIZE+col; col < colMax; col++, indx++) { - if ( fc(y0-TILEBORDER+row,x0-TILEBORDER+col) != 1) - { - int current = 4*image[indx][3] + + for (int col = colMin+(FC(y0-TILEBORDER+row,x0-TILEBORDER+colMin)&1),indx=row*CACHESIZE+col,c=FC(y0-TILEBORDER+row,x0-TILEBORDER+col); col < colMax; col+=2, indx+=2) { + int current = 4*image[indx][3] + 2*(image[indx+u][3] + image[indx-u][3] + image[indx+1][3] + image[indx-1][3]) + image[indx+v][3] + image[indx-v][3] + image[indx+2][3] + image[indx-2][3]; - - image[indx][1] = ((16-current)*(image[indx-1][1] + image[indx+1][1])/2 + current*(image[indx-u][1] + image[indx+u][1])/2)/16; - } + image[indx][1] = ((16-current)*(image[indx-1][1] + image[indx+1][1])/2 + current*(image[indx-u][1] + image[indx+u][1])/2)/16; } } } @@ -3045,10 +3029,44 @@ void RawImageSource::dcb_pp(ushort (*image)[4], int x0, int y0) for (int row=rowMin; row < rowMax; row++) for (int col=colMin, indx=row*CACHESIZE+col; col < colMax; col++, indx++) { - int r1 = ( image[indx-1][0] + image[indx+1][0] + image[indx-u][0] + image[indx+u][0] + image[indx-u-1][0] + image[indx+u+1][0] + image[indx-u+1][0] + image[indx+u-1][0])/8; - int g1 = ( image[indx-1][1] + image[indx+1][1] + image[indx-u][1] + image[indx+u][1] + image[indx-u-1][1] + image[indx+u+1][1] + image[indx-u+1][1] + image[indx+u-1][1])/8; - int b1 = ( image[indx-1][2] + image[indx+1][2] + image[indx-u][2] + image[indx+u][2] + image[indx-u-1][2] + image[indx+u+1][2] + image[indx-u+1][2] + image[indx+u-1][2])/8; - + //int r1 = ( image[indx-1][0] + image[indx+1][0] + image[indx-u][0] + image[indx+u][0] + image[indx-u-1][0] + image[indx+u+1][0] + image[indx-u+1][0] + image[indx+u-1][0])/8; + //int g1 = ( image[indx-1][1] + image[indx+1][1] + image[indx-u][1] + image[indx+u][1] + image[indx-u-1][1] + image[indx+u+1][1] + image[indx-u+1][1] + image[indx+u-1][1])/8; + //int b1 = ( image[indx-1][2] + image[indx+1][2] + image[indx-u][2] + image[indx+u][2] + image[indx-u-1][2] + image[indx+u+1][2] + image[indx-u+1][2] + image[indx+u-1][2])/8; + ushort (*pix)[4] = image+(indx-u-1); + int r1 = (*pix)[0]; + int g1 = (*pix)[1]; + int b1 = (*pix)[2]; + pix++; + r1 += (*pix)[0]; + g1 += (*pix)[1]; + b1 += (*pix)[2]; + pix++; + r1 += (*pix)[0]; + g1 += (*pix)[1]; + b1 += (*pix)[2]; + pix+=CACHESIZE-2; + r1 += (*pix)[0]; + g1 += (*pix)[1]; + b1 += (*pix)[2]; + pix+=2; + r1 += (*pix)[0]; + g1 += (*pix)[1]; + b1 += (*pix)[2]; + pix+=CACHESIZE-2; + r1 += (*pix)[0]; + g1 += (*pix)[1]; + b1 += (*pix)[2]; + pix++; + r1 += (*pix)[0]; + g1 += (*pix)[1]; + b1 += (*pix)[2]; + pix++; + r1 += (*pix)[0]; + g1 += (*pix)[1]; + b1 += (*pix)[2]; + r1 /=8; + g1 /=8; + b1 /=8; r1 = r1 + ( image[indx][1] - g1 ); b1 = b1 + ( image[indx][1] - g1 ); image[indx][0] = CLIP(r1); @@ -3065,16 +3083,12 @@ void RawImageSource::dcb_correction2(ushort (*image)[4], int x0, int y0) dcb_initTileLimits(colMin,rowMin,colMax,rowMax,x0,y0,4); for (int row=rowMin; row < rowMax; row++) { - for (int col=colMin, indx=row*CACHESIZE+col; col < colMax; col++, indx++) { - int c = fc(y0-TILEBORDER+row,x0-TILEBORDER+col); - if (c != 1) - { - int current = 4*image[indx][3] + + for (int col = colMin+(FC(y0-TILEBORDER+row,x0-TILEBORDER+colMin)&1),indx=row*CACHESIZE+col,c=FC(y0-TILEBORDER+row,x0-TILEBORDER+col); col < colMax; col+=2, indx+=2) { + int current = 4*image[indx][3] + 2*(image[indx+u][3] + image[indx-u][3] + image[indx+1][3] + image[indx-1][3]) + image[indx+v][3] + image[indx-v][3] + image[indx+2][3] + image[indx-2][3]; - current = ((16-current)*((image[indx-1][1] + image[indx+1][1])/2 + image[indx][c] - (image[indx+2][c] + image[indx-2][c])/2) + current*((image[indx-u][1] + image[indx+u][1])/2 + image[indx][c] - (image[indx+v][c] + image[indx-v][c])/2))/16; - image[indx][1] = CLIP(current); - } + current = ((16-current)*((image[indx-1][1] + image[indx+1][1])/2 + image[indx][c] - (image[indx+2][c] + image[indx-2][c])/2) + current*((image[indx-u][1] + image[indx+u][1])/2 + image[indx][c] - (image[indx+v][c] + image[indx-v][c])/2))/16; + image[indx][1] = CLIP(current); } } } @@ -3167,7 +3181,6 @@ void RawImageSource::dcb_color_full(ushort (*image)[4], int x0, int y0, float (* // DCB demosaicing main routine (sharp version) void RawImageSource::dcb_demosaic(int iterations, int dcb_enhance) { - red = new unsigned short*[H]; green = new unsigned short*[H]; blue = new unsigned short*[H]; @@ -3226,7 +3239,6 @@ void RawImageSource::dcb_demosaic(int iterations, int dcb_enhance) fill_border(tile,2, x0, y0); copy_to_buffer(buffer, tile); hid(tile,x0,y0); - dcb_color(tile,x0,y0); for (int i=iterations; i>0;i--) { hid2(tile,x0,y0); @@ -3272,7 +3284,7 @@ void RawImageSource::dcb_demosaic(int iterations, int dcb_enhance) for(int i=0; isetProgress (1.0); - } #undef TILEBORDER #undef TILESIZE +#undef CACHESIZE //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //Emil's code for AMaZE