Krita Source Code Documentation
Loading...
Searching...
No Matches
pixels.c File Reference
#include "xcftools.h"
#include "pixels.h"
#include <assert.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  _convertParams
 

Macros

#define DEBUG
 
#define DEF(X)   case GIMP_##X##_IMAGE: layer->pixels.params = &convert##X; break
 
#define OPAQUE   (255 << ALPHA_SHIFT)
 
#define REUSE_RAW_DATA   tiles->tileptrs = (uint32_t*)(xcf_file + ptr)
 
#define RGB_SHIFT   RED_SHIFT, GREEN_SHIFT, BLUE_SHIFT
 

Typedefs

typedef const struct _convertParams convertParams
 

Functions

void applyMask (struct Tile *tile, struct Tile *mask)
 
static int copyRLEpixels (rgba *dest, unsigned npixels, uint32_t ptr, convertParams *params)
 
static int copyStraightPixels (rgba *dest, unsigned npixels, uint32_t ptr, convertParams *params)
 
static int copyTilePixels (struct Tile *dest, uint32_t ptr, convertParams *params)
 
int degrayPixel (rgba pixel)
 
void fillTile (struct Tile *tile, rgba data)
 
struct TileforkTile (struct Tile *tile)
 
void freeTile (struct Tile *tile)
 
struct TilegetLayerTile (struct xcfLayer *layer, const struct rect *where)
 
struct TilegetMaskOrLayerTile (struct tileDimensions *dim, struct xcfTiles *tiles, struct rect want)
 
int initColormap (void)
 
int initLayer (struct xcfLayer *layer)
 
static int initTileDirectory (struct tileDimensions *dim, struct xcfTiles *tiles, const char *type)
 
struct TilenewTile (struct rect r)
 
static int tileDirectoryOneLevel (struct tileDimensions *dim, uint32_t ptr, int *ptrOut)
 
summary_t tileSummary (struct Tile *tile)
 

Variables

rgba colormap [256]
 
unsigned colormapLength =0
 
static convertParams convertChannel = { 1, {ALPHA_SHIFT}, 0, 0 }
 
static convertParams convertColormap = { 3, {RGB_SHIFT}, 0, 0 }
 
static convertParams convertGRAY = { 1, {-1}, OPAQUE, graytable }
 
static convertParams convertGRAYA = { 2, {-1,ALPHA_SHIFT}, 0, graytable }
 
static convertParams convertINDEXED = { 1, {-1}, OPAQUE, colormap }
 
static convertParams convertINDEXEDA = { 2, {-1,ALPHA_SHIFT}, 0, colormap }
 
static convertParams convertRGB = { 3, {RGB_SHIFT}, OPAQUE, 0 }
 
static convertParams convertRGBA = { 4, {RGB_SHIFT, ALPHA_SHIFT}, 0,0 }
 

Macro Definition Documentation

◆ DEBUG

#define DEBUG

Definition at line 19 of file pixels.c.

◆ DEF

#define DEF ( X)    case GIMP_##X##_IMAGE: layer->pixels.params = &convert##X; break

◆ OPAQUE

#define OPAQUE   (255 << ALPHA_SHIFT)

Definition at line 49 of file pixels.c.

◆ REUSE_RAW_DATA

#define REUSE_RAW_DATA   tiles->tileptrs = (uint32_t*)(xcf_file + ptr)

◆ RGB_SHIFT

#define RGB_SHIFT   RED_SHIFT, GREEN_SHIFT, BLUE_SHIFT

Definition at line 45 of file pixels.c.

Typedef Documentation

◆ convertParams

typedef const struct _convertParams convertParams

Function Documentation

◆ applyMask()

void applyMask ( struct Tile * tile,
struct Tile * mask )

Definition at line 531 of file pixels.c.

532{
533 unsigned i ;
534 assertTileCompatibility(tile,mask);
535 assert( tile->count == mask->count );
537 invalidateSummary(tile,0);
538 for( i=0; i < tile->count ;i++ )
539 tile->pixels[i] = NEWALPHA(tile->pixels[i],
540 scaletable[mask->pixels[i]>>ALPHA_SHIFT]
541 [ALPHA(tile->pixels[i])]);
542 freeTile(mask);
543}
void freeTile(struct Tile *tile)
Definition pixels.c:255
#define ALPHA_SHIFT
Definition pixels.h:46
#define ALPHA(rgba)
Definition pixels.h:51
#define NEWALPHA(rgb, a)
Definition pixels.h:54
#define assertTileCompatibility(t1, t2)
Definition pixels.h:110
uint8_t scaletable[256][256]
Definition scaletab.c:22
#define invalidateSummary(tile, mask)
Definition pixels.h:115
#define INIT_SCALETABLE_IF(foo)
Definition pixels.h:63
rgba pixels[TILE_WIDTH *TILE_HEIGHT]
Definition pixels.h:101
unsigned count
Definition pixels.h:100

