コード例 #1
0
ファイル: bandary.c プロジェクト: ChiaraCaiazza/collageMaker
static int
vips_bandary_build( VipsObject *object )
{
	VipsObjectClass *object_class = VIPS_OBJECT_GET_CLASS( object );
	VipsBandaryClass *class = VIPS_BANDARY_GET_CLASS( object ); 
	VipsConversion *conversion = VIPS_CONVERSION( object );
	VipsBandary *bandary = VIPS_BANDARY( object );

	int i;
	VipsImage **decode;
	VipsImage **format;
	VipsImage **size;

	if( VIPS_OBJECT_CLASS( vips_bandary_parent_class )->build( object ) )
		return( -1 );

	if( bandary->n <= 0 ) {
		vips_error( object_class->nickname, 
			"%s", _( "no input images" ) );
		return( -1 );
	}
	if( bandary->n > MAX_INPUT_IMAGES ) {
		vips_error( object_class->nickname, 
			"%s", _( "too many input images" ) );
		return( -1 );
	}

	decode = (VipsImage **) vips_object_local_array( object, bandary->n );
	format = (VipsImage **) vips_object_local_array( object, bandary->n );
	size = (VipsImage **) vips_object_local_array( object, bandary->n );

	for( i = 0; i < bandary->n; i++ )
		if( vips_image_decode( bandary->in[i], &decode[i] ) )
			return( -1 );
	if( vips__formatalike_vec( decode, format, bandary->n ) ||
		vips__sizealike_vec( format, size, bandary->n ) )
		return( -1 );
	bandary->ready = size;

	if( vips_image_pipeline_array( conversion->out, 
		VIPS_DEMAND_STYLE_THINSTRIP, bandary->ready ) )
		return( -1 );

	conversion->out->Bands = bandary->out_bands;
	if( class->format_table )
		conversion->out->BandFmt = 
			class->format_table[bandary->ready[0]->BandFmt];

	if( vips_image_generate( conversion->out,
		vips_start_many, vips_bandary_gen, vips_stop_many, 
		bandary->ready, bandary ) )
		return( -1 );

	return( 0 );
}
コード例 #2
0
ファイル: ifthenelse.c プロジェクト: nrobidoux/libvips
static int
vips_ifthenelse_build( VipsObject *object )
{
	VipsConversion *conversion = VIPS_CONVERSION( object );
	VipsIfthenelse *ifthenelse = (VipsIfthenelse *) object;

	VipsImage *all[3];
	VipsImage **band = (VipsImage **) vips_object_local_array( object, 3 );
	VipsImage **size = (VipsImage **) vips_object_local_array( object, 3 );
	VipsImage **format = 
		(VipsImage **) vips_object_local_array( object, 3 );

	if( VIPS_OBJECT_CLASS( vips_ifthenelse_parent_class )->build( object ) )
		return( -1 );

	/* We have to have the condition image last since we want the output
	 * image to inherit its properties from the then/else parts.
	 */
	all[0] = ifthenelse->in1;
	all[1] = ifthenelse->in2;
	all[2] = ifthenelse->cond;

	/* No need to check input images, sizealike and friends will do this
	 * for us.
	 */

	/* Cast our input images up to a common bands and size.
	 */
	if( vips__bandalike_vec( "VipsIfthenelse", all, band, 3, 0 ) ||
		vips__sizealike_vec( band, size, 3 ) )
		return( -1 );

	/* Condition is cast to uchar, then/else to a common type.
	 */
	if( vips_cast( size[2], &format[2], VIPS_FORMAT_UCHAR, NULL ) )
		return( -1 );
	if( vips__formatalike_vec( size, format, 2 ) ) 
		return( -1 ); 

	if( vips_image_copy_fields_array( conversion->out, format ) )
		return( -1 );
        vips_demand_hint_array( conversion->out, 
		VIPS_DEMAND_STYLE_SMALLTILE, format );

	if( vips_image_generate( conversion->out,
		vips_start_many, vips_ifthenelse_gen, vips_stop_many, 
		format, ifthenelse ) )
		return( -1 );

	return( 0 );
}
コード例 #3
0
ファイル: bandary.c プロジェクト: nrobidoux/libvips
static int
vips_bandary_build( VipsObject *object )
{
	VipsConversion *conversion = VIPS_CONVERSION( object );
	VipsBandary *bandary = (VipsBandary *) object;

	int i;
	VipsImage **format;
	VipsImage **size;

	if( VIPS_OBJECT_CLASS( vips_bandary_parent_class )->build( object ) )
		return( -1 );

	if( bandary->n <= 0 ) {
		vips_error( "VipsBandary", "%s", _( "no input images" ) );
		return( -1 );
	}
	if( bandary->n > MAX_INPUT_IMAGES ) {
		vips_error( "VipsBandary", "%s", _( "too many input images" ) );
		return( -1 );
	}
	if( vips_image_pio_output( conversion->out ) )
		return( -1 );
	for( i = 0; i < bandary->n; i++ )
		if( vips_image_pio_input( bandary->in[i] ) || 
			vips_check_uncoded( "VipsBandary", bandary->in[i] ) )
			return( -1 );

	format = (VipsImage **) vips_object_local_array( object, bandary->n );
	size = (VipsImage **) vips_object_local_array( object, bandary->n );
	if( vips__formatalike_vec( bandary->in, format, bandary->n ) ||
		vips__sizealike_vec( format, size, bandary->n ) )
		return( -1 );
	bandary->ready = size;

	if( vips_image_copy_fields_array( conversion->out, bandary->ready ) )
		return( -1 );
        vips_demand_hint_array( conversion->out, 
		VIPS_DEMAND_STYLE_THINSTRIP, bandary->ready );

	conversion->out->Bands = bandary->out_bands;

	if( vips_image_generate( conversion->out,
		vips_start_many, vips_bandary_gen, vips_stop_many, 
		bandary->ready, bandary ) )
		return( -1 );

	return( 0 );
}
コード例 #4
0
ファイル: vipspng.c プロジェクト: ChiaraCaiazza/collageMaker
static int
png2vips_image( Read *read, VipsImage *out )
{
	int interlace_type = png_get_interlace_type( read->pPng, read->pInfo );
	VipsImage **t = (VipsImage **) 
		vips_object_local_array( VIPS_OBJECT( out ), 3 );

	if( interlace_type != PNG_INTERLACE_NONE ) { 
		/* Arg awful interlaced image. We have to load to a huge mem 
		 * buffer, then copy to out.
		 */
		t[0] = vips_image_new_memory();
		if( png2vips_header( read, t[0] ) ||
			png2vips_interlace( read, t[0] ) ||
			vips_image_write( t[0], out ) )
			return( -1 );
	}
	else {
		t[0] = vips_image_new();
		if( png2vips_header( read, t[0] ) ||
			vips_image_generate( t[0], 
				NULL, png2vips_generate, NULL, 
				read, NULL ) ||
			vips_sequential( t[0], &t[1], 
				"tile_height", 8,
				"access", read->readbehind ? 
					VIPS_ACCESS_SEQUENTIAL : 
					VIPS_ACCESS_SEQUENTIAL_UNBUFFERED,
				NULL ) ||
			vips_image_write( t[1], out ) )
			return( -1 );
	}

	return( 0 );
}
コード例 #5
0
ファイル: ppm.c プロジェクト: FlavioFalcao/libvips
/* Read a ppm/pgm file using mmap().
 */
