From 42dac9209a0a8e73f8f8573f9637ace76b364fdb Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 29 Aug 2014 18:14:22 +0100 Subject: [PATCH] GBoxed almost working --- TODO | 24 +++++++++ libvips/iofuncs/type.c | 120 ++++++++++++++++++++++------------------- python/try2.py | 8 ++- 3 files changed, 94 insertions(+), 58 deletions(-) diff --git a/TODO b/TODO index 29ee2780..6133c00f 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,27 @@ +- python: + + - add more constructors + + - need the filename splitter + + - need more writers + + - need GBoxed + + seems to be almost there! + + we have: + + a = Vips.array_double_new([1,2,3]) + + but no VipsArrayDouble type, strangely + + VipsThing is there? odd + + seems be have spotted that it's just an alias for VipsArea and + elided the type + + - can we pick the vipsthumbnail int shrink factor more intelligently? - vips_resize() should use vipsthumbnail's block/cache/affine/sharpen chain diff --git a/libvips/iofuncs/type.c b/libvips/iofuncs/type.c index 897f55cc..48be7e81 100644 --- a/libvips/iofuncs/type.c +++ b/libvips/iofuncs/type.c @@ -688,6 +688,70 @@ vips_array_int_get_type( void ) return( type ); } +/** + * vips_array_double_new: + * @array: (array length=n): array of double + * @n: number of doubles + * + * Allocate a new array of doubles and copy @array into it. Free with + * vips_area_unref(). + * + * See also: #VipsArea. + * + * Returns: (transfer full): A new #VipsArrayDouble. + */ +VipsArrayDouble * +vips_array_double_new( const double *array, int n ) +{ + VipsArea *area; + double *array_copy; + + area = vips_area_new_array( G_TYPE_DOUBLE, sizeof( double ), n ); + array_copy = vips_area_get_data( area, NULL, NULL, NULL, NULL ); + memcpy( array_copy, array, n * sizeof( double ) ); + +{ + int i; + + printf( "vips_array_double_new: %p\n", area ); + for( i = 0; i < n; i++ ) + printf( "\t%d) %g\n", i, array[i] ); +} + + return( area ); +} + +/** + * vips_array_double_newv: + * @n: number of doubles + * @...: list of double arguments + * + * Allocate a new array of @n doubles and copy @... into it. Free with + * vips_area_unref(). + * + * See also: vips_array_double_new() + * + * Returns: (transfer full): A new #VipsArrayDouble. + */ +VipsArrayDouble * +vips_array_double_newv( int n, ... ) +{ + va_list ap; + VipsArea *area; + double *array; + int i; + + area = vips_area_new_array( G_TYPE_DOUBLE, sizeof( double ), n ); + array = vips_area_get_data( area, NULL, NULL, NULL, NULL ); + + va_start( ap, n ); + for( i = 0; i < n; i++ ) + array[i] = va_arg( ap, double ); + va_end( ap ); + + return( area ); +} + static void transform_array_double_g_string( const GValue *src_value, GValue *dest_value ) { @@ -1179,62 +1243,6 @@ vips_value_set_array_int( GValue *value, const int *array, int n ) return( 0 ); } -/** - * vips_array_double_new: - * @array: (array length=n): array of double - * @n: number of doubles - * - * Allocate a new array of doubles and copy @array into it. Free with - * vips_area_unref(). - * - * See also: #VipsArea. - * - * Returns: (transfer full): A new #VipsArrayDouble. - */ -VipsArrayDouble * -vips_array_double_new( const double *array, int n ) -{ - VipsArea *area; - double *array_copy; - - area = vips_area_new_array( G_TYPE_DOUBLE, sizeof( double ), n ); - array_copy = vips_area_get_data( area, NULL, NULL, NULL, NULL ); - memcpy( array_copy, array, n * sizeof( double ) ); - - return( area ); -} - -/** - * vips_array_double_newv: - * @n: number of doubles - * @...: list of double arguments - * - * Allocate a new array of @n doubles and copy @... into it. Free with - * vips_area_unref(). - * - * See also: vips_array_double_new() - * - * Returns: (transfer full): A new #VipsArrayDouble. - */ -VipsArrayDouble * -vips_array_double_newv( int n, ... ) -{ - va_list ap; - VipsArea *area; - double *array; - int i; - - area = vips_area_new_array( G_TYPE_DOUBLE, sizeof( double ), n ); - array = vips_area_get_data( area, NULL, NULL, NULL, NULL ); - - va_start( ap, n ); - for( i = 0; i < n; i++ ) - array[i] = va_arg( ap, double ); - va_end( ap ); - - return( area ); -} - /** * vips_value_get_array_double: * @value: %GValue to get from diff --git a/python/try2.py b/python/try2.py index e76e8191..b33913d2 100755 --- a/python/try2.py +++ b/python/try2.py @@ -27,5 +27,9 @@ out = a.add(b) print 'out =', out -# we need to get GBoxed working for this -#out = a.linear(1, 2) +ones = Vips.array_double_new([1]) +twos = Vips.array_double_new([2]) + +out = out.linear(ones, twos) + +out.write_to_file("x.v")