diff options
author | Julien Jorge <julien.jorge@stuff-o-matic.com> | 2013-01-10 16:31:25 (EST) |
---|---|---|
committer | Julien Jorge <julien.jorge@stuff-o-matic.com> | 2013-01-10 16:31:25 (EST) |
commit | c29082d538224219586ef453f1291151a01c15bb (patch) | |
tree | 562684ed5430cdf5dad195f25707a6b3f4a4e716 | |
parent | 30aef48ae5ee252dd42f206c4b5b9e770694417c (diff) | |
download | xcftools-c29082d538224219586ef453f1291151a01c15bb.zip xcftools-c29082d538224219586ef453f1291151a01c15bb.tar.gz xcftools-c29082d538224219586ef453f1291151a01c15bb.tar.bz2 |
Add layer group support introduced in Gimp 2.8.
Changes introduced by this commit:
- Update xcf-private.h with the file from the head of git's branch
named gimp-2-8 (commit acebb4ad205901a9e8029a66ed5bca62cf13bc96).
- Increase supported version number from 2 to 3.
- Add the cases for PROP_GROUP_ITEM and PROP_ITEM_PATH in getBasicXcfInfo().
- Add the function printLayerPath() to print the groups containing a given
layer.
- Add an option --path-separator (string) to set the string to use to
separate the groups in the paths.
The output is unchanged for files whose version is lower than 3.
Otherwise, the name of the layer now contains its path in the image and
the marker "group" is added for the group layers in the fourth field.
For example, here is the output of a file containing a single layer
named "a", then one group named "G 1", which contains two layers named
"b 1" and "c 2". The path separator is "|" by default:
Version 3, 10x10 RGB color, 4 layers, compressed RLE
+ 10x10+0+0 RGB-alpha Normal |a
+ 10x10+0+0 RGB-alpha Normal/group |G 1
+ 10x10+0+0 RGB-alpha Normal |G 1|b 1
+ 10x10+0+0 RGB-alpha Normal |G 1|c 2
-rw-r--r-- | gimp/xcf-private.h | 75 | ||||
-rw-r--r-- | options.i | 9 | ||||
-rw-r--r-- | xcf-general.c | 24 | ||||
-rw-r--r-- | xcfinfo.c | 30 | ||||
-rw-r--r-- | xcftools.h | 3 |
5 files changed, 106 insertions, 35 deletions
diff --git a/gimp/xcf-private.h b/gimp/xcf-private.h index 0a5749f..33076d4 100644 --- a/gimp/xcf-private.h +++ b/gimp/xcf-private.h @@ -1,9 +1,9 @@ -/* The GIMP -- an image manipulation program +/* GIMP - The GNU Image Manipulation Program * Copyright (C) 1995 Spencer Kimball and Peter Mattis * - * This program is free software; you can redistribute it and/or modify + * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -12,8 +12,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef __XCF_PRIVATE_H__ @@ -22,33 +21,38 @@ typedef enum { - PROP_END = 0, - PROP_COLORMAP = 1, - PROP_ACTIVE_LAYER = 2, - PROP_ACTIVE_CHANNEL = 3, - PROP_SELECTION = 4, - PROP_FLOATING_SELECTION = 5, - PROP_OPACITY = 6, - PROP_MODE = 7, - PROP_VISIBLE = 8, - PROP_LINKED = 9, - PROP_PRESERVE_TRANSPARENCY = 10, - PROP_APPLY_MASK = 11, - PROP_EDIT_MASK = 12, - PROP_SHOW_MASK = 13, - PROP_SHOW_MASKED = 14, - PROP_OFFSETS = 15, - PROP_COLOR = 16, - PROP_COMPRESSION = 17, - PROP_GUIDES = 18, - PROP_RESOLUTION = 19, - PROP_TATTOO = 20, - PROP_PARASITES = 21, - PROP_UNIT = 22, - PROP_PATHS = 23, - PROP_USER_UNIT = 24, - PROP_VECTORS = 25, - PROP_TEXT_LAYER_FLAGS = 26 + PROP_END = 0, + PROP_COLORMAP = 1, + PROP_ACTIVE_LAYER = 2, + PROP_ACTIVE_CHANNEL = 3, + PROP_SELECTION = 4, + PROP_FLOATING_SELECTION = 5, + PROP_OPACITY = 6, + PROP_MODE = 7, + PROP_VISIBLE = 8, + PROP_LINKED = 9, + PROP_LOCK_ALPHA = 10, + PROP_APPLY_MASK = 11, + PROP_EDIT_MASK = 12, + PROP_SHOW_MASK = 13, + PROP_SHOW_MASKED = 14, + PROP_OFFSETS = 15, + PROP_COLOR = 16, + PROP_COMPRESSION = 17, + PROP_GUIDES = 18, + PROP_RESOLUTION = 19, + PROP_TATTOO = 20, + PROP_PARASITES = 21, + PROP_UNIT = 22, + PROP_PATHS = 23, + PROP_USER_UNIT = 24, + PROP_VECTORS = 25, + PROP_TEXT_LAYER_FLAGS = 26, + PROP_SAMPLE_POINTS = 27, + PROP_LOCK_CONTENT = 28, + PROP_GROUP_ITEM = 29, + PROP_ITEM_PATH = 30, + PROP_GROUP_ITEM_FLAGS = 31 } PropType; typedef enum @@ -71,10 +75,17 @@ typedef enum XCF_STROKETYPE_BEZIER_STROKE = 1 } XcfStrokeType; +typedef enum +{ + XCF_GROUP_ITEM_EXPANDED = 1 +} XcfGroupItemFlagsType; + typedef struct _XcfInfo XcfInfo; struct _XcfInfo { + Gimp *gimp; + GimpProgress *progress; FILE *fp; guint cp; const gchar *filename; @@ -47,6 +47,15 @@ OPTION('j',--bzip,input is bzip2 compressed, )); unzipper = "bzcat" ; break ; + +#ifdef XCFINFO +OPTION('p',--path-separator, (string) use 'string' to separate the groups in the paths, + (This string will be used to separate the name of the containing groups + when manipulating layers. + )); +pathSeparator = optarg ; +break ; +#endif OPTION('z',--gzip,input is gzip compressed, (Equivalent to diff --git a/xcf-general.c b/xcf-general.c index 9d0b4dc..b23c260 100644 --- a/xcf-general.c +++ b/xcf-general.c @@ -196,7 +196,7 @@ getBasicXcfInfo(void) { uint32_t ptr, data, layerfile ; PropType type ; - int i ; + int i, j ; xcfCheckspace(0,14+7*4,"(very short)"); if( strcmp((char*)xcf_file,"gimp xcf file") == 0 ) @@ -207,7 +207,7 @@ getBasicXcfInfo(void) else FatalBadXCF(_("Not an XCF file at all (magic not recognized)")); - if( XCF.version < 0 || XCF.version > 2 ) { + if( XCF.version < 0 || XCF.version > 3 ) { fprintf(stderr, _("Warning: XCF version %d not supported (trying anyway...)\n"), XCF.version); @@ -241,6 +241,7 @@ getBasicXcfInfo(void) for( i = 0 ; i < XCF.numLayers ; i++ ) { struct xcfLayer *L = XCF.layers + i ; ptr = xcfL(layerfile+4*(XCF.numLayers-1-i)) ; + L->mode = GIMP_NORMAL_MODE ; L->opacity = 255 ; L->isVisible = 1 ; @@ -250,6 +251,11 @@ getBasicXcfInfo(void) L->type = xcfL(ptr); ptr+=4 ; L->name = xcfString(ptr,&ptr); L->propptr = ptr ; + + L->isGroup = 0; + L->pathLength = 0; + L->path = NULL; + while( (type = xcfNextprop(&ptr,&data)) != PROP_END ) { switch(type) { case PROP_OPACITY: @@ -270,6 +276,20 @@ getBasicXcfInfo(void) case PROP_MODE: L->mode = xcfL(data); break ; + case PROP_GROUP_ITEM: + L->isGroup = 1 ; + break; + case PROP_ITEM_PATH: + L->pathLength = (ptr - data - 2) / 4 ; + + if ( L->pathLength != 0 ) { + + L->path = xcfmalloc( L->pathLength * sizeof(unsigned) ) ; + + for ( j = 0; j!=L->pathLength; j++ ) + *(L->path + j) = (unsigned)xcfL(data + 4 * j); + } + break; default: /* Ignore unknown properties */ break ; @@ -42,6 +42,23 @@ usage(FILE *where) } } +static void +printLayerPath +( unsigned layerIndex, const char* pathSeparator ) +{ + int depth = XCF.layers[layerIndex].pathLength ; + int i = layerIndex; + + if ( depth != 0 ) { + do { + i++; + } while ( XCF.layers[i].pathLength != depth - 1 ); + + printLayerPath( i, pathSeparator ) ; + printf( "%s%s", pathSeparator, XCF.layers[i].name ); + } +} + int main(int argc,char **argv) { @@ -49,6 +66,7 @@ main(int argc,char **argv) int option ; const char *unzipper = NULL ; const char *infile = NULL ; + const char *pathSeparator = "|"; setlocale(LC_ALL,""); progname = argv[0] ; @@ -95,7 +113,17 @@ main(int argc,char **argv) printf("/%02d%%",XCF.layers[i].opacity * 100 / 255); if( XCF.layers[i].hasMask ) printf(_("/mask")); - printf(" %s\n",XCF.layers[i].name); + if( XCF.layers[i].isGroup ) + printf(_("/group")); + + printf( " " ); + + if ( XCF.version > 2 ) { + printLayerPath( i, pathSeparator ); + printf( "%s", pathSeparator ); + } + + printf("%s\n",XCF.layers[i].name); } return 0 ; @@ -181,6 +181,9 @@ struct xcfLayer { uint32_t propptr ; struct xcfTiles pixels ; struct xcfTiles mask ; + int isGroup ; + unsigned pathLength ; + unsigned *path ; }; extern struct xcfImage { |