Krita Source Code Documentation
Loading...
Searching...
No Matches
pixels.h
Go to the documentation of this file.
1/* Pixel and tile functions for xcftools
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 PIXELS_H
20#define PIXELS_H
21
22#include "xcftools.h"
23
24/* MACROS FOR INTERNAL PIXEL ORDERING HERE */
25/*=========================================*/
26/* In principle the internal representation of pixels may change.
27 * - this was supposed to allow an optimization where a layer could
28 * be represented as a pointer into the mmapped xcf file, if
29 * alignment, bpp, and endianness agreed (the point was that the
30 * pixel representation had to agree with the endianness).
31 *
32 * However, it turns out that the current Gimp _always_ saves images
33 * with RLE encoding of tiles, so such an effort would be in vain.
34 *
35 * Just for modularity, nevertheless try to isolate knowledge of
36 * the RGBA-to-machine-word packing in this section of the
37 * header file. Define new macros if necessary.
38 *
39 * Given that we don't have to agree with the uncompressed
40 * RLE format, we choose to have the alpha in the _least_
41 * significant byte on all archs - it is tested and used more
42 * often than the visible channels.
43 */
44typedef uint32_t rgba ;
45
46#define ALPHA_SHIFT 0
47#define RED_SHIFT 8
48#define GREEN_SHIFT 16
49#define BLUE_SHIFT 24
50
51#define ALPHA(rgba) ((uint8_t)(rgba))
52#define FULLALPHA(rgba) ((uint8_t)(rgba) == 255)
53#define NULLALPHA(rgba) ((uint8_t)(rgba) == 0)
54#define NEWALPHA(rgb,a) (((rgba)(rgb) & 0xFFFFFF00) + (a))
55
56#ifdef PRECOMPUTED_SCALETABLE
57extern const uint8_t scaletable[256][256] ;
58#define INIT_SCALETABLE_IF(foo) ((void)0)
59#else
60extern uint8_t scaletable[256][256] ;
61extern int ok_scaletable ;
62void mk_scaletable(void);
63#define INIT_SCALETABLE_IF(foo) \
64 (ok_scaletable || !(foo) || (mk_scaletable(),0) )
65#endif
66
67extern const rgba graytable[256] ;
68extern rgba colormap[256] ;
69extern unsigned colormapLength ;
70int initLayer(struct xcfLayer *);
71int initColormap();
72
73int degrayPixel(rgba); /* returns -1 for non-gray pixels */
74
75/* ******************************************************* */
76
77#define TILEXn(dim,tx) \
78 ((tx)==(dim).tilesx ? (dim).c.r : (dim).c.l + ((tx)*TILE_WIDTH))
79#define TILEYn(dim,ty) \
80 ((ty)==(dim).tilesy ? (dim).c.b : (dim).c.t + ((ty)*TILE_HEIGHT))
81
82#if defined(__i386__)
83/* This is probably the only common architecture where small constants
84 * are more efficient for byte operations.
85 */
86typedef int8_t summary_t ;
87typedef short int refcount_t ;
88#else
89typedef int summary_t ;
90typedef int refcount_t ;
91#endif
92
93#define TILESUMMARY_UPTODATE 8
94#define TILESUMMARY_ALLNULL 4
95#define TILESUMMARY_ALLFULL 2
96#define TILESUMMARY_CRISP 1 /* everything either null or full */
97struct Tile {
99 summary_t summary ; /* a combination of TIMESUMMARY_FOO constatns */
100 unsigned count ;
102};
103/* Actually, the Tile structures that get allocated many not have
104 * room for that many pixels. We subtract the space for those we don't
105 * use - which is Not Legal C, but ought to be portable.
106 * OTOH, one can also use a static struct Tile for temporary storage.
107 */
108
109
110#define assertTileCompatibility(t1,t2) assert((t1)->count==(t2)->count)
111
112struct Tile *newTile(struct rect);
113struct Tile *forkTile(struct Tile*);
114void freeTile(struct Tile*);
115#define invalidateSummary(tile,mask) \
116 do{ assert((tile)->refcount==1); (tile)->summary &= mask; } while(0)
118
119void fillTile(struct Tile*,rgba);
120
121/* applyMask() destructively changes tile,
122 * applyMask() gets ownership of mask
123 */
124void applyMask(struct Tile *tile, struct Tile *mask);
125
126struct Tile *getLayerTile(struct xcfLayer *,const struct rect *);
127
128struct Tile * getMaskOrLayerTile(struct tileDimensions *dim, struct xcfTiles *tiles, struct rect want);
129
130#endif /* FLATTEN_H */
summary_t tileSummary(struct Tile *tile)
Definition pixels.c:262
uint32_t rgba
Definition pixels.h:44
int initLayer(struct xcfLayer *)
Definition pixels.c:167
struct Tile * getLayerTile(struct xcfLayer *, const struct rect *)
Definition pixels.c:546
int initColormap()
Definition pixels.c:199
unsigned colormapLength
Definition pixels.c:26
int summary_t
Definition pixels.h:89
void fillTile(struct Tile *, rgba)
Definition pixels.c:283
const rgba graytable[256]
Definition table.c:6
struct Tile * newTile(struct rect)
Definition pixels.c:231
struct Tile * getMaskOrLayerTile(struct tileDimensions *dim, struct xcfTiles *tiles, struct rect want)
Definition pixels.c:427
rgba colormap[256]
Definition pixels.c:25
int refcount_t
Definition pixels.h:90
void mk_scaletable(void)
Definition scaletab.c:26
uint8_t scaletable[256][256]
Definition scaletab.c:22
void applyMask(struct Tile *tile, struct Tile *mask)
Definition pixels.c:531
struct Tile * forkTile(struct Tile *)
Definition pixels.c:244
int degrayPixel(rgba)
Definition pixels.c:29
int ok_scaletable
Definition scaletab.c:23
void freeTile(struct Tile *)
Definition pixels.c:255
Definition pixels.h:97
rgba pixels[TILE_WIDTH *TILE_HEIGHT]
Definition pixels.h:101
summary_t summary
Definition pixels.h:99
unsigned count
Definition pixels.h:100
refcount_t refcount
Definition pixels.h:98
#define __ATTRIBUTE__(x)
Definition xcftools.h:55
#define TILE_HEIGHT
Definition xcftools.h:155
#define TILE_WIDTH
Definition xcftools.h:154