From c0610db15db88d5986758b6c8d288d1741e78b4e Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 30 Sep 2011 13:59:05 +0100 Subject: [PATCH] more VipsImage props expose more fields of VipsImage as props --- ChangeLog | 1 + TODO | 14 +---- libvips/conversion/copy.c | 127 ++++++++++++++++++-------------------- libvips/iofuncs/image.c | 61 ++++++++++++++++++ 4 files changed, 125 insertions(+), 78 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5e15c0b0..7415b14c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,7 @@ - added vips_shutdown() - added --vips-leak flag - added VipsCopy +- more VipsImage props 10/8/11 started 7.26.3 - don't use G_VALUE_COLLECT_INIT(), many platforms do not have a glib this diff --git a/TODO b/TODO index 3f8542a4..726254d4 100644 --- a/TODO +++ b/TODO @@ -1,20 +1,10 @@ -- VipsCopy needs optional params for all header fields it can change - - need a vips_argument_lookup(), see vips_argument_map(), since we need to - be able to find out if an optional arg has been set - - added vips_object_get_argument(), look for use of - g_object_class_find_property() and swap for new thing, then back to copy.c - - operation.c could use it too in places - - copy.c things to set interpretation etc. could go into image.c +- vipscopy how would we do meta sets? copy_swap needs doing too, a separate class I guess - or add a "swap" prop and an enum like VIPS_SWAP8, VIPS_SWAP2 etc.? + or add a "swap" prop? we have a enum for native etc. somewhere diff --git a/libvips/conversion/copy.c b/libvips/conversion/copy.c index 446bf585..0369f402 100644 --- a/libvips/conversion/copy.c +++ b/libvips/conversion/copy.c @@ -109,22 +109,19 @@ */ /* Properties. - * - * Order important! Keep in sync with vips_copy_names[] below. */ enum { PROP_INPUT = 1, + PROP_WIDTH, + PROP_HEIGHT, + PROP_BANDS, + PROP_FORMAT, + PROP_CODING, PROP_INTERPRETATION, PROP_XRES, PROP_YRES, PROP_XOFFSET, PROP_YOFFSET, - PROP_BANDS, - PROP_FORMAT, - PROP_CODING, - PROP_WIDTH, - PROP_HEIGHT, - PROP_LAST }; @@ -178,18 +175,16 @@ vips_copy_gen( VipsRegion *or, void *seq, void *a, void *b, gboolean *stop ) /* The props we copy, if set, from the operation to the image. */ static const char *vips_copy_names[] = { - NULL, /* unused */ - NULL, /* PROP_INPUT = 1 */ - "interpretation", /* PROP_INTERPRETATION, */ - "xres", /* PROP_XRES, */ - "yres", /* PROP_YRES, */ - "xoffset", /* PROP_XOFFSET, */ - "xoffset", /* PROP_YOFFSET, */ - "bands", /* PROP_BANDS, */ - "format", /* PROP_FORMAT, */ - "coding", /* PROP_CODING, */ - "width", /* PROP_WIDTH, */ - "height" /* PROP_HEIGHT, */ + "interpretation", + "xres", + "yres", + "xoffset", + "xoffset", + "bands", + "format", + "coding", + "width", + "height" }; static int @@ -214,7 +209,7 @@ vips_copy_build( VipsObject *object ) /* Use props to adjust header fields. */ - for( i = 2; i < PROP_LAST; i++ ) { + for( i = 0; i < VIPS_NUMBER( vips_copy_names ); i++ ) { const char *name = vips_copy_names[i]; GParamSpec *pspec; @@ -274,6 +269,51 @@ vips_copy_class_init( VipsCopyClass *class ) VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsCopy, input ) ); + pspec = g_param_spec_int( "width", "Width", + _( "Image width in pixels" ), + 0, 1000000, 0, + G_PARAM_READWRITE ); + g_object_class_install_property( gobject_class, PROP_WIDTH, pspec ); + vips_object_class_install_argument( vobject_class, pspec, + VIPS_ARGUMENT_SET_ONCE, + G_STRUCT_OFFSET( VipsCopy, width ) ); + + pspec = g_param_spec_int( "height", "Height", + _( "Image height in pixels" ), + 0, 1000000, 0, + G_PARAM_READWRITE ); + g_object_class_install_property( gobject_class, PROP_HEIGHT, pspec ); + vips_object_class_install_argument( vobject_class, pspec, + VIPS_ARGUMENT_SET_ONCE, + G_STRUCT_OFFSET( VipsCopy, height ) ); + + pspec = g_param_spec_int( "bands", "Bands", + _( "Number of bands in image" ), + 0, 1000000, 0, + G_PARAM_READWRITE ); + g_object_class_install_property( gobject_class, PROP_BANDS, pspec ); + vips_object_class_install_argument( vobject_class, pspec, + VIPS_ARGUMENT_SET_ONCE, + G_STRUCT_OFFSET( VipsCopy, bands ) ); + + pspec = g_param_spec_enum( "format", "Format", + _( "Pixel format in image" ), + VIPS_TYPE_BAND_FORMAT, VIPS_FORMAT_UCHAR, + G_PARAM_READWRITE ); + g_object_class_install_property( gobject_class, PROP_FORMAT, pspec ); + vips_object_class_install_argument( vobject_class, pspec, + VIPS_ARGUMENT_SET_ONCE, + G_STRUCT_OFFSET( VipsCopy, format ) ); + + pspec = g_param_spec_enum( "coding", "Coding", + _( "Pixel coding" ), + VIPS_TYPE_CODING, VIPS_CODING_NONE, + G_PARAM_READWRITE ); + g_object_class_install_property( gobject_class, PROP_CODING, pspec ); + vips_object_class_install_argument( vobject_class, pspec, + VIPS_ARGUMENT_SET_ONCE, + G_STRUCT_OFFSET( VipsCopy, coding ) ); + pspec = g_param_spec_enum( "interpretation", "Interpretation", _( "Pixel interpretation" ), VIPS_TYPE_INTERPRETATION, VIPS_INTERPRETATION_MULTIBAND, @@ -320,51 +360,6 @@ vips_copy_class_init( VipsCopyClass *class ) VIPS_ARGUMENT_SET_ONCE, G_STRUCT_OFFSET( VipsCopy, yoffset ) ); - pspec = g_param_spec_int( "bands", "Bands", - _( "Number of bands in image" ), - 0, 1000000, 0, - G_PARAM_READWRITE ); - g_object_class_install_property( gobject_class, PROP_BANDS, pspec ); - vips_object_class_install_argument( vobject_class, pspec, - VIPS_ARGUMENT_SET_ONCE, - G_STRUCT_OFFSET( VipsCopy, bands ) ); - - pspec = g_param_spec_enum( "format", "Format", - _( "Pixel format in image" ), - VIPS_TYPE_BAND_FORMAT, VIPS_FORMAT_UCHAR, - G_PARAM_READWRITE ); - g_object_class_install_property( gobject_class, PROP_FORMAT, pspec ); - vips_object_class_install_argument( vobject_class, pspec, - VIPS_ARGUMENT_SET_ONCE, - G_STRUCT_OFFSET( VipsCopy, format ) ); - - pspec = g_param_spec_enum( "coding", "Coding", - _( "Pixel coding" ), - VIPS_TYPE_CODING, VIPS_CODING_NONE, - G_PARAM_READWRITE ); - g_object_class_install_property( gobject_class, PROP_FORMAT, pspec ); - vips_object_class_install_argument( vobject_class, pspec, - VIPS_ARGUMENT_SET_ONCE, - G_STRUCT_OFFSET( VipsCopy, coding ) ); - - pspec = g_param_spec_int( "width", "Width", - _( "Image width in pixels" ), - 0, 1000000, 0, - G_PARAM_READWRITE ); - g_object_class_install_property( gobject_class, PROP_WIDTH, pspec ); - vips_object_class_install_argument( vobject_class, pspec, - VIPS_ARGUMENT_SET_ONCE, - G_STRUCT_OFFSET( VipsCopy, width ) ); - - pspec = g_param_spec_int( "height", "Height", - _( "Image height in pixels" ), - 0, 1000000, 0, - G_PARAM_READWRITE ); - g_object_class_install_property( gobject_class, PROP_HEIGHT, pspec ); - vips_object_class_install_argument( vobject_class, pspec, - VIPS_ARGUMENT_SET_ONCE, - G_STRUCT_OFFSET( VipsCopy, height ) ); - } static void diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index 13ba9139..23c08075 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -150,6 +150,12 @@ enum { PROP_HEIGHT, PROP_BANDS, PROP_FORMAT, + PROP_CODING, + PROP_INTERPRETATION, + PROP_XRES, + PROP_YRES, + PROP_XOFFSET, + PROP_YOFFSET, PROP_FILENAME, PROP_KILL, PROP_MODE, @@ -1002,6 +1008,61 @@ vips_image_class_init( VipsImageClass *class ) VIPS_ARGUMENT_SET_ONCE, G_STRUCT_OFFSET( VipsImage, BandFmt ) ); + pspec = g_param_spec_enum( "coding", "Coding", + _( "Pixel coding" ), + VIPS_TYPE_CODING, VIPS_CODING_NONE, + G_PARAM_READWRITE ); + g_object_class_install_property( gobject_class, PROP_CODING, pspec ); + vips_object_class_install_argument( vobject_class, pspec, + VIPS_ARGUMENT_SET_ONCE, + G_STRUCT_OFFSET( VipsImage, Coding ) ); + + pspec = g_param_spec_enum( "interpretation", "Interpretation", + _( "Pixel interpretation" ), + VIPS_TYPE_INTERPRETATION, VIPS_INTERPRETATION_MULTIBAND, + G_PARAM_READWRITE ); + g_object_class_install_property( gobject_class, + PROP_INTERPRETATION, pspec ); + vips_object_class_install_argument( vobject_class, pspec, + VIPS_ARGUMENT_SET_ONCE, + G_STRUCT_OFFSET( VipsImage, Type ) ); + + pspec = g_param_spec_double( "xres", "XRes", + _( "Horizontal resolution in pixels/mm" ), + 0, 1000000, 0, + G_PARAM_READWRITE ); + g_object_class_install_property( gobject_class, PROP_XRES, pspec ); + vips_object_class_install_argument( vobject_class, pspec, + VIPS_ARGUMENT_SET_ONCE, + G_STRUCT_OFFSET( VipsImage, Xres ) ); + + pspec = g_param_spec_double( "yres", "YRes", + _( "Vertical resolution in pixels/mm" ), + 0, 1000000, 0, + G_PARAM_READWRITE ); + g_object_class_install_property( gobject_class, PROP_YRES, pspec ); + vips_object_class_install_argument( vobject_class, pspec, + VIPS_ARGUMENT_SET_ONCE, + G_STRUCT_OFFSET( VipsImage, Yres ) ); + + pspec = g_param_spec_int( "xoffset", "XOffset", + _( "Horizontal offset of origin" ), + -10000000, 1000000, 0, + G_PARAM_READWRITE ); + g_object_class_install_property( gobject_class, PROP_XOFFSET, pspec ); + vips_object_class_install_argument( vobject_class, pspec, + VIPS_ARGUMENT_SET_ONCE, + G_STRUCT_OFFSET( VipsImage, Xoffset ) ); + + pspec = g_param_spec_int( "yoffset", "YOffset", + _( "Vertical offset of origin" ), + -10000000, 1000000, 0, + G_PARAM_READWRITE ); + g_object_class_install_property( gobject_class, PROP_YOFFSET, pspec ); + vips_object_class_install_argument( vobject_class, pspec, + VIPS_ARGUMENT_SET_ONCE, + G_STRUCT_OFFSET( VipsImage, Yoffset ) ); + pspec = g_param_spec_string( "filename", "Filename", _( "Image filename" ), NULL,