From b1f01af01bd00c719ef05f5ba64ab1362385b74b Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 11 Nov 2013 14:28:41 +0000 Subject: [PATCH] add vips_crop() a synonym for vips_extract_area() --- ChangeLog | 1 + TODO | 2 -- libvips/conversion/conversion.c | 2 ++ libvips/conversion/extract.c | 59 +++++++++++++++++++++++++++++++ libvips/include/vips/conversion.h | 3 ++ 5 files changed, 65 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1f65bd3a..1f18dde8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,7 @@ times - radiance load supports sequential read - rewritten radiance decode is much faster +- add vips_crop(), a synonym for vips_extract_area() 18/10/13 started 7.36.3 - fix compiler warnings in ubuntu 13.10 diff --git a/TODO b/TODO index 53c9a406..462018cb 100644 --- a/TODO +++ b/TODO @@ -12,8 +12,6 @@ note on memuse page -- add "crop" as a synonym for "extract_area" - - add vips_gamma(), see rad etc. - do conv and morph quickly as simple wrappers over the vips7 operations diff --git a/libvips/conversion/conversion.c b/libvips/conversion/conversion.c index 56582973..edb5c3e8 100644 --- a/libvips/conversion/conversion.c +++ b/libvips/conversion/conversion.c @@ -206,6 +206,7 @@ vips_conversion_operation_init( void ) extern GType vips_insert_get_type( void ); extern GType vips_join_get_type( void ); extern GType vips_extract_area_get_type( void ); + extern GType vips_crop_get_type( void ); extern GType vips_extract_band_get_type( void ); extern GType vips_replicate_get_type( void ); extern GType vips_cast_get_type( void ); @@ -243,6 +244,7 @@ vips_conversion_operation_init( void ) vips_insert_get_type(); vips_join_get_type(); vips_extract_area_get_type(); + vips_crop_get_type(); vips_extract_band_get_type(); vips_replicate_get_type(); vips_cast_get_type(); diff --git a/libvips/conversion/extract.c b/libvips/conversion/extract.c index 8f674170..aab6c774 100644 --- a/libvips/conversion/extract.c +++ b/libvips/conversion/extract.c @@ -267,6 +267,65 @@ vips_extract_area( VipsImage *in, VipsImage **out, return( result ); } +/* A synonym for extract_area. + */ + +GType +vips_crop_get_type( void ) +{ + static GType type = 0; + + if( !type ) { + static const GTypeInfo info = { + sizeof( VipsExtractAreaClass ), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) vips_extract_area_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof( VipsExtractArea ), + 32, /* n_preallocs */ + (GInstanceInitFunc) vips_extract_area_init, + }; + + type = g_type_register_static( VIPS_TYPE_CONVERSION, + "crop", &info, 0 ); + } + + return( type ); +} + +/** + * vips_crop: + * @in: input image + * @out: output image + * @left: left edge of area to extract + * @top: top edge of area to extract + * @width: width of area to extract + * @height: height of area to extract + * @...: %NULL-terminated list of optional named arguments + * + * A synonym for vips_extract_area(). + * + * See also: vips_extract_bands(). + * + * Returns: 0 on success, -1 on error. + */ +int +vips_crop( VipsImage *in, VipsImage **out, + int left, int top, int width, int height, ... ) +{ + va_list ap; + int result; + + va_start( ap, height ); + result = vips_call_split( "crop", ap, in, out, + left, top, width, height ); + va_end( ap ); + + return( result ); +} + typedef struct _VipsExtractBand { VipsBandary parent_instance; diff --git a/libvips/include/vips/conversion.h b/libvips/include/vips/conversion.h index 611f8846..69dc903c 100644 --- a/libvips/include/vips/conversion.h +++ b/libvips/include/vips/conversion.h @@ -108,6 +108,9 @@ int vips_join( VipsImage *main, VipsImage *sub, VipsImage **out, int vips_extract_area( VipsImage *input, VipsImage **output, int left, int top, int width, int height, ... ) __attribute__((sentinel)); +int vips_crop( VipsImage *input, VipsImage **output, + int left, int top, int width, int height, ... ) + __attribute__((sentinel)); int vips_extract_band( VipsImage *input, VipsImage **output, int band, ... ) __attribute__((sentinel)); int vips_replicate( VipsImage *in, VipsImage **out, int across, int down, ... )