static int
read_mmap( FILE *fp, const char *filename, int msb_first, VipsImage *out )
{
	const guint64 header_offset = ftell( fp );
	VipsImage *x = vips_image_new();
	VipsImage **t = (VipsImage **) 
		vips_object_local_array( VIPS_OBJECT( x ), 3 );

	if( vips_rawload( filename, &t[0], 
			out->Xsize, out->Ysize, VIPS_IMAGE_SIZEOF_PEL( out ), 
			"offset", header_offset,
			NULL ) ||
		vips_copy( t[0], &t[1],
			"bands", out->Bands, 
			"format", out->BandFmt, 
			"coding", out->Coding, 
			NULL ) ||
		vips_copy( t[1], &t[2], 
			"swap", !vips_amiMSBfirst(), 
			NULL ) ||
		vips_image_write( t[2], out ) ) {
		g_object_unref( x );
		return( -1 );
	}
	g_object_unref( x );

	return( 0 );
}
コード例 #6
0
ファイル: insert.c プロジェクト: ImageKit/libvips
/* The inverse: take ink to a vec of double. Used in the vips7 compat
 * wrappers. Result valid while im is valid. 
 */
double *
vips__ink_to_vector( const char *domain, VipsImage *im, VipsPel *ink, int *n )
{
	VipsImage **t = (VipsImage **) 
		vips_object_local_array( VIPS_OBJECT( im ), 6 );

	double *result;

#ifdef VIPS_DEBUG
	printf( "vips__ink_to_vector: starting\n" );
#endif /*VIPS_DEBUG*/

	/* Wrap a VipsImage around ink.
	 */
	t[0] = vips_image_new_from_memory( ink, 
		1, 1, VIPS_IMAGE_SIZEOF_PEL( im ), VIPS_FORMAT_UCHAR );
	if( vips_copy( t[0], &t[1], 
		"bands", im->Bands, 
		"format", im->BandFmt, 
		"coding", im->Coding, 
		"interpretation", im->Type, 
		NULL ) )
		return( NULL ); 

	/* The image may be coded .. unpack to double.
	 */
	if( vips_image_decode( t[1], &t[2] ) ||
		vips_cast( t[2], &t[3], VIPS_FORMAT_DOUBLE, NULL ) )
		return( NULL );

	/* To a mem buffer, then copy to out. 
	 */
	if( !(t[4] = vips_image_new_memory()) ||
		vips_image_write( t[3], t[4] ) )
		return( NULL ); 

	if( !(result = VIPS_ARRAY( im, t[4]->Bands, double )) )
		return( NULL ); 
	memcpy( result, t[4]->data, VIPS_IMAGE_SIZEOF_PEL( t[4] ) ); 
	*n = t[4]->Bands; 

#ifdef VIPS_DEBUG
{
	int i;

	printf( "vips__ink_to_vector:\n" );
	printf( "\tink = " ); 
	for( i = 0; i < n; i++ )
		printf( "%d ", ink[i] );
	printf( "\n" ); 

	printf( "\tvec = " ); 
	for( i = 0; i < *n; i++ )
		printf( "%d ", result[i] );
	printf( "\n" ); 
}
#endif /*VIPS_DEBUG*/

	return( result ); 
}
コード例 #7
0
ファイル: webp2vips.c プロジェクト: allsmy/libvips
static int
read_image( Read *read, VipsImage *out )
{
	VipsImage **t = (VipsImage **) 
		vips_object_local_array( VIPS_OBJECT( out ), 3 );
	webp_decoder decoder;

	t[0] = vips_image_new_memory();
	if( read_header( read, t[0] ) )
		return( -1 );
	if( vips_image_write_prepare( t[0] ) ) 
		return( -1 );

	if( t[0]->Bands == 3 )
		decoder = WebPDecodeRGBInto;
	else
		decoder = WebPDecodeRGBAInto;

	if( !decoder( (uint8_t *) read->data, read->length, 
		VIPS_IMAGE_ADDR( t[0], 0, 0 ), 
		VIPS_IMAGE_SIZEOF_IMAGE( t[0] ),
		VIPS_IMAGE_SIZEOF_LINE( t[0] ) ) ) { 
		vips_error( "webp2vips", "%s", _( "unable to read pixels" ) ); 
		return( -1 );
	}

	if( vips_image_write( t[0], out ) )
		return( -1 );

	return( 0 );
}
コード例 #8
0
ファイル: jpeg2vips.c プロジェクト: Jondeen/libvips
/* Auto-rotate, if rotate_image is set.
 */
