Krita Source Code Documentation
Loading...
Searching...
No Matches
palette.h File Reference
#include "xcftools.h"
#include "pixels.h"

Go to the source code of this file.

Macros

#define MAX_PALETTE   256
 

Typedefs

typedef uint8_t index_t
 

Functions

void init_palette_hash (void)
 
int lookup_or_intern (rgba color)
 
int palettify_row (rgba *row, unsigned ncols)
 
int palettify_rows (rgba *rows[], unsigned ncols, unsigned nlines)
 

Variables

rgba palette [MAX_PALETTE]
 
unsigned paletteSize
 

Macro Definition Documentation

◆ MAX_PALETTE

#define MAX_PALETTE   256

Definition at line 25 of file palette.h.

Typedef Documentation

◆ index_t

typedef uint8_t index_t

Definition at line 29 of file palette.h.

Function Documentation

◆ init_palette_hash()

void init_palette_hash ( void )

Definition at line 40 of file palette.c.

41{
42 unsigned i ;
43 for( i=0; i<HASH_SIZE; i++ )
44 masterhash[i] = -1 ;
45 for( i=0; i<MAX_PALETTE; i++ )
46 bucketlinks[i] = -1 ;
47 paletteSize = 0 ;
48}
unsigned paletteSize
Definition palette.c:34
static int masterhash[HASH_SIZE]
Definition palette.c:36
static int bucketlinks[MAX_PALETTE]
Definition palette.c:37
#define HASH_SIZE
Definition palette.c:22
#define MAX_PALETTE
Definition palette.h:25

References bucketlinks, HASH_SIZE, masterhash, MAX_PALETTE, and paletteSize.

◆ lookup_or_intern()

int lookup_or_intern ( rgba color)
inline

Definition at line 51 of file palette.c.

51 {
52 int *target = &masterhash[color % HASH_SIZE];
53 while( *target >= 0 ) {
54 if( palette[*target] == color )
55 return *target ;
57 }
58#if 0
59 fprintf(stderr,"Palette[%u] = %08x (%u --> %d)\n",paletteSize,color,
60 color % HASH_SIZE, *target);
61#endif
63 return -1 ;
65 palette[paletteSize] = color ;
66 return paletteSize++ ;
67}
KisMagneticGraph::vertex_descriptor target(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
rgba palette[MAX_PALETTE]
Definition palette.c:35

References bucketlinks, HASH_SIZE, masterhash, MAX_PALETTE, palette, paletteSize, and target().

◆ palettify_row()

int palettify_row ( rgba * row,
unsigned ncols )

Definition at line 80 of file palette.c.

81{
82 index_t *newrow = (index_t*)row ;
83 assert(sizeof(index_t) <= sizeof(rgba));
84 unsigned i ;
85 for( i=0; i<ncols; i++ ) {
86 int j = lookup_or_intern(row[i]) ;
87 if( j < 0 ) {
88 unpalettify_row(row,i);
89 return 0 ;
90 }
91 newrow[i] = j ;
92 }
93 return 1 ;
94}
static void unpalettify_row(rgba *row, unsigned ncols)
Definition palette.c:70
int lookup_or_intern(rgba color)
Definition palette.c:51
uint8_t index_t
Definition palette.h:29
uint32_t rgba
Definition pixels.h:44

References lookup_or_intern(), and unpalettify_row().

◆ palettify_rows()

int palettify_rows ( rgba * rows[],
unsigned ncols,
unsigned nlines )

Definition at line 97 of file palette.c.

98{
99 unsigned i ;
100 for( i=0; i<nlines; i++ ) {
101 if( !palettify_row(rows[i],ncols) ) {
102 while( i-- )
103 unpalettify_row(rows[i],ncols);
104 return 0 ;
105 }
106 }
107 return 1 ;
108}
int palettify_row(rgba *row, unsigned ncols)
Definition palette.c:80

References palettify_row(), and unpalettify_row().

Variable Documentation

◆ palette

rgba palette[MAX_PALETTE]
extern

Definition at line 35 of file palette.c.

◆ paletteSize

unsigned paletteSize
extern

Definition at line 34 of file palette.c.