References ALPHA, ALPHA_SHIFT, assertTileCompatibility, Tile::count, freeTile(), INIT_SCALETABLE_IF, invalidateSummary, NEWALPHA, Tile::pixels, and scaletable.

◆ copyRLEpixels()

static int copyRLEpixels ( rgba * dest,
unsigned npixels,
uint32_t ptr,
convertParams * params )
inlinestatic

Definition at line 327 of file pixels.c.

328{
329 unsigned i,j ;
330 rgba base_pixel = params->base_pixel ;
331
332#ifdef xDEBUG
333 fprintf(stderr,"RLE stream at %x, want %u x %u pixels, base %x\n",
334 ptr,params->bpp,npixels,base_pixel);
335#endif
336
337 /* This algorithm depends on the indexed byte always being the first one */
338 if( params->shift[0] < -1 )
339 base_pixel = 0 ;
340 for( j = npixels ; j-- ; )
341 dest[j] = base_pixel ;
342
343 for( i = 0 ; i < params->bpp ; i++ ) {
344 int shift = params->shift[i] ;
345 if( shift < 0 )
346 shift = 0 ;
347 for( j = 0 ; j < npixels ; ) {
348 int countspec ;
349 unsigned count ;
350 if (xcfCheckspace(ptr,2,"RLE data stream") != XCF_OK) {
351 return XCF_ERROR;
352 }
353 countspec = (int8_t) xcf_file[ptr++] ;
354 count = countspec >= 0 ? countspec+1 : -countspec ;
355 if( count == 128 ) {
356 if (xcfCheckspace(ptr,3,"RLE long count") != XCF_OK) {
357 return XCF_ERROR;
358 }
359 count = xcf_file[ptr++] << 8 ;
360 count += xcf_file[ptr++] ;
361 }
362 if( j + count > npixels ) {
363 FatalBadXCF("Overlong RLE run at %"PRIX32" (plane %u, %u left)",
364 ptr,i,npixels-j);
365 return XCF_ERROR;
366 }
367 if( countspec >= 0 ) {
368 rgba data = (uint32_t) xcf_file[ptr++] << shift ;
369 while( count-- )
370 dest[j++] += data ;
371 } else {
372 while( count-- )
373 dest[j++] += (uint32_t) xcf_file[ptr++] << shift ;
374 }
375 }
376 if( i == 0 && params->shift[0] < 0 ) {
377 const rgba *lookup = params->lookup ;
378 base_pixel = params->base_pixel ;
379 for( j = npixels ; j-- ; ) {
380 dest[j] = lookup[dest[j]-base_pixel] + base_pixel ;
381 }
382 }
383 }
384#ifdef xDEBUG
385 fprintf(stderr,"RLE decoding OK at %"PRIX32"\n",ptr);
386 /*
387 for( j = 0 ; j < npixels ; j++ ) {
388 if( j % 8 == 0 ) fprintf(stderr,"\n");
389 fprintf(stderr," %8x",dest[j]);
390 }
391 fprintf(stderr,"\n");
392 */
393#endif
394 return XCF_OK;
395}
uint32_t rgba
Definition pixels.h:44
uint32_t base_pixel
Definition pixels.c:42
const rgba * lookup
Definition pixels.c:43
int shift[4]
Definition pixels.c:41
void FatalBadXCF(const char *format,...)
Definition utils.c:66
int xcfCheckspace(uint32_t addr, int spaceafter, const char *format,...)
Definition utils.c:75
uint8_t * xcf_file
Definition xcf-general.c:29
#define XCF_OK
Definition xcftools.h:106
#define XCF_ERROR
Definition xcftools.h:105

References _convertParams::base_pixel, _convertParams::bpp, Tile::count, FatalBadXCF(), _convertParams::lookup, _convertParams::shift, XCF_ERROR, xcf_file, XCF_OK, and xcfCheckspace().

◆ copyStraightPixels()

static int copyStraightPixels ( rgba * dest,
unsigned npixels,
uint32_t ptr,
convertParams * params )
static

Definition at line 299 of file pixels.c.

