From e7efa8e6f2dd967b294776926322f648430dd6b7 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 23 Jan 2014 16:51:32 +0000 Subject: [PATCH] more auto-decode --- ChangeLog | 2 +- TODO | 29 ++--------------------------- libvips/conversion/flatten.c | 21 ++++++++++++++------- libvips/conversion/recomb.c | 21 ++++++++++++++------- libvips/freqfilt/fwfft.c | 17 +++++++++++++---- libvips/freqfilt/invfft.c | 15 ++++++++++++--- libvips/histogram/hist_local.c | 12 ++++++++---- libvips/histogram/histogram.c | 11 ++++++----- libvips/histogram/stdif.c | 12 ++++++++---- 9 files changed, 78 insertions(+), 62 deletions(-) diff --git a/ChangeLog b/ChangeLog index 16cbc04d..069a8d63 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,5 @@ 21/1/14 started 7.39.0 -- fancy auto-decode for all operations +- auto-decode for (almost) all operations 22/1/14 started 7.38.2 - auto RAD decode for affine diff --git a/TODO b/TODO index 733fbad8..b0d478f2 100644 --- a/TODO +++ b/TODO @@ -8,35 +8,10 @@ problem in 7.38 too +- vips_colourspace() needs an option from_space param,? + - check_uncoded() left to do: - conversion/falsecolour.c - conversion/flatten.c - conversion/recomb.c - convolution/sharpen.c - deprecated/im_gradcor.c - deprecated/im_lab_morph.c - deprecated/im_maxpos_avg.c - deprecated/im_measure.c - deprecated/im_vips2mask.c - deprecated/im_zerox.c - deprecated/rename.c - deprecated/tone.c - deprecated/vips7compat.c - foreign/csv.c - foreign/ppm.c - freqfilt/fwfft.c - freqfilt/invfft.c - histogram/hist_local.c - histogram/histogram.c - histogram/hist_plot.c - histogram/maplut.c - histogram/stdif.c - inplace/flood.c - inplace/im_draw_mask.c - inplace/inplace_dispatch.c - iofuncs/error.c - morphology/hitmiss.c resample/quadratic.c - we vips_image_write() a lot, could we do this by diff --git a/libvips/conversion/flatten.c b/libvips/conversion/flatten.c index 889844a9..1bf4626e 100644 --- a/libvips/conversion/flatten.c +++ b/libvips/conversion/flatten.c @@ -300,24 +300,31 @@ vips_flatten_build( VipsObject *object ) VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object ); VipsConversion *conversion = VIPS_CONVERSION( object ); VipsFlatten *flatten = (VipsFlatten *) object; + VipsImage **t = (VipsImage **) vips_object_local_array( object, 1 ); + + VipsImage *in; int i; gboolean black; if( VIPS_OBJECT_CLASS( vips_flatten_parent_class )->build( object ) ) return( -1 ); + in = flatten->in; + + if( vips__image_decode( in, &t[0] ) ) + return( -1 ); + in = t[0]; + /* Trivial case: fall back to copy(). */ if( flatten->in->Bands == 1 ) - return( vips_image_write( flatten->in, conversion->out ) ); + return( vips_image_write( in, conversion->out ) ); - if( vips_check_uncoded( class->nickname, flatten->in ) || - vips_check_noncomplex( class->nickname, flatten->in ) || - vips_image_pio_input( flatten->in ) ) + if( vips_check_noncomplex( class->nickname, in ) ) return( -1 ); if( vips_image_pipelinev( conversion->out, - VIPS_DEMAND_STYLE_THINSTRIP, flatten->in, NULL ) ) + VIPS_DEMAND_STYLE_THINSTRIP, in, NULL ) ) return( -1 ); conversion->out->Bands -= 1; @@ -334,7 +341,7 @@ vips_flatten_build( VipsObject *object ) if( black ) { if( vips_image_generate( conversion->out, vips_start_one, vips_flatten_black_gen, vips_stop_one, - flatten->in, flatten ) ) + in, flatten ) ) return( -1 ); } else { @@ -347,7 +354,7 @@ vips_flatten_build( VipsObject *object ) if( vips_image_generate( conversion->out, vips_start_one, vips_flatten_gen, vips_stop_one, - flatten->in, flatten ) ) + in, flatten ) ) return( -1 ); } diff --git a/libvips/conversion/recomb.c b/libvips/conversion/recomb.c index 9158af0a..0e39beb9 100644 --- a/libvips/conversion/recomb.c +++ b/libvips/conversion/recomb.c @@ -50,6 +50,7 @@ #include #include +#include #include "pconversion.h" @@ -142,19 +143,25 @@ vips_recomb_build( VipsObject *object ) VipsRecomb *recomb = (VipsRecomb *) object; VipsImage **t = (VipsImage **) vips_object_local_array( object, 2 ); + VipsImage *in; + if( VIPS_OBJECT_CLASS( vips_recomb_parent_class )->build( object ) ) return( -1 ); - if( vips_image_pio_input( recomb->in ) || - vips_check_uncoded( class->nickname, recomb->in ) || - vips_check_noncomplex( class->nickname, recomb->in ) ) + in = recomb->in; + + if( vips__image_decode( in, &t[0] ) ) + return( -1 ); + in = t[0]; + + if( vips_check_noncomplex( class->nickname, in ) ) return( -1 ); if( vips_image_pio_input( recomb->m ) || vips_check_uncoded( class->nickname, recomb->m ) || vips_check_noncomplex( class->nickname, recomb->m ) || vips_check_mono( class->nickname, recomb->m ) ) return( -1 ); - if( recomb->in->Bands != recomb->m->Xsize ) { + if( in->Bands != recomb->m->Xsize ) { vips_error( class->nickname, "%s", _( "bands in must equal matrix width" ) ); return( -1 ); @@ -165,16 +172,16 @@ vips_recomb_build( VipsObject *object ) recomb->coeff = t[0]; if( vips_image_pipelinev( conversion->out, - VIPS_DEMAND_STYLE_THINSTRIP, recomb->in, NULL ) ) + VIPS_DEMAND_STYLE_THINSTRIP, in, NULL ) ) return( -1 ); conversion->out->Bands = recomb->m->Ysize; - if( vips_bandfmt_isint( recomb->in->BandFmt ) ) + if( vips_bandfmt_isint( in->BandFmt ) ) conversion->out->BandFmt = VIPS_FORMAT_FLOAT; if( vips_image_generate( conversion->out, vips_start_one, vips_recomb_gen, vips_stop_one, - recomb->in, recomb ) ) + in, recomb ) ) return( -1 ); return( 0 ); diff --git a/libvips/freqfilt/fwfft.c b/libvips/freqfilt/fwfft.c index 3c9fd8b2..813a5cc1 100644 --- a/libvips/freqfilt/fwfft.c +++ b/libvips/freqfilt/fwfft.c @@ -75,6 +75,7 @@ #include #include +#include #include "pfreqfilt.h" #ifdef HAVE_FFTW @@ -294,22 +295,30 @@ vips_fwfft_build( VipsObject *object ) VipsFwfft *fwfft = (VipsFwfft *) object; VipsImage **t = (VipsImage **) vips_object_local_array( object, 4 ); + VipsImage *in; + if( VIPS_OBJECT_CLASS( vips_fwfft_parent_class )-> build( object ) ) return( -1 ); - if( vips_bandfmt_iscomplex( freqfilt->in->BandFmt ) ) { - if( vips__fftproc( VIPS_OBJECT( fwfft ), freqfilt->in, &t[0], + in = freqfilt->in; + + if( vips__image_decode( in, &t[0] ) ) + return( -1 ); + in = t[0]; + + if( vips_bandfmt_iscomplex( in->BandFmt ) ) { + if( vips__fftproc( VIPS_OBJECT( fwfft ), in, &t[1], cfwfft1 ) ) return( -1 ); } else { - if( vips__fftproc( VIPS_OBJECT( fwfft ), freqfilt->in, &t[0], + if( vips__fftproc( VIPS_OBJECT( fwfft ), in, &t[1], rfwfft1 ) ) return( -1 ); } - if( vips_image_write( t[0], freqfilt->out ) ) + if( vips_image_write( t[1], freqfilt->out ) ) return( -1 ); return( 0 ); diff --git a/libvips/freqfilt/invfft.c b/libvips/freqfilt/invfft.c index 30ea23a9..8b8611ee 100644 --- a/libvips/freqfilt/invfft.c +++ b/libvips/freqfilt/invfft.c @@ -64,6 +64,7 @@ #include #include +#include #include "pfreqfilt.h" #ifdef HAVE_FFTW @@ -207,22 +208,30 @@ vips_invfft_build( VipsObject *object ) VipsInvfft *invfft = (VipsInvfft *) object; VipsImage **t = (VipsImage **) vips_object_local_array( object, 4 ); + VipsImage *in; + if( VIPS_OBJECT_CLASS( vips_invfft_parent_class )-> build( object ) ) return( -1 ); + in = freqfilt->in; + + if( vips__image_decode( in, &t[0] ) ) + return( -1 ); + in = t[0]; + if( invfft->real ) { if( vips__fftproc( VIPS_OBJECT( invfft ), - freqfilt->in, &t[0], rinvfft1 ) ) + in, &t[1], rinvfft1 ) ) return( -1 ); } else { if( vips__fftproc( VIPS_OBJECT( invfft ), - freqfilt->in, &t[0], cinvfft1 ) ) + in, &t[1], cinvfft1 ) ) return( -1 ); } - if( vips_image_write( t[0], freqfilt->out ) ) + if( vips_image_write( t[1], freqfilt->out ) ) return( -1 ); return( 0 ); diff --git a/libvips/histogram/hist_local.c b/libvips/histogram/hist_local.c index c9ee1b06..9243ec05 100644 --- a/libvips/histogram/hist_local.c +++ b/libvips/histogram/hist_local.c @@ -60,6 +60,7 @@ #include #include +#include typedef struct _VipsHistLocal { VipsOperation parent_instance; @@ -235,8 +236,11 @@ vips_hist_local_build( VipsObject *object ) in = local->in; - if( vips_check_uncoded( class->nickname, in ) || - vips_check_format( class->nickname, in, VIPS_FORMAT_UCHAR ) ) + if( vips__image_decode( in, &t[0] ) ) + return( -1 ); + in = t[0]; + + if( vips_check_format( class->nickname, in, VIPS_FORMAT_UCHAR ) ) return( -1 ); if( local->width > in->Xsize || @@ -247,13 +251,13 @@ vips_hist_local_build( VipsObject *object ) /* Expand the input. */ - if( vips_embed( in, &t[0], + if( vips_embed( in, &t[1], local->width / 2, local->height / 2, in->Xsize + local->width - 1, in->Ysize + local->height - 1, "extend", VIPS_EXTEND_COPY, NULL ) ) return( -1 ); - in = t[0]; + in = t[1]; g_object_set( object, "out", vips_image_new(), NULL ); diff --git a/libvips/histogram/histogram.c b/libvips/histogram/histogram.c index e57fe2e5..8064dfa7 100644 --- a/libvips/histogram/histogram.c +++ b/libvips/histogram/histogram.c @@ -111,6 +111,7 @@ vips_histogram_build( VipsObject *object ) VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object ); VipsHistogramClass *hclass = VIPS_HISTOGRAM_GET_CLASS( histogram ); + VipsImage **decode; VipsImage **format; VipsImage **band; VipsImage **size; @@ -134,6 +135,7 @@ vips_histogram_build( VipsObject *object ) */ g_assert( !histogram->in[histogram->n] ); + decode = (VipsImage **) vips_object_local_array( object, histogram->n ); format = (VipsImage **) vips_object_local_array( object, histogram->n ); band = (VipsImage **) vips_object_local_array( object, histogram->n ); size = (VipsImage **) vips_object_local_array( object, histogram->n ); @@ -141,8 +143,8 @@ vips_histogram_build( VipsObject *object ) g_object_set( histogram, "out", vips_image_new(), NULL ); for( i = 0; i < histogram->n; i++ ) - if( vips_check_uncoded( class->nickname, histogram->in[i] ) || - vips_check_hist( class->nickname, histogram->in[i] ) ) + if( vips__image_decode( histogram->in[i], &decode[i] ) || + vips_check_hist( class->nickname, decode[i] ) ) return( -1 ); /* Cast our input images up to a common format, bands and size. If @@ -150,13 +152,12 @@ vips_histogram_build( VipsObject *object ) */ if( hclass->input_format != VIPS_FORMAT_NOTSET ) { for( i = 0; i < histogram->n; i++ ) - if( vips_cast( histogram->in[i], &format[i], + if( vips_cast( decode[i], &format[i], hclass->input_format, NULL ) ) return( -1 ); } else { - if( vips__formatalike_vec( histogram->in, - format, histogram->n ) ) + if( vips__formatalike_vec( decode, format, histogram->n ) ) return( -1 ); } diff --git a/libvips/histogram/stdif.c b/libvips/histogram/stdif.c index 59e0fe95..0406bbd2 100644 --- a/libvips/histogram/stdif.c +++ b/libvips/histogram/stdif.c @@ -64,6 +64,7 @@ #include #include +#include typedef struct _VipsStdif { VipsOperation parent_instance; @@ -223,8 +224,11 @@ vips_stdif_build( VipsObject *object ) in = stdif->in; - if( vips_check_uncoded( class->nickname, in ) || - vips_check_format( class->nickname, in, VIPS_FORMAT_UCHAR ) ) + if( vips__image_decode( in, &t[0] ) ) + return( -1 ); + in = t[0]; + + if( vips_check_format( class->nickname, in, VIPS_FORMAT_UCHAR ) ) return( -1 ); if( stdif->width > in->Xsize || @@ -239,13 +243,13 @@ vips_stdif_build( VipsObject *object ) /* Expand the input. */ - if( vips_embed( in, &t[0], + if( vips_embed( in, &t[1], stdif->width / 2, stdif->height / 2, in->Xsize + stdif->width - 1, in->Ysize + stdif->height - 1, "extend", VIPS_EXTEND_COPY, NULL ) ) return( -1 ); - in = t[0]; + in = t[1]; g_object_set( object, "out", vips_image_new(), NULL );