From 3c1815ea67f03ad01fdfcbce7c245fbc1f9fcf41 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 11 Feb 2014 19:27:25 +0000 Subject: [PATCH] fix vector_to_ink was failing if called on an im under construction --- TODO | 1 + libvips/conversion/insert.c | 28 ++++++++++++++++++++-------- libvips/iofuncs/image.c | 2 ++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/TODO b/TODO index 962d400a..d257ca27 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,4 @@ + - nip2 make check is failing - ink to vec etc. should work for complex .. output or accept a double-length diff --git a/libvips/conversion/insert.c b/libvips/conversion/insert.c index 4582c40c..8e46de8e 100644 --- a/libvips/conversion/insert.c +++ b/libvips/conversion/insert.c @@ -87,7 +87,7 @@ typedef struct _VipsInsert { int x; int y; gboolean expand; - VipsArea *background; + VipsArrayDouble *background; /* Pixel we paint calculated from background. */ @@ -221,6 +221,8 @@ vips__vector_to_ink( const char *domain, VipsImage *im, double *vec, int n ) VipsImage **t = (VipsImage **) vips_object_local_array( VIPS_OBJECT( context ), 6 ); + VipsBandFormat format; + int bands; double *ones; VipsPel *result; int i; @@ -229,12 +231,22 @@ vips__vector_to_ink( const char *domain, VipsImage *im, double *vec, int n ) printf( "vips__vector_to_ink: starting\n" ); #endif /*VIPS_DEBUG*/ - /* The image may be coded .. unpack. + /* We need to know the bands and format we are matching to. But im may + * be coded, so simulate decoding. We can't call vips_image_decode() + * on im, since vips__vector_to_ink() needs to be able to work during + * im's construction and im may not be ready yet. */ - if( vips_image_decode( im, &t[0] ) || - vips_check_vector( domain, n, t[0] ) ) { - g_object_unref( context ); - return( NULL ); + if( im->Coding == VIPS_CODING_LABQ ) { + bands = 3; + format = VIPS_FORMAT_SHORT; + } + else if( im->Coding == VIPS_CODING_RAD ) { + bands = 3; + format = VIPS_FORMAT_FLOAT; + } + else { + bands = im->Bands; + format = im->BandFmt; } ones = VIPS_ARRAY( im, n, double ); @@ -243,9 +255,9 @@ vips__vector_to_ink( const char *domain, VipsImage *im, double *vec, int n ) /* Cast vec to match the decoded image. */ - if( vips_black( &t[1], 1, 1, "bands", t[0]->Bands, NULL ) || + if( vips_black( &t[1], 1, 1, "bands", bands, NULL ) || vips_linear( t[1], &t[2], ones, vec, n, NULL ) || - vips_cast( t[2], &t[3], t[0]->BandFmt, NULL ) ) { + vips_cast( t[2], &t[3], format, NULL ) ) { g_object_unref( context ); return( NULL ); } diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index 05fa210f..d274d83e 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -2012,6 +2012,8 @@ vips_image_write_to_file( VipsImage *image, const char *filename ) int vips_image_decode( VipsImage *in, VipsImage **out ) { + /* Keep in sync with vips__vector_to_ink(). + */ if( in->Coding == VIPS_CODING_LABQ ) { if( vips_LabQ2LabS( in, out, NULL ) ) return( -1 );