301{
302 unsigned bpp = params->bpp;
303 const rgba *lookup = params->lookup;
304 rgba base_pixel = params->base_pixel ;
305 uint8_t *bp = xcf_file + ptr ;
306 int response;
307 if ((response = xcfCheckspace(ptr,bpp*npixels,
308 "pixel array (%u x %d bpp) at %"PRIX32,npixels,bpp,ptr)) != XCF_OK) {
309 return XCF_ERROR;
310 }
311 while( npixels-- ) {
312 rgba pixel = base_pixel ;
313 unsigned i ;
314 for( i = 0 ; i < bpp ; i++ ) {
315 if( params->shift[i] < 0 ) {
316 pixel += lookup[*bp++] ;
317 } else {
318 pixel += *bp++ << params->shift[i] ;
319 }
320 }
321 *dest++ = pixel ;
322 }
323 return XCF_OK;
324}

References _convertParams::base_pixel, _convertParams::bpp, _convertParams::lookup, _convertParams::shift, XCF_ERROR, xcf_file, XCF_OK, and xcfCheckspace().

◆ copyTilePixels()

static int copyTilePixels ( struct Tile * dest,
uint32_t ptr,
convertParams * params )
inlinestatic

Definition at line 398 of file pixels.c.

399{
400 if( FULLALPHA(params->base_pixel) )
402 else
403 dest->summary = 0 ;
404 switch( XCF.compression ) {
405 case COMPRESS_NONE:
406 if (copyStraightPixels(dest->pixels,dest->count,ptr,params) != XCF_OK) {
407 return XCF_ERROR;
408 }
409 break ;
410 case COMPRESS_RLE:
411 if (copyRLEpixels(dest->pixels,dest->count,ptr,params) != XCF_OK) {
412 return XCF_ERROR;
413 }
414 break ;
415 default:
416 {
417 FatalUnsupportedXCF(_("%s compression"),
419 return XCF_ERROR;
420 }
421 }
422 return XCF_OK;
423}
const char * showXcfCompressionType(XcfCompressionType x)
Definition enums.c:110
@ COMPRESS_RLE
Definition enums.h:98
@ COMPRESS_NONE
Definition enums.h:97
static int copyRLEpixels(rgba *dest, unsigned npixels, uint32_t ptr, convertParams *params)
Definition pixels.c:327
static int copyStraightPixels(rgba *dest, unsigned npixels, uint32_t ptr, convertParams *params)
Definition pixels.c:299
#define TILESUMMARY_UPTODATE
Definition pixels.h:93
#define FULLALPHA(rgba)
Definition pixels.h:52
#define TILESUMMARY_CRISP
Definition pixels.h:96
#define TILESUMMARY_ALLFULL
Definition pixels.h:95
summary_t summary
Definition pixels.h:99
XcfCompressionType compression
Definition xcftools.h:199
void FatalUnsupportedXCF(const char *format,...)
Definition utils.c:91
struct xcfImage XCF
#define _(s)
Definition xcftools.h:32

References _, _convertParams::base_pixel, COMPRESS_NONE, COMPRESS_RLE, xcfImage::compression, copyRLEpixels(), copyStraightPixels(), Tile::count, FatalUnsupportedXCF(), FULLALPHA, Tile::pixels, showXcfCompressionType(), Tile::summary, TILESUMMARY_ALLFULL, TILESUMMARY_CRISP, TILESUMMARY_UPTODATE, XCF, XCF_ERROR, and XCF_OK.

◆ degrayPixel()

int degrayPixel ( rgba pixel)

Definition at line 29 of file pixels.c.

30{
31 if( ((pixel >> RED_SHIFT) & 255) == ((pixel >> GREEN_SHIFT) & 255) &&
32 ((pixel >> RED_SHIFT) & 255) == ((pixel >> BLUE_SHIFT) & 255) )
33 return (pixel >> RED_SHIFT) & 255 ;
34 return -1 ;
35}
#define RED_SHIFT
Definition pixels.h:47
#define BLUE_SHIFT
Definition pixels.h:49
#define GREEN_SHIFT
Definition pixels.h:48

References BLUE_SHIFT, GREEN_SHIFT, and RED_SHIFT.

◆ fillTile()

void fillTile ( struct Tile * tile,
rgba data )

Definition at line 283 of file pixels.c.

284{
285 unsigned i ;
286 for( i = 0 ; i < tile->count ; i++ )
287 tile->pixels[i] = data ;
288 if( FULLALPHA(data) )
290 else if (NULLALPHA(data) )
292 else
294}
#define TILESUMMARY_ALLNULL
Definition pixels.h:94
#define NULLALPHA(rgba)
Definition pixels.h:53

References Tile::count, FULLALPHA, NULLALPHA, Tile::pixels, Tile::summary, TILESUMMARY_ALLFULL, TILESUMMARY_ALLNULL, TILESUMMARY_CRISP, and TILESUMMARY_UPTODATE.

◆ forkTile()

struct Tile * forkTile ( struct Tile * tile)

Definition at line 244 of file pixels.c.

245{
246 if( ++tile->refcount <= 0 ) {
247 FatalUnsupportedXCF(_("Unbelievably many layers?\n"
248 "More likely to be a bug in %s"),progname);
249 return XCF_PTR_EMPTY;
250 }
251 return tile ;
252}
refcount_t refcount
Definition pixels.h:98
const char * progname
Definition utils.c:25
#define XCF_PTR_EMPTY
Definition xcftools.h:107

References _, FatalUnsupportedXCF(), progname, Tile::refcount, and XCF_PTR_EMPTY.

◆ freeTile()

void freeTile ( struct Tile * tile)

Definition at line 255 of file pixels.c.

256{
257 if( --tile->refcount == 0 )
258 xcffree(tile) ;
259}
void xcffree(void *block)
Definition utils.c:125

References Tile::refcount, and xcffree().

◆ getLayerTile()

struct Tile * getLayerTile ( struct xcfLayer * layer,
const struct rect * where )

Definition at line 546 of file pixels.c.

547{
548 struct Tile *data ;
549
550#ifdef xDEBUG
551 fprintf(stderr,"getLayerTile(%s): (%d-%d),(%d-%d)\n",
552 layer->name,where->l,where->r,where->t,where->b);
553#endif
554
555 if( disjointRects(*where,layer->dim.c) ||
556 layer->opacity == 0 ) {
557 data = newTile(*where);
558 fillTile(data,0);
559 return data ;
560 }
561
562 data = getMaskOrLayerTile(&layer->dim,&layer->pixels,*where);
563 if (data == XCF_PTR_EMPTY) {
564 return XCF_PTR_EMPTY;
565 }
566 if( (data->summary & TILESUMMARY_ALLNULL) != 0 )
567 return data ;
568 if( layer->hasMask ) {
569 struct Tile *mask = getMaskOrLayerTile(&layer->dim,&layer->mask,*where);
570 if (mask == XCF_PTR_EMPTY) { /* error */
571 freeTile(data);
572 return XCF_PTR_EMPTY;
573 }
574 applyMask(data,mask);
575 }
576 if( layer->opacity < 255 ) {
577 const uint8_t *ourtable ;
578 int i ;
581 ourtable = scaletable[layer->opacity] ;
582 for( i=0; i < data->count; i++ )
583 data->pixels[i]
584 = NEWALPHA(data->pixels[i],ourtable[ALPHA(data->pixels[i])]) ;
585 }
586 return data ;
587}
struct Tile * getMaskOrLayerTile(struct tileDimensions *dim, struct xcfTiles *tiles, struct rect want)
Definition pixels.c:427
void applyMask(struct Tile *tile, struct Tile *mask)
Definition pixels.c:531
void fillTile(struct Tile *tile, rgba data)
Definition pixels.c:283
struct Tile * newTile(struct rect r)
Definition pixels.c:231
Definition pixels.h:97
int l
Definition xcftools.h:130
int r
Definition xcftools.h:130
int t
Definition xcftools.h:130
int b
Definition xcftools.h:130
struct rect c
Definition xcftools.h:166
unsigned int opacity
Definition xcftools.h:185
struct xcfTiles pixels
Definition xcftools.h:188
int hasMask
Definition xcftools.h:186
struct tileDimensions dim
Definition xcftools.h:181
const char * name
Definition xcftools.h:182
struct xcfTiles mask
Definition xcftools.h:189
#define disjointRects(A, B)
Definition xcftools.h:135

References ALPHA, applyMask(), rect::b, tileDimensions::c, Tile::count, xcfLayer::dim, disjointRects, fillTile(), freeTile(), getMaskOrLayerTile(), xcfLayer::hasMask, INIT_SCALETABLE_IF, invalidateSummary, rect::l, xcfLayer::mask, xcfLayer::name, NEWALPHA, newTile(), xcfLayer::opacity, Tile::pixels, xcfLayer::pixels, rect::r, scaletable, Tile::summary, rect::t, TILESUMMARY_ALLFULL, TILESUMMARY_ALLNULL, TILESUMMARY_CRISP, and XCF_PTR_EMPTY.

◆ getMaskOrLayerTile()

struct Tile * getMaskOrLayerTile ( struct tileDimensions * dim,
struct xcfTiles * tiles,
struct rect want )

Definition at line 427 of file pixels.c.

429{
430 struct Tile *tile = newTile(want);
431
432 if (want.l >= want.r || want.t >= want.b ) {
433 freeTile(tile);
434 return XCF_PTR_EMPTY;
435 }
436
437 if( tiles->tileptrs == 0 ) {
438 fillTile(tile,0);
439 return tile ;
440 }
441
442#ifdef xDEBUG
443 fprintf(stderr,"getMaskOrLayer: (%d-%d),(%d-%d)\n",left,right,top,bottom);
444#endif
445
446 if( isSubrect(want,dim->c) &&
447 (want.l - dim->c.l) % TILE_WIDTH == 0 &&
448 (want.t - dim->c.t) % TILE_HEIGHT == 0 ) {
449 int tx = TILE_NUM(want.l - dim->c.l);
450 int ty = TILE_NUM(want.t - dim->c.t);
451 if( want.r == TILEXn(*dim,tx+1) && want.b == TILEYn(*dim,ty+1) ) {
452 /* The common case? An entire single tile from the layer */
453 if (copyTilePixels(tile,tiles->tileptrs[tx + ty*dim->tilesx],tiles->params) != XCF_OK) {
454 freeTile(tile);
455 return XCF_PTR_EMPTY;
456 }
457 return tile ;
458 }
459 }
460
461 /* OK, we must construct the wanted tile as a jigsaw */
462 {
463 unsigned width = want.r-want.l ;
464 rgba *pixvert = tile->pixels ;
465 rgba *pixhoriz ;
466 int y, ty, l0, l1 ;
467 int x, tx, c0, c1 ;
468 unsigned lstart, lnum ;
469 unsigned cstart, cnum ;
470
471 if( !isSubrect(want,dim->c) ) {
472 if( want.l < dim->c.l ) pixvert += (dim->c.l - want.l),
473 want.l = dim->c.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,
476 want.t = dim->c.t ;
477 if( want.b > dim->c.b ) want.b = dim->c.b ;
478 fillTile(tile,0);
479 } else {
480 tile->summary = -1 ; /* I.e. whatever the jigsaw pieces say */
481 }
482
483#ifdef xDEBUG
484 fprintf(stderr,"jig0 (%d-%d),(%d-%d)\n",left,right,top,bottom);
485#endif
486
487 for( y=want.t, ty=TILE_NUM(want.t-dim->c.t), l0=TILEYn(*dim,ty);
488 y<want.b;
489 pixvert += lnum*width, ty++, y=l0=l1 ) {
490 l1 = TILEYn(*dim,ty+1) ;
491 lstart = y - l0 ;
492 lnum = (l1 > want.b ? want.b : l1) - y ;
493
494 pixhoriz = pixvert ;
495 for( x=want.l, tx=TILE_NUM(want.l-dim->c.l), c0=TILEXn(*dim,tx);
496 x<want.r;
497 pixhoriz += cnum, tx++, x=c0=c1 ) {
498 c1 = TILEXn(*dim,tx+1);
499 cstart = x - c0 ;
500 cnum = (c1 > want.r ? want.r : c1) - x ;
501
502 {
503 static struct Tile tmptile ;
504 unsigned dwidth = c1-c0 ;
505 unsigned i, j ;
506 tmptile.count = (c1-c0)*(l1-l0) ;
507#ifdef xDEBUG
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);
511#endif
512 if (copyTilePixels(&tmptile,
513 tiles->tileptrs[tx+ty*dim->tilesx],tiles->params) != XCF_OK) {
514 freeTile(tile);
515 return XCF_PTR_EMPTY;
516 }
517
518 for(i=0; i<lnum; i++)
519 for(j=0; j<cnum; j++)
520 pixhoriz[i*width+j]
521 = tmptile.pixels[(i+lstart)*dwidth+(j+cstart)];
522 tile->summary &= tmptile.summary ;
523 }
524 }
525 }
526 }
527 return tile ;
528}
static int copyTilePixels(struct Tile *dest, uint32_t ptr, convertParams *params)
Definition pixels.c:398
#define TILEYn(dim, ty)
Definition pixels.h:79
#define TILEXn(dim, tx)
Definition pixels.h:77
unsigned tilesx
Definition xcftools.h:168
const struct _convertParams * params
Definition xcftools.h:175
uint32_t * tileptrs
Definition xcftools.h:176
#define isSubrect(A, B)
Definition xcftools.h:133
#define TILE_HEIGHT
Definition xcftools.h:155
#define TILE_WIDTH
Definition xcftools.h:154
#define TILE_NUM(x)
Definition xcftools.h:163

