@@ -604,14 +604,14 @@ void RawImageSource::vng4_demosaic () {
plistener - > setProgress ( 0.0 ) ;
}
ushor t ( * brow [ 5 ] ) [ 4 ] , * pix ;
floa t ( * 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 ;
ushor t ( * image ) [ 4 ] ;
floa t ( * image ) [ 4 ] ;
int lcode [ 16 ] [ 16 ] [ 32 ] , shift , i , j ;
image = ( ushor t ( * ) [ 4 ] ) calloc ( H * W , sizeof * image ) ;
image = ( floa t ( * ) [ 4 ] ) calloc ( H * W , sizeof * image ) ;
for ( int ii = 0 ; ii < H ; ii + + )
for ( int jj = 0 ; jj < W ; jj + + )
image [ ii * W + jj ] [ fc ( ii , jj ) ] = rawData [ ii ] [ jj ] ;
@@ -629,7 +629,7 @@ void RawImageSource::vng4_demosaic () {
* ip + + = ( width * y + x ) * 4 + color ;
* ip + + = shift ;
* ip + + = color ;
sum [ color ] + = 1 < < shift ;
sum [ color ] + = ( 1 < < shift ) ;
}
FORCC
if ( c ! = fc ( row , col ) ) {
@@ -644,9 +644,9 @@ void RawImageSource::vng4_demosaic () {
ip = lcode [ row & 15 ] [ col & 15 ] ;
memset ( sum , 0 , sizeof sum ) ;
for ( i = 8 ; i - - ; ip + = 3 )
sum [ ip [ 2 ] ] + = pix [ ip [ 0 ] ] < < ip [ 1 ] ;
sum [ ip [ 2 ] ] + = pix [ ip [ 0 ] ] * ( 1 << ip [ 1 ] ) ;
for ( i = colors ; - - i ; ip + = 2 )
pix [ ip [ 0 ] ] = sum [ ip [ 0 ] ] * ip [ 1 ] > > 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 < < g ) * ip + + = g ;
if ( grads & ( 1 < < g ) ) * ip + + = g ;
* ip + + = - 1 ;
}
* ip + + = INT_MAX ;
@@ -683,7 +683,7 @@ void RawImageSource::vng4_demosaic () {
* ip + + = 0 ;
}
}
brow [ 4 ] = ( ushor t ( * ) [ 4 ] ) calloc ( width * 3 , sizeof * * brow ) ;
brow [ 4 ] = ( floa t ( * ) [ 4 ] ) calloc ( width * 3 , sizeof * * brow ) ;
for ( row = 0 ; row < 3 ; row + + )
brow [ row ] = brow [ 4 ] + row * width ;
for ( row = 2 ; row < height - 2 ; row + + ) { /* Do VNG interpolation */
@@ -693,7 +693,7 @@ void RawImageSource::vng4_demosaic () {
ip = code [ row & prow ] [ col & pcol ] ;
memset ( gval , 0 , sizeof gval ) ;
while ( ( g = ip [ 0 ] ) ! = INT_MAX ) { /* Calculate gradients */
diff = ABS ( pix [ g ] - pix [ ip [ 1 ] ] ) < < ip [ 2 ] ;
diff = ABS ( pix [ g ] - pix [ ip [ 1 ] ] ) * ( 1 << ip [ 2 ] ) ;
gval [ ip [ 3 ] ] + = diff ;
ip + = 5 ;
if ( ( g = ip [ - 1 ] ) = = - 1 ) continue ;
@@ -711,13 +711,13 @@ void RawImageSource::vng4_demosaic () {
memcpy ( brow [ 2 ] [ col ] , pix , sizeof * image ) ;
continue ;
}
thold = gmin + ( gmax > > 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 < H ; i + + ) {
for ( int j = 0 ; j < W ; j + + )
green [ i ] [ j ] = ( image [ i * W + j ] [ 1 ] + image [ i * W + j ] [ 3 ] ) > > 1 ;
green [ i ] [ j ] = ( image [ i * W + j ] [ 1 ] + image [ i * W + j ] [ 3 ] ) / 2 ;
}
// Interpolate R and B
for ( int i = 0 ; i < H ; i + + ) {
@@ -835,9 +835,9 @@ void RawImageSource::ppg_demosaic()
- pix [ - d ] [ 1 ] - pix [ d ] [ 1 ] ;
}
if ( diff [ 0 ] ! = diff [ 1 ] )
pix [ 0 ] [ c ] = CLIP ( guess [ diff [ 0 ] > 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 ( ushor t ( * cache ) [ 4 ] , int x0 , int y0 , float * * rawData )
void RawImageSource : : fill_raw ( floa t ( * 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 ( ushor t ( * cache ) [ 4 ] , int border , int x0 , int y0 )
void RawImageSource : : fill_border ( floa t ( * 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 ( ushor t ( * buffer ) [ 3 ] , ushor t ( * image ) [ 4 ] )
void RawImageSource : : copy_to_buffer ( floa t ( * buffer ) [ 3 ] , floa t ( * 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 ( ushor t ( * image ) [ 4 ] , ushor t ( * buffer ) [ 3 ] )
void RawImageSource : : restore_from_buffer ( floa t ( * image ) [ 4 ] , floa t ( * 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 ( ushor t ( * image ) [ 4 ] , ushor t ( * bufferH ) [ 3 ] , ushor t ( * bufferV ) [ 3 ] , int x0 , int y0 )
void RawImageSource : : dcb_hid ( floa t ( * image ) [ 4 ] , floa t ( * bufferH ) [ 3 ] , floa t ( * 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 ( ushor t ( * image ) [ 4 ] , int x0 , int y0 )
void RawImageSource : : dcb_color ( floa t ( * 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 ( ushor t ( * image ) [ 4 ] , int x0 , int y0 )
void RawImageSource : : dcb_hid2 ( floa t ( * 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 ( ushor t ( * image ) [ 4 ] , int x0 , int y0 )
void RawImageSource : : dcb_map ( floa t ( * 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 + + ) {
ushor t * pix = & ( image [ indx ] [ 1 ] ) ;
floa t * 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 ( ushor t ( * image ) [ 4 ] , int x0 , int y0 )
void RawImageSource : : dcb_correction ( floa t ( * 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 ( ushor t ( * image ) [ 4 ] , int x0 , int y0 )
void RawImageSource : : dcb_pp ( floa t ( * 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;
ushor t ( * pix ) [ 4 ] = image + ( indx - u - 1 ) ;
floa t ( * 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 ( ushor t ( * image ) [ 4 ] , int x0 , int y0 )
void RawImageSource : : dcb_correction2 ( floa t ( * 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 ( ushor t ( * image ) [ 4 ] , int x0 , int y0 )
void RawImageSource : : dcb_refinement ( floa t ( * 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 ( ushor t ( * image ) [ 4 ] , int x0 , int y0 , float ( * chroma ) [ 2 ] )
void RawImageSource : : dcb_color_full ( floa t ( * 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 ( ) ;
ushor t ( * * image ) [ 4 ] = ( ushor t( * * ) [ 4 ] ) calloc ( nthreads , sizeof ( void * ) ) ;
ushor t ( * * image2 ) [ 3 ] = ( ushor t( * * ) [ 3 ] ) calloc ( nthreads , sizeof ( void * ) ) ;
ushor t ( * * image3 ) [ 3 ] = ( ushor t( * * ) [ 3 ] ) calloc ( nthreads , sizeof ( void * ) ) ;
floa t ( * * image ) [ 4 ] = ( floa t( * * ) [ 4 ] ) calloc ( nthreads , sizeof ( void * ) ) ;
floa t ( * * image2 ) [ 3 ] = ( floa t( * * ) [ 3 ] ) calloc ( nthreads , sizeof ( void * ) ) ;
floa t ( * * image3 ) [ 3 ] = ( floa t( * * ) [ 3 ] ) calloc ( nthreads , sizeof ( void * ) ) ;
float ( * * chroma ) [ 2 ] = ( float ( * * ) [ 2 ] ) calloc ( nthreads , sizeof ( void * ) ) ;
for ( int i = 0 ; i < nthreads ; i + + ) {
image [ i ] = ( ushor t( * ) [ 4 ] ) calloc ( CACHESIZE * CACHESIZE , sizeof * * image ) ;
image2 [ i ] = ( ushor t( * ) [ 3 ] ) calloc ( CACHESIZE * CACHESIZE , sizeof * * image2 ) ;
image3 [ i ] = ( ushor t( * ) [ 3 ] ) calloc ( CACHESIZE * CACHESIZE , sizeof * * image3 ) ;
image [ i ] = ( floa t( * ) [ 4 ] ) calloc ( CACHESIZE * CACHESIZE , sizeof * * image ) ;
image2 [ i ] = ( floa t( * ) [ 3 ] ) calloc ( CACHESIZE * CACHESIZE , sizeof * * image2 ) ;
image3 [ i ] = ( floa t( * ) [ 3 ] ) calloc ( CACHESIZE * CACHESIZE , sizeof * * image3 ) ;
chroma [ i ] = ( float ( * ) [ 2 ] ) calloc ( CACHESIZE * CACHESIZE , sizeof * * chroma ) ;
}
# else
ushor t ( * image ) [ 4 ] = ( ushor t( * ) [ 4 ] ) calloc ( CACHESIZE * CACHESIZE , sizeof * image ) ;
ushor t ( * image2 ) [ 3 ] = ( ushor t( * ) [ 3 ] ) calloc ( CACHESIZE * CACHESIZE , sizeof * image2 ) ;
ushor t ( * image3 ) [ 3 ] = ( ushor t( * ) [ 3 ] ) calloc ( CACHESIZE * CACHESIZE , sizeof * image3 ) ;
floa t ( * image ) [ 4 ] = ( floa t( * ) [ 4 ] ) calloc ( CACHESIZE * CACHESIZE , sizeof * image ) ;
floa t ( * image2 ) [ 3 ] = ( floa t( * ) [ 3 ] ) calloc ( CACHESIZE * CACHESIZE , sizeof * image2 ) ;
floa t ( * image3 ) [ 3 ] = ( floa t( * ) [ 3 ] ) calloc ( CACHESIZE * CACHESIZE , sizeof * image3 ) ;
float ( * chroma ) [ 2 ] = ( float ( * ) [ 2 ] ) calloc ( CACHESIZE * CACHESIZE , sizeof * chroma ) ;
# endif
@@ -1565,14 +1565,14 @@ void RawImageSource::dcb_demosaic(int iterations, int dcb_enhance)
# ifdef _OPENMP
int tid = omp_get_thread_num ( ) ;
ushor t ( * tile ) [ 4 ] = image [ tid ] ;
ushor t ( * buffer ) [ 3 ] = image2 [ tid ] ;
ushor t ( * buffer2 ) [ 3 ] = image3 [ tid ] ;
floa t ( * tile ) [ 4 ] = image [ tid ] ;
floa t ( * buffer ) [ 3 ] = image2 [ tid ] ;
floa t ( * buffer2 ) [ 3 ] = image3 [ tid ] ;
float ( * chrm ) [ 2 ] = chroma [ tid ] ;
# else
ushor t ( * tile ) [ 4 ] = image ;
ushor t ( * buffer ) [ 3 ] = image2 ;
ushor t ( * buffer2 ) [ 3 ] = image3 ;
floa t ( * tile ) [ 4 ] = image ;
floa t ( * buffer ) [ 3 ] = image2 ;
floa t ( * buffer2 ) [ 3 ] = image3 ;
float ( * chrm ) [ 2 ] = chroma ;
# endif