1 /* A program that extracts metadata from an XCF file
2 *
3 * This file was written by Henning Makholm <henning@makholm.net>
4 * It is hereby in the public domain.
5 *
6 * In jurisdictions that do not recognise grants of copyright to the
7 * public domain: I, the author and (presumably, in those jurisdictions)
8 * copyright holder, hereby permit anyone to distribute and use this code,
9 * in source code or binary form, with or without modifications. This
10 * permission is world-wide and irrevocable.
11 *
12 * Of course, I will not be liable for any errors or shortcomings in the
13 * code, since I give it away without asking any compenstations.
14 *
15 * If you use or distribute this code, I would appreciate receiving
16 * credit for writing it, in whichever way you find proper and customary.
17 */
18
19 #include "xcftools.h"
20 #include "nlsini.h"
21 #include "options.h"
22
23 #include <stdlib.h>
24 #include <string.h>
25 #include <locale.h>
26 #include <getopt.h>
27
28 /*----------------------------------------------------------------------------*/
29 const struct option long_options[] = {
30 option_help,
31 option_version,
32 option_verbose,
33 option_bzip,
34 option_gzip,
35 option_unpack,
36 option_path_separator,
37 option_utf8,
38 { 0 }
39 };
40
41 /*----------------------------------------------------------------------------*/
42 const char* const short_options = short_options_prefix
43 short_option_help
44 short_option_version
45 short_option_verbose
46 short_option_bzip
47 short_option_gzip
48 short_option_unpack
49 short_option_path_separator
50 short_option_utf8
51 ;
52
53 static void
printLayerPath(unsigned layerIndex,const char * pathSeparator)54 printLayerPath
55 ( unsigned layerIndex, const char* pathSeparator )
56 {
57 int depth = XCF.layers[layerIndex].pathLength ;
58 int i = layerIndex;
59
60 if ( depth != 0 ) {
61 do {
62 i++;
63 } while ( XCF.layers[i].pathLength != depth - 1 );
64
65 printLayerPath( i, pathSeparator ) ;
66 printf( "%s%s", pathSeparator, XCF.layers[i].name );
67 }
68 }
69
70 int
main(int argc,char ** argv)71 main(int argc,char **argv)
72 {
73 int i ;
74
75 struct ProcessControl process;
76
77 setlocale(LC_ALL,"");
78 progname = argv[0] ;
79 nls_init();
80
81 if( argc <= 1 ) gpl_blurb() ;
82
83 init_process_control( &process );
84
85 if ( option_parse
86 ( argc, argv, short_options, long_options, &process, NULL ) )
87 exit(1);
88
89 // set the global flags
90 verboseFlag = process.verboseFlag;
91 use_utf8 = process.use_utf8;
92
93 read_or_mmap_xcf( process.inputFile, process.unzipper );
94 getBasicXcfInfo() ;
95
96 printf(gettext("Version %d, %dx%d %s, %d layers, compressed %s\n"),
97 XCF.version,XCF.width,XCF.height,
98 gettext(showGimpImageBaseType(XCF.type)),
99 XCF.numLayers,
100 gettext(showXcfCompressionType(XCF.compression)));
101
102 for( i = XCF.numLayers ; i-- ; ) {
103 printf("%c %dx%d%+d%+d %s %s",
104 XCF.layers[i].isVisible ? '+' : '-',
105 XCF.layers[i].dim.width, XCF.layers[i].dim.height,
106 XCF.layers[i].dim.c.l, XCF.layers[i].dim.c.t,
107 gettext(showGimpImageType(XCF.layers[i].type)),
108 gettext(showGimpLayerModeEffects(XCF.layers[i].mode)));
109 if( XCF.layers[i].opacity < 255 )
110 printf("/%02d%%",XCF.layers[i].opacity * 100 / 255);
111 if( XCF.layers[i].hasMask )
112 printf(gettext("/mask"));
113 if( XCF.layers[i].isGroup )
114 printf(gettext("/group"));
115
116 printf( " " );
117
118 if ( XCF.version > 2 ) {
119 printLayerPath( i, process.pathSeparator );
120 printf( "%s", process.pathSeparator );
121 }
122
123 printf("%s\n",XCF.layers[i].name);
124 }
125
126 return 0 ;
127 }
128