References rect::b, tileDimensions::c, copyTilePixels(), Tile::count, fillTile(), freeTile(), isSubrect, rect::l, newTile(), xcfTiles::params, Tile::pixels, rect::r, Tile::summary, rect::t, TILE_HEIGHT, TILE_NUM, TILE_WIDTH, xcfTiles::tileptrs, tileDimensions::tilesx, TILEXn, TILEYn, XCF_OK, and XCF_PTR_EMPTY.

◆ initColormap()

int initColormap ( void )

Definition at line 199 of file pixels.c.

199 {
200 uint32_t ncolors ;
201 if( XCF.colormapptr == 0 ) {
202 colormapLength = 0 ;
203 return XCF_OK;
204 }
205 ncolors = xcfL(XCF.colormapptr) ;
206 if( ncolors > 256 ) {
207 FatalUnsupportedXCF(_("Color map has more than 256 entries"));
208 return XCF_ERROR;
209 }
211 return XCF_ERROR;
212 }
213 colormapLength = ncolors ;
214#ifdef xDEBUG
215 {
216 unsigned j ;
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]);
221 }
222 fprintf(stderr,"\n");
223 }
224#endif
225 return XCF_OK;
226}
unsigned colormapLength
Definition pixels.c:26
static convertParams convertColormap
Definition pixels.c:57
rgba colormap[256]
Definition pixels.c:25
uint32_t colormapptr
Definition xcftools.h:202
#define xcfL(a)
Definition xcftools.h:91

