fix vipsheader with new get/set system
This commit is contained in:
parent
3f1f950bff
commit
3681ce0e77
6
TODO
6
TODO
@ -1,3 +1,9 @@
|
|||||||
|
- look at vips_image_get_as_string() vs. vips_buf_appendgv()
|
||||||
|
|
||||||
|
should Hist and getext be true header fields?
|
||||||
|
|
||||||
|
vipsheader is not displaying filename correctly
|
||||||
|
|
||||||
- not sure about utf8 error messages on win
|
- not sure about utf8 error messages on win
|
||||||
|
|
||||||
- strange:
|
- strange:
|
||||||
|
@ -493,19 +493,151 @@ vips_buf_appendd( VipsBuf *buf, int d )
|
|||||||
* @buf: the buffer
|
* @buf: the buffer
|
||||||
* @value: #GValue to format and append
|
* @value: #GValue to format and append
|
||||||
*
|
*
|
||||||
* Format and append a #GValue with g_strdup_value_contents().
|
* Format and append a #GValue. This doesn't use g_strdup_value_contents():
|
||||||
|
* that doesn't do what we want for some types and can change too much between
|
||||||
|
* glib versions.
|
||||||
*
|
*
|
||||||
* Returns: %FALSE on overflow, %TRUE otherwise.
|
* Returns: %FALSE on overflow, %TRUE otherwise.
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
vips_buf_appendgv( VipsBuf *buf, GValue *value )
|
vips_buf_appendgv( VipsBuf *buf, GValue *value )
|
||||||
{
|
{
|
||||||
char *str_value;
|
GType type = G_VALUE_TYPE( value );
|
||||||
|
GType fundamental = g_type_fundamental( type );
|
||||||
|
|
||||||
|
gboolean handled;
|
||||||
gboolean result;
|
gboolean result;
|
||||||
|
|
||||||
str_value = g_strdup_value_contents( value );
|
result = FALSE;
|
||||||
result = vips_buf_appends( buf, str_value );
|
handled = FALSE;
|
||||||
g_free( str_value );
|
|
||||||
|
switch( fundamental ) {
|
||||||
|
case G_TYPE_STRING:
|
||||||
|
/* These are GStrings, vips refstrings are handled by boxed, see
|
||||||
|
* below.
|
||||||
|
*/
|
||||||
|
result = vips_buf_appends( buf, g_value_get_string( value ) );
|
||||||
|
handled = TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case G_TYPE_OBJECT:
|
||||||
|
{
|
||||||
|
GObject *object;
|
||||||
|
|
||||||
|
object = g_value_get_object( value );
|
||||||
|
if( VIPS_IS_OBJECT( object ) ) {
|
||||||
|
vips_object_summary( VIPS_OBJECT( object ), buf );
|
||||||
|
result = TRUE;
|
||||||
|
handled = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case G_TYPE_INT:
|
||||||
|
result = vips_buf_appendf( buf,
|
||||||
|
"%d", g_value_get_int( value ) );
|
||||||
|
handled = TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case G_TYPE_UINT64:
|
||||||
|
result = vips_buf_appendf( buf,
|
||||||
|
"%zd", g_value_get_uint64( value ) );
|
||||||
|
handled = TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case G_TYPE_DOUBLE:
|
||||||
|
result = vips_buf_appendf( buf,
|
||||||
|
"%g", g_value_get_double( value ) );
|
||||||
|
handled = TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case G_TYPE_BOOLEAN:
|
||||||
|
result = vips_buf_appends( buf,
|
||||||
|
g_value_get_boolean( value ) ? "true" : "false" );
|
||||||
|
handled = TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case G_TYPE_ENUM:
|
||||||
|
result = vips_buf_appends( buf,
|
||||||
|
vips_enum_nick( type, g_value_get_enum( value ) ) );
|
||||||
|
handled = TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case G_TYPE_FLAGS:
|
||||||
|
{
|
||||||
|
GFlagsClass *flags_class = g_type_class_ref( type );
|
||||||
|
|
||||||
|
GFlagsValue *v;
|
||||||
|
int flags;
|
||||||
|
|
||||||
|
flags = g_value_get_flags( value );
|
||||||
|
|
||||||
|
while( flags &&
|
||||||
|
(v = g_flags_get_first_value( flags_class, flags )) ) {
|
||||||
|
result = vips_buf_appendf( buf, "%s ", v->value_nick );
|
||||||
|
flags &= ~v->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
handled = TRUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case G_TYPE_BOXED:
|
||||||
|
if( type == VIPS_TYPE_REF_STRING ||
|
||||||
|
type == VIPS_TYPE_BLOB ) {
|
||||||
|
const char *str;
|
||||||
|
size_t str_len;
|
||||||
|
|
||||||
|
str = vips_value_get_ref_string( value, &str_len );
|
||||||
|
result = vips_buf_appends( buf, str );
|
||||||
|
handled = TRUE;
|
||||||
|
}
|
||||||
|
else if( type == VIPS_TYPE_ARRAY_DOUBLE ) {
|
||||||
|
double *arr;
|
||||||
|
int n;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
arr = vips_value_get_array_double( value, &n );
|
||||||
|
for( i = 0; i < n; i++ )
|
||||||
|
result = vips_buf_appendf( buf, "%g ", arr[i] );
|
||||||
|
handled = TRUE;
|
||||||
|
}
|
||||||
|
else if( type == VIPS_TYPE_ARRAY_INT ) {
|
||||||
|
int *arr;
|
||||||
|
int n;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
arr = vips_value_get_array_int( value, &n );
|
||||||
|
for( i = 0; i < n; i++ )
|
||||||
|
result = vips_buf_appendf( buf, "%d ", arr[i] );
|
||||||
|
handled = TRUE;
|
||||||
|
}
|
||||||
|
else if( type == VIPS_TYPE_ARRAY_IMAGE ) {
|
||||||
|
VipsImage **arr;
|
||||||
|
int n;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
arr = vips_value_get_array_image( value, &n );
|
||||||
|
for( i = 0; i < n; i++ ) {
|
||||||
|
vips_object_summary( VIPS_OBJECT( arr[i] ),
|
||||||
|
buf );
|
||||||
|
result = vips_buf_appends( buf, " " );
|
||||||
|
}
|
||||||
|
handled = TRUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !handled ) {
|
||||||
|
char *str_value;
|
||||||
|
|
||||||
|
str_value = g_strdup_value_contents( value );
|
||||||
|
result = vips_buf_appends( buf, str_value );
|
||||||
|
g_free( str_value );
|
||||||
|
}
|
||||||
|
|
||||||
return( result );
|
return( result );
|
||||||
}
|
}
|
||||||
|
@ -1806,6 +1806,7 @@ vips_flags_from_nick( const char *domain, GType type, const char *nick )
|
|||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Scan @buf for the first "%ns" (eg. "%12s") and substitute the
|
/* Scan @buf for the first "%ns" (eg. "%12s") and substitute the
|
||||||
* lowest-numbered one for @sub. @buf is @len bytes in size.
|
* lowest-numbered one for @sub. @buf is @len bytes in size.
|
||||||
*
|
*
|
||||||
|
@ -106,33 +106,16 @@ static void *
|
|||||||
print_field_fn( VipsImage *image, const char *field, GValue *value, void *a )
|
print_field_fn( VipsImage *image, const char *field, GValue *value, void *a )
|
||||||
{
|
{
|
||||||
gboolean *many = (gboolean *) a;
|
gboolean *many = (gboolean *) a;
|
||||||
const char *extra;
|
char str[256];
|
||||||
char *str_value;
|
VipsBuf buf = VIPS_BUF_STATIC( str );
|
||||||
|
|
||||||
/* Look for known enums and decode them.
|
|
||||||
*/
|
|
||||||
extra = NULL;
|
|
||||||
if( strcmp( field, "coding" ) == 0 )
|
|
||||||
extra = vips_enum_nick(
|
|
||||||
VIPS_TYPE_CODING, g_value_get_int( value ) );
|
|
||||||
else if( strcmp( field, "format" ) == 0 )
|
|
||||||
extra = vips_enum_nick(
|
|
||||||
VIPS_TYPE_BAND_FORMAT, g_value_get_int( value ) );
|
|
||||||
else if( strcmp( field, "interpretation" ) == 0 )
|
|
||||||
extra = vips_enum_nick(
|
|
||||||
VIPS_TYPE_INTERPRETATION, g_value_get_int( value ) );
|
|
||||||
|
|
||||||
if( *many )
|
if( *many )
|
||||||
printf( "%s: ", image->filename );
|
printf( "%s: ", image->filename );
|
||||||
|
|
||||||
str_value = g_strdup_value_contents( value );
|
printf( "%s: ", field );
|
||||||
printf( "%s: %s", field, str_value );
|
|
||||||
g_free( str_value );
|
|
||||||
|
|
||||||
if( extra )
|
vips_buf_appendgv( &buf, value );
|
||||||
printf( " - %s", extra );
|
printf( "%s\n", vips_buf_all( &buf ) );
|
||||||
|
|
||||||
printf( "\n" );
|
|
||||||
|
|
||||||
return( NULL );
|
return( NULL );
|
||||||
}
|
}
|
||||||
@ -164,12 +147,14 @@ print_header( VipsImage *im, gboolean many )
|
|||||||
else if( strcmp( main_option_field, "Hist" ) == 0 )
|
else if( strcmp( main_option_field, "Hist" ) == 0 )
|
||||||
printf( "%s", vips_image_get_history( im ) );
|
printf( "%s", vips_image_get_history( im ) );
|
||||||
else {
|
else {
|
||||||
char *str;
|
GValue value = { 0 };
|
||||||
|
char str[256];
|
||||||
|
VipsBuf buf = VIPS_BUF_STATIC( str );
|
||||||
|
|
||||||
if( vips_image_get_as_string( im, main_option_field, &str ) )
|
vips_image_get( im, main_option_field, &value );
|
||||||
return( -1 );
|
vips_buf_appendgv( &buf, &value );
|
||||||
printf( "%s\n", str );
|
printf( "%s\n", str );
|
||||||
g_free( str );
|
g_value_unset( &value );
|
||||||
}
|
}
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
|
Loading…
Reference in New Issue
Block a user