small tidies to vips_gmic.cpp
This commit is contained in:
parent
4c095769f9
commit
b8c47eea9f
@ -63,30 +63,29 @@ typedef VipsOperationClass VipsGMicClass;
|
|||||||
|
|
||||||
#define VIPS_TYPE_GMIC (vips_gmic_get_type())
|
#define VIPS_TYPE_GMIC (vips_gmic_get_type())
|
||||||
#define VIPS_GMIC( obj ) \
|
#define VIPS_GMIC( obj ) \
|
||||||
(G_TYPE_CHECK_INSTANCE_CAST( (obj), \
|
(G_TYPE_CHECK_INSTANCE_CAST( (obj), VIPS_TYPE_GMIC, VipsGMic ))
|
||||||
VIPS_TYPE_GMIC, VipsGMic ))
|
#define VIPS_GMIC_CLASS( klass ) \
|
||||||
#define VIPS_LAYER_CLASS( klass ) \
|
(G_TYPE_CHECK_CLASS_CAST( (klass), VIPS_TYPE_GMIC, VipsGMicClass))
|
||||||
(G_TYPE_CHECK_CLASS_CAST( (klass), \
|
#define VIPS_IS_GMIC( obj ) \
|
||||||
VIPS_TYPE_GMIC, VipsGMicClass))
|
|
||||||
#define VIPS_IS_LAYER( obj ) \
|
|
||||||
(G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_GMIC ))
|
(G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_GMIC ))
|
||||||
#define VIPS_IS_LAYER_CLASS( klass ) \
|
#define VIPS_IS_GMIC_CLASS( klass ) \
|
||||||
(G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_GMIC ))
|
(G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_GMIC ))
|
||||||
#define VIPS_LAYER_GET_CLASS( obj ) \
|
#define VIPS_GMIC_GET_CLASS( obj ) \
|
||||||
(G_TYPE_INSTANCE_GET_CLASS( (obj), \
|
(G_TYPE_INSTANCE_GET_CLASS( (obj), VIPS_TYPE_GMIC, VipsGMicClass ))
|
||||||
VIPS_TYPE_GMIC, VipsGMicClass ))
|
|
||||||
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
G_DEFINE_TYPE( VipsGMic, vips_gmic, VIPS_TYPE_OPERATION );
|
G_DEFINE_TYPE( VipsGMic, vips_gmic, VIPS_TYPE_OPERATION );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
static int gmic_get_tile_border( VipsGMic* vipsgmic )
|
gmic_get_tile_border( VipsGMic *vipsgmic )
|
||||||
{
|
{
|
||||||
return vipsgmic->padding;
|
return( vipsgmic->padding );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define INDEX( IMG, X, Y, Z ) \
|
||||||
|
((*(IMG))( (guint) (X), (guint) (Y), (guint) (Z), 0 ))
|
||||||
|
|
||||||
// copy part of a vips region into a cimg
|
// copy part of a vips region into a cimg
|
||||||
static void
|
static void
|
||||||
vips_to_gmic( VipsRegion *in, VipsRect *area, CImg<float> *img )
|
vips_to_gmic( VipsRegion *in, VipsRect *area, CImg<float> *img )
|
||||||
@ -94,13 +93,13 @@ vips_to_gmic( VipsRegion *in, VipsRect *area, CImg<float>* img )
|
|||||||
VipsImage *im = in->im;
|
VipsImage *im = in->im;
|
||||||
|
|
||||||
for( int y = 0; y < area->height; y++ ) {
|
for( int y = 0; y < area->height; y++ ) {
|
||||||
float *p = (float *) 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 x = 0; x < area->width; x++ ) {
|
||||||
for( int z = 0; z < im->Bands; z++ ) {
|
for( int z = 0; z < im->Bands; z++ )
|
||||||
//const unsigned long off = (unsigned long)img->offset(x,y,z,c);
|
INDEX( img, x, y, z ) = p[z];
|
||||||
(*img)( (unsigned int)x, (unsigned int)y, (unsigned int)z, 0 ) = p[z];
|
|
||||||
}
|
|
||||||
p += im->Bands;
|
p += im->Bands;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,12 +119,13 @@ gmic_to_vips( gmic_image<float> *img, VipsRect *img_rect, VipsRegion *out )
|
|||||||
int y_off = valid->top - img_rect->top;
|
int y_off = valid->top - img_rect->top;
|
||||||
|
|
||||||
for( int y = 0; y < valid->height; y++ ) {
|
for( int y = 0; y < valid->height; y++ ) {
|
||||||
float *p = (float *) 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 x = 0; x < valid->width; x++ ) {
|
||||||
for( int z = 0; z < im->Bands; z++ )
|
for( int z = 0; z < im->Bands; z++ )
|
||||||
p[z] = static_cast<float>( (*img)(
|
p[z] = (float)
|
||||||
(unsigned int)(x + x_off), (unsigned int)(y + y_off), (unsigned int)z, 0 ) );
|
INDEX( img, x + x_off, y + y_off, z );
|
||||||
|
|
||||||
p += im->Bands;
|
p += im->Bands;
|
||||||
}
|
}
|
||||||
@ -138,71 +138,59 @@ gmic_gen( VipsRegion *oreg, void *seq, void *a, void *b, gboolean *stop )
|
|||||||
VipsRegion **ir = (VipsRegion **) seq;
|
VipsRegion **ir = (VipsRegion **) seq;
|
||||||
VipsGMic *vipsgmic = (VipsGMic *) b;
|
VipsGMic *vipsgmic = (VipsGMic *) b;
|
||||||
int ninput = VIPS_AREA( vipsgmic->in )->n;
|
int ninput = VIPS_AREA( vipsgmic->in )->n;
|
||||||
|
|
||||||
const int tile_border = gmic_get_tile_border( vipsgmic );
|
const int tile_border = gmic_get_tile_border( vipsgmic );
|
||||||
|
|
||||||
const VipsRect *r = &oreg->valid;
|
const VipsRect *r = &oreg->valid;
|
||||||
VipsRect* need = vips_rect_dup( r );
|
|
||||||
std::cout<<"gmic_gen(): need before adjust="<<need->left<<","<<need->top<<"+"<<need->width<<"+"<<need->height<<std::endl;
|
VipsRect need;
|
||||||
std::cout<<"gmic_gen(): tile_border="<<tile_border<<std::endl;
|
|
||||||
vips_rect_marginadjust( need, tile_border );
|
|
||||||
std::cout<<"gmic_gen(): need after adjust="<<need->left<<","<<need->top<<"+"<<need->width<<"+"<<need->height<<std::endl;
|
|
||||||
VipsRect image;
|
VipsRect image;
|
||||||
|
|
||||||
if( !ir ) return -1;
|
need = *r;
|
||||||
|
vips_rect_marginadjust( &need, tile_border );
|
||||||
image.left = 0;
|
image.left = 0;
|
||||||
image.top = 0;
|
image.top = 0;
|
||||||
image.width = ir[0]->im->Xsize;
|
image.width = ir[0]->im->Xsize;
|
||||||
image.height = ir[0]->im->Ysize;
|
image.height = ir[0]->im->Ysize;
|
||||||
vips_rect_intersectrect( need, &image, need );
|
vips_rect_intersectrect( &need, &image, &need );
|
||||||
std::cout<<"gmic_gen(): need="<<need->left<<","<<need->top<<"+"<<need->width<<"+"<<need->height<<std::endl;
|
|
||||||
for( int i = 0; ir[i]; i++ ) {
|
for( int i = 0; ir[i]; i++ )
|
||||||
if( vips_region_prepare( ir[i], need ) ) {
|
if( vips_region_prepare( ir[i], &need ) )
|
||||||
vips_free( need );
|
return( -1 );
|
||||||
return( -1 );
|
|
||||||
}
|
gmic gmic_instance;
|
||||||
}
|
gmic_list<float> images;
|
||||||
|
gmic_list<char> images_names;
|
||||||
|
|
||||||
gmic gmic_instance; // Construct first an empty 'gmic' instance.
|
|
||||||
gmic_list<float> images; // List of images, will contain all images pixel data.
|
|
||||||
gmic_list<char> images_names; // List of images names. Can be left empty if no names are associated to images.
|
|
||||||
try {
|
try {
|
||||||
images.assign( (unsigned int)ninput );
|
images.assign( (guint) ninput );
|
||||||
|
|
||||||
for( int i = 0; ir[i]; i++ ) {
|
for( int i = 0; ir[i]; i++ ) {
|
||||||
gmic_image<float> &img = images._data[i];
|
gmic_image<float> &img = images._data[i];
|
||||||
img.assign(need->width,need->height,1,ir[i]->im->Bands);
|
img.assign( need.width, need.height,
|
||||||
vips_to_gmic( ir[0], need, &img );
|
1, ir[i]->im->Bands );
|
||||||
|
vips_to_gmic( ir[0], &need, &img );
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("G'MIC command: %s\n",vipsgmic->command);
|
|
||||||
std::cout<<" ninput="<<ninput
|
|
||||||
<<std::endl;
|
|
||||||
std::cout<<" padding="<<vipsgmic->padding
|
|
||||||
<<" x scale="<<vipsgmic->x_scale<<std::endl;
|
|
||||||
|
|
||||||
gmic_instance.run( vipsgmic->command, images, images_names );
|
gmic_instance.run( vipsgmic->command, images, images_names );
|
||||||
gmic_to_vips( &images._data[0], need, oreg );
|
gmic_to_vips( &images._data[0], &need, oreg );
|
||||||
}
|
}
|
||||||
catch( gmic_exception e ) {
|
catch( gmic_exception e ) {
|
||||||
images.assign((unsigned int)0);
|
images.assign( (guint) 0 );
|
||||||
|
|
||||||
vips_error( "VipsGMic", "%s", e.what() );
|
vips_error( "VipsGMic", "%s", e.what() );
|
||||||
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
images.assign((unsigned int)0);
|
images.assign( (guint) 0 );
|
||||||
/**/
|
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
static int _gmic_build( VipsObject *object )
|
_gmic_build( VipsObject *object )
|
||||||
{
|
{
|
||||||
VipsObjectClass *klass = VIPS_OBJECT_GET_CLASS( object );
|
VipsObjectClass *klass = VIPS_OBJECT_GET_CLASS( object );
|
||||||
//VipsOperation *operation = VIPS_OPERATION( object );
|
|
||||||
VipsGMic *vipsgmic = (VipsGMic *) object;
|
VipsGMic *vipsgmic = (VipsGMic *) object;
|
||||||
|
|
||||||
VipsImage **in;
|
VipsImage **in;
|
||||||
VipsImage **t;
|
VipsImage **t;
|
||||||
int ninput;
|
int ninput;
|
||||||
@ -213,11 +201,10 @@ static int _gmic_build( VipsObject *object )
|
|||||||
|
|
||||||
in = vips_array_image_get( vipsgmic->in, &ninput );
|
in = vips_array_image_get( vipsgmic->in, &ninput );
|
||||||
|
|
||||||
for( i = 0; i < ninput; i++ ) {
|
for( i = 0; i < ninput; i++ )
|
||||||
if( vips_image_pio_input( in[i] ) ||
|
if( vips_image_pio_input( in[i] ) ||
|
||||||
vips_check_coding_known( klass->nickname, in[i] ) )
|
vips_check_coding_known( klass->nickname, in[i] ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
|
||||||
|
|
||||||
t = (VipsImage **) vips_object_local_array( object, ninput );
|
t = (VipsImage **) vips_object_local_array( object, ninput );
|
||||||
for( i = 0; i < ninput; i++ )
|
for( i = 0; i < ninput; i++ )
|
||||||
@ -225,17 +212,10 @@ static int _gmic_build( VipsObject *object )
|
|||||||
return( -1 );
|
return( -1 );
|
||||||
in = t;
|
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.
|
|
||||||
*/
|
|
||||||
g_object_set( vipsgmic, "out", vips_image_new(), NULL );
|
g_object_set( vipsgmic, "out", vips_image_new(), NULL );
|
||||||
|
|
||||||
/* Set demand hints.
|
|
||||||
*/
|
|
||||||
if( vips_image_pipeline_array( vipsgmic->out,
|
if( vips_image_pipeline_array( vipsgmic->out,
|
||||||
VIPS_DEMAND_STYLE_ANY,
|
VIPS_DEMAND_STYLE_ANY, in ) )
|
||||||
in ) )
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
if( ninput > 0 ) {
|
if( ninput > 0 ) {
|
||||||
@ -253,7 +233,6 @@ static int _gmic_build( VipsObject *object )
|
|||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vips_gmic_class_init( VipsGMicClass *klass )
|
vips_gmic_class_init( VipsGMicClass *klass )
|
||||||
{
|
{
|
||||||
@ -263,9 +242,11 @@ vips_gmic_class_init( VipsGMicClass *klass )
|
|||||||
|
|
||||||
gobject_class->set_property = vips_object_set_property;
|
gobject_class->set_property = vips_object_set_property;
|
||||||
gobject_class->get_property = vips_object_get_property;
|
gobject_class->get_property = vips_object_get_property;
|
||||||
|
|
||||||
vobject_class->nickname = "gmic";
|
vobject_class->nickname = "gmic";
|
||||||
vobject_class->description = _( "Vips G'MIC" );
|
vobject_class->description = _( "Vips G'MIC" );
|
||||||
vobject_class->build = _gmic_build;
|
vobject_class->build = _gmic_build;
|
||||||
|
|
||||||
operation_class->flags = VIPS_OPERATION_SEQUENTIAL_UNBUFFERED;
|
operation_class->flags = VIPS_OPERATION_SEQUENTIAL_UNBUFFERED;
|
||||||
|
|
||||||
VIPS_ARG_BOXED( klass, "in", 0,
|
VIPS_ARG_BOXED( klass, "in", 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user