static VipsImage *
read_jpeg_rotate( VipsObject *process, VipsImage *im )
{
	VipsImage **t = (VipsImage **) vips_object_local_array( process, 2 );
	VipsAngle angle = vips_autorot_get_angle( im );

	if( angle != VIPS_ANGLE_D0 ) {
		/* Need to copy to memory or disc, we have to stay seq.
		 */
		const guint64 image_size = VIPS_IMAGE_SIZEOF_IMAGE( im );
		const guint64 disc_threshold = vips_get_disc_threshold();

		if( image_size > disc_threshold ) 
			t[0] = vips_image_new_temp_file( "%s.v" );
		else
			t[0] = vips_image_new_memory();

		if( vips_image_write( im, t[0] ) ||
			vips_rot( t[0], &t[1], angle, NULL ) )
			return( NULL );
		im = t[1];
		(void) vips_image_remove( im, ORIENTATION );
	}

	return( im );
}
コード例 #9
0
ファイル: similarity.c プロジェクト: chinmayAtGit/libvips
static int
vips_similarity_build( VipsObject *object )
{
	VipsResample *resample = VIPS_RESAMPLE( object );
	VipsSimilarity *similarity = (VipsSimilarity *) object;

	VipsImage **t = (VipsImage **) 
		vips_object_local_array( object, 4 );

	double a, b, c, d; 

	if( VIPS_OBJECT_CLASS( vips_similarity_parent_class )->build( object ) )
		return( -1 );

	a = similarity->scale * cos( VIPS_RAD( similarity->angle ) ); 
	b = sin( VIPS_RAD( similarity->angle ) );
	c = -b;
	d = a;

	if( vips_affine( resample->in, &t[0], a, b, c, d, 
		"interpolate", similarity->interpolate,
		"odx", similarity->odx,
		"ody", similarity->ody,
		"idx", similarity->idx,
		"idy", similarity->idy,
		NULL ) ||
		vips_image_write( t[0], resample->out ) )
		return( -1 ); 

	return( 0 );
}
コード例 #10
0
ファイル: webp2vips.c プロジェクト: gargsms/libvips
static int
read_image( Read *read, VipsImage *out )
{
	VipsImage **t = (VipsImage **) 
		vips_object_local_array( VIPS_OBJECT( out ), 3 );

	t[0] = vips_image_new_memory();
	if( read_header( read, t[0] ) )
		return( -1 );
	if( vips_image_write_prepare( t[0] ) ) 
		return( -1 );

	read->config.output.u.RGBA.rgba = VIPS_IMAGE_ADDR( t[0], 0, 0 );
	read->config.output.u.RGBA.stride = VIPS_IMAGE_SIZEOF_LINE( t[0] );
	read->config.output.u.RGBA.size = VIPS_IMAGE_SIZEOF_IMAGE( t[0] );
	read->config.output.is_external_memory = 1;

	if( WebPDecode( (uint8_t *) read->data, read->length, 
		&read->config) != VP8_STATUS_OK ) {
		vips_error( "webp2vips", "%s", _( "unable to read pixels" ) ); 
		return( -1 );
	}

	if( vips_image_write( t[0], out ) )
		return( -1 );

	return( 0 );
}
コード例 #11
0
ファイル: webp2vips.c プロジェクト: binarytemple/debian-vips
static int
read_image( Read *read, VipsImage *out )
{
	VipsImage **t = (VipsImage **) 
		vips_object_local_array( VIPS_OBJECT( out ), 3 );
	guint64 length;
	void *data; 
	int fd;
	webp_decoder decoder;

	/* libwebp makes streaming very hard. We have to read to a full memory
	 * buffer, then copy to out.
	 *
	 * mmap the input file, it's slightly quicker.
	 */
	t[0] = vips_image_new_buffer();
	if( read_header( read, t[0] ) )
		return( -1 );
	if( vips_image_write_prepare( t[0] ) ) 
		return( -1 );

	if( !(fd = vips__open_image_read( read->filename )) )
		return( -1 );
	if( (length = vips_file_length( fd )) < 0 ) {
		vips_tracked_close( fd ); 
		return( -1 );
	}
	if( !(data = vips__mmap( fd, FALSE, length, 0 )) ) {
		vips_tracked_close( fd ); 
		return( -1 );
	}

	if( t[0]->Bands == 3 )
		decoder = WebPDecodeRGBInto;
	else
		decoder = WebPDecodeRGBAInto;

	if( !decoder( (uint8_t *) data, length, 
		VIPS_IMAGE_ADDR( t[0], 0, 0 ), 
		VIPS_IMAGE_SIZEOF_IMAGE( t[0] ),
		VIPS_IMAGE_SIZEOF_LINE( t[0] ) ) ) { 
		vips__munmap( data, length ); 
		vips_tracked_close( fd ); 
		vips_error( "webp2vips", "%s", _( "unable to read pixels" ) ); 
		return( -1 );
	}

	vips__munmap( data, length ); 
	vips_tracked_close( fd ); 

	if( vips_image_write( t[0], out ) )
		return( -1 );

	return( 0 );
}
コード例 #12
0
ファイル: scale.c プロジェクト: ChiaraCaiazza/collageMaker
static int
vips_scale_build( VipsObject *object )
{
	VipsConversion *conversion = VIPS_CONVERSION( object );
	VipsScale *scale = (VipsScale *) object;
	VipsImage **t = (VipsImage **) vips_object_local_array( object, 7 );

	double mx;
	double mn;

	if( VIPS_OBJECT_CLASS( vips_scale_parent_class )->build( object ) )
		return( -1 );

	if( vips_stats( scale->in, &t[0], NULL ) )
		return( -1 );
	mn = *VIPS_MATRIX( t[0], 0, 0 );
	mx = *VIPS_MATRIX( t[0], 1, 0 );

	if( mn == mx ) {
		/* Range of zero: just return black.
		 */
		if( vips_black( &t[1], scale->in->Xsize, scale->in->Ysize, 
			"bands", scale->in->Bands,
			NULL ) ||
			vips_image_write( t[1], conversion->out ) )
			return( -1 );
	}
	else if( scale->log ) { 
		double f = 255.0 / log10( 1.0 + pow( mx, scale->exp ) );

		if( vips_pow_const1( scale->in, &t[2], scale->exp, NULL ) ||
			vips_linear1( t[2], &t[3], 1.0, 1.0, NULL ) ||
			vips_log10( t[3], &t[4], NULL ) ||
			vips_linear1( t[4], &t[5], f, 0.0, 
				"uchar", TRUE, 
				NULL ) ||
			vips_image_write( t[5], conversion->out ) )
			return( -1 );
	}
	else {
		double f = 255.0 / (mx - mn);

		/* Add .5 to get round-to-nearest.
		 */
		double a = -(mn * f) + 0.5;

		if( vips_linear1( scale->in, &t[2], f, a, 
			"uchar", TRUE, 
			NULL ) ||
			vips_image_write( t[2], conversion->out ) )
			return( -1 );
	}

	return( 0 );
}
コード例 #13
0
ファイル: fits.c プロジェクト: FlavioFalcao/libvips
int
vips__fits_read( const char *filename, VipsImage *out )
{
	VipsImage *t;
	int n_bands;

	VIPS_DEBUG_MSG( "fits2vips: reading \"%s\"\n", filename );

	/* fits is naturally a band-separated format. For single-band images
	 * we can just read out. For many bands we read each band out
	 * separately then join them.
	 */

	t = vips_image_new();
	if( vips__fits_read_header( filename, t ) ) {
		g_object_unref( t );
		return( -1 );
	}
	n_bands = t->Bands;
	g_object_unref( t );

	if( n_bands == 1 ) {
		if( fits2vips( filename, out, 0 ) )
			return( -1 );
	}
	else {
		VipsImage **x;
		int i;

		t = vips_image_new();
		x = (VipsImage **) vips_object_local_array( VIPS_OBJECT( t ), 
			n_bands + 1 );

		for( i = 0; i < n_bands; i++ ) {
			x[i] = vips_image_new();
			if( fits2vips( filename, x[i], i ) ) {
				g_object_unref( t );
				return( -1 );
			}
		}

		if( vips_bandjoin( x, &x[n_bands], n_bands, NULL ) ||
			vips_image_write( x[n_bands], out ) ) {
			g_object_unref( t );
			return( -1 );
		}

		g_object_unref( t );
	}

	return( 0 );
}
コード例 #14
0
ファイル: labelregions.c プロジェクト: DINKIN/libvips
static int
vips_labelregions_build( VipsObject *object )
{
	VipsMorphology *morphology = VIPS_MORPHOLOGY( object );
	VipsImage *in = morphology->in;
	VipsImage **t = (VipsImage **) vips_object_local_array( object, 2 );
	VipsImage *mask;

	int segments;
	int *m;
	int x, y;

	if( VIPS_OBJECT_CLASS( vips_labelregions_parent_class )->
		build( object ) )
		return( -1 );

	/* Create the zero mask image in memory.
	 */
	mask = vips_image_new_memory();
	g_object_set( object,
		"mask", mask,
		NULL ); 
	if( vips_black( &t[0], in->Xsize, in->Ysize, NULL ) ||
		vips_cast( t[0], &t[1], VIPS_FORMAT_INT, NULL ) || 
		vips_image_write( t[1], mask ) )
		return( -1 );

	segments = 1;
	m = (int *) mask->data;
	for( y = 0; y < mask->Ysize; y++ ) {
		for( x = 0; x < mask->Xsize; x++ ) {
			if( !m[x] ) {
				/* Use a direct path for speed.
				 */
				if( vips__draw_flood_direct( mask, in, 
					segments, x, y ) )
					return( -1 ); 

				segments += 1;
			}
		}

		m += mask->Xsize;
	}

	g_object_set( object,
		"segments", segments,
		NULL ); 

	return( 0 );
}
コード例 #15
0
ファイル: similarity.c プロジェクト: everbox/libvips
static int
vips_similarity_build( VipsObject *object )
{
	VipsResample *resample = VIPS_RESAMPLE( object );
	VipsSimilarity *similarity = (VipsSimilarity *) object;

	VipsImage **t = (VipsImage **) 
		vips_object_local_array( object, 4 );

	if( VIPS_OBJECT_CLASS( vips_similarity_parent_class )->build( object ) )
		return( -1 );

	/* Use vips_reduce(), if we can.
	 */
	if( similarity->interpolate && 
		strcmp( VIPS_OBJECT_GET_CLASS( similarity->interpolate )->
			nickname, "bicubic" ) == 0 &&
		similarity->angle == 0.0 &&
		similarity->idx == 0.0 &&
		similarity->idy == 0.0 &&
		similarity->odx == 0.0 &&
		similarity->ody == 0.0 ) {
		if( vips_reduce( resample->in, &t[0], 
			1.0 / similarity->scale, 
			1.0 / similarity->scale, NULL ) )  
			return( -1 );
	}
	else {
		double a = similarity->scale * 
			cos( VIPS_RAD( similarity->angle ) ); 
		double b = similarity->scale * 
			-sin( VIPS_RAD( similarity->angle ) );
		double c = -b;
		double d = a;

		if( vips_affine( resample->in, &t[0], a, b, c, d, 
			"interpolate", similarity->interpolate,
			"odx", similarity->odx,
			"ody", similarity->ody,
			"idx", similarity->idx,
			"idy", similarity->idy,
			NULL ) )
			return( -1 );
	}

	if( vips_image_write( t[0], resample->out ) )
		return( -1 ); 

	return( 0 );
}
コード例 #16
0
ファイル: smartcrop.c プロジェクト: jcupitt/libvips
static int
vips_smartcrop_score( VipsSmartcrop *smartcrop, VipsImage *in, 
	int left, int top, int width, int height, double *score )
{
	VipsImage **t = (VipsImage **) 
		vips_object_local_array( VIPS_OBJECT( smartcrop ), 2 );

	if( vips_extract_area( in, &t[0], left, top, width, height, NULL ) ||
		vips_hist_find( t[0], &t[1], NULL ) ||
		vips_hist_entropy( t[1], score, NULL ) )
		return( -1 );

	return( 0 );
}
コード例 #17
0
ファイル: fitsload.c プロジェクト: jcupitt/libvips
static int
vips_foreign_load_fits_load( VipsForeignLoad *load )
{
	VipsForeignLoadFits *fits = (VipsForeignLoadFits *) load;
	VipsImage **t = (VipsImage **) 
		vips_object_local_array( VIPS_OBJECT( fits ), 2 );

	t[0] = vips_image_new();
	if( vips__fits_read( fits->filename, t[0] ) || 
		vips_flip( t[0], &t[1], VIPS_DIRECTION_VERTICAL, NULL ) ||
		vips_image_write( t[1], load->real ) )
		return( -1 );

	return( 0 );
}
コード例 #18
0
ファイル: vipsthumbnail.c プロジェクト: HunterChen/libvips
/* Auto-rotate, if rotate_image is set. 
 */