References _, colormap, colormapLength, xcfImage::colormapptr, convertColormap, copyStraightPixels(), FatalUnsupportedXCF(), XCF, XCF_ERROR, XCF_OK, and xcfL.

◆ initLayer()

int initLayer ( struct xcfLayer * layer)

Definition at line 167 of file pixels.c.

167 {
168 if( layer->dim.ntiles == 0 ||
169 (layer->pixels.hierarchy == 0 && layer->mask.hierarchy == 0) )
170 return XCF_OK;
171 switch(layer->type) {
172#define DEF(X) case GIMP_##X##_IMAGE: layer->pixels.params = &convert##X; break
173 DEF(RGB);
174 DEF(RGBA);
175 DEF(GRAY);
176 DEF(GRAYA);
177 DEF(INDEXED);
178 DEF(INDEXEDA);
179 default:
180 {
181 FatalUnsupportedXCF(_("Layer type %s"),_(showGimpImageType(layer->type)));
182 return XCF_ERROR;
183 }
184
185 }
186 if (initTileDirectory(&layer->dim,&layer->pixels,
187 _(showGimpImageType(layer->type))) != XCF_OK) {
188 return XCF_ERROR;
189 }
190 layer->mask.params = &convertChannel ;
191 if (initTileDirectory(&layer->dim,&layer->mask,"layer mask") != XCF_OK) {
192 return XCF_ERROR;
193 }
194 return XCF_OK;
195}
const char * showGimpImageType(GimpImageType x)
Definition enums.c:54
static int initTileDirectory(struct tileDimensions *dim, struct xcfTiles *tiles, const char *type)
Definition pixels.c:80
static convertParams convertChannel
Definition pixels.c:58
#define DEF(X)
@ RGB
Definition psd.h:54
unsigned ntiles
Definition xcftools.h:169
GimpImageType type
Definition xcftools.h:184
uint32_t hierarchy
Definition xcftools.h:177

