make enum names work again

allow old names in enums, so edivips --format allows IM_BANDFMT_UCHAR,
VIPS_FORMAT_UCHAR and uchar
This commit is contained in:
John Cupitt 2011-07-22 15:56:31 +01:00
parent 0a4e314194
commit cfb076f726
4 changed files with 94 additions and 37 deletions

20
TODO
View File

@ -1,23 +1,3 @@
- try:
edvips --format=IM_BANDFMT_FLOAT babe.v
leaves it set to uchar
im_char2BandFmt() in vips7compat.c must allow old names as well
- VIPS_ENUM_VALUE() returns a GEnumValue, see
http://developer.gnome.org/gobject/stable/gobject-Enumeration-and-Flag-Types.html#GEnumValue
you need a ->value after it (after checking for a NULL result) to get the
int
check all uses ... seems to be only vips7compat, phew
- turn wrap back on, with renames

View File

@ -223,16 +223,98 @@ const char *im_dtype2char( VipsImageType n )
const char *im_dhint2char( VipsDemandStyle style )
{ return( VIPS_ENUM_STRING( VIPS_TYPE_DEMAND_STYLE, style ) ); }
/* Old names for enums, for compat.
*/
static const char *im_Type[] = {
"IM_TYPE_MULTIBAND", /* 0 */
"IM_TYPE_B_W", /* 1 */
"LUMINACE", /* 2 */
"XRAY", /* 3 */
"IR", /* 4 */
"YUV", /* 5 */
"RED_ONLY", /* 6 */
"GREEN_ONLY", /* 7 */
"BLUE_ONLY", /* 8 */
"POWER_SPECTRUM", /* 9 */
"IM_TYPE_HISTOGRAM", /* 10 */
"LUT", /* 11 */
"IM_TYPE_XYZ", /* 12 */
"IM_TYPE_LAB", /* 13 */
"CMC", /* 14 */
"IM_TYPE_CMYK", /* 15 */
"IM_TYPE_LABQ", /* 15 */
"IM_TYPE_RGB", /* 17 */
"IM_TYPE_UCS", /* 18 */
"IM_TYPE_LCH", /* 19 */
"IM_TYPE_LABS", /* 20 */
"<unknown>", /* 21 */
"IM_TYPE_sRGB", /* 22 */
"IM_TYPE_YXY", /* 23 */
"IM_TYPE_FOURIER", /* 24 */
"IM_TYPE_RGB16", /* 25 */
"IM_TYPE_GREY16", /* 26 */
NULL
};
static const char *im_BandFmt[] = {
"IM_BANDFMT_UCHAR",
"IM_BANDFMT_CHAR",
"IM_BANDFMT_USHORT",
"IM_BANDFMT_SHORT",
"IM_BANDFMT_UINT",
"IM_BANDFMT_INT",
"IM_BANDFMT_FLOAT",
"IM_BANDFMT_COMPLEX",
"IM_BANDFMT_DOUBLE",
"IM_BANDFMT_DPCOMPLEX",
NULL
};
static const char *im_Coding[] = {
"IM_CODING_NONE",
"COLQUANT8",
"IM_CODING_LABQ",
"IM_CODING_LABQ_COMPRESSED",
"RGB_COMPRESSED",
"LUM_COMPRESSED",
"IM_CODING_RAD",
NULL
};
static const char *im_dtype[] = {
"IM_NONE",
"IM_SETBUF",
"IM_SETBUF_FOREIGN",
"IM_OPENIN",
"IM_MMAPIN",
"IM_MMAPINRW",
"IM_OPENOUT",
"IM_PARTIAL",
NULL
};
static const char *im_dhint[] = {
"IM_SMALLTILE",
"IM_FATSTRIP",
"IM_THINSTRIP",
"IM_ANY",
NULL
};
/* enum string to int, try the GEnum first, then use a compat *char[] for old
* names.
*/
static int
lookup_enum( GType type, char *names[], const char *name )
lookup_enum( GType type, const char *names[], const char *name )
{
GEnumClass *class;
GEnumValue *value;
int i;
if( (value = VIPS_ENUM_VALUE( type, name )) )
class = g_type_class_ref( type );
if( (value = g_enum_get_value_by_nick( class, name )) )
return( value->value );
if( (value = g_enum_get_value_by_name( class, name )) )
return( value->value );
for( i = 0; names[i]; i++ )
@ -243,15 +325,15 @@ lookup_enum( GType type, char *names[], const char *name )
}
VipsInterpretation im_char2Type( const char *str )
{ return( VIPS_ENUM_VALUE( VIPS_TYPE_INTERPRETATION, str ) ); }
{ return( lookup_enum( VIPS_TYPE_INTERPRETATION, im_Type, str ) ); }
VipsBandFormat im_char2BandFmt( const char *str )
{ return( VIPS_ENUM_VALUE( VIPS_TYPE_BAND_FORMAT, str ) ); }
{ return( lookup_enum( VIPS_TYPE_BAND_FORMAT, im_BandFmt, str ) ); }
VipsCoding im_char2Coding( const char *str )
{ return( VIPS_ENUM_VALUE( VIPS_TYPE_CODING, str ) ); }
{ return( lookup_enum( VIPS_TYPE_CODING, im_Coding, str ) ); }
VipsImageType im_char2dtype( const char *str )
{ return( VIPS_ENUM_VALUE( VIPS_TYPE_IMAGE_TYPE, str ) ); }
{ return( lookup_enum( VIPS_TYPE_IMAGE_TYPE, im_dtype, str ) ); }
VipsDemandStyle im_char2dhint( const char *str )
{ return( VIPS_ENUM_VALUE( VIPS_TYPE_DEMAND_STYLE, str ) ); }
{ return( lookup_enum( VIPS_TYPE_DEMAND_STYLE, im_dhint, str ) ); }
/* Totally useless now.
*/