static VipsImage *
thumbnail_rotate( VipsObject *process, VipsImage *im )
{
	VipsImage **t = (VipsImage **) vips_object_local_array( process, 1 );

	if( rotate_image ) {
		if( vips_rot( im, &t[0], get_angle( im ), NULL ) )
			return( NULL ); 
		im = t[0];

		(void) vips_image_remove( im, ORIENTATION );
	}

	return( im );
}
コード例 #19
0
ファイル: shrink.c プロジェクト: Fasjul/libvips
static int
vips_shrink_build( VipsObject *object )
{
	VipsResample *resample = VIPS_RESAMPLE( object );
	VipsShrink *shrink = (VipsShrink *) object;
	VipsImage **t = (VipsImage **) 
		vips_object_local_array( object, 3 );

	int xshrink_int;
	int yshrink_int;

	if( VIPS_OBJECT_CLASS( vips_shrink_parent_class )->build( object ) )
		return( -1 );

	xshrink_int = (int) shrink->xshrink;
	yshrink_int = (int) shrink->yshrink;

	if( xshrink_int != shrink->xshrink || 
		yshrink_int != shrink->yshrink ) {
		/* Shrink by int factors, affine to final size.
		 */
		int target_width = resample->in->Xsize / shrink->xshrink;
		int target_height = resample->in->Ysize / shrink->yshrink;

		double xresidual;
		double yresidual;

		if( vips_shrinkv( resample->in, &t[0], yshrink_int, NULL ) ||
			vips_shrinkh( t[0], &t[1], xshrink_int, NULL ) )
			return( -1 ); 

		xresidual = (double) target_width / t[1]->Xsize;
		yresidual = (double) target_height / t[1]->Ysize;

		if( vips_affine( t[1], &t[2], 
			xresidual, 0.0, 0.0, yresidual, NULL ) ||
			vips_image_write( t[2], resample->out ) )
			return( -1 );
	}
	else {
		if( vips_shrinkv( resample->in, &t[0], shrink->yshrink, NULL ) ||
			vips_shrinkh( t[0], &t[1], shrink->xshrink, NULL ) ||
			vips_image_write( t[1], resample->out ) )
			return( -1 );
	}

	return( 0 );
}
コード例 #20
0
ファイル: freqmult.c プロジェクト: ChiaraCaiazza/collageMaker
static int
vips_freqmult_build( VipsObject *object )
{
	VipsFreqfilt *freqfilt = VIPS_FREQFILT( object );
	VipsFreqmult *freqmult = (VipsFreqmult *) object;
	VipsImage **t = (VipsImage **) vips_object_local_array( object, 5 );

	VipsImage *in;

	if( VIPS_OBJECT_CLASS( vips_freqmult_parent_class )->
		build( object ) )
		return( -1 );

	in = freqfilt->in;

	if( vips_band_format_iscomplex( in->BandFmt ) ) {
		if( vips_multiply( in, freqmult->mask, &t[0], NULL ) ||
			vips_invfft( t[0], &t[1], "real", TRUE, NULL ) ) 
			return( -1 );

		in = t[1];
	}
	else {
		/* Optimisation: output of vips_invfft() is double, we 
		 * will usually cast to char, so rather than keeping a
		 * large double buffer and partial to char from that, 
		 * cast to a memory buffer and copy to out from that.
		 *
		 * FIXME does this actually work now we're a class? test
		 * perhaps we need a temporary object
		 */
		t[4] = vips_image_new_memory();

		if( vips_fwfft( in, &t[0], NULL ) ||
			vips_multiply( t[0], freqmult->mask, &t[1], NULL ) ||
			vips_invfft( t[1], &t[2], "real", TRUE, NULL ) ||
			vips_cast( t[2], &t[3], in->BandFmt, NULL ) ||
			vips_image_write( t[3], t[4] ) )
			return( -1 );

		in = t[4]; 
	}

	if( vips_image_write( in, freqfilt->out ) )
		return( -1 );

	return( 0 );
}
コード例 #21
0
ファイル: recomb.c プロジェクト: nrobidoux/libvips
static int
vips_recomb_build( VipsObject *object )
{
	VipsConversion *conversion = (VipsConversion *) object;
	VipsRecomb *recomb = (VipsRecomb *) object;
	VipsImage **t = (VipsImage **) vips_object_local_array( object, 2 );

	if( VIPS_OBJECT_CLASS( vips_recomb_parent_class )->build( object ) )
		return( -1 );

	if( vips_image_pio_input( recomb->in ) || 
		vips_check_uncoded( "VipsRecomb", recomb->in ) ||
		vips_check_noncomplex( "VipsRecomb", recomb->in ) )
		return( -1 );
	if( vips_image_pio_input( recomb->m ) || 
		vips_check_uncoded( "VipsRecomb", recomb->m ) ||
		vips_check_noncomplex( "VipsRecomb", recomb->m ) ||
		vips_check_mono( "VipsRecomb", recomb->m ) )
		return( -1 );
	if( recomb->in->Bands != recomb->m->Xsize ) {
		vips_error( "VipsRecomb", 
			"%s", _( "bands in must equal matrix width" ) );
		return( -1 );
	}

	if( vips_cast( recomb->m, &t[0], VIPS_FORMAT_DOUBLE, NULL ) ||
		vips_image_wio_input( t[0] ) )
		return( -1 );
	recomb->coeff = (double *) VIPS_IMAGE_ADDR( t[0], 0, 0 );

	if( vips_image_copy_fields( conversion->out, recomb->in ) )
		return( -1 );
        vips_demand_hint( conversion->out, 
		VIPS_DEMAND_STYLE_THINSTRIP, recomb->in, NULL );

	conversion->out->Bands = recomb->m->Ysize;
	if( vips_bandfmt_isint( recomb->in->BandFmt ) ) 
		conversion->out->BandFmt = VIPS_FORMAT_FLOAT;

	if( vips_image_generate( conversion->out,
		vips_start_one, vips_recomb_gen, vips_stop_one, 
		recomb->in, recomb ) )
		return( -1 );

	return( 0 );
}
コード例 #22
0
ファイル: vipsthumbnail.c プロジェクト: HunterChen/libvips
/* Crop down to the final size, if crop_image is set. 
 */