References _, convertChannel, DEF, xcfLayer::dim, FatalUnsupportedXCF(), xcfTiles::hierarchy, initTileDirectory(), xcfLayer::mask, tileDimensions::ntiles, xcfTiles::params, xcfLayer::pixels, RGB, RGBA, showGimpImageType(), xcfLayer::type, XCF_ERROR, and XCF_OK.

◆ initTileDirectory()

static int initTileDirectory ( struct tileDimensions * dim,
struct xcfTiles * tiles,
const char * type )
static

Definition at line 80 of file pixels.c.

82{
83 uint32_t ptr ;
84 uint32_t data ;
85
86 ptr = tiles->hierarchy ;
87 tiles->hierarchy = 0 ;
88 int ptrOut;
89 if (tileDirectoryOneLevel(dim,ptr, &ptrOut) != XCF_OK) {
90 return XCF_ERROR;
91 }
92 if (ptrOut == XCF_PTR_EMPTY) {
93 return XCF_OK;
94 }
95 ptr = ptrOut;
96 if( tiles->params == &convertChannel ) {
97 /* A layer mask is a channel.
98 * Skip a name and a property list.
99 */
100 xcfString(ptr,&ptr);
101 PropType type;
102 int response;
103 while( (response = xcfNextprop(&ptr,&data, &type)) != XCF_ERROR && type != PROP_END ) {
104
105 }
106 if (response != XCF_OK) {
107 return XCF_ERROR;
108 }
109 uint32_t ptrout;
110 if(xcfOffset(ptr,4*4, &ptrout) != XCF_OK) return XCF_ERROR;
111 ptr = ptrout;
112 if (tileDirectoryOneLevel(dim,ptr, &ptrOut) != XCF_OK) {
113 return XCF_ERROR;
114 }
115 if (ptrOut == XCF_PTR_EMPTY) {
116 return XCF_OK;
117 }
118 ptr = ptrOut;
119 }
120 /* The XCF format has a dummy "hierarchy" level which was
121 * once meant to mean something, but never happened. It contains
122 * the bpp value and a list of "level" pointers; but only the
123 * first level actually contains data.
124 */
125 data = xcfL(ptr) ;
126 if( xcfL(ptr) != tiles->params->bpp ) {
127 FatalBadXCF("%" PRIuPTR " bytes per pixel for %s drawable",
128 xcfL(ptr),
129 type);
130 return XCF_ERROR;
131 }
132 uint32_t ptrout;
133 if(xcfOffset(ptr+4,3*4, &ptrout) != XCF_OK) return XCF_ERROR;
134 ptr = ptrout;
135 if (tileDirectoryOneLevel(dim,ptr, &ptrOut) != XCF_OK) {
136 return XCF_ERROR;
137 }
138 if (ptrOut == XCF_PTR_EMPTY) {
139 return XCF_OK;
140 }
141 ptr = ptrOut;
142
143 if (xcfCheckspace(ptr,dim->ntiles*4+4,"Tile directory at %" PRIX32,ptr) != XCF_OK) {
144 return XCF_ERROR;
145 }
146/* if( xcfL(ptr + dim->ntiles*4) != 0 )
147 FatalBadXCF("Wrong sized tile directory at %" PRIX32,ptr);*/
148
149#define REUSE_RAW_DATA tiles->tileptrs = (uint32_t*)(xcf_file + ptr)
150#if defined(WORDS_BIGENDIAN) && defined(CAN_DO_UNALIGNED_WORDS)
152#else
153# if defined(WORDS_BIGENDIAN)
154 if( (ptr&3) == 0 ) REUSE_RAW_DATA; else
155# endif
156 {
157 unsigned i ;
158 tiles->tileptrs = xcfmalloc(dim->ntiles * sizeof(uint32_t)) ;
159 for( i = 0 ; i < dim->ntiles ; i++ )
160 tiles->tileptrs[i] = xcfL(ptr+i*4);
161 }
162#endif
163 return XCF_OK;
164}
PropType
Definition enums.h:59
@ PROP_END
Definition enums.h:60
#define REUSE_RAW_DATA
static int tileDirectoryOneLevel(struct tileDimensions *dim, uint32_t ptr, int *ptrOut)
Definition pixels.c:63
void * xcfmalloc(size_t size)
Definition utils.c:114
int xcfOffset(uint32_t addr, int spaceafter, uint32_t *apparent)
Definition xcf-general.c:34
int xcfNextprop(uint32_t *master, uint32_t *body, PropType *typeOut)
Definition xcf-general.c:52
const char * xcfString(uint32_t ptr, uint32_t *after)

