Example #1
0
/**
 * im_start_many:
 *
 * Start function for many images in. First client is a pointer to
 * a %NULL-terminated array of input images.
 *
 * See also: im_generate(), im_allocate_input_array()
 */
void *
im_start_many( IMAGE *out, void *client, void *dummy )
{
    IMAGE **in = (IMAGE **) client;

    int i, n;
    REGION **ar;

    /* How many images?
     */
    for( n = 0; in[n]; n++ )
        ;

    /* Alocate space for region array.
     */
    if( !(ar = IM_ARRAY( NULL, n + 1, REGION * )) )
        return( NULL );

    /* Create a set of regions.
     */
    for( i = 0; i < n; i++ )
        if( !(ar[i] = im_region_create( in[i] )) ) {
            im_stop_many( ar, NULL, NULL );
            return( NULL );
        }
    ar[n] = NULL;

    return( ar );
}
Example #2
0
/* 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 );
}
Example #3
0
/**
 * im_start_one:
 *
 * Start function for one image in. Input image is first user data.
 *
 * See also: im_generate().
 */
void *
im_start_one( IMAGE *out, void *client, void *dummy )
{
    IMAGE *in = (IMAGE *) client;

    return( im_region_create( in ) );
}
Example #4
0
/**
 * im_read_point:
 * @image: image to read from
 * @x: position to read
 * @y: position to read
 * @ink: read value here
 *
 * Reads a single point on an image. 
 *
 * @ink is an array of bytes to contain a valid pixel for the image's format.
 * It must have at least IM_IMAGE_SIZEOF_PEL( @im ) bytes.
 *
 * See also: im_draw_point().
 *
 * Returns: 0 on success, or -1 on error.
 */
int
im_read_point( VipsImage *image, int x, int y, VipsPel *ink )
{
	REGION *reg;
	Rect area;

	if( im_check_coding_known( "im_draw_point", image ) ||
		!(reg = im_region_create( image )) )
		return( -1 );

	area.left = x;
	area.top = y;
	area.width = 1;
	area.height = 1;
	if( im_prepare( reg, &area ) ) {
		im_region_free( reg );
		return( -1 );
	}

	memcpy( ink, IM_REGION_ADDR( reg, x, y ), 
		IM_IMAGE_SIZEOF_PEL( image ) );

	im_region_free( reg );

	return( 0 );
}
Example #5
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
Example #6
0
/* 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
Example #7
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 );
}
Example #8
0
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 );
}
Example #9
0
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;
}
Example #10
0
/* 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 );
}
Example #11
0
/* Convolution start function.
 */