static VipsImage *
thumbnail_crop( VipsObject *process, VipsImage *im )
{
	VipsImage **t = (VipsImage **) vips_object_local_array( process, 2 );

	if( crop_image ) {
		int left = (im->Xsize - thumbnail_width) / 2;
		int top = (im->Ysize - thumbnail_height) / 2;

		if( vips_extract_area( im, &t[0], left, top, 
			thumbnail_width, thumbnail_height, NULL ) )
			return( NULL ); 
		im = t[0];
	}

	return( im );
}
コード例 #23
0
ファイル: unary.c プロジェクト: ChiaraCaiazza/collageMaker
static int
vips_unary_build( VipsObject *object )
{
	VipsArithmetic *arithmetic = VIPS_ARITHMETIC( object );
	VipsUnary *unary = VIPS_UNARY( object );

	arithmetic->n = 1;
	arithmetic->in = (VipsImage **) vips_object_local_array( object, 1 );
	arithmetic->in[0] = unary->in;
	if( arithmetic->in[0] )
		g_object_ref( arithmetic->in[0] );

	if( VIPS_OBJECT_CLASS( vips_unary_parent_class )->build( object ) )
		return( -1 );

	return( 0 );
}
コード例 #24
0
ファイル: jpeg2vips.c プロジェクト: Jondeen/libvips
/* Read a cinfo to a VIPS image.
 */