References _convertParams::bpp, convertChannel, FatalBadXCF(), xcfTiles::hierarchy, tileDimensions::ntiles, xcfTiles::params, PROP_END, REUSE_RAW_DATA, tileDirectoryOneLevel(), xcfTiles::tileptrs, XCF_ERROR, XCF_OK, XCF_PTR_EMPTY, xcfCheckspace(), xcfL, xcfmalloc(), xcfNextprop(), xcfOffset(), and xcfString().

◆ newTile()

struct Tile * newTile ( struct rect r)

Definition at line 231 of file pixels.c.

232{
233 unsigned npixels = (unsigned)(r.b-r.t) * (unsigned)(r.r-r.l) ;
234 struct Tile *data
235 = xcfmalloc(sizeof(struct Tile) -
236 sizeof(rgba)*(TILE_HEIGHT*TILE_WIDTH - npixels)) ;
237 data->count = npixels ;
238 data->refcount = 1 ;
239 data->summary = 0 ;
240 return data ;
241}

References Tile::count, Tile::refcount, Tile::summary, TILE_HEIGHT, TILE_WIDTH, and xcfmalloc().

◆ tileDirectoryOneLevel()

static int tileDirectoryOneLevel ( struct tileDimensions * dim,
uint32_t ptr,
int * ptrOut )
inlinestatic

