fix vector_to_ink

was failing if called on an im under construction
This commit is contained in:
John Cupitt 2014-02-11 19:27:25 +00:00
parent 025e56c894
commit 3c1815ea67
3 changed files with 23 additions and 8 deletions

1
TODO
View File

@ -1,3 +1,4 @@
- nip2 make check is failing
- ink to vec etc. should work for complex .. output or accept a double-length

View File

@ -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 );
}

View File

@ -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 );