Esempio n. 1
0
/**
 * im_fits2vips:
 * @filename: file to load
 * @out: image to write to
 *
 * Read a FITS image file into a VIPS image. 
 *
 * See also: im_vips2fits(), #VipsFormat.
 *
 * Returns: 0 on success, -1 on error.
 */
int
im_fits2vips( const char *filename, VipsImage *out )
{
	VipsImage *t;
	int n_bands;

	VIPS_DEBUG_MSG( "im_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.
	 */

	if( !(t = vips_image_new()) ||
		vips_object_local( out, t ) ||
		fits2vips_header( filename, t ) )
		return( -1 );
	n_bands = t->Bands;

	if( n_bands == 1 ) {
		if( !(t = vips_image_new()) ||
			vips_object_local( out, t ) ||
			fits2vips( filename, t, 0 ) )
			return( -1 );
	}
	else {
		VipsImage *acc;
		int i;

		acc = NULL;
		for( i = 0; i < n_bands; i++ ) {
			if( !(t = vips_image_new()) ||
				vips_object_local( out, t ) ||
				fits2vips( filename, t, i ) )
				return( -1 );

			if( !acc )
				acc = t;
			else {
				VipsImage *t2;

				if( !(t2 = vips_image_new()) ||
					vips_object_local( out, t2 ) ||
					im_bandjoin( acc, t, t2 ) )
					return( -1 );
				acc = t2;
			}
		}

		t = acc;
	}

	/* fits has inverted y.
	 */
	if( im_flipver( t, out ) )
		return( -1 );

	return( 0 );
}
Esempio n. 2
0
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 );
}
Esempio n. 3
0
/* 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 );
}
Esempio n. 4
0
static int
vips_merge_build( VipsObject *object )
{
	VipsMerge *merge = (VipsMerge *) object;

	g_object_set( merge, "out", vips_image_new(), NULL ); 

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

	switch( merge->direction ) { 
	case VIPS_DIRECTION_HORIZONTAL:
		if( im_lrmerge( merge->ref, merge->sec, merge->out, 
			merge->dx, merge->dy, merge->mblend ) )
			return( -1 ); 
		break;

	case VIPS_DIRECTION_VERTICAL:
		if( im_tbmerge( merge->ref, merge->sec, merge->out, 
			merge->dx, merge->dy, merge->mblend ) )
			return( -1 ); 
		break;

	default:
		g_assert( 0 );
	}

	return( 0 );
}
Esempio n. 5
0
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 );
}
Esempio n. 6
0
int
main( int argc, char **argv )
{
	GOptionContext *context;
	GError *error = NULL;
	int i;

	if( vips_init( argv[0] ) )
	        vips_error_exit( "unable to start VIPS" );
	textdomain( GETTEXT_PACKAGE );
	setlocale( LC_ALL, "" );

        context = g_option_context_new( _( "- thumbnail generator" ) );

	g_option_context_add_main_entries( context, options, GETTEXT_PACKAGE );
	g_option_context_add_group( context, vips_get_option_group() );

	if( !g_option_context_parse( context, &argc, &argv, &error ) ) {
		if( error ) {
			fprintf( stderr, "%s\n", error->message );
			g_error_free( error );
		}

		vips_error_exit( "try \"%s --help\"", g_get_prgname() );
	}

	g_option_context_free( context );

	if( sscanf( thumbnail_size, "%d x %d", 
		&thumbnail_width, &thumbnail_height ) != 2 ) {
		if( sscanf( thumbnail_size, "%d", &thumbnail_width ) != 1 ) 
			vips_error_exit( "unable to parse size \"%s\" -- "
				"use eg. 128 or 200x300", thumbnail_size );

		thumbnail_height = thumbnail_width;
	}

	for( i = 1; i < argc; i++ ) {
		/* Hang resources for processing this thumbnail off @process.
		 */
		VipsObject *process = VIPS_OBJECT( vips_image_new() ); 

		if( thumbnail_process( process, argv[i] ) ) {
			fprintf( stderr, "%s: unable to thumbnail %s\n", 
				argv[0], argv[i] );
			fprintf( stderr, "%s", vips_error_buffer() );
			vips_error_clear();
		}

		g_object_unref( process );
	}

	vips_shutdown();

	return( 0 );
}
Esempio n. 7
0
/* edvips.c needs this
 */