static int
read_jpeg_image( ReadJpeg *jpeg, VipsImage *out )
{
	struct jpeg_decompress_struct *cinfo = &jpeg->cinfo;
	VipsImage **t = (VipsImage **) 
		vips_object_local_array( VIPS_OBJECT( out ), 3 );

	VipsImage *im;

	/* Here for longjmp() from vips__new_error_exit().
	 */
	if( setjmp( jpeg->eman.jmp ) ) 
		return( -1 );

	t[0] = vips_image_new();
	if( read_jpeg_header( jpeg, t[0] ) )
		return( -1 );

	jpeg_start_decompress( cinfo );

#ifdef DEBUG
	printf( "read_jpeg_image: starting decompress\n" );
#endif /*DEBUG*/

	if( vips_image_generate( t[0], 
		NULL, read_jpeg_generate, NULL, 
		jpeg, NULL ) ||
		vips_sequential( t[0], &t[1], 
			"tile_height", 8,
			"access", jpeg->readbehind ? 
				VIPS_ACCESS_SEQUENTIAL : 
				VIPS_ACCESS_SEQUENTIAL_UNBUFFERED,
			NULL ) )
		return( -1 );

	im = t[1];
	if( jpeg->autorotate )
		im = read_jpeg_rotate( VIPS_OBJECT( out ), im );

	if( vips_image_write( im, out ) )
		return( -1 );

	return( 0 );
}
コード例 #25
0
ファイル: point.c プロジェクト: jcupitt/libvips
static int
vips_point_build( VipsObject *object )
{
	VipsCreate *create = VIPS_CREATE( object );
	VipsPoint *point = VIPS_POINT( object );
	VipsPointClass *class = VIPS_POINT_GET_CLASS( point );
	VipsImage **t = (VipsImage **) vips_object_local_array( object, 4 );

	VipsImage *in;

	if( VIPS_OBJECT_CLASS( vips_point_parent_class )->build( object ) )
		return( -1 );

	t[0] = vips_image_new();
	vips_image_init_fields( t[0],
		point->width, point->height, 1,
		VIPS_FORMAT_FLOAT, VIPS_CODING_NONE, class->interpretation,
		1.0, 1.0 );
	vips_image_pipelinev( t[0], 
		VIPS_DEMAND_STYLE_ANY, NULL );
	if( vips_image_generate( t[0], 
		NULL, vips_point_gen, NULL, point, NULL ) )
		return( -1 );
	in = t[0];

	if( point->uchar ) {
		float min = class->min;
		float max = class->max;
		float range = max - min;

		if( vips_linear1( in, &t[2], 
			255.0 / range, -min * 255.0 / range, 
			"uchar", TRUE,
			NULL ) )
			return( -1 );
		in = t[2];

		/* We don't want FOURIER or whatever in this case.
		 */
		in->Type = VIPS_INTERPRETATION_MULTIBAND;
	}
コード例 #26
0
ファイル: binary.c プロジェクト: ChiaraCaiazza/collageMaker
static int
vips_binary_build( VipsObject *object )
{
	VipsArithmetic *arithmetic = VIPS_ARITHMETIC( object );
	VipsBinary *binary = VIPS_BINARY( object );

	arithmetic->n = 2;
	arithmetic->in = (VipsImage **) vips_object_local_array( object, 2 );
	arithmetic->in[0] = binary->left;
	arithmetic->in[1] = binary->right;

	if( arithmetic->in[0] )
		g_object_ref( arithmetic->in[0] );
	if( arithmetic->in[1] )
		g_object_ref( arithmetic->in[1] );

	if( VIPS_OBJECT_CLASS( vips_binary_parent_class )->build( object ) )
		return( -1 );

	return( 0 );
}
コード例 #27
0
int 
main( int argc, char **argv )
{
        VipsImage *global;
        VipsImage **t;

        if( VIPS_INIT( argv[0] ) )
                return( -1 );

        global = vips_image_new();
        t = (VipsImage **) vips_object_local_array( VIPS_OBJECT( global ), 5 );

	VipsInterpolate *interp = vips_interpolate_new( "bilinear" );

        if( !(t[0] = vips_image_new_from_file( argv[1],
                "access", VIPS_ACCESS_SEQUENTIAL,
                NULL )) )
                vips_error_exit( NULL );

        t[1] = vips_image_new_matrixv( 3, 3, 
                -1.0, -1.0, -1.0, 
                -1.0, 16.0, -1.0,
                -1.0, -1.0, -1.0 );
        vips_image_set_double( t[1], "scale", 8 );

        if( vips_extract_area( t[0], &t[2], 
                100, 100, t[0]->Xsize - 200, t[0]->Ysize - 200, NULL ) ||
                vips_similarity( t[2], &t[3], 
			"scale", 0.9, 
			"interpolate", interp, 
			NULL ) ||
                vips_conv( t[3], &t[4], t[1], NULL ) ||
                vips_image_write_to_file( t[4], argv[2], NULL ) )
                vips_error_exit( NULL ); 

        g_object_unref( global );
        g_object_unref( interp );

        return( 0 );
}
コード例 #28
0
ファイル: statistic.c プロジェクト: FlavioFalcao/libvips
static int
vips_statistic_build( VipsObject *object )
{
	VipsStatistic *statistic = VIPS_STATISTIC( object );
	VipsStatisticClass *sclass = VIPS_STATISTIC_GET_CLASS( statistic );
	VipsImage **t = (VipsImage **) vips_object_local_array( object, 2 );

#ifdef DEBUG
	printf( "vips_statistic_build: " );
	vips_object_print_name( object );
	printf( "\n" );
#endif /*DEBUG*/

	if( VIPS_OBJECT_CLASS( vips_statistic_parent_class )->build( object ) )
		return( -1 );

	statistic->ready = statistic->in;

	if( vips_image_decode( statistic->ready, &t[0] ) )
		return( -1 );
	statistic->ready = t[0];

	/* If there's a format table, cast the input.
	 */
	if( sclass->format_table ) {
		if( vips_cast( statistic->ready, &t[1], 
			sclass->format_table[statistic->in->BandFmt], NULL ) )
			return( -1 );
		statistic->ready = t[1];
	}

	if( vips_sink( statistic->ready, 
		vips_statistic_scan_start, 
		vips_statistic_scan, 
		vips_statistic_scan_stop, 
		statistic, NULL ) )
		return( -1 );

	return( 0 );
}
コード例 #29
0
ファイル: smartcrop.c プロジェクト: jcupitt/libvips
/* Calculate sqrt(b1^2 + b2^2 ...)
 */
static int
pythagoras( VipsSmartcrop *smartcrop, VipsImage *in, VipsImage **out )
{
	VipsImage **t = (VipsImage **) 
		vips_object_local_array( VIPS_OBJECT( smartcrop ), 
			2 * in->Bands + 1 );

	int i;

	for( i = 0; i < in->Bands; i++ ) 
		if( vips_extract_band( in, &t[i], i, NULL ) )
			return( -1 );

	for( i = 0; i < in->Bands; i++ ) 
		if( vips_multiply( t[i], t[i], &t[i + in->Bands], NULL ) )
			return( -1 );

	if( vips_sum( &t[in->Bands], &t[2 * in->Bands], in->Bands, NULL ) ||
		vips_pow_const1( t[2 * in->Bands], out, 0.5, NULL ) )
		return( -1 );

	return( 0 );
}
コード例 #30
0
ファイル: jpeg2vips.c プロジェクト: jieah/libvips
/* Read a cinfo to a VIPS image.
 */
static int
read_jpeg_image( ReadJpeg *jpeg, VipsImage *out )
{
    struct jpeg_decompress_struct *cinfo = &jpeg->cinfo;
    VipsImage **t = (VipsImage **)
                    vips_object_local_array( VIPS_OBJECT( out ), 3 );

    /* Here for longjmp() from vips__new_error_exit().
     */
    if( setjmp( jpeg->eman.jmp ) )
        return( -1 );

    t[0] = vips_image_new();
    if( read_jpeg_header( jpeg, t[0] ) )
        return( -1 );

    /* Set decompressing to make readjpeg_free() call
     * jpeg_stop_decompress().
     */
    jpeg_start_decompress( cinfo );
    jpeg->decompressing = TRUE;

#ifdef DEBUG
    printf( "read_jpeg_image: starting decompress\n" );
#endif /*DEBUG*/

    if( vips_image_generate( t[0],
                             NULL, read_jpeg_generate, NULL,
                             jpeg, NULL ) ||
            vips_sequential( t[0], &t[1],
                             "tile_height", 8,
                             NULL ) ||
            vips_image_write( t[1], out ) )
        return( -1 );

    return( 0 );
}