Definition at line 63 of file pixels.c.

64{
65 if( ptr == 0 ) {
66 *ptrOut = 0;
67 return XCF_OK; /* allowed by xcf, apparently */
68 }
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);
72 *ptrOut = XCF_PTR_EMPTY;
73 return XCF_ERROR;
74 }
75 *ptrOut = (ptr += 8) ;
76 return XCF_OK;
77}

References rect::b, tileDimensions::c, FatalBadXCF(), rect::l, rect::r, rect::t, XCF_ERROR, XCF_OK, XCF_PTR_EMPTY, and xcfL.

◆ tileSummary()

summary_t tileSummary ( struct Tile * tile)

Definition at line 262 of file pixels.c.

263{
264 unsigned i ;
265 summary_t summary ;
266 if( (tile->summary & TILESUMMARY_UPTODATE) != 0 )
267 return tile->summary ;
269 for( i=0; summary && i<tile->count; i++ ) {
270 if( FULLALPHA(tile->pixels[i]) )
271 summary &= ~TILESUMMARY_ALLNULL ;
272 else if( NULLALPHA(tile->pixels[i]) )
273 summary &= ~TILESUMMARY_ALLFULL ;
274 else
275 summary = 0 ;
276 }
277 summary += TILESUMMARY_UPTODATE ;
278 tile->summary = summary ;
279 return summary ;
280}
int summary_t
Definition pixels.h:89

References Tile::count, FULLALPHA, NULLALPHA, Tile::pixels, Tile::summary, TILESUMMARY_ALLFULL, TILESUMMARY_ALLNULL, TILESUMMARY_CRISP, and TILESUMMARY_UPTODATE.

Variable Documentation

◆ colormap

rgba colormap[256]

Definition at line 25 of file pixels.c.

◆ colormapLength

unsigned colormapLength =0

Definition at line 26 of file pixels.c.

◆ convertChannel

convertParams convertChannel = { 1, {ALPHA_SHIFT}, 0, 0 }
static

Definition at line 58 of file pixels.c.

58{ 1, {ALPHA_SHIFT}, 0, 0 };

◆ convertColormap

convertParams convertColormap = { 3, {RGB_SHIFT}, 0, 0 }
static

Definition at line 57 of file pixels.c.

57{ 3, {RGB_SHIFT}, 0, 0 };
#define RGB_SHIFT
Definition pixels.c:45

◆ convertGRAY

convertParams convertGRAY = { 1, {-1}, OPAQUE, graytable }
static

Definition at line 52 of file pixels.c.

52{ 1, {-1}, OPAQUE, graytable };
#define OPAQUE
Definition pixels.c:49
const rgba graytable[256]
Definition table.c:6

◆ convertGRAYA

convertParams convertGRAYA = { 2, {-1,ALPHA_SHIFT}, 0, graytable }
static

Definition at line 53 of file pixels.c.

53{ 2, {-1,ALPHA_SHIFT}, 0, graytable };

◆ convertINDEXED

convertParams convertINDEXED = { 1, {-1}, OPAQUE, colormap }
static

Definition at line 54 of file pixels.c.

54{ 1, {-1}, OPAQUE, colormap };

◆ convertINDEXEDA

convertParams convertINDEXEDA = { 2, {-1,ALPHA_SHIFT}, 0, colormap }
static

Definition at line 55 of file pixels.c.

55{ 2, {-1,ALPHA_SHIFT}, 0, colormap };

◆ convertRGB

convertParams convertRGB = { 3, {RGB_SHIFT}, OPAQUE, 0 }
static

Definition at line 50 of file pixels.c.

50{ 3, {RGB_SHIFT}, OPAQUE, 0 };

◆ convertRGBA

convertParams convertRGBA = { 4, {RGB_SHIFT, ALPHA_SHIFT}, 0,0 }
static

Definition at line 51 of file pixels.c.

51{ 4, {RGB_SHIFT, ALPHA_SHIFT}, 0,0 };