VipsImage *
im_init( const char *filename )
{
	VipsImage *image;

	image = vips_image_new();
	IM_SETSTR( image->filename, filename );

	return( image );
}
Esempio n. 8
0
static gboolean
ismagick( const char *filename )
{
	VipsImage *t;
	int result;

	t = vips_image_new();
	vips_error_freeze();
	result = vips__magick_read_header( filename, t, FALSE );
	g_object_unref( t );
	vips_error_thaw();

	return( result == 0 );
}
Esempio n. 9
0
static gboolean
ismagick( const char *filename )
{
	VipsImage *t;

	t = vips_image_new();
	if( vips__magick_read_header( filename, t ) ) {
		g_object_unref( t );
		return( FALSE );
	}
	g_object_unref( t );

	return( TRUE );
}
Esempio n. 10
0
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 );
}
Esempio n. 11
0
/* Interlaced PNGs need to be entirely decompressed into memory then can be
 * served partially from there. Non-interlaced PNGs may be read sequentially.
 */
gboolean
vips__png_isinterlaced( const char *filename )
{
	VipsImage *image;
	Read *read;
	int interlace_type;

	image = vips_image_new();
	if( !(read = read_new_filename( image, filename, FALSE )) ) {
		g_object_unref( image );
		return( -1 );
	}
	interlace_type = png_get_interlace_type( read->pPng, read->pInfo );
	g_object_unref( image );

	return( interlace_type != PNG_INTERLACE_NONE );
}
Esempio n. 12
0
/* Walk the pyramid allocating resources. 
 */
static int
pyramid_fill( Write *write )
{
	Layer *layer;

	for( layer = write->layer; layer; layer = layer->below ) {
		VipsRect strip_size;

		layer->image = vips_image_new();
		if( vips_image_pipelinev( layer->image, 
			VIPS_DEMAND_STYLE_ANY, write->im, NULL ) ) 
			return( -1 );
		layer->image->Xsize = layer->width;
		layer->image->Ysize = layer->height;

		layer->strip = vips_region_new( layer->image );
		layer->copy = vips_region_new( layer->image );

		/* The regions will get used in the bg thread callback, so 
		 * make sure we don't own them.
		 */
		vips__region_no_ownership( layer->strip );
		vips__region_no_ownership( layer->copy );

		/* Build a line of tiles here. 
		 *
		 * Expand the strip if necessary to make sure we have an even 
		 * number of lines. 
		 */
		strip_size.left = 0;
		strip_size.top = 0;
		strip_size.width = layer->image->Xsize;
		strip_size.height = write->tileh;
		if( (strip_size.height & 1) == 1 )
			strip_size.height += 1;
		if( vips_region_buffer( layer->strip, &strip_size ) ) 
			return( -1 );

		if( !(layer->tif = 
			vips__tiff_openout( layer->lname, write->bigtiff )) ||
			write_tiff_header( write, layer ) )  
			return( -1 );
	}

	return( 0 );
}
Esempio n. 13
0
static int
vips_resample_build( VipsObject *object )
{
	VipsResample *resample = VIPS_RESAMPLE( object );

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

	g_object_set( resample, "out", vips_image_new(), NULL ); 

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

	return( 0 );
}
Esempio n. 14
0
static int
vips_histogram_build( VipsObject *object )
{
	VipsHistogram *histogram = VIPS_HISTOGRAM( object );

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

	g_object_set( histogram, "out", vips_image_new(), NULL ); 

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

	return( 0 );
}
Esempio n. 15
0
/* Interlaced PNGs need to be entirely decompressed into memory then can be
 * served partially from there. Non-interlaced PNGs may be read sequentially.
 */
