Krita Source Code Documentation
Loading...
Searching...
No Matches
xcftools.h
Go to the documentation of this file.
1/* Generic functions and macros for reading XCF files
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#ifndef XCFTOOLS_H
20#define XCFTOOLS_H
21
22#include "config.h"
23#include "enums.h"
24#include <stddef.h>
25#include <stdio.h>
26
27#if defined(HAVE_GETTEXT) && defined(ENABLE_NLS)
28#include <libintl.h>
29#define _(s) gettext(s)
30void nls_init(void);
31#else
32#define _(s) (s)
33#define nls_init() (void)0
34#endif
35#define N_(s) (s)
36
37#if HAVE_INTTYPES_H
38# define __STDC_FORMAT_MACROS
39# include <inttypes.h>
40#else
41/* These legacy fall-backs will probably work on every system
42 * that does not supply a inttypes.h ... */
43typedef unsigned char uint8_t ;
44typedef unsigned long int uint32_t, uintptr_t;
45typedef signed char int8_t ;
46typedef signed long int int32_t ;
47# define PRIX32 "lX"
48# define PRIu32 "lu"
49# define PRIXPTR "lX"
50#endif
51
52#if __GNUC__
53# define __ATTRIBUTE__ __attribute__
54#else
55# define __ATTRIBUTE__(x)
56#endif
57
58#ifdef _WIN32
59#include <winsock2.h>
60#elif HAVE_NETINET_IN_H
61#include <netinet/in.h>
62#elif HAVE_ARPA_INET_H
63# include <arpa/inet.h>
64#elif WORDS_BIGENDIAN
65# define ntohl(x) (x)
66#else
67static inline uint32_t ntohl(uint32_t a) {
68 return (a << 24) + ((a & 0xFF00) << 8) + ((a >> 8) & 0xFF00) + (a >> 24) ;
69}
70#endif
71
72#ifndef HAVE_STRCASECMP
73#define strcasecmp strcmp
74#endif
75
76/* Read a single word value from the XCF file */
77
78/* Use + instead of | because that allows LEA instructions */
79#define xcfBE(a) ( ((uint32_t)xcf_file[(a) ] << 24) + \
80 ((uint32_t)xcf_file[(a)+1] << 16) + \
81 ((uint32_t)xcf_file[(a)+2] << 8 ) + \
82 ((uint32_t)xcf_file[(a)+3] ) )
83#define xcfLE(a) ( ((uint32_t)xcf_file[(a) ] ) + \
84 ((uint32_t)xcf_file[(a)+1] << 8 ) + \
85 ((uint32_t)xcf_file[(a)+2] << 16) + \
86 ((uint32_t)xcf_file[(a)+3] << 24) )
87
88#if defined(CAN_DO_UNALIGNED_WORDS)
89# define xcfL(a) ntohl(*(uint32_t *)(xcf_file + (a)))
90#else
91# define xcfL(a) ((a) & 3 ? xcfBE(a) : ntohl(*(uint32_t *)(xcf_file + (a))))
92#endif
93
94/* ****************************************************************** */
95
96/* The following are exported from am OS-specific source file;
97 * io-unix.c on unixish systems.
98 */
99void read_or_mmap_xcf(const char* filename, const char *unzipper);
101
102/* ****************************************************************** */
103/* utils.c */
104
105#define XCF_ERROR 1
106#define XCF_OK 0
107#define XCF_PTR_EMPTY 0
108
109extern const char *progname ;
110extern int verboseFlag ;
111
112void *xcfmalloc(size_t size);
113void xcffree(void*);
114
115void FatalGeneric(int status,const char* format,...)
116 __ATTRIBUTE__((format(printf,2,3))) ;
117void FatalUnexpected(const char* format,...)
118 __ATTRIBUTE__((format(printf,1,2))) ;
119void FatalBadXCF(const char* format,...)
120 __ATTRIBUTE__((format(printf,1,2))) ;
121void FatalUnsupportedXCF(const char* format,...)
122 __ATTRIBUTE__((format(printf,1,2))) ;
123
124void gpl_blurb(void);
125
126FILE* openout(const char*);
127int closeout(FILE *,const char*);
128
129struct rect {
130 int t, b, l, r ;
131};
132
133#define isSubrect(A,B) \
134 ((A).l >= (B).l && (A).r <= (B).r && (A).t >= (B).t && (A).b <= (B).b)
135#define disjointRects(A,B) \
136 ((A).l >= (B).r || (A).r <= (B).l || (A).t >= (B).b || (A).b <= (B).t)
137
138/* ****************************************************************** */
139/* xcf-general.c */
140
141extern uint8_t *xcf_file ;
142extern size_t xcf_length ;
143extern int use_utf8 ;
144
145int xcfCheckspace(uint32_t addr,int spaceafter, const char *format,...)
146 __ATTRIBUTE__((format(printf,3,4)));
147int xcfOffset(uint32_t addr,int spaceafter, uint32_t* apparent);
148
149int xcfNextprop(uint32_t *master,uint32_t *body, PropType* type);
150const char* xcfString(uint32_t ptr,uint32_t *after);
151
152/* These are hardcoded in the Gimp sources: */
153#define TILE_SHIFT 6
154#define TILE_WIDTH (1<<TILE_SHIFT)
155#define TILE_HEIGHT (1<<TILE_SHIFT)
156/* These definitions of TILE_LEFT and TILE_TOP work correctly for negative
157 * numbers, but on the other hand depend on TILE_WIDTH and TILE_HEIGHT
158 * being powers of 2. That's okay, because the tile size cannot change
159 * anyway.
160 */
161#define TILE_LEFT(x) ((x) & -TILE_WIDTH)
162#define TILE_TOP(y) ((y) & -TILE_HEIGHT)
163#define TILE_NUM(x) ((x) >> TILE_SHIFT)
164
166 struct rect c ;
167 unsigned width, height ;
168 unsigned tilesx, tilesy ;
169 unsigned ntiles ;
170};
171/* computeDimensions assumes that width, height, c.l, and c.t are set */
173
174struct xcfTiles {
175 const struct _convertParams *params ;
176 uint32_t *tileptrs ;
177 uint32_t hierarchy ;
178};
179
194
204
205int getBasicXcfInfo(void);
206
207#endif /* XCFTOOLS_H */
GimpLayerModeEffects
Definition enums.h:8
XcfCompressionType
Definition enums.h:96
GimpImageType
Definition enums.h:48
GimpImageBaseType
Definition enums.h:40
PropType
Definition enums.h:59
int b
Definition xcftools.h:130
struct rect c
Definition xcftools.h:166
unsigned tilesx
Definition xcftools.h:168
unsigned height
Definition xcftools.h:167
unsigned tilesy
Definition xcftools.h:168
unsigned width
Definition xcftools.h:167
unsigned ntiles
Definition xcftools.h:169
GimpImageBaseType type
Definition xcftools.h:198
XcfCompressionType compression
Definition xcftools.h:199
unsigned height
Definition xcftools.h:197
unsigned width
Definition xcftools.h:197
int numLayers
Definition xcftools.h:200
struct xcfLayer * layers
Definition xcftools.h:201
int version
Definition xcftools.h:196
uint32_t colormapptr
Definition xcftools.h:202
unsigned int opacity
Definition xcftools.h:185
unsigned pathLength
Definition xcftools.h:191
int isVisible
Definition xcftools.h:186
GimpLayerModeEffects mode
Definition xcftools.h:183
struct xcfTiles pixels
Definition xcftools.h:188
int isGroup
Definition xcftools.h:190
int hasMask
Definition xcftools.h:186
uint32_t propptr
Definition xcftools.h:187
struct tileDimensions dim
Definition xcftools.h:181
unsigned * path
Definition xcftools.h:192
const char * name
Definition xcftools.h:182
GimpImageType type
Definition xcftools.h:184
struct xcfTiles mask
Definition xcftools.h:189
const struct _convertParams * params
Definition xcftools.h:175
uint32_t hierarchy
Definition xcftools.h:177
uint32_t * tileptrs
Definition xcftools.h:176
int use_utf8
Definition xcf-general.c:31
void FatalGeneric(int status, const char *format,...) __ATTRIBUTE__((format(printf
int xcfNextprop(uint32_t *master, uint32_t *body, PropType *type)
Definition xcf-general.c:52
void * xcfmalloc(size_t size)
Definition utils.c:114
int getBasicXcfInfo(void)
FILE * openout(const char *)
Definition utils.c:138
void free_or_close_xcf(void)
#define __ATTRIBUTE__(x)
Definition xcftools.h:55
struct xcfImage XCF
void void void void FatalUnsupportedXCF(const char *format,...) __ATTRIBUTE__((format(printf
void void FatalUnexpected(const char *format,...) __ATTRIBUTE__((format(printf
int verboseFlag
Definition utils.c:26
int int xcfOffset(uint32_t addr, int spaceafter, uint32_t *apparent)
Definition xcf-general.c:34
const char * xcfString(uint32_t ptr, uint32_t *after)
void void void FatalBadXCF(const char *format,...) __ATTRIBUTE__((format(printf
#define nls_init()
Definition xcftools.h:33
void read_or_mmap_xcf(const char *filename, const char *unzipper)
int computeDimensions(struct tileDimensions *)
void void void void void gpl_blurb(void)
Definition utils.c:102
size_t xcf_length
Definition xcf-general.c:30
int closeout(FILE *, const char *)
Definition utils.c:152
const char * progname
Definition utils.c:25
int xcfCheckspace(uint32_t addr, int spaceafter, const char *format,...) __ATTRIBUTE__((format(printf
uint8_t * xcf_file
Definition xcf-general.c:29
void xcffree(void *)
Definition utils.c:125