/** * 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 ); }
static VipsFits * vips_fits_new_write( VipsImage *in, const char *filename ) { VipsImage *flip; VipsImage *type; VipsFits *fits; int status; status = 0; if( im_check_noncomplex( "im_vips2fits", in ) || im_check_uncoded( "im_vips2fits", in ) ) return( NULL ); /* Cast to a supported format. */ if( !(type = vips_image_new()) || vips_object_local( in, type ) || im_clip2fmt( in, type, vips_fits_bandfmt[in->BandFmt] ) ) return( NULL ); in = type; /* FITS has (0,0) in the bottom left, we need to flip. */ if( !(flip = vips_image_new()) || vips_object_local( in, flip ) || im_flipver( in, flip ) ) return( NULL ); in = flip; if( !(fits = VIPS_NEW( in, VipsFits )) ) return( NULL ); fits->filename = im_strdup( NULL, filename ); fits->image = in; fits->fptr = NULL; fits->lock = NULL; fits->band_select = -1; fits->buffer = NULL; g_signal_connect( in, "close", G_CALLBACK( vips_fits_close_cb ), fits ); if( !(fits->filename = im_strdup( NULL, filename )) ) return( NULL ); /* We need to be able to hold one scanline of one band. */ if( !(fits->buffer = VIPS_ARRAY( NULL, VIPS_IMAGE_SIZEOF_ELEMENT( in ) * in->Xsize, PEL )) ) return( NULL ); /* fits_create_file() will fail if there's a file of thet name, unless * we put a "!" in front ofthe filename. This breaks conventions with * the rest of vips, so just unlink explicitly. */ g_unlink( filename ); if( fits_create_file( &fits->fptr, filename, &status ) ) { im_error( "fits", _( "unable to write to \"%s\"" ), filename ); vips_fits_error( status ); return( NULL ); } fits->lock = g_mutex_new(); return( fits ); }
/* Call im_flipver via arg vector. */ static int flipver_vec( im_object *argv ) { return( im_flipver( argv[0], argv[1] ) ); }