gboolean
vips__png_isinterlaced_buffer( const void *buffer, size_t length )
{
	VipsImage *image;
	Read *read;
	int interlace_type;

	image = vips_image_new();

	if( !(read = read_new_buffer( image, buffer, length, TRUE )) ) { 
		g_object_unref( image );
		return( -1 );
	}
	interlace_type = png_get_interlace_type( read->pPng, read->pInfo );
	g_object_unref( image );

	return( interlace_type != PNG_INTERLACE_NONE );
}
Esempio n. 16
0
static int
vips_conversion_build( VipsObject *object )
{
	VipsConversion *conversion = VIPS_CONVERSION( object );

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

	g_object_set( conversion, "out", vips_image_new(), NULL ); 

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

	return( 0 );
}
Esempio n. 17
0
/* 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 );
}
Esempio n. 18
0
int
vips__openslide_read( const char *filename, VipsImage *out, int layer )
{
	ReadSlide *rslide;
	VipsImage *raw;
	VipsImage *t;

	VIPS_DEBUG_MSG( "vips__openslide_read: %s %d\n", 
		filename, layer );

	/* Tile cache: keep enough for two complete rows of tiles. OpenSlide
	 * has its own tile cache, but it's not large enough for a complete
	 * scan line.
	 */
	raw = vips_image_new();
	vips_object_local( out, raw );

	if( !(rslide = readslide_new( filename, raw, layer, NULL )) )
		return( -1 );

	if( vips_image_generate( raw, 
		NULL, vips__openslide_generate, NULL, rslide, NULL ) )
		return( -1 );

	/* Copy to out, adding a cache. Enough tiles for a complete row, plus
	 * 50%.
	 */
	if( vips_tilecache( raw, &t, 
		"tile_width", TILE_WIDTH, 
		"tile_height", TILE_WIDTH,
		"max_tiles", (int) (1.5 * (1 + raw->Xsize / TILE_WIDTH)),
		NULL ) ) 
		return( -1 );
	if( vips_image_write( t, out ) ) {
		g_object_unref( t );
		return( -1 );
	}
	g_object_unref( t );

	return( 0 );
}
Esempio n. 19
0
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;
	}
Esempio n. 20
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 );
}
Esempio n. 21
0
static int
vips_mosaic1_build( VipsObject *object )
{
	VipsMosaic1 *mosaic1 = (VipsMosaic1 *) object;

	joinfn jfn;

	g_object_set( mosaic1, "out", vips_image_new(), NULL ); 

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

	if( !mosaic1->interpolate )
		mosaic1->interpolate = vips_interpolate_new( "bilinear" );

	jfn = mosaic1->direction == VIPS_DIRECTION_HORIZONTAL ?
		im__lrmerge1 : im__tbmerge1;

	if( mosaic1->search ) {
		if( rotjoin_search( mosaic1->ref, mosaic1->sec, mosaic1->out, 
			jfn,
			mosaic1->bandno,
			mosaic1->xr1, mosaic1->yr1, mosaic1->xs1, mosaic1->ys1, 
			mosaic1->xr2, mosaic1->yr2, mosaic1->xs2, mosaic1->ys2,
			mosaic1->hwindow, mosaic1->harea, 
			0,
			mosaic1->mblend ) )
			return( -1 );
	}
	else {
		if( rotjoin( mosaic1->ref, mosaic1->sec, mosaic1->out, 
			jfn,
			mosaic1->xr1, mosaic1->yr1, mosaic1->xs1, mosaic1->ys1, 
			mosaic1->xr2, mosaic1->yr2, mosaic1->xs2, mosaic1->ys2,
			mosaic1->mblend ) )
			return( -1 );
	}

	return( 0 );
}
Esempio n. 22
0
int
vips__gdal_read( const char *filename, VipsImage *out )
{
	Read *read;
	VipsImage *raw;
	VipsImage *t;

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

	raw = vips_image_new();
	vips_object_local( out, raw );

	if( !(read = read_new( filename, raw )) )
		return( -1 );

	if( vips_image_generate( raw, 
		NULL, vips__gdal_generate, NULL, read, NULL ) )
		return( -1 );

	/* Copy to out, adding a cache. Enough tiles for a complete row, plus
	 * 50%.
	 */
	if( vips_tilecache( raw, &t, 
		"tile_width", read->tile_width, 
		"tile_height", read->tile_height,
		"max_tiles", 
			(int) (1.5 * (1 + raw->Xsize / read->tile_width)),
		"threaded", FALSE,
		NULL ) ) 
		return( -1 );
	if( vips_image_write( t, out ) ) {
		g_object_unref( t );
		return( -1 );
	}
	g_object_unref( t );

	return( 0 );
}
Esempio n. 23
0
/* 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 );
}
Esempio n. 24
0
/* Process the first @n bands with @fn, detach and reattach remaining bands.
 */
