From 2bcbcc0c124d523745111bec6a08e66e8e114731 Mon Sep 17 00:00:00 2001 From: ffsup2 Date: Wed, 21 Jul 2010 23:39:36 +0200 Subject: [PATCH] Ported updates to dcb from author Jacek Gozdz --- rtengine/rawimagesource.cc | 180 +++++++++++++++++++++++++------------ rtengine/rawimagesource.h | 8 +- 2 files changed, 125 insertions(+), 63 deletions(-) diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index fc3e50539..4d5cd9158 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -2617,43 +2617,97 @@ void RawImageSource::fill_border( ushort (*cache )[4], int border, int x0, int y } } // saves red and blue -void RawImageSource::copy_to_buffer( ushort (*buffer)[2], ushort (*image)[4]) +void RawImageSource::copy_to_buffer( ushort (*buffer)[3], ushort (*image)[4]) { for (int indx=0; indx < CACHESIZE*CACHESIZE; indx++) { buffer[indx][0]=image[indx][0]; //R - buffer[indx][1]=image[indx][2]; //B + buffer[indx][2]=image[indx][2]; //B } } // restores red and blue -void RawImageSource::restore_from_buffer(ushort (*image)[4], ushort (*buffer)[2]) +void RawImageSource::restore_from_buffer(ushort (*image)[4], ushort (*buffer)[3]) { for (int indx=0; indx < CACHESIZE*CACHESIZE; indx++) { image[indx][0]=buffer[indx][0]; //R - image[indx][2]=buffer[indx][1]; //B + image[indx][2]=buffer[indx][2]; //B } } -// fast green interpolation -void RawImageSource::hid(ushort (*image)[4], int x0, int y0) +// First pass green interpolation +void RawImageSource::dcb_hid(ushort (*image)[4],ushort (*bufferH)[3], ushort (*bufferV)[3], int x0, int y0) { - int u=CACHESIZE, v=2*CACHESIZE; + const int u=CACHESIZE, v=2*CACHESIZE; int rowMin,colMin,rowMax,colMax; dcb_initTileLimits(colMin,rowMin,colMax,rowMax,x0,y0,2); - + + // green pixels for (int row = rowMin; row < rowMax; row++) { 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 = (image[indx+u][1] + image[indx-u][1] + image[indx-1][1] + image[indx+1][1])/4 + - (image[indx][c] - ( image[indx+v][c] + image[indx-v][c] + image[indx-2][c] + image[indx+2][c])/4)/2; - image[indx][1] = CLIP(current); + int current = ( image[indx-1][1] + image[indx+1][1])/2; + bufferH[indx][1] = CLIP(current); + current = (image[indx+u][1] + image[indx-u][1])/2; + bufferV[indx][1] = CLIP(current); } - } + } + // red in blue pixel, blue in red pixel + for (int row=rowMin; row < rowMax; row++) + for (int col=colMin+(FC(y0-TILEBORDER+row,x0-TILEBORDER+colMin) & 1), indx=row*CACHESIZE+col, c=2-FC(y0-TILEBORDER+row,x0-TILEBORDER+col); col < colMax; col+=2, indx+=2) { + int current = ( 4*bufferH[indx][1] + - bufferH[indx+u+1][1] - bufferH[indx+u-1][1] - bufferH[indx-u+1][1] - bufferH[indx-u-1][1] + + image[indx+u+1][c] + image[indx+u-1][c] + image[indx-u+1][c] + image[indx-u-1][c] )/4; + bufferH[indx][c] = CLIP(current); + current = ( 4*bufferV[indx][1] + - bufferV[indx+u+1][1] - bufferV[indx+u-1][1] - bufferV[indx-u+1][1] - bufferV[indx-u-1][1] + + image[indx+u+1][c] + image[indx+u-1][c] + image[indx-u+1][c] + image[indx-u-1][c] )/4; + bufferV[indx][c] = CLIP(current); + + } + + // red or blue in green pixels + for (int row=rowMin; rowdata ); if( !xTile || !yTile || xTile==wTiles-1 || yTile==hTiles-1) - fill_border(tile,2, x0, y0); - copy_to_buffer(buffer, tile); - hid(tile,x0,y0); - dcb_color(tile,x0,y0); + fill_border(tile,6, x0, y0); + dcb_hid(tile,buffer,buffer2,x0,y0); + copy_to_buffer(buffer, tile); for (int i=iterations; i>0;i--) { - hid2(tile,x0,y0); - hid2(tile,x0,y0); - hid2(tile,x0,y0); + dcb_hid2(tile,x0,y0); + dcb_hid2(tile,x0,y0); + dcb_hid2(tile,x0,y0); dcb_map(tile,x0,y0); dcb_correction(tile,x0,y0); } - if( iterations ) - dcb_color(tile,x0,y0); - dcb_pp(tile,x0,y0); - hid2(tile,x0,y0); - hid2(tile,x0,y0); - hid2(tile,x0,y0); - dcb_map(tile,x0,y0); - dcb_correction2(tile,x0,y0); - restore_from_buffer(tile, buffer); - dcb_map(tile,x0,y0); - dcb_correction(tile,x0,y0); dcb_color(tile,x0,y0); dcb_pp(tile,x0,y0); dcb_map(tile,x0,y0); + dcb_correction2(tile,x0,y0); + dcb_map(tile,x0,y0); + dcb_correction(tile,x0,y0); + dcb_color(tile,x0,y0); + dcb_map(tile,x0,y0); dcb_correction(tile,x0,y0); dcb_map(tile,x0,y0); dcb_correction(tile,x0,y0); + dcb_map(tile,x0,y0); restore_from_buffer(tile, buffer); dcb_color(tile,x0,y0); if (dcb_enhance) { @@ -3007,11 +3067,13 @@ void RawImageSource::dcb_demosaic(int iterations, int dcb_enhance) for(int i=0; isetProgress (1.0); diff --git a/rtengine/rawimagesource.h b/rtengine/rawimagesource.h index 20e290399..2d3a88127 100644 --- a/rtengine/rawimagesource.h +++ b/rtengine/rawimagesource.h @@ -157,15 +157,15 @@ class RawImageSource : public ImageSource { void dcb_initTileLimits(int &colMin, int &rowMin, int &colMax, int &rowMax, int x0, int y0, int border); void fill_raw( ushort (*cache )[4], int x0, int y0, ushort** rawData); void fill_border( ushort (*cache )[4], int border, int x0, int y0); - void copy_to_buffer(ushort (*image2)[2], ushort (*image)[4]); - void hid(ushort (*image)[4], int x0, int y0); + void copy_to_buffer(ushort (*image2)[3], ushort (*image)[4]); + void dcb_hid(ushort (*image)[4], ushort (*bufferH)[3], ushort (*bufferV)[3], int x0, int y0); void dcb_color(ushort (*image)[4], int x0, int y0); - void hid2(ushort (*image)[4], int x0, int y0); + void dcb_hid2(ushort (*image)[4], int x0, int y0); void dcb_map(ushort (*image)[4], int x0, int y0); void dcb_correction(ushort (*image)[4], int x0, int y0); void dcb_pp(ushort (*image)[4], int x0, int y0); void dcb_correction2(ushort (*image)[4], int x0, int y0); - void restore_from_buffer(ushort (*image)[4], ushort (*image2)[2]); + void restore_from_buffer(ushort (*image)[4], ushort (*image2)[3]); void dcb_refinement(ushort (*image)[4], int x0, int y0); void dcb_color_full(ushort (*image)[4], int x0, int y0, float (*chroma)[2]);