View File

@ -155,13 +155,6 @@ G_STMT_START { \
#define VIPS_ENUM_NICK( ENUM, VALUE ) \
(g_enum_get_value( g_type_class_ref( ENUM ), VALUE )->value_nick)
/* Given a string, look up the value. Look up as a nick first, then try as a
* name.
*/
#define VIPS_ENUM_VALUE( ENUM, STR ) \
(g_enum_get_value_by_nick( g_type_class_ref( ENUM ), STR ) || \
g_enum_get_value_by_name( g_type_class_ref( ENUM ), STR ))
/* Like GFunc, but return a value.
*/
typedef void *(*VipsSListMap2Fn)( void *, void *, void * );

View File

@ -84,11 +84,13 @@ static GOptionEntry entries[] = {
{ "bands", 'b', 0, G_OPTION_ARG_STRING, &bands,
N_( "set Bands to N" ), "N" },
{ "format", 'f', 0, G_OPTION_ARG_STRING, &format,
N_( "set BandFmt to F (eg. IM_BANDFMT_UCHAR)" ), "F" },
N_( "set BandFmt to F (eg. uchar, float)" ), "F" },
{ "type", 't', 0, G_OPTION_ARG_STRING, &type,
N_( "set Type to T (eg. IM_TYPE_XYZ)" ), "T" },
N_( "set Type to T (deprecated, use interpretation)" ), "T" },
{ "interpretation", 'i', 0, G_OPTION_ARG_STRING, &type,
N_( "set interpretation to I (eg. xyz)" ), "I" },
{ "coding", 'c', 0, G_OPTION_ARG_STRING, &coding,
N_( "set Coding to C (eg. IM_CODING_LABQ)" ), "C" },
N_( "set Coding to C (eg. labq)" ), "C" },
{ "xres", 'X', 0, G_OPTION_ARG_STRING, &xres,
N_( "set Xres to R pixels/mm" ), "R" },
{ "yres", 'Y', 0, G_OPTION_ARG_STRING, &yres,