diff --git a/libvips/arithmetic/getpoint.c b/libvips/arithmetic/getpoint.c index 1bbd7fce..a012f001 100644 --- a/libvips/arithmetic/getpoint.c +++ b/libvips/arithmetic/getpoint.c @@ -88,28 +88,35 @@ G_DEFINE_TYPE( VipsGetpoint, vips_getpoint, VIPS_TYPE_OPERATION ); static int vips_getpoint_build( VipsObject *object ) { - VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object ); VipsGetpoint *getpoint = (VipsGetpoint *) object; - VipsImage **t = (VipsImage **) vips_object_local_array( object, 2 ); + VipsImage **t = (VipsImage **) vips_object_local_array( object, 4 ); double *vector; - int n; VipsArrayDouble *out_array; if( VIPS_OBJECT_CLASS( vips_getpoint_parent_class )->build( object ) ) return( -1 ); - t[1] = vips_image_new_memory(); + /* Crop, decode and unpack to double. + */ if( vips_crop( getpoint->in, &t[0], getpoint->x, getpoint->y, 1, 1, NULL ) || - vips_image_write( t[0], t[1] ) ) - return( -1 ); - - if( !(vector = vips__ink_to_vector( class->nickname, - getpoint->in, VIPS_IMAGE_ADDR( t[1], 0, 0 ), &n )) ) + vips_image_decode( t[0], &t[1] ) || + vips_cast( t[1], &t[2], VIPS_FORMAT_DOUBLE, NULL ) ) return( -1 ); - out_array = vips_array_double_new( vector, n ); + /* To a mem buffer, then copy to out. + */ + vips_image_set_int( t[2], "hide-progress", 1 ); + if( !(t[3] = vips_image_new_memory()) || + vips_image_write( t[2], t[3] ) ) + return( -1 ); + + if( !(vector = VIPS_ARRAY( getpoint->in, t[3]->Bands, double )) ) + return( -1 ); + memcpy( vector, t[3]->data, VIPS_IMAGE_SIZEOF_PEL( t[3] ) ); + + out_array = vips_array_double_new( vector, t[3]->Bands ); g_object_set( object, "out_array", out_array, NULL ); diff --git a/libvips/conversion/insert.c b/libvips/conversion/insert.c index 68172a22..5e25c79d 100644 --- a/libvips/conversion/insert.c +++ b/libvips/conversion/insert.c @@ -343,70 +343,6 @@ vips__vector_to_ink( const char *domain, return( result ); } -/* The inverse: take ink to a vec of double. Used in the vips7 compat - * wrappers. Result valid while im is valid. - */ -double * -vips__ink_to_vector( const char *domain, VipsImage *im, VipsPel *ink, int *n ) -{ - VipsImage **t = (VipsImage **) - vips_object_local_array( VIPS_OBJECT( im ), 6 ); - - double *result; - -#ifdef VIPS_DEBUG - printf( "vips__ink_to_vector: starting\n" ); -#endif /*VIPS_DEBUG*/ - - /* Wrap a VipsImage around ink. - */ - t[0] = vips_image_new_from_memory( ink, VIPS_IMAGE_SIZEOF_PEL( im ), - 1, 1, VIPS_IMAGE_SIZEOF_PEL( im ), VIPS_FORMAT_UCHAR ); - if( vips_copy( t[0], &t[1], - "bands", im->Bands, - "format", im->BandFmt, - "coding", im->Coding, - "interpretation", im->Type, - NULL ) ) - return( NULL ); - - /* The image may be coded .. unpack to double. - */ - if( vips_image_decode( t[1], &t[2] ) || - vips_cast( t[2], &t[3], VIPS_FORMAT_DOUBLE, NULL ) ) - return( NULL ); - - /* To a mem buffer, then copy to out. - */ - if( !(t[4] = vips_image_new_memory()) || - vips_image_write( t[3], t[4] ) ) - return( NULL ); - - if( !(result = VIPS_ARRAY( im, t[4]->Bands, double )) ) - return( NULL ); - memcpy( result, t[4]->data, VIPS_IMAGE_SIZEOF_PEL( t[4] ) ); - *n = t[4]->Bands; - -#ifdef VIPS_DEBUG -{ - int i; - - printf( "vips__ink_to_vector:\n" ); - printf( "\tink = " ); - for( i = 0; i < n; i++ ) - printf( "%d ", ink[i] ); - printf( "\n" ); - - printf( "\tvec = " ); - for( i = 0; i < *n; i++ ) - printf( "%g ", result[i] ); - printf( "\n" ); -} -#endif /*VIPS_DEBUG*/ - - return( result ); -} - static int vips_insert_build( VipsObject *object ) { diff --git a/libvips/deprecated/vips7compat.c b/libvips/deprecated/vips7compat.c index b83edc42..202de963 100644 --- a/libvips/deprecated/vips7compat.c +++ b/libvips/deprecated/vips7compat.c @@ -5703,3 +5703,67 @@ vips_popenf( const char *fmt, const char *mode, ... ) return( NULL ); } +/* We used to use this for getpoint(), but since it was the only caller in + * vips8 it's now deprecated. + */ +double * +vips__ink_to_vector( const char *domain, VipsImage *im, VipsPel *ink, int *n ) +{ + VipsImage **t = (VipsImage **) + vips_object_local_array( VIPS_OBJECT( im ), 6 ); + + double *result; + +#ifdef VIPS_DEBUG + printf( "vips__ink_to_vector: starting\n" ); +#endif /*VIPS_DEBUG*/ + + /* Wrap a VipsImage around ink. + */ + t[0] = vips_image_new_from_memory( ink, VIPS_IMAGE_SIZEOF_PEL( im ), + 1, 1, VIPS_IMAGE_SIZEOF_PEL( im ), VIPS_FORMAT_UCHAR ); + if( vips_copy( t[0], &t[1], + "bands", im->Bands, + "format", im->BandFmt, + "coding", im->Coding, + "interpretation", im->Type, + NULL ) ) + return( NULL ); + + /* The image may be coded .. unpack to double. + */ + if( vips_image_decode( t[1], &t[2] ) || + vips_cast( t[2], &t[3], VIPS_FORMAT_DOUBLE, NULL ) ) + return( NULL ); + + /* To a mem buffer, then copy to out. + */ + if( !(t[4] = vips_image_new_memory()) || + vips_image_write( t[3], t[4] ) ) + return( NULL ); + + if( !(result = VIPS_ARRAY( im, t[4]->Bands, double )) ) + return( NULL ); + memcpy( result, t[4]->data, VIPS_IMAGE_SIZEOF_PEL( t[4] ) ); + *n = t[4]->Bands; + +#ifdef VIPS_DEBUG +{ + int i; + + printf( "vips__ink_to_vector:\n" ); + printf( "\tink = " ); + for( i = 0; i < n; i++ ) + printf( "%d ", ink[i] ); + printf( "\n" ); + + printf( "\tvec = " ); + for( i = 0; i < *n; i++ ) + printf( "%g ", result[i] ); + printf( "\n" ); +} +#endif /*VIPS_DEBUG*/ + + return( result ); +} + diff --git a/libvips/include/vips/internal.h b/libvips/include/vips/internal.h index d228d536..f9a18f3e 100644 --- a/libvips/include/vips/internal.h +++ b/libvips/include/vips/internal.h @@ -183,11 +183,6 @@ VipsPel *vips__vector_to_pels( const char *domain, double *real, double *imag, int n ); VipsPel *vips__vector_to_ink( const char *domain, VipsImage *im, double *real, double *imag, int n ); -double *vips__ink_to_vector( const char *domain, - VipsImage *im, VipsPel *ink, int *n ); - -VipsPel *im__vector_to_ink( const char *domain, - VipsImage *im, int n, double *vec ); int vips__draw_flood_direct( VipsImage *image, VipsImage *test, int serial, int x, int y ); diff --git a/libvips/include/vips/vips7compat.h b/libvips/include/vips/vips7compat.h index ac34a710..99bcc10f 100644 --- a/libvips/include/vips/vips7compat.h +++ b/libvips/include/vips/vips7compat.h @@ -1224,6 +1224,12 @@ VipsWindow *vips_window_ref( VipsImage *im, int top, int height ); FILE *vips_popenf( const char *fmt, const char *mode, ... ) __attribute__((format(printf, 1, 3))); +double *vips__ink_to_vector( const char *domain, + VipsImage *im, VipsPel *ink, int *n ); + +VipsPel *im__vector_to_ink( const char *domain, + VipsImage *im, int n, double *vec ); + /* This stuff is very, very old and should not be used by anyone now. */ #ifdef VIPS_ENABLE_ANCIENT