From d1f5225e581f06cf247ce1ad0e0c49b43d8e2522 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 27 Jan 2012 17:36:25 +0000 Subject: [PATCH] more robust char->enum edvips has much safer char->enum conversion --- TODO | 2 +- libvips/include/vips/image.h | 4 ++++ libvips/iofuncs/enumtypes.c | 4 ++++ tools/edvips.c | 20 +++++++++++++++----- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index 3bc6574d..0f7209e6 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,5 @@ - viewing an image tagged as fourier in nip2 is broken, which operation is - failing? + failing? im_abs()? - add a fft test to the suite diff --git a/libvips/include/vips/image.h b/libvips/include/vips/image.h index ff8736f8..601bb22e 100644 --- a/libvips/include/vips/image.h +++ b/libvips/include/vips/image.h @@ -85,6 +85,7 @@ extern "C" { * See also: vips_demand_hint(). */ typedef enum { + VIPS_DEMAND_STYLE_ERROR = -1, VIPS_DEMAND_STYLE_SMALLTILE, VIPS_DEMAND_STYLE_FATSTRIP, VIPS_DEMAND_STYLE_THINSTRIP, @@ -95,6 +96,7 @@ typedef enum { * does not imply that any fields in IMAGE have valid data. */ typedef enum { + VIPS_IMAGE_ERROR = -1, VIPS_IMAGE_NONE, /* no type set */ VIPS_IMAGE_SETBUF, /* malloced memory array */ VIPS_IMAGE_SETBUF_FOREIGN, /* memory array, don't free on close */ @@ -137,6 +139,7 @@ typedef enum { * new numbers from the end. */ typedef enum { + VIPS_INTERPRETATION_ERROR = -1, VIPS_INTERPRETATION_MULTIBAND = 0, VIPS_INTERPRETATION_B_W = 1, VIPS_INTERPRETATION_HISTOGRAM = 10, @@ -206,6 +209,7 @@ typedef enum { * new numbers from the end. */ typedef enum { + VIPS_CODING_ERROR = -1, VIPS_CODING_NONE = 0, VIPS_CODING_LABQ = 2, VIPS_CODING_RAD = 6, diff --git a/libvips/iofuncs/enumtypes.c b/libvips/iofuncs/enumtypes.c index 4199bd8f..1e58c360 100644 --- a/libvips/iofuncs/enumtypes.c +++ b/libvips/iofuncs/enumtypes.c @@ -356,6 +356,7 @@ vips_demand_style_get_type( void ) if( etype == 0 ) { static const GEnumValue values[] = { + {VIPS_DEMAND_STYLE_ERROR, "VIPS_DEMAND_STYLE_ERROR", "error"}, {VIPS_DEMAND_STYLE_SMALLTILE, "VIPS_DEMAND_STYLE_SMALLTILE", "smalltile"}, {VIPS_DEMAND_STYLE_FATSTRIP, "VIPS_DEMAND_STYLE_FATSTRIP", "fatstrip"}, {VIPS_DEMAND_STYLE_THINSTRIP, "VIPS_DEMAND_STYLE_THINSTRIP", "thinstrip"}, @@ -375,6 +376,7 @@ vips_image_type_get_type( void ) if( etype == 0 ) { static const GEnumValue values[] = { + {VIPS_IMAGE_ERROR, "VIPS_IMAGE_ERROR", "error"}, {VIPS_IMAGE_NONE, "VIPS_IMAGE_NONE", "none"}, {VIPS_IMAGE_SETBUF, "VIPS_IMAGE_SETBUF", "setbuf"}, {VIPS_IMAGE_SETBUF_FOREIGN, "VIPS_IMAGE_SETBUF_FOREIGN", "setbuf-foreign"}, @@ -398,6 +400,7 @@ vips_interpretation_get_type( void ) if( etype == 0 ) { static const GEnumValue values[] = { + {VIPS_INTERPRETATION_ERROR, "VIPS_INTERPRETATION_ERROR", "error"}, {VIPS_INTERPRETATION_MULTIBAND, "VIPS_INTERPRETATION_MULTIBAND", "multiband"}, {VIPS_INTERPRETATION_B_W, "VIPS_INTERPRETATION_B_W", "b-w"}, {VIPS_INTERPRETATION_HISTOGRAM, "VIPS_INTERPRETATION_HISTOGRAM", "histogram"}, @@ -457,6 +460,7 @@ vips_coding_get_type( void ) if( etype == 0 ) { static const GEnumValue values[] = { + {VIPS_CODING_ERROR, "VIPS_CODING_ERROR", "error"}, {VIPS_CODING_NONE, "VIPS_CODING_NONE", "none"}, {VIPS_CODING_LABQ, "VIPS_CODING_LABQ", "labq"}, {VIPS_CODING_RAD, "VIPS_CODING_RAD", "rad"}, diff --git a/tools/edvips.c b/tools/edvips.c index 7b781706..e755898f 100644 --- a/tools/edvips.c +++ b/tools/edvips.c @@ -176,17 +176,27 @@ main( int argc, char **argv ) if( bands ) parse_pint( bands, &im->Bands ); if( format ) { - if( (im->BandFmt = im_char2BandFmt( format )) < 0 ) + VipsBandFormat f; + + if( (f = im_char2BandFmt( format )) < 0 ) error_exit( _( "bad format %s" ), format ); - im->Bbits = im_bits_of_fmt( im->BandFmt ); + im->BandFmt = f; + im->Bbits = im_bits_of_fmt( f ); } if( interpretation ) { - if( (im->Type = im_char2Type( interpretation )) < 0 ) - error_exit( _( "bad interpretation %s" ), interpretation ); + VipsInterpretation i; + + if( (i = im_char2Type( interpretation )) < 0 ) + error_exit( _( "bad interpretation %s" ), + interpretation ); + im->Type = i; } if( coding ) { - if( (im->Coding = im_char2Coding( coding )) < 0 ) + VipsCoding c; + + if( (c = im_char2Coding( coding )) < 0 ) error_exit( _( "bad coding %s" ), coding ); + im->Coding = c; } if( xres ) im->Xres = atof( xres );