/* Build a new symbol table. */ SymbolTable * im__build_symtab( IMAGE *out, int sz ) { SymbolTable *st = IM_NEW( out, SymbolTable ); int i; if( !st ) return( NULL ); if( !(st->table = IM_ARRAY( out, sz, GSList * )) ) return( NULL ); st->sz = sz; st->im = out; st->novl = 0; st->nim = 0; st->njoin = 0; st->root = NULL; st->leaf = NULL; st->fac = NULL; if( im_add_close_callback( out, (im_callback_fn) junk_table, st, NULL ) ) return( NULL ); for( i = 0; i < sz; i++ ) st->table[i] = NULL; return( st ); }
/** * im_copy_file: * @in: input image * @out: output image * * Copy an image to a disc file, then copy again to output. If the image is * already a disc file, just copy straight through. * * The disc file is allocated in the same way as im_system_image(). * The file is automatically deleted when @out is closed. * * See also: im_copy(), im_system_image(). * * Returns: 0 on success, -1 on error */ int im_copy_file( IMAGE *in, IMAGE *out ) { if( !im_isfile( in ) ) { IMAGE *disc; if( !(disc = im__open_temp( "%s.v" )) ) return( -1 ); if( im_add_close_callback( out, (im_callback_fn) im_close, disc, NULL ) ) { im_close( disc ); return( -1 ); } if( im_copy( in, disc ) || im_copy( disc, out ) ) return( -1 ); } else { if( im_copy( in, out ) ) return( -1 ); } return( 0 ); }
static Read * read_new( IMAGE *in, IMAGE *out, int tile_width, int tile_height, int max_tiles ) { Read *read; if( !(read = IM_NEW( NULL, Read )) ) return( NULL ); read->in = in; read->out = out; read->tile_width = tile_width; read->tile_height = tile_height; read->max_tiles = max_tiles; read->time = 0; read->ntiles = 0; read->lock = g_mutex_new(); read->cache = NULL; if( im_add_close_callback( out, (im_callback_fn) read_destroy, read, NULL ) ) { read_destroy( read ); return( NULL ); } return( read ); }
static int system_image_vec( im_object *argv ) { IMAGE *in = argv[0]; IMAGE *out = argv[1]; char *in_format = argv[2]; char *out_format = argv[3]; char *cmd = argv[4]; char **log = (char **) &argv[5]; IMAGE *out_image; if( !(out_image = im_system_image( in, in_format, out_format, cmd, log )) ) { im_error( "im_system_image", "%s", *log ); return( -1 ); } if( im_copy( out_image, out ) || im_add_close_callback( out, (im_callback_fn) im_close, out_image, NULL ) ) { im_close( out_image ); return( -1 ); } return( 0 ); }
/* Make a DOUBLEMASK local to an image descriptor. */ static DOUBLEMASK * local_mask( IMAGE *out, DOUBLEMASK *mask ) { if( !mask ) return( NULL ); if( im_add_close_callback( out, (im_callback_fn) im_free_dmask, mask, NULL ) ) { im_free_dmask( mask ); return( NULL ); } return( mask ); }
/** * im_local_imask: * @out: image to make the mask local to * @mask: mask to local-ize * * @out takes ownership of @mask: when @out is closed, @mask will be closed * for you. If im_local_imask() itself fails, the mask is also freed. * * See also: im_local_dmask(). * * Returns: the mask, or NULL on error. */ INTMASK * im_local_imask( VipsImage *out, INTMASK *mask ) { if( im_check_imask( "im_local_dmask", mask ) ) return( NULL ); if( im_add_close_callback( out, (im_callback_fn) im_free_imask, mask, NULL ) ) { im_free_imask( mask ); return( NULL ); } return( mask ); }
/* Make a leaf for a file. */ static JoinNode * build_node( SymbolTable *st, char *name ) { JoinNode *node = IM_NEW( st->im, JoinNode ); int n = hash( name ); /* Fill fields. */ if( !node || !(node->name = im_strdup( st->im, name )) ) return( NULL ); node->type = JOIN_LEAF; node->dirty = 0; node->mwidth = -2; node->st = st; im__transform_init( &node->cumtrn ); node->trnim = NULL; node->arg1 = NULL; node->arg2 = NULL; node->overlaps = NULL; node->im = NULL; node->index = 0; if( im_add_close_callback( st->im, (im_callback_fn) junk_node, node, NULL ) ) return( NULL ); /* Try to open. */ if( (node->im = im__global_open_image( st, name )) ) { /* There is a file there - set width and height. */ node->cumtrn.oarea.width = node->im->Xsize; node->cumtrn.oarea.height = node->im->Ysize; } else { /* Clear the error buffer to lessen confusion. */ im_error_clear(); } st->table[n] = g_slist_prepend( st->table[n], node ); return( node ); }
static Read * read_new( const char *filename, IMAGE *im ) { Read *read; static int inited = 0; if( !inited ) { #ifdef HAVE_MAGICKCOREGENESIS MagickCoreGenesis( im_get_argv0(), MagickFalse ); #else /*!HAVE_MAGICKCOREGENESIS*/ InitializeMagick( "" ); #endif /*HAVE_MAGICKCOREGENESIS*/ inited = 1; } if( !(read = IM_NEW( NULL, Read )) ) return( NULL ); read->filename = im_strdup( NULL, filename ); read->im = im; read->image = NULL; read->image_info = CloneImageInfo( NULL ); GetExceptionInfo( &read->exception ); read->n_frames = 0; read->frames = NULL; read->frame_height = 0; read->lock = g_mutex_new(); if( im_add_close_callback( im, (im_callback_fn) read_destroy, read, NULL ) ) { read_destroy( read ); return( NULL ); } if( !read->filename || !read->image_info ) return( NULL ); im_strncpy( read->image_info->filename, filename, MaxTextExtent ); #ifdef DEBUG printf( "im_magick2vips: read_new: %s\n", read->filename ); #endif /*DEBUG*/ return( read ); }
/* Make something local to an image descriptor ... pass in a constructor * and a destructor, plus three args. */ void * im_local( IMAGE *im, im_construct_fn cons, im_callback_fn dest, void *a, void *b, void *c ) { void *obj; if( !im ) { im_error( "im_local", "%s", _( "NULL image descriptor" ) ); return( NULL ); } if( !(obj = cons( a, b, c )) ) return( NULL ); if( im_add_close_callback( im, (im_callback_fn) dest, obj, a ) ) { dest( obj, a ); return( NULL ); } return( obj ); }
static Conv * conv_new( IMAGE *in, IMAGE *out, INTMASK *mask ) { Conv *conv = IM_NEW( out, Conv ); if( !conv ) return( NULL ); conv->in = in; conv->out = out; conv->mask = NULL; conv->size = mask->xsize * mask->ysize; conv->scale = mask->scale * mask->scale; conv->underflow = 0; conv->overflow = 0; if( im_add_close_callback( out, (im_callback_fn) conv_destroy, conv, NULL ) || !(conv->mask = im_dup_imask( mask, "conv_mask" )) ) return( NULL ); return( conv ); }
static int affinei( IMAGE *in, IMAGE *out, VipsInterpolate *interpolate, Transformation *trn ) { Affine *affine; double edge; /* Make output image. */ if( im_piocheck( in, out ) ) return( -1 ); if( im_cp_desc( out, in ) ) return( -1 ); /* Need a copy of the params for the lifetime of out. */ if( !(affine = IM_NEW( out, Affine )) ) return( -1 ); affine->interpolate = NULL; if( im_add_close_callback( out, (im_callback_fn) affine_free, affine, NULL ) ) return( -1 ); affine->in = in; affine->out = out; affine->interpolate = interpolate; g_object_ref( interpolate ); affine->trn = *trn; if( im__transform_calc_inverse( &affine->trn ) ) return( -1 ); out->Xsize = affine->trn.oarea.width; out->Ysize = affine->trn.oarea.height; /* Normally SMALLTILE ... except if this is a size up/down affine. */ if( affine->trn.b == 0.0 && affine->trn.c == 0.0 ) { if( im_demand_hint( out, IM_FATSTRIP, in, NULL ) ) return( -1 ); } else { if( im_demand_hint( out, IM_SMALLTILE, in, NULL ) ) return( -1 ); } /* Check for coordinate overflow ... we want to be able to hold the * output space inside INT_MAX / TRANSFORM_SCALE. */ edge = INT_MAX / VIPS_TRANSFORM_SCALE; if( affine->trn.oarea.left < -edge || affine->trn.oarea.top < -edge || IM_RECT_RIGHT( &affine->trn.oarea ) > edge || IM_RECT_BOTTOM( &affine->trn.oarea ) > edge ) { im_error( "im_affinei", "%s", _( "output coordinates out of range" ) ); return( -1 ); } /* Generate! */ if( im_generate( out, im_start_one, affinei_gen, im_stop_one, in, affine ) ) return( -1 ); return( 0 ); }
/* The main part of the benchmark ... transform labq to labq. Chain several of * these together to get a CPU-bound operation. */ static int benchmark( IMAGE *in, IMAGE *out ) { IMAGE *t[18]; double one[3] = { 1.0, 1.0, 1.0 }; double zero[3] = { 0.0, 0.0, 0.0 }; double darken[3] = { 1.0 / 1.18, 1.0, 1.0 }; double whitepoint[3] = { 1.06, 1.0, 1.01 }; double shadow[3] = { -2, 0, 0 }; double white[3] = { 100, 0, 0 }; DOUBLEMASK *d652d50 = im_create_dmaskv( "d652d50", 3, 3, 1.13529, -0.0604663, -0.0606321, 0.0975399, 0.935024, -0.0256156, -0.0336428, 0.0414702, 0.994135 ); im_add_close_callback( out, (im_callback_fn) im_free_dmask, d652d50, NULL ); return( /* Set of descriptors for this operation. */ im_open_local_array( out, t, 18, "im_benchmark", "p" ) || /* Unpack to float. */ im_LabQ2Lab( in, t[0] ) || /* Crop 100 pixels off all edges. */ im_extract_area( t[0], t[1], 100, 100, t[0]->Xsize - 200, t[0]->Ysize - 200 ) || /* Shrink by 10%, bilinear interp. */ im_affinei_all( t[1], t[2], vips_interpolate_bilinear_static(), 0.9, 0, 0, 0.9, 0, 0 ) || /* Find L ~= 100 areas (white surround). */ im_extract_band( t[2], t[3], 0 ) || im_moreconst( t[3], t[4], 99 ) || /* Adjust white point and shadows. */ im_lintra_vec( 3, darken, t[2], zero, t[5] ) || im_Lab2XYZ( t[5], t[6] ) || im_recomb( t[6], t[7], d652d50 ) || im_lintra_vec( 3, whitepoint, t[7], zero, t[8] ) || im_lintra( 1.5, t[8], 0.0, t[9] ) || im_XYZ2Lab( t[9], t[10] ) || im_lintra_vec( 3, one, t[10], shadow, t[11] ) || /* Make a solid white image. */ im_black( t[12], t[4]->Xsize, t[4]->Ysize, 3 ) || im_lintra_vec( 3, zero, t[12], white, t[13] ) || /* Reattach border. */ im_ifthenelse( t[4], t[13], t[11], t[14] ) || /* Sharpen. */ im_Lab2LabQ( t[14], t[15] ) || im_sharpen( t[15], out, 11, 2.5, 40, 20, 0.5, 1.5 ) ); }
static Morph * morph_new( IMAGE *in, IMAGE *out, INTMASK *mask, MorphOp op ) { const int n_mask = mask->xsize * mask->ysize; Morph *morph; int i; /* If in is not uchar, do (!=0) to make a uchar image. */ if( in->BandFmt != IM_BANDFMT_UCHAR ) { IMAGE *t; if( !(t = im_open_local( out, "morph_new", "p" )) || im_notequalconst( in, t, 0 ) ) return( NULL ); in = t; } if( im_piocheck( in, out ) || im_check_uncoded( "morph", in ) || im_check_format( "morph", in, IM_BANDFMT_UCHAR ) || im_check_imask( "morph", mask ) ) return( NULL ); for( i = 0; i < n_mask; i++ ) if( mask->coeff[i] != 0 && mask->coeff[i] != 128 && mask->coeff[i] != 255 ) { im_error( "morph", _( "bad mask element (%d " "should be 0, 128 or 255)" ), mask->coeff[i] ); return( NULL ); } if( !(morph = IM_NEW( out, Morph )) ) return( NULL ); morph->in = in; morph->out = out; morph->mask = NULL; morph->op = op; morph->n_pass = 0; for( i = 0; i < MAX_PASS; i++ ) morph->pass[i].vector = NULL; if( im_add_close_callback( out, (im_callback_fn) morph_close, morph, NULL ) || !(morph->mask = im_dup_imask( mask, "morph" )) ) return( NULL ); /* Generate code for this mask / image, if possible. */ if( vips_vector_isenabled() ) { if( pass_compile( morph ) ) pass_free( morph ); } return( morph ); }
/* Dilate an image. */ int im_dilate_raw( IMAGE *in, IMAGE *out, INTMASK *m ) { INTMASK *msk; /* Check mask has odd number of elements in width and height. */ if( m->xsize < 1 || !(m->xsize & 0x1) || m->ysize < 1 || !(m->ysize & 0x1) ) { im_error( "im_dilate", _( "mask size not odd" ) ); return( -1 ); } /* Standard checks. */ if( im_piocheck( in, out ) ) return( -1 ); if( in->Coding != IM_CODING_NONE || in->Bbits != 8 || in->BandFmt != IM_BANDFMT_UCHAR ) { im_error( "im_dilate", _( "uchar uncoded only" ) ); return( -1 ); } if( im_cp_desc( out, in ) ) return( -1 ); /* Prepare output. Consider a 7x7 mask and a 7x7 image --- the output * would be 1x1. */ if( im_cp_desc( out, in ) ) return( -1 ); out->Xsize -= m->xsize - 1; out->Ysize -= m->ysize - 1; if( out->Xsize <= 0 || out->Ysize <= 0 ) { im_error( "im_dilate", _( "image too small for mask" ) ); return( -1 ); } /* Take a copy of m. */ if( !(msk = im_dup_imask( m, "conv_mask" )) ) return( -1 ); if( im_add_close_callback( out, (im_callback_fn) im_free_imask, msk, NULL ) ) { im_free_imask( msk ); return( -1 ); } /* Set demand hints. FATSTRIP is good for us, as THINSTRIP will cause * too many recalculations on overlaps. */ if( im_demand_hint( out, IM_FATSTRIP, in, NULL ) ) return( -1 ); /* Generate! */ if( im_generate( out, dilate_start, dilate_gen, dilate_stop, in, msk ) ) return( -1 ); out->Xoffset = -m->xsize / 2; out->Yoffset = -m->ysize / 2; return( 0 ); }