static int
vips_process_n( const char *domain, VipsImage *in, VipsImage **out, 
	int n, VipsColourTransformFn fn )
{
	if( in->Bands > n ) {
		VipsImage *scope = vips_image_new();
		VipsImage **t = (VipsImage **) 
			vips_object_local_array( VIPS_OBJECT( scope ), 4 );

		if( vips_extract_band( in, &t[0], 0,
			"n", n, 
			NULL ) ||
			vips_extract_band( in, &t[1], n,
				"n", in->Bands - n, 
				NULL ) ||
			fn( t[0], &t[2], NULL ) ||
			vips_cast( t[1], &t[3], t[2]->BandFmt, 
				NULL ) ||
			vips_bandjoin2( t[2], t[3], out, NULL ) ) {
			g_object_unref( scope );
			return( -1 );
		}

		g_object_unref( scope );
	}
	else if( in->Bands == n ) {
		if( fn( in, out, NULL ) )
			return( -1 );
	}
	else {
		vips_error( domain, "%s", _( "too few bands for operation" ) ); 
		return( -1 );
	}

	return( 0 );
}
Esempio n. 25
0
/* Can this PPM file be read with a mmap?
 */
static int
isppmmmap( const char *filename )
{
	VipsImage *im;
        FILE *fp;
	int bits;
	int ascii;
	int msb_first;

	if( !(fp = vips__file_open_read( filename, NULL, FALSE )) ) 
                return( -1 );

	im = vips_image_new(); 
	if( read_header( fp, im, &bits, &ascii, &msb_first ) ) {
		g_object_unref( im );
		fclose( fp );

		return( 0 );
	}
	g_object_unref( im );
	fclose( fp );

	return( !ascii && bits >= 8 );
}
Esempio n. 26
0
			} \
		} \
}

