From 1e31a821e553fd8e1b902b0f283340cda34e6a9c Mon Sep 17 00:00:00 2001 From: Emil Martinec Date: Wed, 13 Apr 2011 07:02:30 -0500 Subject: [PATCH] converting DCB and vng4 to float. --- rtengine/demosaic_algos.cc | 88 +++++++++++++++++++------------------- rtengine/rawimagesource.cc | 13 +++--- rtengine/rawimagesource.h | 26 +++++------ rtengine/shmap.cc | 7 --- 4 files changed, 62 insertions(+), 72 deletions(-) diff --git a/rtengine/demosaic_algos.cc b/rtengine/demosaic_algos.cc index 9837a0622..f691d955c 100644 --- a/rtengine/demosaic_algos.cc +++ b/rtengine/demosaic_algos.cc @@ -604,14 +604,14 @@ void RawImageSource::vng4_demosaic () { plistener->setProgress (0.0); } - ushort (*brow[5])[4], *pix; + float (*brow[5])[4], *pix; int prow=7, pcol=1, *ip, *code[16][16], gval[8], gmin, gmax, sum[4]; int row, col, x, y, x1, x2, y1, y2, t, weight, grads, color, diag; int g, diff, thold, num, c, width=W, height=H, colors=4; - ushort (*image)[4]; + float (*image)[4]; int lcode[16][16][32], shift, i, j; - image = (ushort (*)[4]) calloc (H*W, sizeof *image); + image = (float (*)[4]) calloc (H*W, sizeof *image); for (int ii=0; ii> 8; + pix[ip[0]] = sum[ip[0]] * ip[1] /256; } // lin_interpolate(); @@ -669,7 +669,7 @@ void RawImageSource::vng4_demosaic () { *ip++ = (y2*width + x2)*4 + color; *ip++ = weight; for (g=0; g < 8; g++) - if (grads & 1<> 1); + thold = gmin + (gmax /2); memset (sum, 0, sizeof sum); for (num=g=0; g < 8; g++,ip+=2) { /* Average the neighbors */ if (gval[g] <= thold) { FORCC if (c == color && ip[1]) - sum[c] += (pix[c] + pix[ip[1]]) >> 1; + sum[c] += (pix[c] + pix[ip[1]]) /2; else sum[c] += pix[ip[0] + c]; num++; @@ -744,7 +744,7 @@ void RawImageSource::vng4_demosaic () { for (int i=0; i> 1; + green[i][j] = (image[i*W+j][1] + image[i*W+j][3]) /2; } // Interpolate R and B for (int i=0; i diff[1]] >> 1); + pix[0][c] = CLIP(guess[diff[0] > diff[1]] /2); else - pix[0][c] = CLIP((guess[0]+guess[1]) >> 2); + pix[0][c] = CLIP((guess[0]+guess[1]) /4); } if(plistener) plistener->setProgress(0.67 + 0.33*row/(height-1)); } @@ -1151,7 +1151,7 @@ inline void RawImageSource::dcb_initTileLimits(int &colMin, int &rowMin, int &co if( x0+TILESIZE+TILEBORDER >= W-border) colMax = TILEBORDER+W-border-x0; } -void RawImageSource::fill_raw( ushort (*cache )[4], int x0, int y0, float** rawData) +void RawImageSource::fill_raw( float (*cache )[4], int x0, int y0, float** rawData) { int rowMin,colMin,rowMax,colMax; dcb_initTileLimits(colMin,rowMin,colMax,rowMax,x0,y0,0); @@ -1162,7 +1162,7 @@ void RawImageSource::fill_raw( ushort (*cache )[4], int x0, int y0, float** rawD } } -void RawImageSource::fill_border( ushort (*cache )[4], int border, int x0, int y0) +void RawImageSource::fill_border( float (*cache )[4], int border, int x0, int y0) { unsigned row, col, y, x, f, c, sum[8]; int colors = 3; @@ -1190,7 +1190,7 @@ void RawImageSource::fill_border( ushort (*cache )[4], int border, int x0, int y } } // saves red and blue -void RawImageSource::copy_to_buffer( ushort (*buffer)[3], ushort (*image)[4]) +void RawImageSource::copy_to_buffer( float (*buffer)[3], float (*image)[4]) { for (int indx=0; indx < CACHESIZE*CACHESIZE; indx++) { buffer[indx][0]=image[indx][0]; //R @@ -1199,7 +1199,7 @@ void RawImageSource::copy_to_buffer( ushort (*buffer)[3], ushort (*image)[4]) } // restores red and blue -void RawImageSource::restore_from_buffer(ushort (*image)[4], ushort (*buffer)[3]) +void RawImageSource::restore_from_buffer(float (*image)[4], float (*buffer)[3]) { for (int indx=0; indx < CACHESIZE*CACHESIZE; indx++) { image[indx][0]=buffer[indx][0]; //R @@ -1208,7 +1208,7 @@ void RawImageSource::restore_from_buffer(ushort (*image)[4], ushort (*buffer)[3] } // First pass green interpolation -void RawImageSource::dcb_hid(ushort (*image)[4],ushort (*bufferH)[3], ushort (*bufferV)[3], int x0, int y0) +void RawImageSource::dcb_hid(float (*image)[4],float (*bufferH)[3], float (*bufferV)[3], int x0, int y0) { const int u=CACHESIZE, v=2*CACHESIZE; int rowMin,colMin,rowMax,colMax; @@ -1278,7 +1278,7 @@ void RawImageSource::dcb_hid(ushort (*image)[4],ushort (*bufferH)[3], ushort (*b // missing colors are interpolated -void RawImageSource::dcb_color(ushort (*image)[4], int x0, int y0) +void RawImageSource::dcb_color(float (*image)[4], int x0, int y0) { const int u=CACHESIZE; int rowMin,colMin,rowMax,colMax; @@ -1304,7 +1304,7 @@ void RawImageSource::dcb_color(ushort (*image)[4], int x0, int y0) } // green correction -void RawImageSource::dcb_hid2(ushort (*image)[4], int x0, int y0) +void RawImageSource::dcb_hid2(float (*image)[4], int x0, int y0) { const int u=CACHESIZE, v=2*CACHESIZE; int rowMin,colMin,rowMax,colMax; @@ -1324,7 +1324,7 @@ void RawImageSource::dcb_hid2(ushort (*image)[4], int x0, int y0) // 1 = vertical // 0 = horizontal // saved in image[][3] -void RawImageSource::dcb_map(ushort (*image)[4], int x0, int y0) +void RawImageSource::dcb_map(float (*image)[4], int x0, int y0) { const int u=4*CACHESIZE; int rowMin,colMin,rowMax,colMax; @@ -1332,7 +1332,7 @@ void RawImageSource::dcb_map(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++) { - ushort *pix = &(image[indx][1]); + float *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 @@ -1343,7 +1343,7 @@ void RawImageSource::dcb_map(ushort (*image)[4], int x0, int y0) // interpolated green pixels are corrected using the map -void RawImageSource::dcb_correction(ushort (*image)[4], int x0, int y0) +void RawImageSource::dcb_correction(float (*image)[4], int x0, int y0) { const int u=CACHESIZE, v=2*CACHESIZE; int rowMin,colMin,rowMax,colMax; @@ -1360,7 +1360,7 @@ void RawImageSource::dcb_correction(ushort (*image)[4], int x0, int y0) } // R and B smoothing using green contrast, all pixels except 2 pixel wide border -void RawImageSource::dcb_pp(ushort (*image)[4], int x0, int y0) +void RawImageSource::dcb_pp(float (*image)[4], int x0, int y0) { const int u=CACHESIZE; int rowMin,colMin,rowMax,colMax; @@ -1371,7 +1371,7 @@ void RawImageSource::dcb_pp(ushort (*image)[4], int x0, int y0) //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); + float (*pix)[4] = image+(indx-u-1); int r1 = (*pix)[0]; int g1 = (*pix)[1]; int b1 = (*pix)[2]; @@ -1415,7 +1415,7 @@ void RawImageSource::dcb_pp(ushort (*image)[4], int x0, int y0) // interpolated green pixels are corrected using the map // with correction -void RawImageSource::dcb_correction2(ushort (*image)[4], int x0, int y0) +void RawImageSource::dcb_correction2(float (*image)[4], int x0, int y0) { const int u=CACHESIZE, v=2*CACHESIZE; int rowMin,colMin,rowMax,colMax; @@ -1433,7 +1433,7 @@ void RawImageSource::dcb_correction2(ushort (*image)[4], int x0, int y0) } // image refinement -void RawImageSource::dcb_refinement(ushort (*image)[4], int x0, int y0) +void RawImageSource::dcb_refinement(float (*image)[4], int x0, int y0) { const int u=CACHESIZE, v=2*CACHESIZE, w=3*CACHESIZE; int rowMin,colMin,rowMax,colMax; @@ -1476,7 +1476,7 @@ void RawImageSource::dcb_refinement(ushort (*image)[4], int x0, int y0) } // missing colors are interpolated using high quality algorithm by Luis Sanz Rodríguez -void RawImageSource::dcb_color_full(ushort (*image)[4], int x0, int y0, float (*chroma)[2]) +void RawImageSource::dcb_color_full(float (*image)[4], int x0, int y0, float (*chroma)[2]) { const int u=CACHESIZE, v=2*CACHESIZE, w=3*CACHESIZE; int rowMin,colMin,rowMax,colMax; @@ -1539,20 +1539,20 @@ void RawImageSource::dcb_demosaic(int iterations, int dcb_enhance) int tilesDone=0; #ifdef _OPENMP int nthreads = omp_get_max_threads(); - ushort (**image)[4] = (ushort(**)[4]) calloc( nthreads,sizeof( void*) ); - ushort (**image2)[3] = (ushort(**)[3]) calloc( nthreads,sizeof( void*) ); - ushort (**image3)[3] = (ushort(**)[3]) calloc( nthreads,sizeof( void*) ); + float (**image)[4] = (float(**)[4]) calloc( nthreads,sizeof( void*) ); + float (**image2)[3] = (float(**)[3]) calloc( nthreads,sizeof( void*) ); + float (**image3)[3] = (float(**)[3]) calloc( nthreads,sizeof( void*) ); float (**chroma)[2] = (float (**)[2]) calloc( nthreads,sizeof( void*) ); for(int i=0; i(b)?(b):(a)) #define DIST(a,b) (ABS(a-b)) #define MAXVAL 0xffff +#define CLIP(a) ((a)>0?((a)(b)) {temp=(a);(a)=(b);(b)=temp;} } @@ -1702,17 +1704,12 @@ TMatrix work = iccStore->workingSpaceInverseMatrix (cmp.working); for (int j=0; jwidth; j++) { float newr = mat[0][0]*im->r[i][j] + mat[0][1]*im->g[i][j] + mat[0][2]*im->b[i][j]; - if (newr<0) newr=0; else if (newr>0xffff) newr=0xffff; - float newg = mat[1][0]*im->r[i][j] + mat[1][1]*im->g[i][j] + mat[1][2]*im->b[i][j]; - if (newg<0) newg=0; else if (newg>0xffff) newg=0xffff; - float newb = mat[2][0]*im->r[i][j] + mat[2][1]*im->g[i][j] + mat[2][2]*im->b[i][j]; - if (newb<0) newb=0; else if (newb>0xffff) newb=0xffff; - im->r[i][j] = (newr); - im->g[i][j] = (newg); - im->b[i][j] = (newb); + im->r[i][j] = CLIP((int)newr); + im->g[i][j] = CLIP((int)newg); + im->b[i][j] = CLIP((int)newb); } } else { diff --git a/rtengine/rawimagesource.h b/rtengine/rawimagesource.h index 52e6ac9cb..9c40077fb 100644 --- a/rtengine/rawimagesource.h +++ b/rtengine/rawimagesource.h @@ -175,19 +175,19 @@ class RawImageSource : public ImageSource { void ahd_demosaic(int winx, int winy, int winw, int winh); void border_interpolate(int border, float (*image)[4], int start = 0, int end = 0); 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, float** rawData); - void fill_border( ushort (*cache )[4], int border, 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 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)[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]); + void fill_raw( float (*cache )[4], int x0, int y0, float** rawData); + void fill_border( float (*cache )[4], int border, int x0, int y0); + void copy_to_buffer(float (*image2)[3], float (*image)[4]); + void dcb_hid(float (*image)[4], float (*bufferH)[3], float (*bufferV)[3], int x0, int y0); + void dcb_color(float (*image)[4], int x0, int y0); + void dcb_hid2(float (*image)[4], int x0, int y0); + void dcb_map(float (*image)[4], int x0, int y0); + void dcb_correction(float (*image)[4], int x0, int y0); + void dcb_pp(float (*image)[4], int x0, int y0); + void dcb_correction2(float (*image)[4], int x0, int y0); + void restore_from_buffer(float (*image)[4], float (*image2)[3]); + void dcb_refinement(float (*image)[4], int x0, int y0); + void dcb_color_full(float (*image)[4], int x0, int y0, float (*chroma)[2]); void transLine (float* red, float* green, float* blue, int i, Imagefloat* image, int tran, int imw, int imh, int fw); void hflip (Imagefloat* im); diff --git a/rtengine/shmap.cc b/rtengine/shmap.cc index 24d72d085..030fbec93 100644 --- a/rtengine/shmap.cc +++ b/rtengine/shmap.cc @@ -128,13 +128,6 @@ void SHMap::update (Imagefloat* img, float** buffer, double radius, double lumi[ level += 1; indx = 1-indx; } - /*dirpyr_shmap(dirpyrlo[0], dirpyrlo[1], W, H, rangefn, 1, scale ); - scale = 4; - dirpyr_shmap(dirpyrlo[1], dirpyrlo[0], W, H, rangefn, 2, scale ); - scale = 8; - dirpyr_shmap(dirpyrlo[0], dirpyrlo[1], W, H, rangefn, 3, scale ); - scale = 16; - dirpyr_shmap(dirpyrlo[1], map, W, H, rangefn, 3, scale );*/ dirpyr_shmap(dirpyrlo[1-indx], map, W, H, rangefn, level, scale );