2009-08-16 17:00:08 +02:00
|
|
|
/* @(#) Command; reads the header of a Vasari picture file.
|
|
|
|
* @(#) Usage: header vasari_file
|
|
|
|
* @(#)
|
|
|
|
*
|
|
|
|
* Copyright: Birkbeck College, History of Art Dept, London, VASARI project.
|
|
|
|
*
|
|
|
|
* Author: Nicos Dessipris
|
|
|
|
* Written on: 17/01/1990
|
|
|
|
* Modified on : 17/04/1990, 2/6/93 K.Martinez
|
|
|
|
* 16/6/93 JC
|
|
|
|
* - now calls im_mmapin instead of bizzare bogosity
|
|
|
|
* 1/6/95 JC
|
|
|
|
* - extra field argument for testing particular bits of the header
|
|
|
|
* 29/10/98 JC
|
|
|
|
* - now uses im_open()
|
|
|
|
* 24/5/01 JC
|
|
|
|
* - uses im_tiff2vips_header() etc., for speed
|
|
|
|
* 7/5/03 JC
|
|
|
|
* - uses im_open_header()
|
|
|
|
* 1/8/05
|
|
|
|
* - uses new header API, for great smallness
|
|
|
|
* 4/8/05
|
|
|
|
* - back to plain im_open() now that's lazy enough for us
|
|
|
|
* 9/9/05
|
|
|
|
* - display meta fields in save format, if possible
|
|
|
|
* 20/9/05
|
|
|
|
* - new field name "getext" reads extension block
|
|
|
|
* 24/8/06
|
|
|
|
* - use GOption, loop over args
|
|
|
|
* 4/1/07
|
|
|
|
* - use im_history_get()
|
|
|
|
* 29/2/08
|
|
|
|
* - don't stop on error
|
2009-08-18 13:38:17 +02:00
|
|
|
* 23/7/09
|
|
|
|
* - ... but do return an error code if anything failed
|
2009-11-06 14:00:51 +01:00
|
|
|
* 6/11/09
|
|
|
|
* - added im_history_get(), im_getexp(), im_printdesc() as wrapped
|
|
|
|
* functions, so "header" is now obsolete
|
2013-02-27 13:51:26 +01:00
|
|
|
* 27/2/13
|
|
|
|
* - convert to vips8 API
|
2020-06-29 13:06:34 +02:00
|
|
|
* 29/6/20
|
|
|
|
* - allow "stdin" as a filename
|
2009-08-16 17:00:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
This file is part of VIPS.
|
|
|
|
|
|
|
|
VIPS is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2013-03-07 06:40:19 +01:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
02110-1301 USA
|
2009-08-16 17:00:08 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif /*HAVE_CONFIG_H*/
|
|
|
|
#include <vips/intl.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2010-05-25 18:46:03 +02:00
|
|
|
#include <locale.h>
|
2009-08-16 17:00:08 +02:00
|
|
|
|
|
|
|
#include <vips/vips.h>
|
|
|
|
#include <vips/internal.h>
|
2009-10-05 23:19:02 +02:00
|
|
|
#include <vips/debug.h>
|
2009-08-16 17:00:08 +02:00
|
|
|
|
|
|
|
static char *main_option_field = NULL;
|
2011-12-01 14:17:40 +01:00
|
|
|
static gboolean main_option_all = FALSE;
|
2009-08-16 17:00:08 +02:00
|
|
|
|
|
|
|
static GOptionEntry main_option[] = {
|
2011-12-01 14:17:40 +01:00
|
|
|
{ "all", 'a', 0, G_OPTION_ARG_NONE, &main_option_all,
|
|
|
|
N_( "show all fields" ), NULL },
|
2009-08-16 17:00:08 +02:00
|
|
|
{ "field", 'f', 0, G_OPTION_ARG_STRING, &main_option_field,
|
|
|
|
N_( "print value of FIELD (\"getext\" reads extension block, "
|
|
|
|
"\"Hist\" reads image history)" ),
|
|
|
|
"FIELD" },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A non-fatal error. Print the vips error buffer and continue.
|
|
|
|
*/
|
|
|
|
static void
|
2011-12-02 10:10:11 +01:00
|
|
|
print_error( void )
|
2009-08-16 17:00:08 +02:00
|
|
|
{
|
2013-02-27 13:51:26 +01:00
|
|
|
fprintf( stderr, "%s: %s", g_get_prgname(), vips_error_buffer() );
|
|
|
|
vips_error_clear();
|
2009-08-16 17:00:08 +02:00
|
|
|
}
|
|
|
|
|
2011-11-30 15:56:57 +01:00
|
|
|
static void *
|
|
|
|
print_field_fn( VipsImage *image, const char *field, GValue *value, void *a )
|
|
|
|
{
|
|
|
|
gboolean *many = (gboolean *) a;
|
2016-11-01 11:14:12 +01:00
|
|
|
char str[256];
|
|
|
|
VipsBuf buf = VIPS_BUF_STATIC( str );
|
2011-11-30 15:56:57 +01:00
|
|
|
|
2020-06-29 13:06:34 +02:00
|
|
|
if( *many &&
|
|
|
|
image->filename )
|
2011-11-30 15:56:57 +01:00
|
|
|
printf( "%s: ", image->filename );
|
|
|
|
|
2016-11-01 11:14:12 +01:00
|
|
|
printf( "%s: ", field );
|
2011-11-30 15:56:57 +01:00
|
|
|
|
2016-11-01 11:14:12 +01:00
|
|
|
vips_buf_appendgv( &buf, value );
|
|
|
|
printf( "%s\n", vips_buf_all( &buf ) );
|
2011-11-30 15:56:57 +01:00
|
|
|
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
2009-08-16 17:00:08 +02:00
|
|
|
/* Print header, or parts of header.
|
|
|
|
*/
|
|
|
|
static int
|
2020-06-29 13:06:34 +02:00
|
|
|
print_header( VipsImage *image, gboolean many )
|
2009-08-16 17:00:08 +02:00
|
|
|
{
|
2011-12-01 14:17:40 +01:00
|
|
|
if( !main_option_field ) {
|
2020-06-29 13:06:34 +02:00
|
|
|
if( image->filename )
|
|
|
|
printf( "%s: ", image->filename );
|
2011-12-01 14:17:40 +01:00
|
|
|
|
2020-06-29 13:06:34 +02:00
|
|
|
vips_object_print_summary( VIPS_OBJECT( image ) );
|
2011-12-01 14:17:40 +01:00
|
|
|
|
|
|
|
if( main_option_all )
|
2020-06-29 13:06:34 +02:00
|
|
|
(void) vips_image_map( image, print_field_fn, &many );
|
2011-12-01 14:17:40 +01:00
|
|
|
}
|
2009-08-16 17:00:08 +02:00
|
|
|
else if( strcmp( main_option_field, "getext" ) == 0 ) {
|
2020-06-29 13:06:34 +02:00
|
|
|
if( vips__has_extension_block( image ) ) {
|
2009-08-16 17:00:08 +02:00
|
|
|
void *buf;
|
|
|
|
int size;
|
|
|
|
|
2020-06-29 13:06:34 +02:00
|
|
|
if( !(buf =
|
|
|
|
vips__read_extension_block( image, &size )) )
|
2009-08-16 17:00:08 +02:00
|
|
|
return( -1 );
|
|
|
|
printf( "%s", (char *) buf );
|
2013-02-27 13:51:26 +01:00
|
|
|
g_free( buf );
|
2009-08-16 17:00:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( strcmp( main_option_field, "Hist" ) == 0 )
|
2020-06-29 13:06:34 +02:00
|
|
|
printf( "%s", vips_image_get_history( image ) );
|
2009-08-16 17:00:08 +02:00
|
|
|
else {
|
2016-11-01 12:51:20 +01:00
|
|
|
char *str;
|
2009-08-16 17:00:08 +02:00
|
|
|
|
2020-06-29 13:06:34 +02:00
|
|
|
if( vips_image_get_as_string( image, main_option_field, &str ) )
|
2017-02-24 15:30:26 +01:00
|
|
|
return( -1 );
|
2013-02-27 13:51:26 +01:00
|
|
|
printf( "%s\n", str );
|
2016-11-01 12:51:20 +01:00
|
|
|
g_free( str );
|
2009-08-16 17:00:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main( int argc, char *argv[] )
|
|
|
|
{
|
|
|
|
GOptionContext *context;
|
2014-11-18 12:29:32 +01:00
|
|
|
GOptionGroup *main_group;
|
2009-08-16 17:00:08 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
int i;
|
2009-08-18 13:38:17 +02:00
|
|
|
int result;
|
2009-08-16 17:00:08 +02:00
|
|
|
|
2014-11-18 12:29:32 +01:00
|
|
|
if( VIPS_INIT( argv[0] ) )
|
2013-02-27 13:51:26 +01:00
|
|
|
vips_error_exit( "unable to start VIPS" );
|
2010-05-25 18:46:03 +02:00
|
|
|
textdomain( GETTEXT_PACKAGE );
|
|
|
|
setlocale( LC_ALL, "" );
|
2009-08-16 17:00:08 +02:00
|
|
|
|
2016-08-17 13:14:43 +02:00
|
|
|
/* On Windows, argv is ascii-only .. use this to get a utf-8 version of
|
|
|
|
* the args.
|
|
|
|
*/
|
2021-03-06 13:47:48 +01:00
|
|
|
#ifdef G_OS_WIN32
|
2016-08-17 13:14:43 +02:00
|
|
|
argv = g_win32_get_command_line();
|
2021-03-06 13:47:48 +01:00
|
|
|
#endif /*G_OS_WIN32*/
|
2016-08-17 13:14:43 +02:00
|
|
|
|
2009-08-16 17:00:08 +02:00
|
|
|
context = g_option_context_new( _( "- print image header" ) );
|
2014-11-18 12:29:32 +01:00
|
|
|
main_group = g_option_group_new( NULL, NULL, NULL, NULL, NULL );
|
|
|
|
g_option_group_add_entries( main_group, main_option );
|
|
|
|
vips_add_option_entries( main_group );
|
|
|
|
g_option_group_set_translation_domain( main_group, GETTEXT_PACKAGE );
|
|
|
|
g_option_context_set_main_group( context, main_group );
|
2009-08-16 17:00:08 +02:00
|
|
|
|
2021-03-06 13:47:48 +01:00
|
|
|
#ifdef G_OS_WIN32
|
2016-08-17 13:14:43 +02:00
|
|
|
if( !g_option_context_parse_strv( context, &argv, &error ) )
|
2021-03-06 13:47:48 +01:00
|
|
|
#else /*!G_OS_WIN32*/
|
2016-08-17 13:14:43 +02:00
|
|
|
if( !g_option_context_parse( context, &argc, &argv, &error ) )
|
2021-03-06 13:47:48 +01:00
|
|
|
#endif /*G_OS_WIN32*/
|
2016-08-17 13:14:43 +02:00
|
|
|
{
|
2009-08-16 17:00:08 +02:00
|
|
|
if( error ) {
|
|
|
|
fprintf( stderr, "%s\n", error->message );
|
|
|
|
g_error_free( error );
|
|
|
|
}
|
|
|
|
|
2013-02-27 13:51:26 +01:00
|
|
|
vips_error_exit( "try \"%s --help\"", g_get_prgname() );
|
2009-08-16 17:00:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
g_option_context_free( context );
|
|
|
|
|
2009-08-18 13:38:17 +02:00
|
|
|
result = 0;
|
|
|
|
|
2016-08-17 13:14:43 +02:00
|
|
|
for( i = 1; argv[i]; i++ ) {
|
2020-06-29 13:06:34 +02:00
|
|
|
VipsImage *image;
|
|
|
|
char filename[VIPS_PATH_MAX];
|
|
|
|
char option_string[VIPS_PATH_MAX];
|
|
|
|
|
|
|
|
vips__filename_split8( argv[i], filename, option_string );
|
|
|
|
if( strcmp( filename, "stdin" ) == 0 ) {
|
|
|
|
VipsSource *source;
|
|
|
|
|
|
|
|
if( !(source = vips_source_new_from_descriptor( 0 )) )
|
|
|
|
return( -1 );
|
|
|
|
if( !(image = vips_image_new_from_source( source,
|
|
|
|
option_string, NULL )) ) {
|
|
|
|
VIPS_UNREF( source );
|
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
VIPS_UNREF( source );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if( !(image =
|
|
|
|
vips_image_new_from_file( argv[i], NULL )) ) {
|
|
|
|
print_error();
|
|
|
|
result = 1;
|
|
|
|
}
|
2009-08-18 13:38:17 +02:00
|
|
|
}
|
2009-08-16 17:00:08 +02:00
|
|
|
|
2020-06-29 13:06:34 +02:00
|
|
|
if( image &&
|
|
|
|
print_header( image, argv[2] != NULL ) ) {
|
2011-12-02 10:10:11 +01:00
|
|
|
print_error();
|
2009-08-18 13:38:17 +02:00
|
|
|
result = 1;
|
|
|
|
}
|
2009-08-16 17:00:08 +02:00
|
|
|
|
2020-06-29 13:06:34 +02:00
|
|
|
if( image )
|
|
|
|
g_object_unref( image );
|
2009-08-16 17:00:08 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 13:14:43 +02:00
|
|
|
/* We don't free this on error exit, sadly.
|
|
|
|
*/
|
2021-03-06 13:47:48 +01:00
|
|
|
#ifdef G_OS_WIN32
|
2016-08-17 13:14:43 +02:00
|
|
|
g_strfreev( argv );
|
2021-03-06 13:47:48 +01:00
|
|
|
#endif /*G_OS_WIN32*/
|
2016-08-17 13:14:43 +02:00
|
|
|
|
2011-09-24 11:17:32 +02:00
|
|
|
vips_shutdown();
|
|
|
|
|
2009-08-18 13:38:17 +02:00
|
|
|
return( result );
|
2009-08-16 17:00:08 +02:00
|
|
|
}
|