From c35e2e5427b5c5a1c97bfcff7069c0996d9960f8 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 2 Jun 2015 13:32:48 +0100 Subject: [PATCH] add RefString getter to python now unpacks VipsRefString on get_value() --- ChangeLog | 1 + TODO | 2 ++ libvips/include/vips/type.h | 6 ++++++ libvips/iofuncs/type.c | 22 ++++++++++++++++++++++ python/Vips.py | 1 + 5 files changed, 32 insertions(+) diff --git a/ChangeLog b/ChangeLog index 887f8456..0af100b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ - vips_copy() can turn 1xN or Nx1 M-band images into MxN one-band images - added bandand() bandor() bandeor() convenience funcs to Python - oops, base64 encode could pad by up to two zero bytes +- added VipsRefString as a thing that gi bindings can unpack 7/5/15 started 8.0.3 - dzsave and tif pyr write could fail for some image dimensions, thanks Jonas diff --git a/TODO b/TODO index 1e1ac37e..6094c1ac 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,5 @@ +- does ruby need to unpack RefString as well? what about C++? + - how about something like vips_grid() which turns a tall thin one-band image into a much smaller many-band image? diff --git a/libvips/include/vips/type.h b/libvips/include/vips/type.h index fab060ab..16e0e4d4 100644 --- a/libvips/include/vips/type.h +++ b/libvips/include/vips/type.h @@ -135,6 +135,12 @@ GType vips_save_string_get_type( void ); * The #GType for a #VipsRefString. */ #define VIPS_TYPE_REF_STRING (vips_ref_string_get_type()) + +typedef struct _VipsRefString { + VipsArea area; +} VipsRefString; + +const char *vips_ref_string_get( VipsRefString *refstr, size_t *length ); GType vips_ref_string_get_type( void ); /** diff --git a/libvips/iofuncs/type.c b/libvips/iofuncs/type.c index 4f0aab8b..6501e130 100644 --- a/libvips/iofuncs/type.c +++ b/libvips/iofuncs/type.c @@ -502,6 +502,28 @@ transform_save_string_ref_string( const GValue *src_value, GValue *dest_value ) vips_value_get_save_string( src_value ) ); } +/** + * vips_ref_string_get: + * @refstr: the #VipsRefString to fetch from + * @length: (allow-none): return length here, optionally + * + * Get a pointer to the private string inside a refstr. Handy for language + * bindings. + * + * See also: vips_value_get_ref_string(). + * + * Returns: (transfer none): The C string held by @refstr. + */ +const char * +vips_ref_string_get( VipsRefString *refstr, size_t *length ) +{ + VipsArea *area = VIPS_AREA( refstr ); + + g_assert( area->type == G_TYPE_DOUBLE ); + + return( vips_area_get_data( area, length, NULL, NULL, NULL ) ); +} + GType vips_ref_string_get_type( void ) { diff --git a/python/Vips.py b/python/Vips.py index a739d290..95e6d0fc 100644 --- a/python/Vips.py +++ b/python/Vips.py @@ -95,6 +95,7 @@ def imageize(match_image, value): # bytes(). unpack_types = [[Vips.Blob, lambda x: bytes(x.get())], + [Vips.RefString, lambda x: x.get()], [Vips.ArrayDouble, lambda x: x.get()], [Vips.ArrayImage, lambda x: x.get()], [Vips.ArrayInt, lambda x: x.get()]]