diff --git a/ChangeLog b/ChangeLog index a97c1924..7a6adf91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,5 @@ 21/1/14 started 7.39.0 -- auto-decode for (almost) all operations +- auto-decode for (almost) all operations, see vips_image_decode() - background render thread cleans up and quits neatly - colourspace has a source_space option - operations can be tagged as "deprecated" diff --git a/TODO b/TODO index 3831bfd4..2bf0c0a2 100644 --- a/TODO +++ b/TODO @@ -1,21 +1,4 @@ -- check_uncoded() left to do: - - resample/quadratic.c - -- move vips__image_decode() into the public API - -- we vips_image_write() a lot, could we do this by - - int - vips_image_write( in, out ) - { - g_object_ref( in) - vips_object_local( out,in ) - } - - i.e. do everything at pipe build time - - inplace can we set a region for the pixels we will modify? diff --git a/libvips/arithmetic/arithmetic.c b/libvips/arithmetic/arithmetic.c index a8aea1de..e273cea0 100644 --- a/libvips/arithmetic/arithmetic.c +++ b/libvips/arithmetic/arithmetic.c @@ -539,7 +539,7 @@ vips_arithmetic_build( VipsObject *object ) /* Decode RAD/LABQ etc. */ for( i = 0; i < arithmetic->n; i++ ) - if( vips__image_decode( arithmetic->in[i], &decode[i] ) ) + if( vips_image_decode( arithmetic->in[i], &decode[i] ) ) return( -1 ); /* Cast our input images up to a common format, bands and size. diff --git a/libvips/arithmetic/statistic.c b/libvips/arithmetic/statistic.c index 1ab1cc2f..e4553c5f 100644 --- a/libvips/arithmetic/statistic.c +++ b/libvips/arithmetic/statistic.c @@ -123,7 +123,7 @@ vips_statistic_build( VipsObject *object ) statistic->ready = statistic->in; - if( vips__image_decode( statistic->ready, &t[0] ) ) + if( vips_image_decode( statistic->ready, &t[0] ) ) return( -1 ); statistic->ready = t[0]; diff --git a/libvips/colour/colour.c b/libvips/colour/colour.c index 3645dc88..0ea7e6ee 100644 --- a/libvips/colour/colour.c +++ b/libvips/colour/colour.c @@ -628,13 +628,13 @@ vips_colour_difference_build( VipsObject *object ) extra = NULL; if( left ) { - if( vips__image_decode( left, &t[0] ) ) + if( vips_image_decode( left, &t[0] ) ) return( -1 ); left = t[0]; } if( right ) { - if( vips__image_decode( right, &t[1] ) ) + if( vips_image_decode( right, &t[1] ) ) return( -1 ); right = t[1]; } diff --git a/libvips/conversion/bandary.c b/libvips/conversion/bandary.c index 06ede11a..2bda6da4 100644 --- a/libvips/conversion/bandary.c +++ b/libvips/conversion/bandary.c @@ -146,7 +146,7 @@ vips_bandary_build( VipsObject *object ) size = (VipsImage **) vips_object_local_array( object, bandary->n ); for( i = 0; i < bandary->n; i++ ) - if( vips__image_decode( bandary->in[i], &decode[i] ) ) + if( vips_image_decode( bandary->in[i], &decode[i] ) ) return( -1 ); if( vips__formatalike_vec( decode, format, bandary->n ) || vips__sizealike_vec( format, size, bandary->n ) ) diff --git a/libvips/conversion/cast.c b/libvips/conversion/cast.c index 9a080fdb..eadcefaa 100644 --- a/libvips/conversion/cast.c +++ b/libvips/conversion/cast.c @@ -446,7 +446,7 @@ vips_cast_build( VipsObject *object ) if( in->BandFmt == cast->format ) return( vips_image_write( in, conversion->out ) ); - if( vips__image_decode( in, &t[0] ) ) + if( vips_image_decode( in, &t[0] ) ) return( -1 ); in = t[0]; diff --git a/libvips/conversion/falsecolour.c b/libvips/conversion/falsecolour.c index 867e6fe2..630b5b2c 100644 --- a/libvips/conversion/falsecolour.c +++ b/libvips/conversion/falsecolour.c @@ -349,7 +349,7 @@ vips_falsecolour_build( VipsObject *object ) * want to work for images which aren't in a recognised space, like * MULTIBAND. */ - if( vips__image_decode( falsecolour->in, &t[1] ) || + if( vips_image_decode( falsecolour->in, &t[1] ) || vips_extract_band( t[1], &t[2], 0, NULL ) || vips_cast( t[2], &t[3], VIPS_FORMAT_UCHAR, NULL ) || vips_maplut( t[3], &t[4], t[0], NULL ) || diff --git a/libvips/conversion/flatten.c b/libvips/conversion/flatten.c index 1bf4626e..85baee21 100644 --- a/libvips/conversion/flatten.c +++ b/libvips/conversion/flatten.c @@ -311,7 +311,7 @@ vips_flatten_build( VipsObject *object ) in = flatten->in; - if( vips__image_decode( in, &t[0] ) ) + if( vips_image_decode( in, &t[0] ) ) return( -1 ); in = t[0]; diff --git a/libvips/conversion/recomb.c b/libvips/conversion/recomb.c index 0e39beb9..6adee2dc 100644 --- a/libvips/conversion/recomb.c +++ b/libvips/conversion/recomb.c @@ -150,7 +150,7 @@ vips_recomb_build( VipsObject *object ) in = recomb->in; - if( vips__image_decode( in, &t[0] ) ) + if( vips_image_decode( in, &t[0] ) ) return( -1 ); in = t[0]; diff --git a/libvips/convolution/conv.c b/libvips/convolution/conv.c index 151a23bb..48ebe4ec 100644 --- a/libvips/convolution/conv.c +++ b/libvips/convolution/conv.c @@ -94,7 +94,7 @@ vips_conv_build( VipsObject *object ) /* Unpack for processing. */ - if( vips__image_decode( in, &t[0] ) ) + if( vips_image_decode( in, &t[0] ) ) return( -1 ); in = t[0]; diff --git a/libvips/freqfilt/fwfft.c b/libvips/freqfilt/fwfft.c index 813a5cc1..618f8db2 100644 --- a/libvips/freqfilt/fwfft.c +++ b/libvips/freqfilt/fwfft.c @@ -303,7 +303,7 @@ vips_fwfft_build( VipsObject *object ) in = freqfilt->in; - if( vips__image_decode( in, &t[0] ) ) + if( vips_image_decode( in, &t[0] ) ) return( -1 ); in = t[0]; diff --git a/libvips/freqfilt/invfft.c b/libvips/freqfilt/invfft.c index 8b8611ee..e20e5822 100644 --- a/libvips/freqfilt/invfft.c +++ b/libvips/freqfilt/invfft.c @@ -216,7 +216,7 @@ vips_invfft_build( VipsObject *object ) in = freqfilt->in; - if( vips__image_decode( in, &t[0] ) ) + if( vips_image_decode( in, &t[0] ) ) return( -1 ); in = t[0]; diff --git a/libvips/histogram/hist_local.c b/libvips/histogram/hist_local.c index 9243ec05..15c518f7 100644 --- a/libvips/histogram/hist_local.c +++ b/libvips/histogram/hist_local.c @@ -236,7 +236,7 @@ vips_hist_local_build( VipsObject *object ) in = local->in; - if( vips__image_decode( in, &t[0] ) ) + if( vips_image_decode( in, &t[0] ) ) return( -1 ); in = t[0]; diff --git a/libvips/histogram/histogram.c b/libvips/histogram/histogram.c index 8064dfa7..e4edf5b2 100644 --- a/libvips/histogram/histogram.c +++ b/libvips/histogram/histogram.c @@ -143,7 +143,7 @@ vips_histogram_build( VipsObject *object ) g_object_set( histogram, "out", vips_image_new(), NULL ); for( i = 0; i < histogram->n; i++ ) - if( vips__image_decode( histogram->in[i], &decode[i] ) || + if( vips_image_decode( histogram->in[i], &decode[i] ) || vips_check_hist( class->nickname, decode[i] ) ) return( -1 ); diff --git a/libvips/histogram/stdif.c b/libvips/histogram/stdif.c index 0406bbd2..86521614 100644 --- a/libvips/histogram/stdif.c +++ b/libvips/histogram/stdif.c @@ -224,7 +224,7 @@ vips_stdif_build( VipsObject *object ) in = stdif->in; - if( vips__image_decode( in, &t[0] ) ) + if( vips_image_decode( in, &t[0] ) ) return( -1 ); in = t[0]; diff --git a/libvips/include/vips/image.h b/libvips/include/vips/image.h index 5a59cc86..34f8a617 100644 --- a/libvips/include/vips/image.h +++ b/libvips/include/vips/image.h @@ -430,6 +430,8 @@ VipsImage *vips_image_new_temp_file( const char *format ); int vips_image_write( VipsImage *image, VipsImage *out ); int vips_image_write_to_file( VipsImage *image, const char *filename ); +int vips_image_decode( VipsImage *in, VipsImage **out ); + gboolean vips_image_isMSBfirst( VipsImage *image ); gboolean vips_image_isfile( VipsImage *image ); gboolean vips_image_ispartial( VipsImage *image ); diff --git a/libvips/include/vips/internal.h b/libvips/include/vips/internal.h index e29d64df..39c233b6 100644 --- a/libvips/include/vips/internal.h +++ b/libvips/include/vips/internal.h @@ -297,8 +297,6 @@ IMAGE *vips__deprecated_open_write( const char *filename ); int vips__input_interpolate_init( im_object *obj, char *str ); -int vips__image_decode( VipsImage *in, VipsImage **out ); - #ifdef __cplusplus } #endif /*__cplusplus*/ diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index e97bcdef..0b9cef78 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -1997,6 +1997,37 @@ vips_image_write_to_file( VipsImage *image, const char *filename ) return( 0 ); } +/** + * vips_image_decode: + * @in: image to decode + * @out: write to this image + * + * A convenience function to unpack to a format that we can compute with. + * @out->Coding is always VIPS_CODING_NONE. + * + * See also: vips_LabQ2LabS(), vips_rad2float(). + * + * Returns: 0 on success, or -1 on error. + */ +int +vips_image_decode( VipsImage *in, VipsImage **out ) +{ + if( in->Coding == VIPS_CODING_LABQ ) { + if( vips_LabQ2LabS( in, out, NULL ) ) + return( -1 ); + } + else if( in->Coding == VIPS_CODING_RAD ) { + if( vips_rad2float( in, out, NULL ) ) + return( -1 ); + } + else { + if( vips_copy( in, out, NULL ) ) + return( -1 ); + } + + return( 0 ); +} + /** * vips_image_isMSBfirst: * @image: image to test diff --git a/libvips/morphology/morph.c b/libvips/morphology/morph.c index 8ce26671..e8e037c5 100644 --- a/libvips/morphology/morph.c +++ b/libvips/morphology/morph.c @@ -93,7 +93,7 @@ vips_morph_build( VipsObject *object ) in = morphology->in; - if( vips__image_decode( in, &t[0] ) ) + if( vips_image_decode( in, &t[0] ) ) return( -1 ); in = t[0]; diff --git a/libvips/morphology/rank.c b/libvips/morphology/rank.c index b88154a5..a6388918 100644 --- a/libvips/morphology/rank.c +++ b/libvips/morphology/rank.c @@ -341,7 +341,7 @@ vips_rank_build( VipsObject *object ) in = morphology->in; - if( vips__image_decode( in, &t[0] ) ) + if( vips_image_decode( in, &t[0] ) ) return( -1 ); in = t[0]; diff --git a/libvips/resample/affine.c b/libvips/resample/affine.c index 7d17a06e..13659405 100644 --- a/libvips/resample/affine.c +++ b/libvips/resample/affine.c @@ -375,27 +375,6 @@ vips_affine_gen( VipsRegion *or, void *seq, void *a, void *b, gboolean *stop ) return( 0 ); } -/* Unpack to a format that we can compute with. - */ -int -vips__image_decode( VipsImage *in, VipsImage **out ) -{ - if( in->Coding == VIPS_CODING_LABQ ) { - if( vips_LabQ2LabS( in, out, NULL ) ) - return( -1 ); - } - else if( in->Coding == VIPS_CODING_RAD ) { - if( vips_rad2float( in, out, NULL ) ) - return( -1 ); - } - else { - if( vips_copy( in, out, NULL ) ) - return( -1 ); - } - - return( 0 ); -} - static int vips_affine_build( VipsObject *object ) { @@ -485,7 +464,7 @@ vips_affine_build( VipsObject *object ) return( -1 ); } - if( vips__image_decode( in, &t[0] ) ) + if( vips_image_decode( in, &t[0] ) ) return( -1 ); in = t[0]; diff --git a/libvips/resample/shrink.c b/libvips/resample/shrink.c index f27e4bf9..0604f4d5 100644 --- a/libvips/resample/shrink.c +++ b/libvips/resample/shrink.c @@ -347,7 +347,7 @@ vips_shrink_build( VipsObject *object ) /* Unpack for processing. */ - if( vips__image_decode( in, &t[0] ) ) + if( vips_image_decode( in, &t[0] ) ) return( -1 ); in = t[0];