From 4c095769f92cbafee743c9445c76a4e42d565d87 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 6 Oct 2014 22:02:41 +0100 Subject: [PATCH] process all gmic images as float --- libvips/cimg/vips_gmic.cpp | 89 ++++++++++---------------------------- 1 file changed, 24 insertions(+), 65 deletions(-) diff --git a/libvips/cimg/vips_gmic.cpp b/libvips/cimg/vips_gmic.cpp index 4b0818af..4598b625 100644 --- a/libvips/cimg/vips_gmic.cpp +++ b/libvips/cimg/vips_gmic.cpp @@ -88,13 +88,13 @@ static int gmic_get_tile_border( VipsGMic* vipsgmic ) } // copy part of a vips region into a cimg -template static void -vips_to_gmic( VipsRegion *in, VipsRect *area, CImg* img ) +static void +vips_to_gmic( VipsRegion *in, VipsRect *area, CImg* img ) { VipsImage *im = in->im; for( int y = 0; y < area->height; y++ ) { - T *p = (T *) VIPS_REGION_ADDR( in, area->left, area->top + y ); + float *p = (float *) VIPS_REGION_ADDR( in, area->left, area->top + y ); for( int x = 0; x < area->width; x++ ) { for( int z = 0; z < im->Bands; z++ ) { @@ -108,8 +108,8 @@ vips_to_gmic( VipsRegion *in, VipsRect *area, CImg* img ) // write a CImg to a vips region // fill out->valid, img has pixels in img_rect -template static void -gmic_to_vips( gmic_image *img, VipsRect *img_rect, VipsRegion *out ) +static void +gmic_to_vips( gmic_image *img, VipsRect *img_rect, VipsRegion *out ) { VipsImage *im = out->im; VipsRect *valid = &out->valid; @@ -120,11 +120,11 @@ gmic_to_vips( gmic_image *img, VipsRect *img_rect, VipsRegion *out ) int y_off = valid->top - img_rect->top; for( int y = 0; y < valid->height; y++ ) { - T *p = (T *) VIPS_REGION_ADDR( out, valid->left, valid->top + y ); + float *p = (float *) VIPS_REGION_ADDR( out, valid->left, valid->top + y ); for( int x = 0; x < valid->width; x++ ) { for( int z = 0; z < im->Bands; z++ ) - p[z] = static_cast( (*img)( + p[z] = static_cast( (*img)( (unsigned int)(x + x_off), (unsigned int)(y + y_off), (unsigned int)z, 0 ) ); p += im->Bands; @@ -132,8 +132,8 @@ gmic_to_vips( gmic_image *img, VipsRect *img_rect, VipsRegion *out ) } } -template static int -_gmic_gen( VipsRegion *oreg, void *seq, void *a, void *b, gboolean *stop ) +static int +gmic_gen( VipsRegion *oreg, void *seq, void *a, void *b, gboolean *stop ) { VipsRegion **ir = (VipsRegion **) seq; VipsGMic *vipsgmic = (VipsGMic *) b; @@ -143,10 +143,10 @@ _gmic_gen( VipsRegion *oreg, void *seq, void *a, void *b, gboolean *stop ) const VipsRect *r = &oreg->valid; VipsRect* need = vips_rect_dup( r ); - std::cout<<"_gmic_gen(): need before adjust="<left<<","<top<<"+"<width<<"+"<height<top<<"+"<width<<"+"<height<top<<"+"<width<<"+"<height<top<<"+"<width<<"+"<height<im->Xsize; image.height = ir[0]->im->Ysize; vips_rect_intersectrect( need, &image, need ); - std::cout<<"_gmic_gen(): need="<left<<","<top<<"+"<width<<"+"<height<top<<"+"<width<<"+"<height< img; - //vips_to_gmic( ir[0], need, &img ); - /**/ gmic gmic_instance; // Construct first an empty 'gmic' instance. - gmic_list images; // List of images, will contain all images pixel data. + gmic_list images; // List of images, will contain all images pixel data. gmic_list images_names; // List of images names. Can be left empty if no names are associated to images. try { images.assign( (unsigned int)ninput ); for( int i = 0; ir[i]; i++ ) { - gmic_image& img = images._data[i]; + gmic_image& img = images._data[i]; img.assign(need->width,need->height,1,ir[i]->im->Bands); - vips_to_gmic( ir[0], need, &img ); + vips_to_gmic( ir[0], need, &img ); } printf("G'MIC command: %s\n",vipsgmic->command); @@ -185,7 +182,7 @@ _gmic_gen( VipsRegion *oreg, void *seq, void *a, void *b, gboolean *stop ) <<" x scale="<x_scale<command,images,images_names); - gmic_to_vips( &images._data[0], need, oreg ); + gmic_to_vips( &images._data[0], need, oreg ); } catch( gmic_exception e ) { images.assign((unsigned int)0); @@ -201,57 +198,13 @@ _gmic_gen( VipsRegion *oreg, void *seq, void *a, void *b, gboolean *stop ) } -static int -gmic_gen( VipsRegion *oreg, void *seq, void *a, void *b, gboolean *stop ) -{ - VipsRegion **ir = (VipsRegion **) seq; - - if( !ir ) return -1; - - std::cout<<"ir[0]->im->BandFmt: "<im->BandFmt<im->BandFmt ) { - case VIPS_FORMAT_UCHAR: - //return _gmic_gen(oreg, seq, a, b, stop); - break; - - case VIPS_FORMAT_CHAR: - break; - - case VIPS_FORMAT_USHORT: - //return _gmic_gen(oreg, seq, a, b, stop); - break; - - case VIPS_FORMAT_SHORT: - break; - - case VIPS_FORMAT_UINT: - break; - - case VIPS_FORMAT_INT: - break; - - case VIPS_FORMAT_FLOAT: - return _gmic_gen(oreg, seq, a, b, stop); - break; - - case VIPS_FORMAT_DOUBLE: - break; - - default: - g_assert( 0 ); - break; - } - - return 0; -} - - static int _gmic_build( VipsObject *object ) { VipsObjectClass *klass = VIPS_OBJECT_GET_CLASS( object ); //VipsOperation *operation = VIPS_OPERATION( object ); VipsGMic *vipsgmic = (VipsGMic *) object; VipsImage **in; + VipsImage **t; int ninput; int i; @@ -266,6 +219,12 @@ static int _gmic_build( VipsObject *object ) return( -1 ); } + t = (VipsImage **) vips_object_local_array( object, ninput ); + for( i = 0; i < ninput; i++ ) + if( vips_cast( in[i], &t[i], VIPS_FORMAT_FLOAT, NULL ) ) + return( -1 ); + in = t; + /* Get ready to write to @out. @out must be set via g_object_set() so * that vips can see the assignment. It'll complain that @out hasn't * been set otherwise.