45#define RGB_SHIFT RED_SHIFT, GREEN_SHIFT, BLUE_SHIFT
49#define OPAQUE (255 << ALPHA_SHIFT)
69 if(
xcfL(ptr ) != dim->
c.
r - dim->
c.
l ||
70 xcfL(ptr+4) != dim->
c.
b - dim->
c.
t ) {
71 FatalBadXCF(
"Drawable size mismatch at %" PRIX32, ptr);
75 *ptrOut = (ptr += 8) ;
127 FatalBadXCF(
"%" PRIuPTR
" bytes per pixel for %s drawable",
149#define REUSE_RAW_DATA tiles->tileptrs = (uint32_t*)(xcf_file + ptr)
150#if defined(WORDS_BIGENDIAN) && defined(CAN_DO_UNALIGNED_WORDS)
153# if defined(WORDS_BIGENDIAN)
159 for( i = 0 ; i < dim->
ntiles ; i++ )
171 switch(layer->
type) {
172#define DEF(X) case GIMP_##X##_IMAGE: layer->pixels.params = &convert##X; break
206 if( ncolors > 256 ) {
217 fprintf(stderr,
"Colormap decoding OK\n");
218 for( j = 0 ; j < ncolors ; j++ ) {
219 if( j % 8 == 0 ) fprintf(stderr,
"\n");
220 fprintf(stderr,
" %08x",
colormap[j]);
222 fprintf(stderr,
"\n");
233 unsigned npixels = (unsigned)(r.b-r.t) * (unsigned)(r.r-r.l) ;
237 data->
count = npixels ;
248 "More likely to be a bug in %s"),
progname);
271 summary &= ~TILESUMMARY_ALLNULL ;
273 summary &= ~TILESUMMARY_ALLFULL ;
286 for( i = 0 ; i < tile->
count ; i++ )
302 unsigned bpp = params->
bpp;
308 "pixel array (%u x %d bpp) at %"PRIX32,npixels,bpp,ptr)) !=
XCF_OK) {
312 rgba pixel = base_pixel ;
314 for( i = 0 ; i < bpp ; i++ ) {
315 if( params->
shift[i] < 0 ) {
316 pixel += lookup[*bp++] ;
318 pixel += *bp++ << params->
shift[i] ;
333 fprintf(stderr,
"RLE stream at %x, want %u x %u pixels, base %x\n",
334 ptr,params->
bpp,npixels,base_pixel);
338 if( params->
shift[0] < -1 )
340 for( j = npixels ; j-- ; )
341 dest[j] = base_pixel ;
343 for( i = 0 ; i < params->
bpp ; i++ ) {
344 int shift = params->
shift[i] ;
347 for( j = 0 ; j < npixels ; ) {
353 countspec = (int8_t)
xcf_file[ptr++] ;
354 count = countspec >= 0 ? countspec+1 : -countspec ;
362 if( j +
count > npixels ) {
363 FatalBadXCF(
"Overlong RLE run at %"PRIX32
" (plane %u, %u left)",
367 if( countspec >= 0 ) {
373 dest[j++] += (uint32_t)
xcf_file[ptr++] << shift ;
376 if( i == 0 && params->
shift[0] < 0 ) {
379 for( j = npixels ; j-- ; ) {
380 dest[j] = lookup[dest[j]-base_pixel] + base_pixel ;
385 fprintf(stderr,
"RLE decoding OK at %"PRIX32
"\n",ptr);
432 if (want.
l >= want.
r || want.
t >= want.
b ) {
443 fprintf(stderr,
"getMaskOrLayer: (%d-%d),(%d-%d)\n",left,right,top,bottom);
451 if( want.
r ==
TILEXn(*dim,tx+1) && want.
b ==
TILEYn(*dim,ty+1) ) {
463 unsigned width = want.
r-want.
l ;
468 unsigned lstart, lnum ;
469 unsigned cstart, cnum ;
472 if( want.
l < dim->
c.
l ) pixvert += (dim->
c.
l - want.
l),
474 if( want.
r > dim->
c.
r ) want.
r = dim->
c.
r ;
475 if( want.
t < dim->
c.
t ) pixvert += (dim->
c.
t - want.
t) * width,
477 if( want.
b > dim->
c.
b ) want.
b = dim->
c.
b ;
484 fprintf(stderr,
"jig0 (%d-%d),(%d-%d)\n",left,right,top,bottom);
489 pixvert += lnum*width, ty++, y=l0=l1 ) {
492 lnum = (l1 > want.
b ? want.
b : l1) - y ;
497 pixhoriz += cnum, tx++, x=c0=c1 ) {
500 cnum = (c1 > want.
r ? want.
r : c1) - x ;
503 static struct Tile tmptile ;
504 unsigned dwidth = c1-c0 ;
506 tmptile.
count = (c1-c0)*(l1-l0) ;
508 fprintf(stderr,
"jig ty=%u(%u-%u-%u)(%u+%u) tx=%u(%u-%u-%u)(%u+%u)\n",
509 ty,l0,y,l1,lstart,lnum,
510 tx,c0,x,c1,cstart,cnum);
518 for(i=0; i<lnum; i++)
519 for(j=0; j<cnum; j++)
521 = tmptile.
pixels[(i+lstart)*dwidth+(j+cstart)];
538 for( i=0; i < tile->
count ;i++ )
551 fprintf(stderr,
"getLayerTile(%s): (%d-%d),(%d-%d)\n",
552 layer->
name,where->
l,where->
r,where->
t,where->
b);
577 const uint8_t *ourtable ;
582 for( i=0; i < data->
count; i++ )
const char * showXcfCompressionType(XcfCompressionType x)
const char * showGimpImageType(GimpImageType x)
static int initTileDirectory(struct tileDimensions *dim, struct xcfTiles *tiles, const char *type)
static int copyRLEpixels(rgba *dest, unsigned npixels, uint32_t ptr, convertParams *params)
summary_t tileSummary(struct Tile *tile)
struct Tile * getLayerTile(struct xcfLayer *layer, const struct rect *where)
static convertParams convertINDEXED
static convertParams convertRGB
static int copyStraightPixels(rgba *dest, unsigned npixels, uint32_t ptr, convertParams *params)
static convertParams convertColormap
static convertParams convertChannel
int degrayPixel(rgba pixel)
static convertParams convertRGBA
static convertParams convertGRAYA
int initLayer(struct xcfLayer *layer)
static convertParams convertGRAY
void freeTile(struct Tile *tile)
struct Tile * getMaskOrLayerTile(struct tileDimensions *dim, struct xcfTiles *tiles, struct rect want)
static convertParams convertINDEXEDA
static int copyTilePixels(struct Tile *dest, uint32_t ptr, convertParams *params)
static int tileDirectoryOneLevel(struct tileDimensions *dim, uint32_t ptr, int *ptrOut)
void applyMask(struct Tile *tile, struct Tile *mask)
void fillTile(struct Tile *tile, rgba data)
struct Tile * newTile(struct rect r)
const struct _convertParams convertParams
struct Tile * forkTile(struct Tile *tile)
#define TILESUMMARY_UPTODATE
#define TILESUMMARY_ALLNULL
#define TILESUMMARY_CRISP
#define TILESUMMARY_ALLFULL
const rgba graytable[256]
#define assertTileCompatibility(t1, t2)
uint8_t scaletable[256][256]
#define invalidateSummary(tile, mask)
#define INIT_SCALETABLE_IF(foo)
rgba pixels[TILE_WIDTH *TILE_HEIGHT]
XcfCompressionType compression
struct tileDimensions dim
const struct _convertParams * params
void FatalUnsupportedXCF(const char *format,...)
void * xcfmalloc(size_t size)
void xcffree(void *block)
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 xcfNextprop(uint32_t *master, uint32_t *body, PropType *typeOut)
const char * xcfString(uint32_t ptr, uint32_t *after)