static void *
aconvsep_start( IMAGE *out, void *a, void *b )
{
	IMAGE *in = (IMAGE *) a;
	Lines *lines = (Lines *) b;

	AConvSep *seq;

	if( !(seq = IM_NEW( out, AConvSep )) )
		return( NULL );

	/* Init!
	 */
	seq->lines = lines;
	seq->ir = im_region_create( in );
	seq->start = IM_ARRAY( out, lines->n_lines, int );
	seq->end = IM_ARRAY( out, lines->n_lines, int );
	if( vips_band_format_isint( out->BandFmt ) )
		seq->sum = IM_ARRAY( out, lines->n_lines, int );
	else
Example #12
0
/* Morph start function.
 */
static void *
morph_start( IMAGE *out, void *a, void *b )
{
	IMAGE *in = (IMAGE *) a;
	Morph *morph = (Morph *) b;
	int n_mask = morph->mask->xsize * morph->mask->ysize;
	int sz = IM_IMAGE_N_ELEMENTS( in );

	MorphSequence *seq;

	if( !(seq = IM_NEW( out, MorphSequence )) )
		return( NULL );

	/* Init!
	 */
	seq->morph = morph;
	seq->ir = NULL;
	seq->soff = NULL;
	seq->ss = 0;
	seq->coff = NULL;
	seq->cs = 0;
	seq->last_bpl = -1;
	seq->t1 = NULL;
	seq->t2 = NULL;

	/* Attach region and arrays.
	 */
	seq->ir = im_region_create( in );
	seq->soff = IM_ARRAY( out, n_mask, int );
	seq->coff = IM_ARRAY( out, n_mask, int );
	seq->t1 = IM_ARRAY( NULL, sz, VipsPel );
	seq->t2 = IM_ARRAY( NULL, sz, VipsPel );
	if( !seq->ir || !seq->soff || !seq->coff || !seq->t1 || !seq->t2  ) {
		morph_stop( seq, in, NULL );
		return( NULL );
	}

	return( seq );
}
Example #13
0
static void *
stretch_start( IMAGE *out, void *a, void *b )
{
	IMAGE *in = (IMAGE *) a;
	StretchInfo *sin = (StretchInfo *) b;
	SeqInfo *seq;

        if( !(seq = IM_NEW( out, SeqInfo )) )
		return( NULL );

        seq->sin = sin;
	seq->ir = im_region_create( in );
	seq->lsk = IM_IMAGE_N_ELEMENTS( out );
        seq->buf = IM_ARRAY( out, 4*seq->lsk, unsigned short );

        if( !seq->buf || !seq->ir ) {
		stretch_stop( seq, NULL, NULL );
        	return( NULL );
	}

	return( (void *)seq );
}
Example #14
0
/* Make a sequence value.
 */
static void *
shrink_start( IMAGE *out, void *a, void *b )
{
    IMAGE *in = (IMAGE *) a;
    ShrinkInfo *st = (ShrinkInfo *) b;
    SeqInfo *seq;

    if( !(seq = IM_NEW( out, SeqInfo )) )
        return( NULL );

    /* Init!
     */
    seq->ir = NULL;
    seq->off = NULL;
    seq->ir = im_region_create( in );
    seq->off = IM_ARRAY( out, st->np, int );
    if( !seq->off || !seq->ir ) {
        shrink_stop( seq, in, st );
        return( NULL );
    }

    return( (void *) seq );
}
Example #15
0
/* Attach a generate function to an image.
 */
int
im_generate( IMAGE *im,
	im_start_fn start, im_generate_fn generate, im_stop_fn stop,
        void *a, void *b )
{
        int res;
	REGION *or;
	im_threadgroup_t *tg;

	g_assert( !im_image_sanity( im ) );

	if( im->Xsize <= 0 || im->Ysize <= 0 || im->Bands <= 0 ) {
		im_error( "im_generate", _( "bad dimensions" ) );
		return( -1 );
	}
 
        /* Look at output type to decide our action.
         */
        switch( im->dtype ) {
        case IM_PARTIAL:
                /* Output to partial image. Just attach functions and return.
                 */
                if( im->generate || im->start || im->stop ) {
                        im_error( "im_generate", _( "func already attached" ) );
                        return( -1 );
                }

                im->start = start;
                im->generate = generate;
                im->stop = stop;
                im->client1 = a;
                im->client2 = b;
 
#ifdef DEBUG_IO
                printf( "im_generate: attaching partial callbacks\n" );
#endif /*DEBUG_IO*/
 
                break;
 
        case IM_SETBUF:
        case IM_SETBUF_FOREIGN:
        case IM_MMAPINRW:
        case IM_OPENOUT:
                /* Eval now .. sanity check.
                 */
                if( im->generate || im->start || im->stop ) {
                        im_error( "im_generate", _( "func already attached" ) );
                        return( -1 );
                }

                /* Get output ready.
                 */
                if( im_setupout( im ) )
                        return( -1 );

                /* Attach callbacks.
                 */
                im->start = start;
                im->generate = generate;
                im->stop = stop;
                im->client1 = a;
                im->client2 = b;

                /* Evaluate. Two output styles: to memory area (im_setbuf()
                 * or im_mmapinrw()) or to file (im_openout()).
                 */
		if( !(or = im_region_create( im )) )
			return( -1 );
		if( !(tg = im_threadgroup_create( im )) ) {
			im_region_free( or );
			return( -1 );
		}
                if( im->dtype == IM_OPENOUT )
                        res = im_wbuffer( tg, write_vips, NULL, NULL );
                else
                        res = eval_to_memory( tg, or );

                /* Clean up.
                 */
		im_threadgroup_free( tg );
		im_region_free( or );

                /* Error?
                 */
                if( res )
                        return( -1 );
 
                break;
 
        default:
                /* Not a known output style.
                 */
		im_error( "im_generate", _( "unable to output to a %s image" ),
			im_dtype2char( im->dtype ) );
                return( -1 );
        }
 
        return( 0 );
}