static int
vips_maplut_build( VipsObject *object )
{
	VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
	VipsMaplut *maplut = (VipsMaplut *) object;
	VipsImage **t = (VipsImage **) vips_object_local_array( object, 2 );

	VipsImage *in;
	VipsImage *lut;
	int i;

	g_object_set( object, "out", vips_image_new(), NULL ); 

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

	in = maplut->in;
	lut = maplut->lut;

	if( vips_check_hist( class->nickname, lut ) ||
		vips_check_uncoded( class->nickname, lut ) )
		return( -1 );

	/* Cast @in to u8/u16/u32 to make the index image.
	 */
	if( vips_cast( in, &t[0], bandfmt_maplut[in->BandFmt], NULL ) )
		return( -1 );
Esempio n. 27
0
static int
vips_colourspace_build( VipsObject *object )
{
	VipsColourspace *colourspace = (VipsColourspace *) object; 

	int i, j;
	VipsImage *x;
	VipsImage **t = (VipsImage **) 
		vips_object_local_array( object, 1 );
	VipsImage **pipe = (VipsImage **) 
		vips_object_local_array( object, MAX_STEPS );

	VipsInterpretation interpretation;

	/* Verify that all input args have been set.
	 */
	if( VIPS_OBJECT_CLASS( vips_colourspace_parent_class )->
		build( object ) )
		return( -1 );

	x = colourspace->in;

	/* Unpack radiance-coded images. We can't use interpretation for this,
	 * since rad images can be scRGB or XYZ.
	 */
	if( x->Coding == VIPS_CODING_RAD ) {
		if( vips_rad2float( x, &t[0], NULL ) )
			return( -1 );
		x = t[0]; 
	}

	if( vips_object_argument_isset( object, "source_space" ) )
		interpretation = colourspace->source_space;
	else
		interpretation = vips_image_guess_interpretation( x );

	/* Treat RGB as sRGB. If you want some other treatment,
	 * you'll need to use the icc funcs.
	 */
	if( interpretation == VIPS_INTERPRETATION_RGB )
		interpretation = VIPS_INTERPRETATION_sRGB;

	/* No conversion necessary.
	 */
	if( interpretation == colourspace->space ) {
		g_object_set( colourspace, "out", vips_image_new(), NULL ); 

		return( vips_image_write( colourspace->in, colourspace->out ) );
	}

	for( i = 0; i < VIPS_NUMBER( vips_colour_routes ); i++ )
		if( vips_colour_routes[i].from == interpretation &&
			vips_colour_routes[i].to == colourspace->space )
			break;
	if( i == VIPS_NUMBER( vips_colour_routes ) ) {
		vips_error( "vips_colourspace", 
			_( "no known route between '%s' and '%s'" ),
			vips_enum_nick( VIPS_TYPE_INTERPRETATION, 
				interpretation ),
			vips_enum_nick( VIPS_TYPE_INTERPRETATION, 
				colourspace->space ) );
		return( -1 );
	}

	for( j = 0; vips_colour_routes[i].route[j]; j++ ) {
		if( vips_colour_routes[i].route[j]( x, &pipe[j], NULL ) ) 
			return( -1 );
		x = pipe[j];
	}

	g_object_set( colourspace, "out", vips_image_new(), NULL ); 
	if( vips_image_write( x, colourspace->out ) )
		return( -1 );

	return( 0 );
}
Esempio n. 28
0
static int
vips_mosaic_build( VipsObject *object )
{
	VipsMosaic *mosaic = (VipsMosaic *) object;

	VipsImage *x;
	int dx0;
	int dy0;
	double scale1;
	double angle1;
	double dx1;
	double dy1;

	g_object_set( mosaic, "out", vips_image_new(), NULL ); 

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

	/* A placeholder used to ensure that memory used by the analysis 
	 * phase is freed as soon as possible.
	 */
	x = vips_image_new(); 

	switch( mosaic->direction ) { 
	case VIPS_DIRECTION_HORIZONTAL:
		if( im__find_lroverlap( mosaic->ref, mosaic->sec, x,
			mosaic->bandno, 
			mosaic->xref, mosaic->yref, mosaic->xsec, mosaic->ysec,
			mosaic->hwindow, mosaic->harea, 
			&dx0, &dy0,
			&scale1, &angle1, 
			&dx1, &dy1 ) ) {
			g_object_unref( x );
			return( -1 );
		}
		g_object_unref( x );
		break;

	case VIPS_DIRECTION_VERTICAL:
		if( im__find_tboverlap( mosaic->ref, mosaic->sec, x,
			mosaic->bandno, 
			mosaic->xref, mosaic->yref, mosaic->xsec, mosaic->ysec,
			mosaic->hwindow, mosaic->harea, 
			&dx0, &dy0,
			&scale1, &angle1, 
			&dx1, &dy1 ) ) {
			g_object_unref( x );
			return( -1 );
		}
		g_object_unref( x );
		break;

	default:
		g_assert_not_reached();

		/* Compiler warnings.
		 */
		dx0 = 0;
		dy0 = 0;
		scale1 = 1;
		angle1 = 1;
		dx1 = 0;
		dy1 = 0;
	}

	g_object_set( mosaic, 
		"dx0", dx0, 
		"dy0", dy0,
		"scale1", scale1, 
		"angle1", angle1, 
		"dx1", dx1, 
		"dy1", dy1,
		NULL ); 

	if( vips_merge( mosaic->ref, mosaic->sec, &x, 
		mosaic->direction, mosaic->dx0, mosaic->dy0, 
		"mblend", mosaic->mblend,
		NULL ) )
		return( -1 );
	if( vips_image_write( x, mosaic->out ) ) {
		g_object_unref( x ); 
		return( -1 ); 
	}
	g_object_unref( x ); 

	return( 0 );
}
Esempio n. 29
0
static int
vips_compass_build( VipsObject *object )
{
	VipsConvolution *convolution = (VipsConvolution *) object;
	VipsCompass *compass = (VipsCompass *) object;
	VipsImage **masks;
	VipsImage *mask;
	VipsImage **images;
	int i; 
	VipsImage **abs;
	VipsImage **combine;
	VipsImage *x;

	g_object_set( compass, "out", vips_image_new(), NULL ); 

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

	masks = (VipsImage **) 
		vips_object_local_array( object, compass->times );
	images = (VipsImage **) 
		vips_object_local_array( object, compass->times );
	abs = (VipsImage **) 
		vips_object_local_array( object, compass->times );
	combine = (VipsImage **) 
		vips_object_local_array( object, compass->times );

	mask = convolution->M;
	for( i = 0; i < compass->times; i++ ) {
		if( vips_conv( convolution->in, &images[i], mask, 
			"precision", compass->precision,
			"layers", compass->layers,
			"cluster", compass->cluster,
			NULL ) )
			return( -1 ); 
		if( vips_rot45( mask, &masks[i],
			"angle", compass->angle,
			NULL ) )
			return( -1 ); 

		mask = masks[i];
	}

	for( i = 0; i < compass->times; i++ )
		if( vips_abs( images[i], &abs[i], NULL ) )
			return( -1 ); 

	switch( compass->combine ) { 
	case VIPS_COMBINE_MAX:
		if( vips_bandrank( abs, &combine[0], compass->times,
			"index", compass->times - 1,
			NULL ) )
			return( -1 ); 
		x = combine[0];
		break;

	case VIPS_COMBINE_SUM:
		x = abs[0];
		for( i = 1; i < compass->times; i++ ) {
			if( vips_add( x, abs[i], &combine[i], NULL ) )
				return( -1 );
			x = combine[i];
		}
		break;

	default:
		/* Silence compiler wrning.
		 */
		x = NULL;
		g_assert( 0 );
	}

	if( vips_image_write( x, convolution->out ) )
		return( -1 ); 

	return( 0 );
}
Esempio n. 30
0
static void
gegl_load_prepare (GeglOperation * operation)
{
  GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
  GeglNode *node = operation->node;

  guint64 hash;

  printf ("gegl_load_prepare: 1\n");

  hash = 0;
  hash = GEGL_VIPS_HASH_STRING( hash, o->path );

  if (!node->vips_image || node->vips_hash != hash)
    {
      VipsImage *image;
      VipsImage *t[10];

      image = vips_image_new ("p");

      /*
      // load as linear float with a LUT
      if (vips_image_new_array (VIPS_OBJECT(image), t, 4) ||
        !(t[3] = vips_image_new_from_file (o->path, "r")) ||
	 im_identity (t[0], 1) ||
	 im_powtra (t[0], t[1], 1.0 / 2.4) ||
	 im_lintra (255.0 / pow (255.0, 1.0 / 2.4), t[1], 0.0, t[2]) ||
	 im_maplut (t[3], image, t[2]))
	{
	  gegl_vips_error ("load");
	  g_object_unref (image);
	  return;
	}
		 */

      /*
      // load as linear float with a LUT, add an alpha channel
      if (vips_image_new_array (VIPS_OBJECT(image), t, 10) ||
        !(t[0] = vips_image_new_from_file (o->path, "r")) ||
	 im_black (t[1], 1, 1, 1) ||
	 im_lintra (1, t[1], 255.0, t[2]) ||
	 im_clip2fmt (t[2], t[3], VIPS_FORMAT_UCHAR) ||
	 im_embed (t[3], t[4], 1, 0, 0, t[0]->Xsize, t[0]->Ysize) ||
	 im_bandjoin (t[0], t[4], t[5]) ||
	 im_identity (t[6], 1) ||
	 im_powtra (t[6], t[7], 1.0 / 2.4) ||
	 im_lintra (255.0 / pow (255.0, 1.0 / 2.4), t[7], 0.0, t[8]) ||
	 im_maplut (t[5], image, t[8]))
	{
	  gegl_vips_error ("load");
	  g_object_unref (image);
	  return;
	}
		 */

      /*
      // load as linear float, no LUT
      if (vips_image_new_array (VIPS_OBJECT(image), t, 4) ||
        !(t[0] = vips_image_new_from_file (o->path, "r")) ||
	 im_lintra (1.0 / 255.0, t[0], 0.0, t[1]) ||
	 im_powtra (t[1], image, 1.0 / 2.4))
	{
	  gegl_vips_error ("load");
	  g_object_unref (image);
	  return;
	}
	 */

      /*
      // load as linear float, no LUT, add an alpha channel
      if (vips_image_new_array (VIPS_OBJECT(image), t, 8) ||
        !(t[0] = vips_image_new_from_file (o->path, "r")) ||
	 im_black (t[2], 1, 1, 1) ||
	 im_lintra (1, t[2], 255.0, t[3]) ||
	 im_clip2fmt (t[3], t[4], VIPS_FORMAT_UCHAR) ||
	 im_embed (t[4], t[5], 1, 0, 0, t[0]->Xsize, t[0]->Ysize) ||
	 im_bandjoin (t[0], t[5], t[6]) ||
	 im_lintra (1.0 / 255.0, t[6], 0.0, t[7]) ||
	 im_powtra (t[7], image, 1.0 / 2.4))
	{
	  gegl_vips_error ("load");
	  g_object_unref (image);
	  return;
	}
	*/

      /*

	 int version

       */
	if (!(image = vips_image_new_from_file (o->path, "r")))
	  {
	    gegl_vips_error ("load");
	    return;
	  }


      node->vips_image = image;
      node->vips_hash = hash;

      printf ("gegl_load_prepare:\n");
      printf ("\tpath = %s\n", o->path);
      printf ("\tattaching to node = %p\n", node);
    }

  return;
}