static Write * write_new( IMAGE *in ) { Write *write; if( !(write = IM_NEW( NULL, Write )) ) return( NULL ); memset( write, 0, sizeof( Write ) ); if( !(write->in = im__convert_saveable( in, IM__RGB_CMYK, bandfmt_jpeg )) ) { im_error( "im_vips2jpeg", "%s", _( "unable to convert to saveable format" ) ); write_destroy( write ); return( NULL ); } write->row_pointer = NULL; write->cinfo.err = jpeg_std_error( &write->eman.pub ); write->eman.pub.error_exit = new_error_exit; write->eman.pub.output_message = new_output_message; write->eman.fp = NULL; write->profile_bytes = NULL; write->profile_length = 0; write->inverted = NULL; return( write ); }
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 Tile * tile_new( Read *read ) { Tile *tile; if( !(tile = IM_NEW( NULL, Tile )) ) return( NULL ); tile->read = read; tile->region = NULL; tile->time = read->time; tile->x = -1; tile->y = -1; read->cache = g_slist_prepend( read->cache, tile ); g_assert( read->ntiles >= 0 ); read->ntiles += 1; if( !(tile->region = im_region_create( read->in )) ) { tile_destroy( tile ); return( NULL ); } im__region_no_ownership( tile->region ); return( tile ); }
/* Convolution start function. */ static void * aconv_start( IMAGE *out, void *a, void *b ) { IMAGE *in = (IMAGE *) a; Boxes *boxes = (Boxes *) b; AConvSequence *seq; if( !(seq = IM_NEW( out, AConvSequence )) ) return( NULL ); /* Init! */ seq->boxes = boxes; seq->ir = im_region_create( in ); /* n_velement should be the largest possible dimension. */ g_assert( boxes->n_velement >= boxes->n_hline ); g_assert( boxes->n_velement >= boxes->n_vline ); seq->start = IM_ARRAY( out, boxes->n_velement, int ); seq->end = IM_ARRAY( out, boxes->n_velement, int ); if( vips_band_format_isint( out->BandFmt ) ) seq->sum = IM_ARRAY( out, boxes->n_velement, int ); else
int im_XYZ2Lab_temp( IMAGE *in, IMAGE *out, double X0, double Y0, double Z0 ) { im_colour_temperature *temp; /* Check input image. */ if( !(temp = IM_NEW( out, im_colour_temperature )) ) return( -1 ); if( in->Bands != 3 || in->BandFmt != IM_BANDFMT_FLOAT || in->Coding != IM_CODING_NONE ) { im_error( "im_XYZ2Lab", _( "not 3-band uncoded float" ) ); return( -1 ); } /* Prepare the output image */ if( im_cp_desc( out, in) ) return( -1 ); out->Type = IM_TYPE_LAB; /* Do the processing. */ imb_XYZ2Lab_tables(); temp->X0 = X0; temp->Y0 = Y0; temp->Z0 = Z0; if( im_wrapone( in, out, (im_wrapone_fn) imb_XYZ2Lab, temp, NULL ) ) return( -1 ); return( 0 ); }
/* Convolution start function. */ static void * conv_start( IMAGE *out, void *a, void *b ) { IMAGE *in = (IMAGE *) a; Conv *conv = (Conv *) b; ConvSequence *seq; if( !(seq = IM_NEW( out, ConvSequence )) ) return( NULL ); /* Init! */ seq->conv = conv; seq->ir = NULL; seq->sum = NULL; seq->underflow = 0; seq->overflow = 0; /* Attach region and arrays. */ seq->ir = im_region_create( in ); if( vips_bandfmt_isint( conv->out->BandFmt ) ) seq->sum = (PEL *) IM_ARRAY( out, IM_IMAGE_N_ELEMENTS( in ), int ); else
static x_set *x_anal( IMAGE *im, double *xs, unsigned int n ){ unsigned int i; x_set *x_vals= IM_NEW( im, x_set ); if( ! x_vals ) return( NULL ); x_vals-> xs= IM_ARRAY( im, 2 * n, double ); if( ! x_vals-> xs ) return( NULL ); x_vals-> difs= x_vals-> xs + n; x_vals-> n= n; x_vals-> mean= 0.0; for( i= 0; i < n; ++i ){ x_vals-> xs[ i ]= xs[ i ]; x_vals-> mean+= xs[ i ]; } x_vals-> mean/= n; x_vals-> nsig2= 0.0; for( i= 0; i < n; ++i ){ x_vals-> difs[ i ]= xs[ i ] - x_vals-> mean; x_vals-> nsig2+= x_vals-> difs[ i ] * x_vals-> difs[ i ]; } x_vals-> err_term= ( 1.0 / (double) n ) + ( ( x_vals-> mean * x_vals-> mean ) / x_vals-> nsig2 ); return( x_vals ); }
/** * im_gaussnoise: * @out: output image * @x: output width * @y: output height * @mean: average value in output * @sigma: standard deviation in output * * Make a one band float image of gaussian noise with the specified * distribution. The noise distribution is created by averaging 12 random * numbers with the appropriate weights. * * See also: im_addgnoise(), im_make_xy(), im_text(), im_black(). * * Returns: 0 on success, -1 on error */ int im_gaussnoise( IMAGE *out, int x, int y, double mean, double sigma ) { GnoiseInfo *gin; if( x <= 0 || y <= 0 ) { im_error( "im_gaussnoise", "%s", _( "bad parameter" ) ); return( -1 ); } if( im_poutcheck( out ) ) return( -1 ); im_initdesc( out, x, y, 1, IM_BBITS_FLOAT, IM_BANDFMT_FLOAT, IM_CODING_NONE, IM_TYPE_B_W, 1.0, 1.0, 0, 0 ); if( im_demand_hint( out, IM_ANY, NULL ) ) return( -1 ); /* Save parameters. */ if( !(gin = IM_NEW( out, GnoiseInfo )) ) return( -1 ); gin->mean = mean; gin->sigma = sigma; if( im_generate( out, NULL, gnoise_gen, NULL, gin, NULL ) ) return( -1 ); return( 0 ); }
/* Start function. */ static void * dilate_start( IMAGE *out, void *a, void *b ) { IMAGE *in = (IMAGE *) a; INTMASK *msk = (INTMASK *) b; int sz = msk->xsize * msk->ysize; SeqInfo *seq; if( !(seq = IM_NEW( out, SeqInfo )) ) return( NULL ); /* Init! */ seq->ir = NULL; seq->soff = NULL; seq->ss = 0; seq->coff = NULL; seq->cs = 0; seq->last_bpl = -1; /* Attach region and arrays. */ seq->ir = im_region_create( in ); seq->soff = IM_ARRAY( out, sz, int ); seq->coff = IM_ARRAY( out, sz, int ); if( !seq->ir || !seq->soff || !seq->coff ) { dilate_stop( seq, in, NULL ); return( NULL ); } return( seq ); }
/* Build a Histogram. */ static Histogram * hist_build( IMAGE *index, IMAGE *value, IMAGE *out, int bands, int size ) { Histogram *hist; if( !(hist = IM_NEW( NULL, Histogram )) ) return( NULL ); hist->index = index; hist->value = value; hist->out = out; hist->vreg = NULL; hist->bands = bands; hist->size = size; hist->mx = 0; hist->bins = NULL; if( !(hist->bins = IM_ARRAY( NULL, bands * size, double )) || !(hist->vreg = im_region_create( value )) ) { hist_free( hist ); return( NULL ); } memset( hist->bins, 0, bands * size * sizeof( double ) ); return( hist ); }
/** * im_lab_morph: * @in: input image * @out: output image * @mask: cast correction table * @L_offset: L adjustment * @L_scale: L adjustment * @a_scale: a scale * @b_scale: b scale * * Morph an image in CIELAB colour space. Useful for certain types of gamut * mapping, or correction of greyscales on some printers. * * We perform three adjustments: * * <itemizedlist> * <listitem> * <para> * <emphasis>cast</emphasis> * * Pass in @mask containing CIELAB readings for a neutral greyscale. For * example: * * <tgroup cols='3' align='left' colsep='1' rowsep='1'> * <tbody> * <row> * <entry>3</entry> * <entry>4</entry> * </row> * <row> * <entry>14.23</entry> * <entry>4.8</entry> * <entry>-3.95</entry> * </row> * <row> * <entry>18.74</entry> * <entry>2.76</entry> * <entry>-2.62</entry> * </row> * <row> * <entry>23.46</entry> * <entry>1.4</entry> * <entry>-1.95</entry> * </row> * <row> * <entry>27.53</entry> * <entry>1.76</entry> * <entry>-2.01</entry> * </row> * </tbody> * </tgroup> * * Interpolation from this makes cast corrector. The top and tail are * interpolated towards [0, 0, 0] and [100, 0, 0], intermediate values are * interpolated along straight lines fitted between the specified points. * Rows may be in any order (ie. they need not be sorted on L*). * * Each pixel is displaced in a/b by the amount specified for that L in the * table. * </para> * </listitem> * <listitem> * <para> * <emphasis>L*</emphasis> * * Pass in scale and offset for L. L' = (L + offset) * scale. * </para> * </listitem> * <listitem> * <para> * <emphasis>saturation</emphasis> * * scale a and b by these amounts, eg. 1.5 increases saturation. * </para> * </listitem> * </itemizedlist> * * Find the top two by generating and printing a greyscale. Find the bottom * by printing a Macbeth and looking at a/b spread * * Returns: 0 on success, -1 on error. */ int im_lab_morph( IMAGE *in, IMAGE *out, DOUBLEMASK *mask, double L_offset, double L_scale, double a_scale, double b_scale ) { Params *parm; /* Recurse for coded images. */ if( in->Coding == IM_CODING_LABQ ) { IMAGE *t[2]; if( im_open_local_array( out, t, 2, "im_lab_morph", "p" ) || im_LabQ2Lab( in, t[0] ) || im_lab_morph( t[0], t[1], mask, L_offset, L_scale, a_scale, b_scale ) || im_Lab2LabQ( t[1], out ) ) return( -1 ); return( 0 ); } if( !(parm = IM_NEW( out, Params )) || morph_init( parm, in, out, L_scale, L_offset, mask, a_scale, b_scale ) ) return( -1 ); return( im__colour_unary( "im_lab_morph", in, out, IM_TYPE_LAB, (im_wrapone_fn) morph_buffer, parm, NULL ) ); }
/* 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 ); }
int im_stdif_raw( IMAGE *in, IMAGE *out, double a, double m0, double b, double s0, int xwin, int ywin ) { StdifInfo *inf; if( xwin > in->Xsize || ywin > in->Ysize ) { im_error( "im_stdif", "%s", _( "window too large" ) ); return( -1 ); } if( xwin <= 0 || ywin <= 0 ) { im_error( "im_lhisteq", "%s", _( "window too small" ) ); return( -1 ); } if( m0 < 0 || m0 > 255 || a < 0 || a > 1.0 || b < 0 || b > 2 || s0 < 0 || s0 > 255 ) { im_error( "im_stdif", "%s", _( "parameters out of range" ) ); return( -1 ); } if( im_check_format( "im_stdif", in, IM_BANDFMT_UCHAR ) || im_check_uncoded( "im_stdif", in ) || im_check_mono( "im_stdif", in ) || im_piocheck( in, out ) ) return( -1 ); if( im_cp_desc( out, in ) ) return( -1 ); out->Xsize -= xwin; out->Ysize -= ywin; /* Save parameters. */ if( !(inf = IM_NEW( out, StdifInfo )) ) return( -1 ); inf->xwin = xwin; inf->ywin = ywin; inf->a = a; inf->m0 = m0; inf->b = b; inf->s0 = s0; /* 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 ); /* Write the hist. */ if( im_generate( out, im_start_one, stdif_gen, im_stop_one, in, inf ) ) return( -1 ); return( 0 ); }
/* New sequence value. */ static void * start_fn( IMAGE *im, void *a, void *b ) { MinInfo *inf = (MinInfo *) a; Seq *seq = IM_NEW( NULL, Seq ); seq->inf = inf; seq->valid = 0; return( seq ); }
int im_contrast_surface_raw (IMAGE * in, IMAGE * out, int half_win_size, int spacing) { #define FUNCTION_NAME "im_contrast_surface_raw" cont_surf_params_t *params; if (im_piocheck (in, out) || im_check_uncoded (FUNCTION_NAME, in) || im_check_mono (FUNCTION_NAME, in) || im_check_format (FUNCTION_NAME, in, IM_BANDFMT_UCHAR)) return -1; if (half_win_size < 1 || spacing < 1) { im_error (FUNCTION_NAME, "%s", _("bad parameters")); return -1; } if (DOUBLE (half_win_size) >= LESSER (in->Xsize, in->Ysize)) { im_error (FUNCTION_NAME, "%s", _("parameters would result in zero size output image")); return -1; } params = IM_NEW (out, cont_surf_params_t); if (!params) return -1; params->half_win_size = half_win_size; params->spacing = spacing; if (im_cp_desc (out, in)) return -1; out->BandFmt = IM_BANDFMT_UINT; out->Xsize = 1 + ((in->Xsize - DOUBLE_ADD_ONE (half_win_size)) / spacing); out->Ysize = 1 + ((in->Ysize - DOUBLE_ADD_ONE (half_win_size)) / spacing); out->Xoffset = -half_win_size; out->Yoffset = -half_win_size; if (im_demand_hint (out, IM_FATSTRIP, in, NULL)) return -1; return im_generate (out, im_start_one, cont_surf_gen, im_stop_one, in, params); #undef FUNCTION_NAME }
/* New sequence value. */ static void * maxposavg_start( IMAGE *in, void *a, void *b ) { Maxposavg *global_maxposavg = (Maxposavg *) b; Maxposavg *maxposavg; if( !(maxposavg = IM_NEW( NULL, Maxposavg )) ) return( NULL ); *maxposavg = *global_maxposavg; return( (void *) maxposavg ); }
/* Morph an image. */ int im_lab_morph( IMAGE *in, IMAGE *out, DOUBLEMASK *mask, double L_offset, double L_scale, double a_scale, double b_scale ) { Params *parm; /* Recurse for coded images. */ if( in->Coding == IM_CODING_LABQ ) { IMAGE *t1 = im_open_local( out, "im_lab_morph:1", "p" ); IMAGE *t2 = im_open_local( out, "im_lab_morph:2", "p" ); if( !t1 || !t2 || im_LabQ2Lab( in, t1 ) || im_lab_morph( t1, t2, mask, L_offset, L_scale, a_scale, b_scale ) || im_Lab2LabQ( t2, out ) ) return( -1 ); return( 0 ); } if( in->Coding != IM_CODING_NONE ) { im_errormsg( "im_lab_morph: must be uncoded or IM_CODING_LABQ" ); return( -1 ); } if( in->BandFmt != IM_BANDFMT_FLOAT && in->BandFmt != IM_BANDFMT_DOUBLE ) { im_errormsg( "im_lab_morph: must be uncoded float or double" ); return( -1 ); } if( in->Bands != 3 ) { im_errormsg( "im_lab_morph: must be 3 bands" ); return( -1 ); } if( !(parm = IM_NEW( out, Params )) || morph_init( parm, in, out, L_scale, L_offset, mask, a_scale, b_scale ) ) return( -1 ); if( im_cp_desc( out, in ) ) return( -1 ); out->Type = IM_TYPE_LAB; if( im_wrapone( in, out, (im_wrapone_fn) morph_buffer, parm, NULL ) ) return( -1 ); return( 0 ); }
int im_lhisteq_raw( IMAGE *in, IMAGE *out, int xwin, int ywin ) { LhistInfo *inf; if( im_check_mono( "im_lhisteq", in ) || im_check_uncoded( "im_lhisteq", in ) || im_check_format( "im_lhisteq", in, IM_BANDFMT_UCHAR ) || im_piocheck( in, out ) ) return( -1 ); if( xwin > in->Xsize || ywin > in->Ysize ) { im_error( "im_lhisteq", "%s", _( "window too large" ) ); return( -1 ); } if( xwin <= 0 || ywin <= 0 ) { im_error( "im_lhisteq", "%s", _( "window too small" ) ); return( -1 ); } if( im_cp_desc( out, in ) ) return( -1 ); out->Xsize -= xwin - 1; out->Ysize -= ywin - 1; /* Save parameters. */ if( !(inf = IM_NEW( out, LhistInfo )) ) return( -1 ); inf->xwin = xwin; inf->ywin = ywin; inf->npels = xwin * ywin; /* 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 ); if( im_generate( out, im_start_one, lhist_gen, im_stop_one, in, inf ) ) return( -1 ); out->Xoffset = -xwin / 2; out->Yoffset = -xwin / 2; return( 0 ); }
/* Add a callback to an IMAGE. We can't use IM_NEW(), note! Freed eventually by * im__close(), or by im_generate(), etc. for evalend callbacks. */ static int add_callback( IMAGE *im, GSList **cblist, im_callback_fn fn, void *a, void *b ) { VCallback *cbs; if( !(cbs = IM_NEW( NULL, VCallback )) ) return( -1 ); cbs->fn = fn; cbs->a = a; cbs->b = b; cbs->im = im; *cblist = g_slist_prepend( *cblist, cbs ); return( 0 ); }
static Read * read_new( const char *filename, IMAGE *out ) { Read *read; if( !(read = IM_NEW( NULL, Read )) ) return( NULL ); read->filename = im_strdup( NULL, filename ); read->out = out; read->mat = NULL; read->var = NULL; if( !(read->mat = Mat_Open( filename, MAT_ACC_RDONLY )) ) { im_error( "im_mat2vips", _( "unable to open \"%s\"" ), filename ); read_destroy( read ); return( NULL ); } for(;;) { if( !(read->var = Mat_VarReadNextInfo( read->mat )) ) { im_error( "im_mat2vips", _( "no matrix variables in \"%s\"" ), filename ); read_destroy( read ); return( NULL ); } #ifdef DEBUG printf( "im_mat2vips: seen:\n" ); printf( "var->name == %s\n", read->var->name ); printf( "var->class_type == %d\n", read->var->class_type ); printf( "var->rank == %d\n", read->var->rank ); #endif /*DEBUG*/ /* Vector to colour image is OK for us. */ if( read->var->rank >= 1 && read->var->rank <= 3 ) break; IM_FREEF( Mat_VarFree, read->var ); } return( read ); }
/* Build a lut table. */ static LutInfo * build_luts( IMAGE *out, IMAGE *lut ) { LutInfo *st; int i, x; VipsPel *q; if( !(st = IM_NEW( out, LutInfo )) ) return( NULL ); /* Make luts. We unpack the LUT image into a C 2D array to speed * processing. */ st->fmt = lut->BandFmt; st->es = IM_IMAGE_SIZEOF_ELEMENT( lut ); st->nb = lut->Bands; st->sz = lut->Xsize * lut->Ysize; st->clp = st->sz - 1; st->overflow = 0; st->table = NULL; if( im_add_evalstart_callback( out, (im_callback_fn) lut_start, st, NULL ) || im_add_evalend_callback( out, (im_callback_fn) lut_end, st, NULL ) ) return( NULL ); /* Attach tables. */ if( !(st->table = IM_ARRAY( out, lut->Bands, VipsPel * )) ) return( NULL ); for( i = 0; i < lut->Bands; i++ ) if( !(st->table[i] = IM_ARRAY( out, st->sz * st->es, VipsPel )) ) return( NULL ); /* Scan LUT and fill table. */ q = (VipsPel *) lut->data; for( x = 0; x < st->sz; x++ ) for( i = 0; i < st->nb; i++ ) { memcpy( st->table[i] + x * st->es, q, st->es ); q += st->es; } return( st ); }
/* 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 Write * write_new( IMAGE *in, int fd ) { Write *write; if( !(write = IM_NEW( NULL, Write )) ) return( NULL ); write->in = in; write->fd = fd; if( !write->fd ) { write_destroy( write ); return( NULL ); } return( write ); }
/* Make a new overlap struct. */ static OverlapInfo * build_overlap( JoinNode *node, JoinNode *other, Rect *overlap ) { OverlapInfo *lap = IM_NEW( node->st->im, OverlapInfo ); if( !lap ) return( NULL ); lap->node = node; lap->other = other; lap->overlap = *overlap; lap->nstats = NULL; lap->ostats = NULL; node->overlaps = g_slist_prepend( node->overlaps, lap ); node->st->novl++; return( lap ); }
static void *gradcor_start( IMAGE *out, void *vptr_large, void *unrequired ){ gradcor_seq_t *seq= IM_NEW( NULL, gradcor_seq_t ); if( ! seq ) return NULL; seq-> region_xgrad= (int*) NULL; seq-> region_ygrad= (int*) NULL; seq-> region_xgrad_area= 0; seq-> region_ygrad_area= 0; seq-> reg= im_region_create( (IMAGE*) vptr_large ); if( ! seq-> reg ){ im_free( (void*) seq ); return NULL; } return (void*) seq; }
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 ); }
/* Our start function. */ static void * maplut_start( IMAGE *out, void *a, void *b ) { IMAGE *in = (IMAGE *) a; Seq *seq; if( !(seq = IM_NEW( out, Seq )) ) return( NULL ); /* Init! */ seq->ir = NULL; seq->overflow = 0; if( !(seq->ir = im_region_create( in )) ) return( NULL ); return( seq ); }
static int shrink( IMAGE *in, IMAGE *out, double xshrink, double yshrink ) { ShrinkInfo *st; /* Prepare output. Note: we round the output width down! */ if( im_cp_desc( out, in ) ) return( -1 ); out->Xsize = in->Xsize / xshrink; out->Ysize = in->Ysize / yshrink; out->Xres = in->Xres / xshrink; out->Yres = in->Yres / yshrink; if( out->Xsize <= 0 || out->Ysize <= 0 ) { im_error( "im_shrink", "%s", _( "image has shrunk to nothing" ) ); return( -1 ); } /* Build and attach state struct. */ if( !(st = IM_NEW( out, ShrinkInfo )) ) return( -1 ); st->xshrink = xshrink; st->yshrink = yshrink; st->mw = ceil( xshrink ); st->mh = ceil( yshrink ); st->np = st->mw * st->mh; /* Set demand hints. We want THINSTRIP, as we will be demanding a * large area of input for each output line. */ if( im_demand_hint( out, IM_THINSTRIP, in, NULL ) ) return( -1 ); /* Generate! */ if( im_generate( out, shrink_start, shrink_gen, shrink_stop, in, st ) ) return( -1 ); return( 0 ); }
static Mask * mask_new( VipsImage *im, int x, int y, PEL *ink, VipsImage *mask_im ) { Mask *mask; Rect area, image; if( im_check_coding_noneorlabq( "im_draw_mask", im ) || im_incheck( mask_im ) || im_check_mono( "im_draw_mask", mask_im ) || im_check_uncoded( "im_draw_mask", mask_im ) || im_check_format( "im_draw_mask", mask_im, IM_BANDFMT_UCHAR ) || !(mask = IM_NEW( NULL, Mask )) ) return( NULL ); if( !im__draw_init( DRAW( mask ), im, ink ) ) { mask_free( mask ); return( NULL ); } mask->x = x; mask->y = y; mask->mask_im = mask_im; /* Find the area we draw on the image. */ area.left = x; area.top = y; area.width = mask_im->Xsize; area.height = mask_im->Ysize; image.left = 0; image.top = 0; image.width = im->Xsize; image.height = im->Ysize; im_rect_intersectrect( &area, &image, &mask->image_clip ); /* And the area of the mask image we use. */ mask->mask_clip = mask->image_clip; mask->mask_clip.left -= x; mask->mask_clip.top -= y; return( mask ); }
static Read * read_new( const char *name, IMAGE *out ) { Read *read; if( !(read = IM_NEW( NULL, Read )) ) return( NULL ); read->name = im_strdup( NULL, name ); read->out = out; read->fp = NULL; read->pPng = NULL; read->pInfo = NULL; read->row_pointer = NULL; read->data = NULL; if( !(read->fp = im__file_open_read( name, NULL )) ) { read_destroy( read ); return( NULL ); } if( !(read->pPng = png_create_read_struct( PNG_LIBPNG_VER_STRING, NULL, user_error_function, user_warning_function )) ) { read_destroy( read ); return( NULL ); } /* Catch PNG errors from png_create_info_struct(). */ if( setjmp( read->pPng->jmpbuf ) ) { read_destroy( read ); return( NULL ); } if( !(read->pInfo = png_create_info_struct( read->pPng )) ) { read_destroy( read ); return( NULL ); } return( read ); }