diff --git a/TODO b/TODO index 333fc20c..932c7fa7 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,13 @@ +- why not renname VipsBandFormat as VipsFormat? cf. VipsCoding, + VipsInterpretation etc. + - image->progress needs renaming, perhaps image->progress_signal? - im_sanity() should become a method on VipsObject, see debug.c +- REGION needs moving at the same time, since regions have to ref their image, + argh + - pre/post/close should be on VipsObject, not VipsImage diff --git a/libvips/include/vips/image.h b/libvips/include/vips/image.h index 1fa91e3f..17415cfc 100644 --- a/libvips/include/vips/image.h +++ b/libvips/include/vips/image.h @@ -352,6 +352,7 @@ void vips_image_invalidate_all( VipsImage *image ); void vips_image_preeval( VipsImage *image ); void vips_image_eval( VipsImage *image, int w, int h ); void vips_image_posteval( VipsImage *image ); +int vips_image_test_kill( VipsImage *image ); VipsImage *vips_image_new( const char *mode ); VipsImage *vips_image_new_from_file( const char *filename, const char *mode ); @@ -359,6 +360,7 @@ VipsImage *vips_image_new_from_file_raw( const char *filename, int xsize, int ysize, int bands, int offset ); VipsImage *vips_image_new_from_memory( void *buffer, int xsize, int ysize, int bands, VipsBandFormat bandfmt ); +VipsImage *vips_image_new_disc_temp( const char *format ); gboolean vips_image_isMSBfirst( VipsImage *image ); gboolean vips_image_isfile( VipsImage *image ); @@ -366,6 +368,11 @@ gboolean vips_image_ispartial( VipsImage *image ); int vips_format_sizeof( VipsBandFormat format ); +int vips_image_copy_fields_array( VipsImage *out, VipsImage *in[] ); +int vips_image_copy_fieldsv( VipsImage *out, VipsImage *in1, ... ) + __attribute__((sentinel)); +int vips_image_copy_fields( VipsImage *out, VipsImage *in ); + #define vips_image_open_local( IM, NAME, MODE ) \ @@ -389,31 +396,6 @@ void vips_initdesc( VipsImage *image, float xres, float yres, int xo, int yo ); -int vips_cp_desc( VipsImage *out, VipsImage *in ); -int vips_cp_descv( VipsImage *out, VipsImage *in1, ... ) - __attribute__((sentinel)); -int vips_cp_desc_array( VipsImage *out, VipsImage *in[] ); - -VipsImage *vips_binfile( const char *name, - int xsize, int ysize, int bands, int offset ); -VipsImage *vips_image( void *buffer, - int xsize, int ysize, int bands, VipsBandFormat bandfmt ); - -typedef void *(*im_construct_fn)( void *, void *, void * ); - -/* Also used for im_add_close_callback() etc. - */ -typedef int (*im_callback_fn)( void *a, void *b ); - -void *im_local( VipsImage *im, - im_construct_fn cons, im_callback_fn dest, void *a, void *b, void *c ); -int im_local_array( VipsImage *im, void **out, int n, - im_construct_fn cons, im_callback_fn dest, void *a, void *b, void *c ); -char *im_strdup( VipsImage *im, const char *str ); -VipsImage *im__open_temp( const char *format ); - -int im_bits_of_fmt( VipsBandFormat fmt ); - #ifdef __cplusplus } #endif /*__cplusplus*/ diff --git a/libvips/include/vips/memory.h b/libvips/include/vips/memory.h index 119a2824..5165e848 100644 --- a/libvips/include/vips/memory.h +++ b/libvips/include/vips/memory.h @@ -72,6 +72,7 @@ G_STMT_START { \ #define VIPS_ARRAY( IM, N, T ) ((T *) im_malloc( (IM), (N) * sizeof( T ))) void *im_malloc( VipsImage *im, size_t size ); +char *im_strdup( VipsImage *im, const char *str ); int im_free( void *s ); #ifdef __cplusplus diff --git a/libvips/include/vips/meta.h b/libvips/include/vips/meta.h index e94492e9..4c856223 100644 --- a/libvips/include/vips/meta.h +++ b/libvips/include/vips/meta.h @@ -100,6 +100,11 @@ size_t im_ref_string_get_length( const GValue *value ); * * The #GType for an #im_blob. */ + +/* Also used for eg. im_local() and friends. + */ +typedef int (*im_callback_fn)( void *a, void *b ); + #define IM_TYPE_BLOB (im_blob_get_type()) GType im_blob_get_type( void ); void *im_blob_get( const GValue *value, size_t *length ); diff --git a/libvips/iofuncs/Makefile.am b/libvips/iofuncs/Makefile.am index ce759ea4..b84aca56 100644 --- a/libvips/iofuncs/Makefile.am +++ b/libvips/iofuncs/Makefile.am @@ -11,7 +11,6 @@ libiofuncs_la_SOURCES = \ error.c \ image.c \ vips.c \ - im_cp_desc.c \ im_demand_hint.c \ im_generate.c \ im_histlin.c \ diff --git a/libvips/iofuncs/check.c b/libvips/iofuncs/check.c index 96a8714e..f8050227 100644 --- a/libvips/iofuncs/check.c +++ b/libvips/iofuncs/check.c @@ -20,7 +20,7 @@ * - checks for partial images added * - now uses type field * 31/8/93 JC - * - returns ok for IM_MMAPINRW type files now too + * - returns ok for VIPS_IMAGE_MMAPINRW type files now too * - returns -1 rather than 1 on error * - ANSIfied * 1/10/97 JC @@ -121,12 +121,13 @@ convert_ptob( IMAGE *im ) { IMAGE *t1; - /* Change to IM_SETBUF. First, make a memory buffer and copy into that. + /* Change to VIPS_IMAGE_SETBUF. First, make a memory buffer and copy + * into that. */ - if( !(t1 = im_open( "im_incheck:1", "t" )) ) + if( !(t1 = vips_image_new( "t" )) ) return( -1 ); if( im_copy( im, t1 ) ) { - im_close( t1 ); + g_object_unref( t1 ); return( -1 ); } @@ -134,14 +135,13 @@ convert_ptob( IMAGE *im ) * would kill of lots of regions and cause dangling pointers * elsewhere. */ - im->dtype = IM_SETBUF; + im->dtype = VIPS_IMAGE_SETBUF; im->data = t1->data; t1->data = NULL; /* Close temp image. */ - if( im_close( t1 ) ) - return( -1 ); + g_object_unref( t1 ); return( 0 ); } @@ -156,7 +156,7 @@ convert_otom( IMAGE *im ) if( im_mapfile( im ) ) return( -1 ); im->data = im->baseaddr + im->sizeof_header; - im->dtype = IM_MMAPIN; + im->dtype = VIPS_IMAGE_MMAPIN; return( 0 ); } @@ -165,10 +165,10 @@ convert_otom( IMAGE *im ) * im_incheck: * @im: image to check * - * Check that an image is readable via the IM_IMAGE_ADDR() macro. If it isn't, - * try to transform it so that IM_IMAGE_ADDR() can work. + * Check that an image is readable via the VIPS_IMAGE_ADDR() macro. If it isn't, + * try to transform it so that VIPS_IMAGE_ADDR() can work. * - * See also: im_outcheck(), im_pincheck(), im_rwcheck(), IM_IMAGE_ADDR(). + * See also: im_outcheck(), im_pincheck(), im_rwcheck(), VIPS_IMAGE_ADDR(). * * Returns: 0 on succeess, or -1 on error. */ @@ -182,25 +182,25 @@ im_incheck( IMAGE *im ) #endif/*DEBUG_IO*/ switch( im->dtype ) { - case IM_SETBUF: - case IM_SETBUF_FOREIGN: + case VIPS_IMAGE_SETBUF: + case VIPS_IMAGE_SETBUF_FOREIGN: /* Should have been written to. */ if( !im->data ) { - im_error( "im_incheck", + vips_error( "im_incheck", "%s", _( "no image data" ) ); return( -1 ); } break; - case IM_MMAPIN: - case IM_MMAPINRW: + case VIPS_IMAGE_MMAPIN: + case VIPS_IMAGE_MMAPINRW: /* Can read from all these, in principle anyway. */ break; - case IM_PARTIAL: + case VIPS_IMAGE_PARTIAL: #ifdef DEBUG_IO printf( "im_incheck: converting partial image to WIO\n" ); #endif/*DEBUG_IO*/ @@ -212,7 +212,7 @@ im_incheck( IMAGE *im ) break; - case IM_OPENIN: + case VIPS_IMAGE_OPENIN: #ifdef DEBUG_IO printf( "im_incheck: converting openin image for old-style input\n" ); #endif/*DEBUG_IO*/ @@ -224,7 +224,7 @@ im_incheck( IMAGE *im ) break; - case IM_OPENOUT: + case VIPS_IMAGE_OPENOUT: /* Close file down and reopen as input. I guess this will only * work for vips files? */ @@ -234,7 +234,7 @@ im_incheck( IMAGE *im ) if( im__close( im ) || im_openin( im ) || im_incheck( im ) ) { - im_error( "im_incheck", + vips_error( "im_incheck", _( "auto-rewind for %s failed" ), im->filename ); return( -1 ); @@ -243,7 +243,7 @@ im_incheck( IMAGE *im ) break; default: - im_error( "im_incheck", + vips_error( "im_incheck", "%s", _( "image not readable" ) ); return( -1 ); } @@ -273,41 +273,41 @@ im_outcheck( IMAGE *im ) #endif/*DEBUG_IO*/ switch( im->dtype ) { - case IM_PARTIAL: + case VIPS_IMAGE_PARTIAL: /* Make sure nothing is attached. */ if( im->generate ) { - im_error( "im_outcheck", + vips_error( "im_outcheck", "%s", _( "image already written" ) ); return( -1 ); } /* Cannot do old-style write to PARTIAL. Turn to SETBUF. */ - im->dtype = IM_SETBUF; + im->dtype = VIPS_IMAGE_SETBUF; /* Fall through to SETBUF case. */ - case IM_SETBUF: + case VIPS_IMAGE_SETBUF: /* Check that it has not been im_setupout(). */ if( im->data ) { - im_error( "im_outcheck", + vips_error( "im_outcheck", "%s", _( "image already written" ) ); return( -1 ); } break; - case IM_OPENOUT: - case IM_SETBUF_FOREIGN: + case VIPS_IMAGE_OPENOUT: + case VIPS_IMAGE_SETBUF_FOREIGN: /* Can write to this ok. */ break; default: - im_error( "im_outcheck", + vips_error( "im_outcheck", "%s", _( "image not writeable" ) ); return( -1 ); } @@ -320,7 +320,7 @@ im_outcheck( IMAGE *im ) * @in: input image * @out: output image * - * A convenience function to check a pair of images for IO via IM_IMAGE_ADDR() + * A convenience function to check a pair of images for IO via VIPS_IMAGE_ADDR() * and im_writeline(). * * See also: im_incheck(), im_outcheck(). @@ -338,7 +338,7 @@ im_iocheck( IMAGE *in, IMAGE *out ) * @im: image to make read-write * * Gets an image ready for an in-place operation, such as im_insertplace(). - * Operations like this both read and write with IM_IMAGE_ADDR(). + * Operations like this both read and write with VIPS_IMAGE_ADDR(). * * See also: im_insertplace(), im_incheck(). * @@ -351,7 +351,7 @@ im_rwcheck( IMAGE *im ) * generate im_partial() files. */ if( im_incheck( im ) ) { - im_error( "im_rwcheck", + vips_error( "im_rwcheck", "%s", _( "unable to rewind file" ) ); return( -1 ); } @@ -359,14 +359,14 @@ im_rwcheck( IMAGE *im ) /* Look at the type. */ switch( im->dtype ) { - case IM_SETBUF: - case IM_SETBUF_FOREIGN: - case IM_MMAPINRW: + case VIPS_IMAGE_SETBUF: + case VIPS_IMAGE_SETBUF_FOREIGN: + case VIPS_IMAGE_MMAPINRW: /* No action necessary. */ break; - case IM_MMAPIN: + case VIPS_IMAGE_MMAPIN: /* Try to remap read-write. */ if( im_remapfilerw( im ) ) @@ -375,7 +375,7 @@ im_rwcheck( IMAGE *im ) break; default: - im_error( "im_rwcheck", + vips_error( "im_rwcheck", "%s", _( "bad file type" ) ); return( -1 ); } @@ -404,12 +404,12 @@ im_pincheck( IMAGE *im ) #endif /*DEBUG_IO*/ switch( im->dtype ) { - case IM_SETBUF: - case IM_SETBUF_FOREIGN: + case VIPS_IMAGE_SETBUF: + case VIPS_IMAGE_SETBUF_FOREIGN: /* Should have been written to. */ if( !im->data ) { - im_error( "im_pincheck", "%s", _( "no image data" ) ); + vips_error( "im_pincheck", "%s", _( "no image data" ) ); return( -1 ); } @@ -421,29 +421,30 @@ im_pincheck( IMAGE *im ) break; - case IM_PARTIAL: + case VIPS_IMAGE_PARTIAL: /* Should have had generate functions attached. */ if( !im->generate ) { - im_error( "im_pincheck", "%s", _( "no image data" ) ); + vips_error( "im_pincheck", "%s", _( "no image data" ) ); return( -1 ); } break; - case IM_MMAPIN: - case IM_MMAPINRW: - case IM_OPENIN: + case VIPS_IMAGE_MMAPIN: + case VIPS_IMAGE_MMAPINRW: + case VIPS_IMAGE_OPENIN: break; - case IM_OPENOUT: + case VIPS_IMAGE_OPENOUT: /* Close file down and reopen as im_mmapin. */ #ifdef DEBUG_IO printf( "im_pincheck: auto-rewind of %s\n", im->filename ); #endif/*DEBUG_IO*/ - if( im__close( im ) || im_openin( im ) ) { - im_error( "im_pincheck", + if( im__close( im ) || + im_openin( im ) ) { + vips_error( "im_pincheck", _( "auto-rewind for %s failed" ), im->filename ); return( -1 ); @@ -452,7 +453,7 @@ im_pincheck( IMAGE *im ) break; default: - im_error( "im_pincheck", "%s", _( "image not readable" ) ); + vips_error( "im_pincheck", "%s", _( "image not readable" ) ); return( -1 ); } @@ -474,7 +475,7 @@ int im_poutcheck( IMAGE *im ) { if( !im ) { - im_error( "im_poutcheck", "%s", _( "null image descriptor" ) ); + vips_error( "im_poutcheck", "%s", _( "null image descriptor" ) ); return( -1 ); } @@ -483,36 +484,36 @@ im_poutcheck( IMAGE *im ) #endif /*DEBUG_IO*/ switch( im->dtype ) { - case IM_SETBUF: + case VIPS_IMAGE_SETBUF: /* Check that it has not been im_setupout(). */ if( im->data ) { - im_error( "im_poutcheck", "%s", + vips_error( "im_poutcheck", "%s", _( "image already written" ) ); return( -1 ); } break; - case IM_PARTIAL: + case VIPS_IMAGE_PARTIAL: /* Make sure nothing is attached. */ if( im->generate ) { - im_error( "im_poutcheck", "%s", + vips_error( "im_poutcheck", "%s", _( "image already written" ) ); return( -1 ); } break; - case IM_OPENOUT: - case IM_SETBUF_FOREIGN: + case VIPS_IMAGE_OPENOUT: + case VIPS_IMAGE_SETBUF_FOREIGN: /* Okeydoke. Not much checking here. */ break; default: - im_error( "im_poutcheck", "%s", _( "image not writeable" ) ); + vips_error( "im_poutcheck", "%s", _( "image not writeable" ) ); return( -1 ); } @@ -546,15 +547,15 @@ im_piocheck( IMAGE *in, IMAGE *out ) * If not, set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 on OK, or -1 on error. */ int im_check_uncoded( const char *domain, IMAGE *im ) { - if( im->Coding != IM_CODING_NONE ) { - im_error( domain, "%s", _( "image must be uncoded" ) ); + if( im->Coding != VIPS_CODING_NONE ) { + vips_error( domain, "%s", _( "image must be uncoded" ) ); return( -1 ); } @@ -570,7 +571,7 @@ im_check_uncoded( const char *domain, IMAGE *im ) * If not, set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 on OK, or -1 on error. */ @@ -579,9 +580,9 @@ im_check_coding_noneorlabq( const char *domain, IMAGE *im ) { /* These all have codings that extract/ifthenelse/etc can ignore. */ - if( im->Coding != IM_CODING_NONE && - im->Coding != IM_CODING_LABQ ) { - im_error( domain, + if( im->Coding != VIPS_CODING_NONE && + im->Coding != VIPS_CODING_LABQ ) { + vips_error( domain, "%s", _( "image coding must be NONE or LABQ" ) ); return( -1 ); } @@ -598,7 +599,7 @@ im_check_coding_noneorlabq( const char *domain, IMAGE *im ) * If not, set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 on OK, or -1 on error. */ @@ -607,10 +608,10 @@ im_check_coding_known( const char *domain, IMAGE *im ) { /* These all have codings that extract/ifthenelse/etc can ignore. */ - if( im->Coding != IM_CODING_NONE && - im->Coding != IM_CODING_LABQ && - im->Coding != IM_CODING_RAD ) { - im_error( domain, "%s", _( "unknown image coding" ) ); + if( im->Coding != VIPS_CODING_NONE && + im->Coding != VIPS_CODING_LABQ && + im->Coding != VIPS_CODING_RAD ) { + vips_error( domain, "%s", _( "unknown image coding" ) ); return( -1 ); } @@ -626,17 +627,17 @@ im_check_coding_known( const char *domain, IMAGE *im ) * If not, set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 on OK, or -1 on error. */ int im_check_coding_rad( const char *domain, IMAGE *im ) { - if( im->Coding != IM_CODING_RAD || - im->BandFmt != IM_BANDFMT_UCHAR || + if( im->Coding != VIPS_CODING_RAD || + im->BandFmt != VIPS_FORMAT_UCHAR || im->Bands != 4 ) { - im_error( domain, "%s", _( "Radiance coding only" ) ); + vips_error( domain, "%s", _( "Radiance coding only" ) ); return( -1 ); } @@ -652,17 +653,17 @@ im_check_coding_rad( const char *domain, IMAGE *im ) * If not, set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 on OK, or -1 on error. */ int im_check_coding_labq( const char *domain, IMAGE *im ) { - if( im->Coding != IM_CODING_LABQ || - im->BandFmt != IM_BANDFMT_UCHAR || + if( im->Coding != VIPS_CODING_LABQ || + im->BandFmt != VIPS_FORMAT_UCHAR || im->Bands != 4 ) { - im_error( domain, "%s", _( "LABQ coding only" ) ); + vips_error( domain, "%s", _( "LABQ coding only" ) ); return( -1 ); } @@ -678,7 +679,7 @@ im_check_coding_labq( const char *domain, IMAGE *im ) * Otherwise set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -686,7 +687,7 @@ int im_check_mono( const char *domain, IMAGE *im ) { if( im->Bands != 1 ) { - im_error( domain, "%s", _( "image must one band" ) ); + vips_error( domain, "%s", _( "image must one band" ) ); return( -1 ); } @@ -703,7 +704,7 @@ im_check_mono( const char *domain, IMAGE *im ) * Otherwise set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -711,7 +712,7 @@ int im_check_bands( const char *domain, IMAGE *im, int bands ) { if( im->Bands != bands ) { - im_error( domain, _( "image must have %d bands" ), bands ); + vips_error( domain, _( "image must have %d bands" ), bands ); return( -1 ); } @@ -727,7 +728,7 @@ im_check_bands( const char *domain, IMAGE *im, int bands ) * Otherwise set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -735,7 +736,7 @@ int im_check_bands_1or3( const char *domain, IMAGE *im ) { if( im->Bands != 1 && im->Bands != 3 ) { - im_error( domain, "%s", + vips_error( domain, "%s", _( "image must have one or three bands" ) ); return( -1 ); } @@ -754,7 +755,7 @@ im_check_bands_1or3( const char *domain, IMAGE *im ) * If not, set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 on OK, or -1 on error. */ @@ -763,7 +764,7 @@ im_check_bands_1orn( const char *domain, IMAGE *im1, IMAGE *im2 ) { if( im1->Bands != im2->Bands && (im1->Bands != 1 && im2->Bands != 1) ) { - im_error( domain, "%s", + vips_error( domain, "%s", _( "images must have the same number of bands, " "or one must be single-band" ) ); return( -1 ); @@ -791,7 +792,7 @@ int im_check_bands_1orn_unary( const char *domain, IMAGE *im, int n ) { if( im->Bands != 1 && im->Bands != n ) { - im_error( domain, _( "image must have 1 or %d bands" ), n ); + vips_error( domain, _( "image must have 1 or %d bands" ), n ); return( -1 ); } @@ -807,7 +808,7 @@ im_check_bands_1orn_unary( const char *domain, IMAGE *im, int n ) * Otherwise set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -815,7 +816,7 @@ int im_check_noncomplex( const char *domain, IMAGE *im ) { if( vips_bandfmt_iscomplex( im->BandFmt ) ) { - im_error( domain, "%s", _( "image must be non-complex" ) ); + vips_error( domain, "%s", _( "image must be non-complex" ) ); return( -1 ); } @@ -831,7 +832,7 @@ im_check_noncomplex( const char *domain, IMAGE *im ) * Otherwise set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -839,7 +840,7 @@ int im_check_complex( const char *domain, IMAGE *im ) { if( !vips_bandfmt_iscomplex( im->BandFmt ) ) { - im_error( domain, "%s", _( "image must be complex" ) ); + vips_error( domain, "%s", _( "image must be complex" ) ); return( -1 ); } @@ -856,16 +857,17 @@ im_check_complex( const char *domain, IMAGE *im ) * Otherwise set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ int -im_check_format( const char *domain, IMAGE *im, VipsBandFmt fmt ) +im_check_format( const char *domain, IMAGE *im, VipsBandFormat fmt ) { if( im->BandFmt != fmt ) { - im_error( domain, - _( "image must be %s" ), im_BandFmt2char( fmt ) ); + vips_error( domain, + _( "image must be %s" ), + VIPS_ENUM_STRING( VIPS_TYPE_BAND_FORMAT, fmt ) ); return( -1 ); } @@ -881,7 +883,7 @@ im_check_format( const char *domain, IMAGE *im, VipsBandFmt fmt ) * Otherwise set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -889,7 +891,7 @@ int im_check_int( const char *domain, IMAGE *im ) { if( !vips_bandfmt_isint( im->BandFmt ) ) { - im_error( domain, "%s", _( "image must be integer" ) ); + vips_error( domain, "%s", _( "image must be integer" ) ); return( -1 ); } @@ -905,7 +907,7 @@ im_check_int( const char *domain, IMAGE *im ) * Otherwise set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -913,7 +915,7 @@ int im_check_uint( const char *domain, IMAGE *im ) { if( !vips_bandfmt_isuint( im->BandFmt ) ) { - im_error( domain, "%s", _( "image must be unsigned integer" ) ); + vips_error( domain, "%s", _( "image must be unsigned integer" ) ); return( -1 ); } @@ -929,18 +931,18 @@ im_check_uint( const char *domain, IMAGE *im ) * Otherwise set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ int im_check_8or16( const char *domain, IMAGE *im ) { - if( im->BandFmt != IM_BANDFMT_UCHAR && - im->BandFmt != IM_BANDFMT_USHORT && - im->BandFmt != IM_BANDFMT_CHAR && - im->BandFmt != IM_BANDFMT_SHORT ) { - im_error( domain, "%s", + if( im->BandFmt != VIPS_FORMAT_UCHAR && + im->BandFmt != VIPS_FORMAT_USHORT && + im->BandFmt != VIPS_FORMAT_CHAR && + im->BandFmt != VIPS_FORMAT_SHORT ) { + vips_error( domain, "%s", _( "image must be 8- or 16-bit integer, " "signed or unsigned" ) ); return( -1 ); @@ -958,16 +960,16 @@ im_check_8or16( const char *domain, IMAGE *im ) * Otherwise set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ int im_check_u8or16( const char *domain, IMAGE *im ) { - if( im->BandFmt != IM_BANDFMT_UCHAR && - im->BandFmt != IM_BANDFMT_USHORT ) { - im_error( domain, "%s", + if( im->BandFmt != VIPS_FORMAT_UCHAR && + im->BandFmt != VIPS_FORMAT_USHORT ) { + vips_error( domain, "%s", _( "image must be 8- or 16-bit unsigned integer" ) ); return( -1 ); } @@ -983,17 +985,17 @@ im_check_u8or16( const char *domain, IMAGE *im ) * Check that the image is 8 or 16-bit unsigned integer, or float. * Otherwise set an error message and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ int im_check_u8or16orf( const char *domain, IMAGE *im ) { - if( im->BandFmt != IM_BANDFMT_UCHAR && - im->BandFmt != IM_BANDFMT_USHORT && - im->BandFmt != IM_BANDFMT_FLOAT ) { - im_error( domain, "%s", + if( im->BandFmt != VIPS_FORMAT_UCHAR && + im->BandFmt != VIPS_FORMAT_USHORT && + im->BandFmt != VIPS_FORMAT_FLOAT ) { + vips_error( domain, "%s", _( "image must be 8- or 16-bit unsigned integer, " "or float" ) ); return( -1 ); @@ -1010,18 +1012,18 @@ im_check_u8or16orf( const char *domain, IMAGE *im ) * Check that the image is unsigned int or float. * Otherwise set an error message and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ int im_check_uintorf( const char *domain, IMAGE *im ) { - if( im->BandFmt != IM_BANDFMT_UCHAR && - im->BandFmt != IM_BANDFMT_USHORT && - im->BandFmt != IM_BANDFMT_UINT && - im->BandFmt != IM_BANDFMT_FLOAT ) { - im_error( domain, "%s", + if( im->BandFmt != VIPS_FORMAT_UCHAR && + im->BandFmt != VIPS_FORMAT_USHORT && + im->BandFmt != VIPS_FORMAT_UINT && + im->BandFmt != VIPS_FORMAT_FLOAT ) { + vips_error( domain, "%s", _( "image must be unsigned int or float" ) ); return( -1 ); } @@ -1039,7 +1041,7 @@ im_check_uintorf( const char *domain, IMAGE *im ) * If not, set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -1047,7 +1049,7 @@ int im_check_size_same( const char *domain, IMAGE *im1, IMAGE *im2 ) { if( im1->Xsize != im2->Xsize || im1->Ysize != im2->Ysize ) { - im_error( domain, "%s", _( "images must match in size" ) ); + vips_error( domain, "%s", _( "images must match in size" ) ); return( -1 ); } @@ -1064,7 +1066,7 @@ im_check_size_same( const char *domain, IMAGE *im1, IMAGE *im2 ) * If not, set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -1072,7 +1074,7 @@ int im_check_bands_same( const char *domain, IMAGE *im1, IMAGE *im2 ) { if( im1->Bands != im2->Bands ) { - im_error( domain, "%s", + vips_error( domain, "%s", _( "images must have the same number of bands" ) ); return( -1 ); } @@ -1091,7 +1093,7 @@ im_check_bands_same( const char *domain, IMAGE *im1, IMAGE *im2 ) * If not, set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -1100,7 +1102,7 @@ im_check_bandno( const char *domain, IMAGE *im, int bandno ) { if( bandno < -1 || bandno > im->Bands - 1 ) { - im_error( domain, "bandno must be -1, or less than %d", + vips_error( domain, "bandno must be -1, or less than %d", im->Bands ); return( -1 ); } @@ -1118,7 +1120,7 @@ im_check_bandno( const char *domain, IMAGE *im, int bandno ) * If not, set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -1126,7 +1128,7 @@ int im_check_format_same( const char *domain, IMAGE *im1, IMAGE *im2 ) { if( im1->BandFmt != im2->BandFmt ) { - im_error( domain, "%s", + vips_error( domain, "%s", _( "images must have the same band format" ) ); return( -1 ); } @@ -1144,7 +1146,7 @@ im_check_format_same( const char *domain, IMAGE *im1, IMAGE *im2 ) * If not, set an error message * and return non-zero. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -1152,7 +1154,7 @@ int im_check_coding_same( const char *domain, IMAGE *im1, IMAGE *im2 ) { if( im1->Coding != im2->Coding ) { - im_error( domain, "%s", + vips_error( domain, "%s", _( "images must have the same coding" ) ); return( -1 ); } @@ -1169,7 +1171,7 @@ im_check_coding_same( const char *domain, IMAGE *im1, IMAGE *im2 ) * Operations with a vector constant need a 1-element vector, or a vector with * the same number of elements as there are bands in the image. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -1177,7 +1179,7 @@ int im_check_vector( const char *domain, int n, IMAGE *im ) { if( n != 1 && im->Bands != 1 && n != im->Bands ) { - im_error( domain, + vips_error( domain, _( "vector must have 1 or %d elements" ), im->Bands ); return( -1 ); } @@ -1194,7 +1196,7 @@ im_check_vector( const char *domain, int n, IMAGE *im ) * 65536 elements. Return 0 if the image will pass as a histogram, or -1 and * set an error message otherwise. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -1202,12 +1204,12 @@ int im_check_hist( const char *domain, IMAGE *im ) { if( im->Xsize != 1 && im->Ysize != 1 ) { - im_error( domain, "%s", + vips_error( domain, "%s", _( "histograms must have width or height 1" ) ); return( -1 ); } if( im->Xsize * im->Ysize > 65536 ) { - im_error( domain, "%s", + vips_error( domain, "%s", _( "histograms must have not have more than " "65536 elements" ) ); return( -1 ); @@ -1223,7 +1225,7 @@ im_check_hist( const char *domain, IMAGE *im ) * * Sanity-check a mask parameter. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -1236,7 +1238,7 @@ im_check_imask( const char *domain, INTMASK *mask ) mask->xsize <= 0 || mask->ysize <= 0 || !mask->coeff ) { - im_error( "im_conv", "%s", _( "nonsense mask parameters" ) ); + vips_error( "im_conv", "%s", _( "nonsense mask parameters" ) ); return( -1 ); } @@ -1250,7 +1252,7 @@ im_check_imask( const char *domain, INTMASK *mask ) * * Sanity-check a mask parameter. * - * See also: im_error(). + * See also: vips_error(). * * Returns: 0 if OK, -1 otherwise. */ @@ -1263,7 +1265,7 @@ im_check_dmask( const char *domain, DOUBLEMASK *mask ) mask->xsize <= 0 || mask->ysize <= 0 || !mask->coeff ) { - im_error( "im_conv", "%s", _( "nonsense mask parameters" ) ); + vips_error( "im_conv", "%s", _( "nonsense mask parameters" ) ); return( -1 ); } @@ -1277,21 +1279,21 @@ im_check_dmask( const char *domain, DOUBLEMASK *mask ) * Return %TRUE if @fmt is one of the integer types. */ gboolean -vips_bandfmt_isint( VipsBandFmt fmt ) +vips_bandfmt_isint( VipsBandFormat fmt ) { switch( fmt ) { - case IM_BANDFMT_UCHAR: - case IM_BANDFMT_CHAR: - case IM_BANDFMT_USHORT: - case IM_BANDFMT_SHORT: - case IM_BANDFMT_UINT: - case IM_BANDFMT_INT: + case VIPS_FORMAT_UCHAR: + case VIPS_FORMAT_CHAR: + case VIPS_FORMAT_USHORT: + case VIPS_FORMAT_SHORT: + case VIPS_FORMAT_UINT: + case VIPS_FORMAT_INT: return( TRUE ); - case IM_BANDFMT_FLOAT: - case IM_BANDFMT_DOUBLE: - case IM_BANDFMT_COMPLEX: - case IM_BANDFMT_DPCOMPLEX: + case VIPS_FORMAT_FLOAT: + case VIPS_FORMAT_DOUBLE: + case VIPS_FORMAT_COMPLEX: + case VIPS_FORMAT_DPCOMPLEX: return( FALSE ); default: @@ -1307,21 +1309,21 @@ vips_bandfmt_isint( VipsBandFmt fmt ) * Return %TRUE if @fmt is one of the unsigned integer types. */ gboolean -vips_bandfmt_isuint( VipsBandFmt fmt ) +vips_bandfmt_isuint( VipsBandFormat fmt ) { switch( fmt ) { - case IM_BANDFMT_UCHAR: - case IM_BANDFMT_USHORT: - case IM_BANDFMT_UINT: + case VIPS_FORMAT_UCHAR: + case VIPS_FORMAT_USHORT: + case VIPS_FORMAT_UINT: return( 1 ); - case IM_BANDFMT_INT: - case IM_BANDFMT_SHORT: - case IM_BANDFMT_CHAR: - case IM_BANDFMT_FLOAT: - case IM_BANDFMT_DOUBLE: - case IM_BANDFMT_COMPLEX: - case IM_BANDFMT_DPCOMPLEX: + case VIPS_FORMAT_INT: + case VIPS_FORMAT_SHORT: + case VIPS_FORMAT_CHAR: + case VIPS_FORMAT_FLOAT: + case VIPS_FORMAT_DOUBLE: + case VIPS_FORMAT_COMPLEX: + case VIPS_FORMAT_DPCOMPLEX: return( 0 ); default: @@ -1337,21 +1339,21 @@ vips_bandfmt_isuint( VipsBandFmt fmt ) * Return %TRUE if @fmt is one of the float types. */ gboolean -vips_bandfmt_isfloat( VipsBandFmt fmt ) +vips_bandfmt_isfloat( VipsBandFormat fmt ) { switch( fmt ) { - case IM_BANDFMT_FLOAT: - case IM_BANDFMT_DOUBLE: + case VIPS_FORMAT_FLOAT: + case VIPS_FORMAT_DOUBLE: return( 1 ); - case IM_BANDFMT_UCHAR: - case IM_BANDFMT_CHAR: - case IM_BANDFMT_USHORT: - case IM_BANDFMT_SHORT: - case IM_BANDFMT_UINT: - case IM_BANDFMT_INT: - case IM_BANDFMT_COMPLEX: - case IM_BANDFMT_DPCOMPLEX: + case VIPS_FORMAT_UCHAR: + case VIPS_FORMAT_CHAR: + case VIPS_FORMAT_USHORT: + case VIPS_FORMAT_SHORT: + case VIPS_FORMAT_UINT: + case VIPS_FORMAT_INT: + case VIPS_FORMAT_COMPLEX: + case VIPS_FORMAT_DPCOMPLEX: return( 0 ); default: @@ -1367,21 +1369,21 @@ vips_bandfmt_isfloat( VipsBandFmt fmt ) * Return %TRUE if @fmt is one of the complex types. */ gboolean -vips_bandfmt_iscomplex( VipsBandFmt fmt ) +vips_bandfmt_iscomplex( VipsBandFormat fmt ) { switch( fmt ) { - case IM_BANDFMT_COMPLEX: - case IM_BANDFMT_DPCOMPLEX: + case VIPS_FORMAT_COMPLEX: + case VIPS_FORMAT_DPCOMPLEX: return( 1 ); - case IM_BANDFMT_UCHAR: - case IM_BANDFMT_CHAR: - case IM_BANDFMT_USHORT: - case IM_BANDFMT_SHORT: - case IM_BANDFMT_UINT: - case IM_BANDFMT_INT: - case IM_BANDFMT_FLOAT: - case IM_BANDFMT_DOUBLE: + case VIPS_FORMAT_UCHAR: + case VIPS_FORMAT_CHAR: + case VIPS_FORMAT_USHORT: + case VIPS_FORMAT_SHORT: + case VIPS_FORMAT_UINT: + case VIPS_FORMAT_INT: + case VIPS_FORMAT_FLOAT: + case VIPS_FORMAT_DOUBLE: return( 0 ); default: diff --git a/libvips/iofuncs/im_cp_desc.c b/libvips/iofuncs/im_cp_desc.c deleted file mode 100644 index 8e69b61d..00000000 --- a/libvips/iofuncs/im_cp_desc.c +++ /dev/null @@ -1,188 +0,0 @@ -/* copy iamge descriptors - * - * Copyright: Nicos Dessipris - * Written on: 09/02/1990 - * Modified on : 22/2/93 By Kirk Martinez: v6.3 - * 28/10/1992 J.Cupitt - * - now calls im_cp_Hist, and hence frees old history correctly - * 10/5/93 J.Cupitt - * - checks return result from im_cp_Hist() - * 22/11/00 JC - * - ANSIfied - * 5/9/02 JC - * - copy Xoffset/Yoffset too - * 14/4/04 JC - * - hmm, in fact no, zero them - * 6/6/05 Markus Wollgarten - * - copy Meta - * 29/8/05 - * - added im_cp_descv() and im_cp_desc_array() - * 2/9/05 - * - simplified ... no more skip the first line stuff - * 4/1/07 - * - merge hists with history_list instead - */ - -/* - - This file is part of VIPS. - - VIPS is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - */ - -/* - - These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk - - */ - -#ifdef HAVE_CONFIG_H -#include -#endif /*HAVE_CONFIG_H*/ -#include - -#include -#include -#include - -#include -#include - -#ifdef WITH_DMALLOC -#include -#endif /*WITH_DMALLOC*/ - -/** - * im_cp_desc_array: - * @out: image to copy to - * @in: %NULL-terminated array of images to copy from - * - * Copy fields from all the input images to the output image. There must be at - * least one input image. If you are making an image which has no input images - * (for example, im_black() or im_vips2jpeg()), use im_initdesc() instead. - * - * The first input image is used to set the main fields of @out (@XSize, @Coding - * and so on). - * - * Metadata from all the image is merged on to @out, with lower-numbered items - * overriding higher. So for example, if @in[0] and @in[1] both have an item - * called "icc-profile", it's the profile attached to @in[0] that will end up - * on @out. - * - * Image history is completely copied from all @in. @out will have the history - * of all the intput images. - * - * See also: im_cp_descv(), im_cp_desc(). - * - * Returns: 0 on success, -1 on error. - */ -int -im_cp_desc_array( IMAGE *out, IMAGE *in[] ) -{ - int i; - int ni; - - g_assert( in[0] ); - - out->Xsize = in[0]->Xsize; - out->Ysize = in[0]->Ysize; - out->Bands = in[0]->Bands; - out->Bbits = in[0]->Bbits; - out->BandFmt = in[0]->BandFmt; - out->Type = in[0]->Type; - out->Coding = in[0]->Coding; - out->Xres = in[0]->Xres; - out->Yres = in[0]->Yres; - out->Xoffset = 0; - out->Yoffset = 0; - - /* Count number of images. - */ - for( ni = 0; in[ni]; ni++ ) - ; - - /* Need to copy last-to-first so that in0 meta will override any - * earlier meta. - */ - im__meta_destroy( out ); - for( i = ni - 1; i >= 0; i-- ) - if( im__meta_cp( out, in[i] ) ) - return( -1 ); - - /* Merge hists first to last. - */ - for( i = 0; in[i]; i++ ) - out->history_list = im__gslist_gvalue_merge( out->history_list, - in[i]->history_list ); - - return( 0 ); -} - -/* Max number of images we can handle. - */ -#define MAX_IMAGES (1000) - -/** - * im_cp_descv: - * @out: image to copy to - * @in1: first image to copy from - * @Varargs: %NULL-terminated list of images to copy from - * - * Copy fields from all the input images to the output image. A convenience - * function over im_cp_desc_array(). - * - * See also: im_cp_desc_array(), im_cp_desc(). - * - * Returns: 0 on success, -1 on error. - */ -int -im_cp_descv( IMAGE *out, IMAGE *in1, ... ) -{ - va_list ap; - int i; - IMAGE *in[MAX_IMAGES]; - - in[0] = in1; - va_start( ap, in1 ); - for( i = 1; i < MAX_IMAGES && (in[i] = va_arg( ap, IMAGE * )); i++ ) - ; - va_end( ap ); - if( i == MAX_IMAGES ) { - vips_error( "im_cp_descv", - "%s", _( "too many images" ) ); - return( -1 ); - } - - return( im_cp_desc_array( out, in ) ); -} - -/** - * im_cp_desc: - * @out: image to copy to - * @in: image to copy from - * - * Copy fields from @in to @out. A convenience - * function over im_cp_desc_array(). - * - * See also: im_cp_desc_array(), im_cp_descv(). - * - * Returns: 0 on success, -1 on error. - */ -int -im_cp_desc( IMAGE *out, IMAGE *in ) -{ - return( im_cp_descv( out, in, NULL ) ); -} diff --git a/libvips/iofuncs/im_generate.c b/libvips/iofuncs/im_generate.c index fc055de0..908a3d21 100644 --- a/libvips/iofuncs/im_generate.c +++ b/libvips/iofuncs/im_generate.c @@ -377,9 +377,9 @@ im_generate( IMAGE *im, } /* We don't use this, but make sure it's set in case any old binaries - * are expectiing it. + * are expecting it. */ - im->Bbits = im_bits_of_fmt( im->BandFmt ); + im->Bbits = vips_format_sizeof( im->BandFmt ) << 3; /* Look at output type to decide our action. */ diff --git a/libvips/iofuncs/im_prepare.c b/libvips/iofuncs/im_prepare.c index a3d9d26d..3e34fbd1 100644 --- a/libvips/iofuncs/im_prepare.c +++ b/libvips/iofuncs/im_prepare.c @@ -93,20 +93,6 @@ fill_region( REGION *reg ) return( 0 ); } -int -im__test_kill( IMAGE *im ) -{ - /* Has kill been set for this image? If yes, abort evaluation. - */ - if( im->kill ) { - vips_error( "im__test_kill", _( "killed for image \"%s\"" ), - im->filename ); - return( -1 ); - } - - return( 0 ); -} - /** * im_prepare: * @reg: region to prepare diff --git a/libvips/iofuncs/im_setupout.c b/libvips/iofuncs/im_setupout.c index 2b880c51..fe250402 100644 --- a/libvips/iofuncs/im_setupout.c +++ b/libvips/iofuncs/im_setupout.c @@ -99,7 +99,7 @@ im_setupout( IMAGE *im ) /* We don't use this, but make sure it's set in case any old binaries * are expectiing it. */ - im->Bbits = im_bits_of_fmt( im->BandFmt ); + im->Bbits = vips_format_sizeof( im->BandFmt ) << 3; if( im->dtype == VIPS_IMAGE_PARTIAL ) { /* Make it into a im_setbuf() image. diff --git a/libvips/iofuncs/im_wrapmany.c b/libvips/iofuncs/im_wrapmany.c index 74452ef2..3a03a75f 100644 --- a/libvips/iofuncs/im_wrapmany.c +++ b/libvips/iofuncs/im_wrapmany.c @@ -60,7 +60,7 @@ typedef struct { /* Maximum number of input images -- why not? */ -#define IM_MAX_INPUT_IMAGES (64) +#define MAX_INPUT_IMAGES (64) /* Convert a REGION. */ @@ -70,7 +70,7 @@ process_region( REGION *or, void *seq, void *a, void *b ) REGION **ir = (REGION **) seq; Bundle *bun = (Bundle *) b; - PEL *p[IM_MAX_INPUT_IMAGES], *q; + PEL *p[MAX_INPUT_IMAGES], *q; int i, y; /* Prepare all input regions and make buffer pointers. @@ -87,7 +87,7 @@ process_region( REGION *or, void *seq, void *a, void *b ) /* Convert linewise. */ for( y = 0; y < or->valid.height; y++ ) { - PEL *p1[IM_MAX_INPUT_IMAGES]; + PEL *p1[MAX_INPUT_IMAGES]; /* Make a copy of p[] which the buffer function can mess up if * it wants. @@ -125,7 +125,7 @@ dupims( IMAGE *out, IMAGE **in ) /* Allocate new array. */ - if( !(new = IM_ARRAY( out, n + 1, IMAGE * )) ) + if( !(new = VIPS_ARRAY( out, n + 1, IMAGE * )) ) return( NULL ); /* Copy. @@ -169,15 +169,15 @@ dupims( IMAGE *out, IMAGE **in ) int im_wrapmany( IMAGE **in, IMAGE *out, im_wrapmany_fn fn, void *a, void *b ) { - Bundle *bun = IM_NEW( out, Bundle ); + Bundle *bun = VIPS_NEW( out, Bundle ); int i, n; /* Count input images. */ for( n = 0; in[n]; n++ ) ; - if( n >= IM_MAX_INPUT_IMAGES - 1 ) { - im_error( "im_wrapmany", "%s", _( "too many input images" ) ); + if( n >= MAX_INPUT_IMAGES - 1 ) { + vips_error( "im_wrapmany", "%s", _( "too many input images" ) ); return( -1 ); } @@ -194,7 +194,7 @@ im_wrapmany( IMAGE **in, IMAGE *out, im_wrapmany_fn fn, void *a, void *b ) */ for( i = 0; i < n; i++ ) { if( in[i]->Xsize != out->Xsize || in[i]->Ysize != out->Ysize ) { - im_error( "im_wrapmany", + vips_error( "im_wrapmany", "%s", _( "descriptors differ in size" ) ); return( -1 ); } @@ -208,7 +208,7 @@ im_wrapmany( IMAGE **in, IMAGE *out, im_wrapmany_fn fn, void *a, void *b ) /* Hint demand style. Being a buffer processor, we are happiest with * thin strips. */ - if( im_demand_hint_array( out, IM_THINSTRIP, in ) ) + if( im_demand_hint_array( out, VIPS_DEMAND_STYLE_THINSTRIP, in ) ) return( -1 ); /* Generate! @@ -258,7 +258,7 @@ wrapone_gen( void **ins, void *out, int width, Bundle *bun, void *dummy ) int im_wrapone( IMAGE *in, IMAGE *out, im_wrapone_fn fn, void *a, void *b ) { - Bundle *bun = IM_NEW( out, Bundle ); + Bundle *bun = VIPS_NEW( out, Bundle ); IMAGE *invec[2]; /* Heh, yuk. We cast back above. @@ -314,7 +314,7 @@ int im_wraptwo( IMAGE *in1, IMAGE *in2, IMAGE *out, im_wraptwo_fn fn, void *a, void *b ) { - Bundle *bun = IM_NEW( out, Bundle ); + Bundle *bun = VIPS_NEW( out, Bundle ); IMAGE *invec[3]; bun->fn = (im_wrapmany_fn) fn; diff --git a/libvips/iofuncs/im_writeline.c b/libvips/iofuncs/im_writeline.c index b289cc4c..9e8c7cfe 100644 --- a/libvips/iofuncs/im_writeline.c +++ b/libvips/iofuncs/im_writeline.c @@ -67,67 +67,62 @@ /** * im_writeline: + * @image: image to write to * @ypos: vertical position of scan-line to write - * @im: image to write to * @linebuffer: scanline of pixels * * Write a line of pixels to an image. This function must be called repeatedly * with @ypos increasing from 0 to @YSize - - * 1. @linebuffer must be IM_IMAGE_SIZEOF_LINE() bytes long. + * @linebuffer must be IM_IMAGE_SIZEOF_LINE() bytes long. * * See also: im_setupout(), im_generate(). * * Returns: 0 on success, or -1 on error. */ int -im_writeline( int ypos, IMAGE *im, PEL *linebuffer ) +vips_image_write_line( VipsImage *image, int ypos, PEL *linebuffer ) { - int linesize = IM_IMAGE_SIZEOF_LINE( im ); - char *tmp; + int linesize = VIPS_IMAGE_SIZEOF_LINE( image ); /* Is this the start of eval? */ if( ypos == 0 ) - im__start_eval( im ); + vips_image_preeval( image ); /* Possible cases for output: FILE or SETBUF. */ - switch( im->dtype ) { - case IM_SETBUF: - case IM_SETBUF_FOREIGN: - tmp = im->data + ypos * linesize; - memcpy( tmp, linebuffer, linesize ); - + switch( image->dtype ) { + case VIPS_IMAGE_SETBUF: + case VIPS_IMAGE_SETBUF_FOREIGN: + memcpy( IM_IMAGE_ADDR( image, 0, ypos ), linebuffer, linesize ); break; - case IM_OPENOUT: + case VIPS_IMAGE_OPENOUT: /* Don't use ypos for this. */ - if( im__write( im->fd, linebuffer, linesize ) ) + if( im__write( image->fd, linebuffer, linesize ) ) return( -1 ); - break; default: - im_error( "im_writeline", + vips_error( "im_writeline", _( "unable to output to a %s image" ), - im_dtype2char( im->dtype ) ); + VIPS_ENUM_STRING( VIPS_TYPE_DEMAND_STYLE, + image->dtype ) ); return( -1 ); } /* Trigger evaluation callbacks for this image. */ - if( im__handle_eval( im, im->Xsize, 1 ) ) - return( -1 ); - if( im__test_kill( im ) ) + vips_image_eval( image, image->Xsize, 1 ); + if( im__test_kill( image ) ) return( -1 ); /* Is this the end of eval? */ - if( ypos == im->Ysize - 1 ) { - if( im__end_eval( im ) || - im__trigger_callbacks( im->writtenfns ) ) - return( -1 ); + if( ypos == image->Ysize - 1 ) { + vips_image_posteval( image ); + vips_image_written( image ); } return( 0 ); diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index 700e5dea..6f2db82d 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -588,7 +588,7 @@ lazy_real_image( Lazy *lazy ) !(vips_format_get_flags( lazy->format, lazy->filename ) & VIPS_FORMAT_PARTIAL) && vips_image_size( lazy->image ) > disc_threshold() ) { - if( !(real = im__open_temp( "%s.v" )) ) + if( !(real = vips_image_new_disc_temp( "%s.v" )) ) return( NULL ); #ifdef DEBUG @@ -1344,6 +1344,20 @@ vips_image_posteval( VipsImage *image ) } } +int +vips_image_test_kill( VipsImage *image ) +{ + /* Has kill been set for this image? If yes, abort evaluation. + */ + if( image->kill ) { + vips_error( "vips_image_test_kill", + _( "killed for image \"%s\"" ), image->filename ); + return( -1 ); + } + + return( 0 ); +} + /** * vips_image_new: * @mode: mode to open with @@ -1367,7 +1381,7 @@ vips_image_posteval( VipsImage *image ) * * * - * Returns: the image descriptor on success and NULL on error. + * Returns: the new #VipsImage, or %NULL on error. */ VipsImage * vips_image_new( const char *mode ) @@ -1465,7 +1479,7 @@ vips_image_new( const char *mode ) * * * - * Returns: the image descriptor on success and NULL on error. + * Returns: the new #VipsImage, or %NULL on error. */ VipsImage * vips_image_new_from_file( const char *filename, const char *mode ) @@ -1540,7 +1554,7 @@ vips_image_new_from_file_raw( const char *filename, * * See also: im_binfile(), im_raw2vips(), im_open(). * - * Returns: the new #IMAGE, or %NULL on error. + * Returns: the new #VipsImage, or %NULL on error. */ VipsImage * vips_image_new_from_memory( void *buffer, @@ -1565,6 +1579,51 @@ vips_image_new_from_memory( void *buffer, return( image ); } +static void +vips_image_new_temp_cb( VipsImage *image ) +{ + g_assert( image->filename ); + + unlink( image->filename ); +} + +/** + * vips_image_new_disc_temp: + * @format: format of file + * + * Make a "w" disc #VipsImage which will be automatically unlinked when it is + * destroyed. @format is something like "%s.v" for a vips file. + * + * The file is created in the temporary directory, see im__temp_name(). + * + * See also: im__temp_name(). + * + * Returns: the new #VipsImage, or %NULL on error. + */ +VipsImage * +vips_image_new_disc_temp( const char *format ) +{ + char *name; + VipsImage *image; + + if( !(name = im__temp_name( format )) ) + return( NULL ); + + if( !(image = vips_image_new_from_file( name, "w" )) ) { + g_free( name ); + return( NULL ); + } + g_free( name ); + + /* Needs to be postclose so we can rewind after write without + * deleting the file. + */ + g_signal_connect( image, "postclose", + G_CALLBACK( vips_image_new_temp_cb ), NULL ); + + return( image ); +} + /** * vips_image_isMSBfirst: * @image: image to test @@ -1640,7 +1699,7 @@ const size_t vips_image__sizeof_bandformat[] = { 2 * sizeof( double ) /* VIPS_FORMAT_DPCOMPLEX */ }; -/* Return number of pel bits for band format, or -1 on error. +/* Return number of bytes for a band format, or -1 on error. */ int vips_format_sizeof( VipsBandFormat format ) @@ -1651,5 +1710,126 @@ vips_format_sizeof( VipsBandFormat format ) vips_image__sizeof_bandformat[format] ); } +/** + * vips_image_copy_fields_array: + * @out: image to copy to + * @in: %NULL-terminated array of images to copy from + * + * Copy fields from all the input images to the output image. There must be at + * least one input image. + * + * The first input image is used to set the main fields of @out (@XSize, @Coding + * and so on). + * + * Metadata from all the image is merged on to @out, with lower-numbered items + * overriding higher. So for example, if @in[0] and @in[1] both have an item + * called "icc-profile", it's the profile attached to @in[0] that will end up + * on @out. + * + * Image history is completely copied from all @in. @out will have the history + * of all the intput images. + * + * See also: vips_image_copy_fieldsv(), vips_image_copy_fields(). + * + * Returns: 0 on success, -1 on error. + */ +int +vips_image_copy_fields_array( IMAGE *out, IMAGE *in[] ) +{ + int i; + int ni; + + g_assert( in[0] ); + + out->Xsize = in[0]->Xsize; + out->Ysize = in[0]->Ysize; + out->Bands = in[0]->Bands; + out->Bbits = in[0]->Bbits; + out->BandFmt = in[0]->BandFmt; + out->Type = in[0]->Type; + out->Coding = in[0]->Coding; + out->Xres = in[0]->Xres; + out->Yres = in[0]->Yres; + out->Xoffset = 0; + out->Yoffset = 0; + + /* Count number of images. + */ + for( ni = 0; in[ni]; ni++ ) + ; + + /* Need to copy last-to-first so that in0 meta will override any + * earlier meta. + */ + im__meta_destroy( out ); + for( i = ni - 1; i >= 0; i-- ) + if( im__meta_cp( out, in[i] ) ) + return( -1 ); + + /* Merge hists first to last. + */ + for( i = 0; in[i]; i++ ) + out->history_list = im__gslist_gvalue_merge( out->history_list, + in[i]->history_list ); + + return( 0 ); +} + +/* Max number of images we can handle. + */ +#define MAX_IMAGES (1000) + +/** + * vips_image_copy_fieldsv: + * @out: image to copy to + * @in1: first image to copy from + * @Varargs: %NULL-terminated list of images to copy from + * + * Copy fields from all the input images to the output image. A convenience + * function over vips_image_copy_fields_array(). + * + * See also: vips_image_copy_fields_array(), vips_image_copy_fields(). + * + * Returns: 0 on success, -1 on error. + */ +int +vips_image_copy_fieldsv( IMAGE *out, IMAGE *in1, ... ) +{ + va_list ap; + int i; + IMAGE *in[MAX_IMAGES]; + + in[0] = in1; + va_start( ap, in1 ); + for( i = 1; i < MAX_IMAGES && (in[i] = va_arg( ap, IMAGE * )); i++ ) + ; + va_end( ap ); + if( i == MAX_IMAGES ) { + vips_error( "im_cp_descv", + "%s", _( "too many images" ) ); + return( -1 ); + } + + return( vips_image_copy_fields_array( out, in ) ); +} + +/** + * vips_image_copy_fields: + * @out: image to copy to + * @in: image to copy from + * + * Copy fields from @in to @out. A convenience + * function over vips_image_copy_fields_array(). + * + * See also: vips_image_copy_fields_array(), vips_image_copy_fieldsv(). + * + * Returns: 0 on success, -1 on error. + */ +int +vips_image_copy_fields( IMAGE *out, IMAGE *in ) +{ + return( vips_image_copy_fieldsv( out, in, NULL ) ); +} + diff --git a/libvips/iofuncs/memory.c b/libvips/iofuncs/memory.c index fa9676b6..331ebf47 100644 --- a/libvips/iofuncs/memory.c +++ b/libvips/iofuncs/memory.c @@ -178,6 +178,12 @@ im_free( void *s ) return( 0 ); } +static void +im_malloc_cb( VipsImage *image, char *buf ) +{ + im_free( buf ); +} + /** * im_malloc: * @im: allocate memory local to this #IMAGE, or %NULL @@ -219,10 +225,10 @@ im_malloc( IMAGE *im, size_t size ) g_assert( 0 ); #endif /*DEBUG*/ - im_error( "im_malloc", + vips_error( "im_malloc", _( "out of memory --- size == %dMB" ), (int) (size / (1024.0*1024.0)) ); - im_warn( "im_malloc", + vips_warn( "im_malloc", _( "out of memory --- size == %dMB" ), (int) (size / (1024.0*1024.0)) ); return( NULL ); @@ -260,11 +266,9 @@ im_malloc( IMAGE *im, size_t size ) printf( "woah! big!\n" ); #endif /*DEBUGM*/ - if( im && im_add_close_callback( im, - (im_callback_fn) im_free, buf, NULL ) ) { - im_free( buf ); - return( NULL ); - } - + if( im ) + g_signal_connect( im, "close", + G_CALLBACK( im_malloc_cb ), buf ); + return( buf ); } diff --git a/libvips/iofuncs/package.c b/libvips/iofuncs/package.c index 7d73ab85..648fcd4d 100644 --- a/libvips/iofuncs/package.c +++ b/libvips/iofuncs/package.c @@ -94,7 +94,7 @@ static im_arg_desc guess_prefix_args[] = { static int guess_prefix_vec( im_object *argv ) { - const char *prefix = im_guess_prefix( argv[0], argv[1] ); + const char *prefix = vips_guess_prefix( argv[0], argv[1] ); if( !prefix ) { argv[2] = NULL; @@ -113,7 +113,7 @@ static im_function guess_prefix_desc = { "guess install area", /* Description */ 0, /* Flags */ guess_prefix_vec, /* Dispatch function */ - IM_NUMBER( guess_prefix_args ), /* Size of arg list */ + VIPS_NUMBER( guess_prefix_args ), /* Size of arg list */ guess_prefix_args /* Arg list */ }; @@ -130,7 +130,7 @@ static im_arg_desc guess_libdir_args[] = { static int guess_libdir_vec( im_object *argv ) { - const char *libdir = im_guess_libdir( argv[0], argv[1] ); + const char *libdir = vips_guess_libdir( argv[0], argv[1] ); if( !libdir ) { argv[2] = NULL; @@ -149,7 +149,7 @@ static im_function guess_libdir_desc = { "guess library area", /* Description */ 0, /* Flags */ guess_libdir_vec, /* Dispatch function */ - IM_NUMBER( guess_libdir_args ), /* Size of arg list */ + VIPS_NUMBER( guess_libdir_args ),/* Size of arg list */ guess_libdir_args /* Arg list */ }; @@ -177,7 +177,7 @@ static im_function header_int_desc = { "extract int fields from header", /* Description */ 0, /* Flags */ header_int_vec, /* Dispatch function */ - IM_NUMBER( header_int_args ), /* Size of arg list */ + VIPS_NUMBER( header_int_args ), /* Size of arg list */ header_int_args /* Arg list */ }; @@ -209,7 +209,7 @@ static im_function header_get_typeof_desc = { "return field type", /* Description */ 0, /* Flags */ header_get_typeof_vec, /* Dispatch function */ - IM_NUMBER( header_get_typeof_args ),/* Size of arg list */ + VIPS_NUMBER( header_get_typeof_args ),/* Size of arg list */ header_get_typeof_args /* Arg list */ }; @@ -237,7 +237,7 @@ static im_function header_double_desc = { "extract double fields from header", /* Description */ 0, /* Flags */ header_double_vec, /* Dispatch function */ - IM_NUMBER( header_double_args ), /* Size of arg list */ + VIPS_NUMBER( header_double_args ), /* Size of arg list */ header_double_args /* Arg list */ }; @@ -273,7 +273,7 @@ static im_function header_string_desc = { "extract fields from headers as strings", /* Description */ 0, /* Flags */ header_string_vec, /* Dispatch function */ - IM_NUMBER( header_string_args ), /* Size of arg list */ + VIPS_NUMBER( header_string_args ),/* Size of arg list */ header_string_args /* Arg list */ }; @@ -306,7 +306,7 @@ static im_function history_get_desc = { "return the image history as a string", /* Description */ 0, /* Flags */ history_get_vec, /* Dispatch function */ - IM_NUMBER( history_get_args ), /* Size of arg list */ + VIPS_NUMBER( history_get_args ),/* Size of arg list */ history_get_args /* Arg list */ }; @@ -340,7 +340,7 @@ static im_function getext_desc = { "return the image metadata XML as a string", /* Description */ 0, /* Flags */ getext_vec, /* Dispatch function */ - IM_NUMBER( getext_args ), /* Size of arg list */ + VIPS_NUMBER( getext_args ), /* Size of arg list */ getext_args /* Arg list */ }; @@ -367,7 +367,7 @@ static im_function printdesc_desc = { "print an image header to stdout", /* Description */ 0, /* Flags */ printdesc_vec, /* Dispatch function */ - IM_NUMBER( printdesc_args ), /* Size of arg list */ + VIPS_NUMBER( printdesc_args ), /* Size of arg list */ printdesc_args /* Arg list */ }; @@ -382,7 +382,7 @@ static im_arg_desc version_string_args[] = { static int version_string_vec( im_object *argv ) { - if( !(argv[0] = im_strdup( NULL, im_version_string() )) ) + if( !(argv[0] = im_strdup( NULL, vips_version_string() )) ) return( -1 ); return( 0 ); @@ -395,7 +395,7 @@ static im_function version_string_desc = { "VIPS version string", /* Description */ 0, /* Flags */ version_string_vec, /* Dispatch function */ - IM_NUMBER( version_string_args ), /* Size of arg list */ + VIPS_NUMBER( version_string_args ),/* Size of arg list */ version_string_args /* Arg list */ }; @@ -414,7 +414,7 @@ version_vec( im_object *argv ) int flag = *((int *) argv[0]); int *out = ((int *) argv[1]); - int version = im_version( flag ); + int version = vips_version( flag ); if( version < 0 ) return( -1 ); @@ -431,7 +431,7 @@ static im_function version_desc = { "VIPS version number", /* Description */ 0, /* Flags */ version_vec, /* Dispatch function */ - IM_NUMBER( version_args ), /* Size of arg list */ + VIPS_NUMBER( version_args ), /* Size of arg list */ version_args /* Arg list */ }; @@ -465,7 +465,7 @@ static im_function cache_desc = { "cache results of an operation",/* Description */ 0, /* Flags */ cache_vec, /* Dispatch function */ - IM_NUMBER( cache_args ), /* Size of arg list */ + VIPS_NUMBER( cache_args ), /* Size of arg list */ cache_args /* Arg list */ }; @@ -489,17 +489,15 @@ binfile_vec( im_object *argv ) int height = *((int *) argv[3]); int bands = *((int *) argv[4]); int offset = *((int *) argv[5]); - IMAGE *im; + VipsImage *im; - if( !(im = im_binfile( argv[0], width, height, bands, offset )) ) + if( !(im = vips_image_new_from_file_raw( argv[0], + width, height, bands, offset )) ) return( -1 ); + vips_object_local( argv[1], im ); - if( im_copy( im, argv[1] ) || - im_add_close_callback( argv[1], - (im_callback_fn) im_close, im, NULL ) ) { - im_close( im ); + if( im_copy( im, argv[1] ) ) return( -1 ); - } return( 0 ); } @@ -511,7 +509,7 @@ static im_function binfile_desc = { "open a headerless binary file",/* Description */ 0, /* Flags */ binfile_vec, /* Dispatch function */ - IM_NUMBER( binfile_args ), /* Size of arg list */ + VIPS_NUMBER( binfile_args ), /* Size of arg list */ binfile_args /* Arg list */ }; @@ -537,7 +535,7 @@ static im_function *iofuncs_list[] = { */ static im_package im__iofuncs = { "iofuncs", - IM_NUMBER( iofuncs_list ), + VIPS_NUMBER( iofuncs_list ), iofuncs_list }; @@ -587,15 +585,15 @@ plugin_free( Plugin *plug ) if( plug->module ) { if( !g_module_close( plug->module ) ) { - im_error( "plugin", + vips_error( "plugin", _( "unable to close plugin \"%s\"" ), name ); - im_error( "plugin", "%s", g_module_error() ); + vips_error( "plugin", "%s", g_module_error() ); return( -1 ); } plug->module = NULL; } - IM_FREE( plug->name ); + VIPS_FREE( plug->name ); plug->pack = NULL; im_free( plug ); @@ -612,14 +610,14 @@ im_load_plugin( const char *name ) Plugin *plug; if( !g_module_supported() ) { - im_error( "plugin", + vips_error( "plugin", "%s", _( "plugins not supported on this platform" ) ); return( NULL ); } /* Build a new plugin. */ - if( !(plug = IM_NEW( NULL, Plugin )) ) + if( !(plug = VIPS_NEW( NULL, Plugin )) ) return( NULL ); plug->module = NULL; plug->name = NULL; @@ -636,8 +634,8 @@ im_load_plugin( const char *name ) /* Open library. */ if( !(plug->module = g_module_open( name, 0 )) ) { - im_error( "plugin", _( "unable to open plugin \"%s\"" ), name ); - im_error( "plugin", "%s", g_module_error() ); + vips_error( "plugin", _( "unable to open plugin \"%s\"" ), name ); + vips_error( "plugin", "%s", g_module_error() ); plugin_free( plug ); return( NULL ); @@ -649,10 +647,10 @@ im_load_plugin( const char *name ) */ if( !g_module_symbol( plug->module, "package_table", (gpointer *) ((void *) &plug->pack) ) ) { - im_error( "plugin", + vips_error( "plugin", _( "unable to find symbol \"package_table\" " "in plugin \"%s\"" ), name ); - im_error( "plugin", "%s", g_module_error() ); + vips_error( "plugin", "%s", g_module_error() ); plugin_free( plug ); return( NULL ); @@ -662,7 +660,7 @@ im_load_plugin( const char *name ) */ if( !plug->pack->name || plug->pack->nfuncs < 0 || plug->pack->nfuncs > 10000 ) { - im_error( "plugin", + vips_error( "plugin", _( "corrupted package table in plugin \"%s\"" ), name ); plugin_free( plug ); @@ -753,7 +751,7 @@ im_map_packages( VSListMap2Fn fn, void *a ) /* If not there, try main VIPS package list. */ if( !r ) - for( i = 0; i < IM_NUMBER( built_in ); i++ ) + for( i = 0; i < VIPS_NUMBER( built_in ); i++ ) if( (r = fn( built_in[i], a, NULL )) ) return( r ); @@ -783,7 +781,7 @@ im_find_function( const char *name ) (VSListMap2Fn) search_package, (void *) name ); if( !fn ) { - im_error( "im_find_function", _( "\"%s\" not found" ), name ); + vips_error( "im_find_function", _( "\"%s\" not found" ), name ); return( NULL ); } @@ -810,7 +808,7 @@ im_find_package( const char *name ) (VSListMap2Fn) package_name, (void *) name ); if( !pack ) { - im_error( "im_find_package", _( "\"%s\" not found" ), name ); + vips_error( "im_find_package", _( "\"%s\" not found" ), name ); return( NULL ); } @@ -837,7 +835,7 @@ im_package_of_function( const char *name ) (VSListMap2Fn) package_function, (void *) name ); if( !pack ) { - im_error( "im_package_of_function", + vips_error( "im_package_of_function", _( "\"%s\" not found" ), name ); return( NULL ); } @@ -947,7 +945,7 @@ build_args( im_function *fn, im_object *vargv, int argc, char **argv ) */ if( type->flags & IM_TYPE_ARG ) { if( !argv[j] ) { - im_error( "im_run_command", + vips_error( "im_run_command", "%s", _( "too few arguments" ) ); return( -1 ); } @@ -969,7 +967,7 @@ build_args( im_function *fn, im_object *vargv, int argc, char **argv ) /* Have we used up all the command-line args? */ if( argv[j] ) { - im_error( "im_run_command", "%s", _( "too many arguments" ) ); + vips_error( "im_run_command", "%s", _( "too many arguments" ) ); return( -1 ); } @@ -978,12 +976,10 @@ build_args( im_function *fn, im_object *vargv, int argc, char **argv ) /* Free a region, but return 0 so we can be used as a close callback. */ -static int -region_free( REGION *reg ) +static void +region_local_image_cb( VipsImage *main, REGION *reg ) { im_region_free( reg ); - - return( 0 ); } /* Make a region on sub, closed by callback on main. @@ -995,12 +991,8 @@ region_local_image( IMAGE *main, IMAGE *sub ) if( !(reg = im_region_create( sub )) ) return( -1 ); - if( im_add_close_callback( main, - (im_callback_fn) region_free, reg, NULL ) ) { - im_region_free( reg ); - - return( -1 ); - } + g_signal_connect( main, "close", + G_CALLBACK( region_local_image_cb ), reg ); return( 0 ); } @@ -1199,7 +1191,7 @@ im_version( int flag ) return( IM_MICRO_VERSION ); default: - im_error( "im_version", "%s", _( "flag not 0,1,2" ) ); + vips_error( "im_version", "%s", _( "flag not 0, 1, 2" ) ); return( -1 ); } } diff --git a/libvips/iofuncs/region.c b/libvips/iofuncs/region.c index d88050d1..865e354c 100644 --- a/libvips/iofuncs/region.c +++ b/libvips/iofuncs/region.c @@ -205,7 +205,7 @@ im__call_start( REGION *reg ) g_mutex_unlock( im->sslock ); if( !reg->seq ) { - im_error( "im__call_start", + vips_error( "im__call_start", _( "start function failed for image %s" ), im->filename ); return( -1 ); @@ -311,7 +311,7 @@ im_region_create( IMAGE *im ) g_assert( !im_image_sanity( im ) ); - if( !(reg = IM_NEW( NULL, REGION )) ) + if( !(reg = VIPS_NEW( NULL, REGION )) ) return( NULL ); reg->im = im; @@ -351,8 +351,8 @@ im_region_create( IMAGE *im ) static void im_region_reset( REGION *reg ) { - IM_FREEF( im_window_unref, reg->window ); - IM_FREEF( im_buffer_unref, reg->buffer ); + VIPS_FREEF( im_window_unref, reg->window ); + VIPS_FREEF( im_buffer_unref, reg->buffer ); reg->invalid = FALSE; } @@ -450,7 +450,7 @@ im_region_buffer( REGION *reg, Rect *r ) /* Test for empty. */ if( im_rect_isempty( &clipped ) ) { - im_error( "im_region_buffer", + vips_error( "im_region_buffer", "%s", _( "valid clipped to nothing" ) ); return( -1 ); } @@ -470,7 +470,7 @@ im_region_buffer( REGION *reg, Rect *r ) * and new buffer ref in one call to reduce malloc/free * cycling. */ - IM_FREEF( im_window_unref, reg->window ); + VIPS_FREEF( im_window_unref, reg->window ); if( !(reg->buffer = im_buffer_unref_ref( reg->buffer, im, &clipped )) ) return( -1 ); @@ -518,7 +518,7 @@ im_region_image( REGION *reg, Rect *r ) /* Test for empty. */ if( im_rect_isempty( &clipped ) ) { - im_error( "im_region_image", + vips_error( "im_region_image", "%s", _( "valid clipped to nothing" ) ); return( -1 ); } @@ -564,7 +564,7 @@ im_region_image( REGION *reg, Rect *r ) reg->data = reg->window->data; } else { - im_error( "im_region_image", + vips_error( "im_region_image", "%s", _( "bad image type" ) ); return( -1 ); } @@ -610,7 +610,7 @@ im_region_region( REGION *reg, REGION *dest, Rect *r, int x, int y ) if( !dest->data || IM_IMAGE_SIZEOF_PEL( dest->im ) != IM_IMAGE_SIZEOF_PEL( reg->im ) ) { - im_error( "im_region_region", + vips_error( "im_region_region", "%s", _( "inappropriate region type" ) ); return( -1 ); } @@ -643,7 +643,7 @@ im_region_region( REGION *reg, REGION *dest, Rect *r, int x, int y ) /* Test that dest->valid is large enough. */ if( !im_rect_includesrect( &dest->valid, &wanted ) ) { - im_error( "im_region_region", + vips_error( "im_region_region", "%s", _( "dest too small" ) ); return( -1 ); } @@ -662,7 +662,7 @@ im_region_region( REGION *reg, REGION *dest, Rect *r, int x, int y ) /* Test for empty. */ if( im_rect_isempty( &final ) ) { - im_error( "im_region_region", + vips_error( "im_region_region", "%s", _( "valid clipped to nothing" ) ); return( -1 ); } @@ -731,7 +731,7 @@ im_region_position( REGION *reg, int x, int y ) req.height = reg->valid.height; im_rect_intersectrect( &image, &req, &clipped ); if( x < 0 || y < 0 || im_rect_isempty( &clipped ) ) { - im_error( "im_region_position", "%s", _( "bad position" ) ); + vips_error( "im_region_position", "%s", _( "bad position" ) ); return( -1 ); } diff --git a/libvips/iofuncs/sink.c b/libvips/iofuncs/sink.c index 6d4c26d1..334afb5d 100644 --- a/libvips/iofuncs/sink.c +++ b/libvips/iofuncs/sink.c @@ -112,7 +112,7 @@ sink_call_stop( Sink *sink, SinkThreadState *state ) VIPS_DEBUG_MSG( "sink_call_stop: state = %p\n", state ); if( sink->stop( state->seq, sink->a, sink->b ) ) { - im_error( "vips_sink", + vips_error( "vips_sink", _( "stop function failed for image \"%s\"" ), sink->im->filename ); return( -1 ); @@ -131,7 +131,7 @@ sink_thread_state_dispose( GObject *gobject ) Sink *sink = (Sink *) ((VipsThreadState *) state)->a; sink_call_stop( sink, state ); - IM_FREEF( im_region_free, state->reg ); + VIPS_FREEF( im_region_free, state->reg ); G_OBJECT_CLASS( sink_thread_state_parent_class )->dispose( gobject ); } @@ -147,7 +147,7 @@ sink_call_start( Sink *sink, SinkThreadState *state ) state->seq = sink->start( sink->t, sink->a, sink->b ); if( !state->seq ) { - im_error( "vips_sink", + vips_error( "vips_sink", _( "start function failed for image \"%s\"" ), sink->im->filename ); return( -1 ); @@ -202,7 +202,7 @@ sink_thread_state_new( VipsImage *im, void *a ) static void sink_free( Sink *sink ) { - IM_FREEF( im_close, sink->t ); + VIPS_FREEF( g_object_unref, sink->t ); } static int @@ -221,7 +221,7 @@ sink_init( Sink *sink, sink->a = a; sink->b = b; - if( !(sink->t = im_open( "iterate", "p" )) || + if( !(sink->t = vips_image_new( "p" )) || im_copy( sink->im, sink->t ) ) { sink_free( sink ); return( -1 ); @@ -340,7 +340,7 @@ vips_sink_tile( VipsImage *im, /* We don't use this, but make sure it's set in case any old binaries * are expecting it. */ - im->Bbits = im_bits_of_fmt( im->BandFmt ); + im->Bbits = vips_format_sizeof( im->BandFmt ) << 3; if( sink_init( &sink, im, start, generate, stop, a, b ) ) return( -1 ); diff --git a/libvips/iofuncs/sinkdisc.c b/libvips/iofuncs/sinkdisc.c index 5cf24a2a..93e11926 100644 --- a/libvips/iofuncs/sinkdisc.c +++ b/libvips/iofuncs/sinkdisc.c @@ -168,7 +168,7 @@ wbuffer_free( WriteBuffer *wbuffer ) wbuffer->thread = NULL; } - IM_FREEF( im_region_free, wbuffer->region ); + VIPS_FREEF( im_region_free, wbuffer->region ); im_semaphore_destroy( &wbuffer->go ); im_semaphore_destroy( &wbuffer->nwrite ); im_semaphore_destroy( &wbuffer->done ); @@ -223,7 +223,7 @@ wbuffer_new( Write *write ) { WriteBuffer *wbuffer; - if( !(wbuffer = IM_NEW( NULL, WriteBuffer )) ) + if( !(wbuffer = VIPS_NEW( NULL, WriteBuffer )) ) return( NULL ); wbuffer->write = write; wbuffer->region = NULL; @@ -248,7 +248,8 @@ wbuffer_new( Write *write ) */ if( !(wbuffer->thread = g_thread_create( wbuffer_write_thread, wbuffer, TRUE, NULL )) ) { - im_error( "wbuffer_new", "%s", _( "unable to create thread" ) ); + vips_error( "wbuffer_new", + "%s", _( "unable to create thread" ) ); wbuffer_free( wbuffer ); return( NULL ); } @@ -273,7 +274,7 @@ wbuffer_flush( Write *write ) /* Previous write suceeded? */ if( write->buf_back->write_errno ) { - im_error_system( write->buf_back->write_errno, + vips_error_system( write->buf_back->write_errno, "wbuffer_write", "%s", _( "write failed" ) ); return( -1 ); } @@ -465,8 +466,8 @@ write_init( Write *write, static void write_free( Write *write ) { - IM_FREEF( wbuffer_free, write->buf ); - IM_FREEF( wbuffer_free, write->buf_back ); + VIPS_FREEF( wbuffer_free, write->buf ); + VIPS_FREEF( wbuffer_free, write->buf_back ); } /** diff --git a/libvips/iofuncs/sinkmemory.c b/libvips/iofuncs/sinkmemory.c index d08b16fe..63843111 100644 --- a/libvips/iofuncs/sinkmemory.c +++ b/libvips/iofuncs/sinkmemory.c @@ -195,7 +195,7 @@ vips_sink_memory( VipsImage *im ) /* We don't use this, but make sure it's set in case any old binaries * are expecting it. */ - im->Bbits = im_bits_of_fmt( im->BandFmt ); + im->Bbits = vips_format_sizeof( im->BandFmt ) << 3; if( sink_init( &sink, im ) ) return( -1 ); diff --git a/libvips/iofuncs/sinkscreen.c b/libvips/iofuncs/sinkscreen.c index 7419ae8d..03c36642 100644 --- a/libvips/iofuncs/sinkscreen.c +++ b/libvips/iofuncs/sinkscreen.c @@ -1085,12 +1085,12 @@ vips_sink_screen( VipsImage *in, VipsImage *out, VipsImage *mask, } if( im_piocheck( in, out ) || - im_cp_desc( out, in ) || + vips_image_copy_fields( out, in ) || im_demand_hint( out, VIPS_DEMAND_STYLE_SMALLTILE, in, NULL ) ) return( -1 ); if( mask ) { if( im_poutcheck( mask ) || - im_cp_desc( mask, in ) || + vips_image_copy_fields( mask, in ) || im_demand_hint( mask, VIPS_DEMAND_STYLE_SMALLTILE, in, NULL ) ) return( -1 ); diff --git a/libvips/iofuncs/util.c b/libvips/iofuncs/util.c index aff424f3..9a7f7682 100644 --- a/libvips/iofuncs/util.c +++ b/libvips/iofuncs/util.c @@ -1573,33 +1573,3 @@ im__temp_name( const char *format ) return( name ); } - -/* Make a disc IMAGE which will be automatically unlinked on im_close(). - * Format is something like "%s.v" for a vips file. - */ -IMAGE * -im__open_temp( const char *format ) -{ - char *name; - IMAGE *disc; - - if( !(name = im__temp_name( format )) ) - return( NULL ); - - if( !(disc = im_open( name, "w" )) ) { - g_free( name ); - return( NULL ); - } - g_free( name ); - - /* Needs to be postclose so we can rewind after write without - * deleting the file. - */ - if( im_add_postclose_callback( disc, - (im_callback_fn) unlink, disc->filename, NULL ) ) { - im_close( disc ); - g_unlink( name ); - } - - return( disc ); -} diff --git a/libvips/iofuncs/vips.c b/libvips/iofuncs/vips.c index 4c318ea4..011ed02d 100644 --- a/libvips/iofuncs/vips.c +++ b/libvips/iofuncs/vips.c @@ -280,7 +280,7 @@ im__read_header_bytes( IMAGE *im, unsigned char *from ) /* Set this ourselves ... bbits is deprecated in the file format. */ - im->Bbits = im_bits_of_fmt( im->BandFmt ); + im->Bbits = vips_format_sizeof( im->BandFmt ) << 3; return( 0 ); }