record the image loader

and display in header too
This commit is contained in:
John Cupitt 2013-02-27 12:51:26 +00:00
parent ad2156a6d2
commit 2d085f753b
5 changed files with 38 additions and 40 deletions

View File

@ -3,6 +3,8 @@
raised an error (thanks Todd) raised an error (thanks Todd)
- fix another dzsave corner-case (thanks Martin) - fix another dzsave corner-case (thanks Martin)
- neater output for "header" - neater output for "header"
- added VIPS_META_LOADER: record the loader name
= header displays this hint
31/8/12 started 7.31.0 31/8/12 started 7.31.0
- redone im_Lab2XYZ(), im_XYZ2Lab(), im_Lab2LCh(), im_LCh2Lab(), im_UCS2LCh, - redone im_Lab2XYZ(), im_XYZ2Lab(), im_Lab2LCh(), im_LCh2Lab(), im_UCS2LCh,

View File

@ -850,6 +850,9 @@ vips_foreign_load_build( VipsObject *object )
g_object_set( object, "out", vips_image_new(), NULL ); g_object_set( object, "out", vips_image_new(), NULL );
vips_image_set_string( load->out,
VIPS_META_LOADER, class->nickname );
#ifdef DEBUG #ifdef DEBUG
printf( "vips_foreign_load_build: triggering ->header()\n" ); printf( "vips_foreign_load_build: triggering ->header()\n" );
#endif /*DEBUG*/ #endif /*DEBUG*/

View File

@ -84,6 +84,14 @@ extern "C" {
*/ */
#define VIPS_META_RESOLUTION_UNIT "resolution-unit" #define VIPS_META_RESOLUTION_UNIT "resolution-unit"
/**
* VIPS_META_LOADER:
*
* Record the name of the original loader here. Handy for hinting file formats
* and for debugging.
*/
#define VIPS_META_LOADER "vips-loader"
guint64 vips_format_sizeof( VipsBandFormat format ); guint64 vips_format_sizeof( VipsBandFormat format );
int vips_image_get_width( const VipsImage *image ); int vips_image_get_width( const VipsImage *image );

View File

@ -395,6 +395,7 @@ static void
vips_image_summary( VipsObject *object, VipsBuf *buf ) vips_image_summary( VipsObject *object, VipsBuf *buf )
{ {
VipsImage *image = VIPS_IMAGE( object ); VipsImage *image = VIPS_IMAGE( object );
char *p;
vips_buf_appendf( buf, "%dx%d", vips_buf_appendf( buf, "%dx%d",
vips_image_get_width( image ), vips_image_get_height( image ) ); vips_image_get_width( image ), vips_image_get_height( image ) );
@ -416,6 +417,10 @@ vips_image_summary( VipsObject *object, VipsBuf *buf )
vips_image_get_coding( image ) ) ); vips_image_get_coding( image ) ) );
} }
if( vips_image_get_typeof( image, VIPS_META_LOADER ) &&
!vips_image_get_string( image, VIPS_META_LOADER, &p ) )
vips_buf_appendf( buf, ", %s", p );
VIPS_OBJECT_CLASS( vips_image_parent_class )->summary( object, buf ); VIPS_OBJECT_CLASS( vips_image_parent_class )->summary( object, buf );
} }

View File

