25#elif !defined(ICONV_CONST)
26# define ICONV_CONST const
34xcfOffset(uint32_t addr,
int spaceafter, uint32_t* apparent)
42 *apparent =
xcfL(addr);
44 "Too large offset (%" PRIX32
") at position %" PRIX32,
45 *apparent,addr) !=
XCF_OK) {
60 uint32_t ptr,
length, total, minlength ;
77 ncolors =
xcfL(ptr+8) ;
79 FatalBadXCF(
"Colormap has %" PRIu32
" entries",ncolors);
88 length = minlength = 4+3*ncolors;
96 default: minlength = 0;
break;
99 FatalBadXCF(
"Short %s property at %" PRIX32
" (%" PRIu32
"<%" PRIu32
")",
109 if((response =
xcfCheckspace(ptr,total,
"Overlong property at %" PRIX32,ptr)) != 0) {
132 if( after ) *after = ptr +
length ;
134 FatalBadXCF(
"String at %" PRIX32
" not zero-terminated",ptr-4);
147 if( utf8master[i] == 0 ) {
148 FatalBadXCF(
"String at %" PRIX32
" has embedded zeroes",ptr-4);
151 if( (int8_t) utf8master[i] < 0 )
156 size_t targetsize =
length+1 ;
157 int sloppy_translation = 0 ;
158 iconv_t cd = iconv_open(
"//TRANSLIT",
"UTF-8");
159 if( cd == (iconv_t) -1 ) {
160 cd = iconv_open(
"",
"UTF-8");
161 sloppy_translation = 1 ;
163 if( cd == (iconv_t) -1 )
169 char *outbuf = buffer ;
171 size_t outcount = targetsize ;
173 size_t result = iconv(cd,&inbuf,&incount,&outbuf,&outcount) ;
174 if( result == (
size_t)-1 && errno == EILSEQ &&
175 sloppy_translation && outcount > 0 ) {
178 while( (int8_t)*inbuf < 0 ) inbuf++, incount-- ;
181 if( result != (
size_t)-1 ) {
192 if( errno == EILSEQ || errno == EINVAL ) {
193 FatalBadXCF(
"Bad UTF-8 encoding '%s' at %" PRIXPTR,
194 inbuf,(uintptr_t)((inbuf-utf8master)+ptr));
197 if( errno == E2BIG ) {
198 targetsize += 1+incount ;
208 static int warned = 0 ;
210 fprintf(stderr,
_(
"Warning: one or more layer names could not be\n"
211 " translated to the local character set.\n"));
225 if ((d->c.l + d->width) * 4 > INT_MAX) {
226 FatalBadXCF((
"Width is too large (%d)! Stopping execution...\n"), (d->c.l + d->width));
230 if ((d->c.t + d->height) * 4 > INT_MAX) {
231 FatalBadXCF((
"Height is too large (%d)! Stopping execution...\n"), (d->c.t + d->height));
236 d->c.r = d->c.l + d->width ;
237 d->c.b = d->c.t + d->height ;
240 d->ntiles = d->tilesx * d->tilesy ;
250 uint32_t ptr, data, layerfile ;
261 if( strcmp((
char*)
xcf_file,
"gimp xcf file") == 0 )
267 FatalBadXCF(
_(
"Not an XCF file at all (magic not recognized)"));
272 fprintf(stderr,
_(
"Warning: XCF version %d not supported (trying anyway...)\n"),
XCF.
version);
283 if (errorStatus !=
XCF_OK) {
303 errorStatus =
xcfOffset(ptr,8*4, &ptrout);
304 if (errorStatus !=
XCF_OK) {
qreal length(const QPointF &vec)
const char * showPropType(PropType x)
XcfCompressionType compression
GimpLayerModeEffects mode
struct tileDimensions dim
void * xcfmalloc(size_t size)
void xcffree(void *block)
void FatalUnexpected(const char *format,...)
void FatalBadXCF(const char *format,...)
int xcfCheckspace(uint32_t addr, int spaceafter, const char *format,...)
int xcfOffset(uint32_t addr, int spaceafter, uint32_t *apparent)
int getBasicXcfInfo(void)
int xcfNextprop(uint32_t *master, uint32_t *body, PropType *typeOut)
const char * xcfString(uint32_t ptr, uint32_t *after)
int computeDimensions(struct tileDimensions *d)