static int vips2csv( IMAGE *in, FILE *fp, const char *sep ) { int w = IM_IMAGE_N_ELEMENTS( in ); int es = IM_IMAGE_SIZEOF_ELEMENT( in ); int x, y; PEL *p; p = (PEL *) in->data; for( y = 0; y < in->Ysize; y++ ) { for( x = 0; x < w; x++ ) { if( x > 0 ) fprintf( fp, "%s", sep ); switch( in->BandFmt ) { case IM_BANDFMT_UCHAR: PRINT_INT( unsigned char ); break; case IM_BANDFMT_CHAR: PRINT_INT( char ); break; case IM_BANDFMT_USHORT: PRINT_INT( unsigned short ); break; case IM_BANDFMT_SHORT: PRINT_INT( short ); break; case IM_BANDFMT_UINT: PRINT_INT( unsigned int ); break; case IM_BANDFMT_INT: PRINT_INT( int ); break; case IM_BANDFMT_FLOAT: PRINT_FLOAT( float ); break; case IM_BANDFMT_DOUBLE: PRINT_FLOAT( double ); break; case IM_BANDFMT_COMPLEX: PRINT_COMPLEX( float ); break; case IM_BANDFMT_DPCOMPLEX: PRINT_COMPLEX( double ); break; default: assert( 0 ); } p += es; } fprintf( fp, "\n" ); } return( 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 ); }
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 ); }
/** * im_profile: * @in: input image * @out: output image * @dir: search direction * * im_profile() searches inward from the edge of @in and finds the * first non-zero pixel. It outputs an image containing a list of the offsets * for each row or column. * * If @dir == 0, then im_profile() searches down from the top edge, writing an * image as wide as the input image, but only 1 pixel high, containing the * number of pixels down to the first non-zero pixel for each column of input * pixels. * * If @dir == 1, then im_profile() searches across from the left edge, * writing an image as high as the input image, but only 1 pixel wide, * containing the number of pixels across to the * first non-zero pixel for each row of input pixels. * * See also: im_cntlines(). * * Returns: 0 on success, -1 on error */ int im_profile( IMAGE *in, IMAGE *out, int dir ) { int sz; unsigned short *buf; int x, y, b; /* 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, "im_profile", "p" )) || im_notequalconst( in, t, 0 ) ) return( -1 ); in = t; } /* Check im. */ if( im_iocheck( in, out ) || im_check_uncoded( "im_profile", in ) || im_check_format( "im_profile", in, IM_BANDFMT_UCHAR ) ) return( -1 ); if( dir != 0 && dir != 1 ) { im_error( "im_profile", "%s", _( "dir not 0 or 1" ) ); return( -1 ); } if( im_cp_desc( out, in ) ) return( -1 ); out->Type = IM_TYPE_HISTOGRAM; if( dir == 0 ) { out->Xsize = in->Xsize; out->Ysize = 1; } else { out->Xsize = 1; out->Ysize = in->Ysize; } out->BandFmt = IM_BANDFMT_USHORT; if( im_setupout( out ) ) return( -1 ); sz = IM_IMAGE_N_ELEMENTS( out ); if( !(buf = IM_ARRAY( out, sz, unsigned short )) ) return( -1 ); if( dir == 0 ) { /* Find vertical lines. */ for( x = 0; x < sz; x++ ) { PEL *p = (PEL *) IM_IMAGE_ADDR( in, 0, 0 ) + x; int lsk = IM_IMAGE_SIZEOF_LINE( in ); for( y = 0; y < in->Ysize; y++ ) { if( *p ) break; p += lsk; } buf[x] = y; } if( im_writeline( 0, out, (PEL *) buf ) ) return( -1 ); } else { /* Search horizontal lines. */ for( y = 0; y < in->Ysize; y++ ) { PEL *p = (PEL *) IM_IMAGE_ADDR( in, 0, y ); for( b = 0; b < in->Bands; b++ ) { PEL *p1; p1 = p + b; for( x = 0; x < in->Xsize; x++ ) { if( *p1 ) break; p1 += in->Bands; } buf[b] = x; } if( im_writeline( y, out, (PEL *) buf ) ) return( -1 ); } } return( 0 ); }