@ -36,6 +36,8 @@
* 6/11/09 * 6/11/09
* - added im_history_get(), im_getexp(), im_printdesc() as wrapped * - added im_history_get(), im_getexp(), im_printdesc() as wrapped
* functions, so "header" is now obsolete * functions, so "header" is now obsolete
* 27/2/13
* - convert to vips8 API
*/ */
/* /*
@ -95,8 +97,8 @@ static GOptionEntry main_option[] = {
static void static void
print_error( void ) print_error( void )
{ {
fprintf( stderr, "%s: %s", g_get_prgname(), im_error_buffer() ); fprintf( stderr, "%s: %s", g_get_prgname(), vips_error_buffer() );
im_error_clear(); vips_error_clear();
} }
static void * static void *
@ -137,7 +139,7 @@ print_field_fn( VipsImage *image, const char *field, GValue *value, void *a )
/* Print header, or parts of header. /* Print header, or parts of header.
*/ */
static int static int
print_header( IMAGE *im, gboolean many ) print_header( VipsImage *im, gboolean many )
{ {
if( !main_option_field ) { if( !main_option_field ) {
printf( "%s: ", im->filename ); printf( "%s: ", im->filename );
@ -148,47 +150,25 @@ print_header( IMAGE *im, gboolean many )
(void) vips_image_map( im, print_field_fn, &many ); (void) vips_image_map( im, print_field_fn, &many );
} }
else if( strcmp( main_option_field, "getext" ) == 0 ) { else if( strcmp( main_option_field, "getext" ) == 0 ) {
if( im__has_extension_block( im ) ) { if( vips__has_extension_block( im ) ) {
void *buf; void *buf;
int size; int size;
if( !(buf = im__read_extension_block( im, &size )) ) if( !(buf = vips__read_extension_block( im, &size )) )
return( -1 ); return( -1 );
printf( "%s", (char *) buf ); printf( "%s", (char *) buf );
im_free( buf ); g_free( buf );
} }
} }
else if( strcmp( main_option_field, "Hist" ) == 0 ) else if( strcmp( main_option_field, "Hist" ) == 0 )
printf( "%s", im_history_get( im ) ); printf( "%s", vips_image_get_history( im ) );
else { else {
GValue value = { 0 }; char *str;
GType type;
if( im_header_get( im, main_option_field, &value ) ) if( vips_image_get_as_string( im, main_option_field, &str ) )
return( -1 ); return( -1 );
printf( "%s\n", str );
/* Display the save form, if there is one. This way we display g_free( str );
* something useful for ICC profiles, xml fields, etc.
*/
type = G_VALUE_TYPE( &value );
if( g_value_type_transformable( type, IM_TYPE_SAVE_STRING ) ) {
GValue save_value = { 0 };
g_value_init( &save_value, IM_TYPE_SAVE_STRING );
if( !g_value_transform( &value, &save_value ) )
return( -1 );
printf( "%s\n", im_save_string_get( &save_value ) );
g_value_unset( &save_value );
}
else {
char *str_value;
str_value = g_strdup_value_contents( &value );
printf( "%s\n", str_value );
g_free( str_value );
}
g_value_unset( &value );
} }
return( 0 ); return( 0 );
@ -202,8 +182,8 @@ main( int argc, char *argv[] )
int i; int i;
int result; int result;
if( im_init_world( argv[0] ) ) if( vips_init( argv[0] ) )
error_exit( "unable to start VIPS" ); vips_error_exit( "unable to start VIPS" );
textdomain( GETTEXT_PACKAGE ); textdomain( GETTEXT_PACKAGE );
setlocale( LC_ALL, "" ); setlocale( LC_ALL, "" );
@ -211,7 +191,7 @@ main( int argc, char *argv[] )
g_option_context_add_main_entries( context, g_option_context_add_main_entries( context,
main_option, GETTEXT_PACKAGE ); main_option, GETTEXT_PACKAGE );
g_option_context_add_group( context, im_get_option_group() ); g_option_context_add_group( context, vips_get_option_group() );
if( !g_option_context_parse( context, &argc, &argv, &error ) ) { if( !g_option_context_parse( context, &argc, &argv, &error ) ) {
if( error ) { if( error ) {
@ -219,7 +199,7 @@ main( int argc, char *argv[] )
g_error_free( error ); g_error_free( error );
} }
error_exit( "try \"%s --help\"", g_get_prgname() ); vips_error_exit( "try \"%s --help\"", g_get_prgname() );
} }
g_option_context_free( context ); g_option_context_free( context );
@ -227,9 +207,9 @@ main( int argc, char *argv[] )
result = 0; result = 0;
for( i = 1; i < argc; i++ ) { for( i = 1; i < argc; i++ ) {
IMAGE *im; VipsImage *im;
if( !(im = im_open( argv[i], "r" )) ) { if( !(im = vips_image_new_from_file( argv[i] )) ) {
print_error(); print_error();
result = 1; result = 1;
} }
@ -241,7 +221,7 @@ main( int argc, char *argv[] )
} }
if( im ) if( im )
im_close( im ); g_object_unref( im );
} }
vips_shutdown(); vips_shutdown();