1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
/************************************************************************/
/* */
/* Color allocation, mainly for bitmap images. */
/* */
/************************************************************************/
# ifndef BMCOLOR_H
# define BMCOLOR_H
/************************************************************************/
/* */
/* An RGB8 Color. */
/* The most usual way to display images on a computer screen. */
/* */
/* An RGB16 Color. */
/* Used to match X11's way of handling colors. */
/* */
/* NOTE that the structs use native types so the 8/16 indication is */
/* more a suggestion than an implementation reality. */
/* */
/************************************************************************/
typedef struct RGB8Color
{
unsigned char rgb8Red;
unsigned char rgb8Green;
unsigned char rgb8Blue;
unsigned char rgb8Alpha;
} RGB8Color;
typedef struct RGB16Color
{
unsigned short rgb16Red;
unsigned short rgb16Green;
unsigned short rgb16Blue;
unsigned char rgb16Alpha;
} RGB16Color;
/************************************************************************/
/* */
/* For color approximation, anti aliasing and dithering */
/* */
/************************************************************************/
typedef struct AllocatorColor
{
RGB16Color acColorValues;
unsigned long acColorNumber;
unsigned char acAllocated;
# define AC_UNALOCATED 0
# define AC_ALOCATED 1
# define AC_CALCULATED 2
# define AC_COPIED 3
} AllocatorColor;
# define acRed acColorValues.rgb16Red
# define acGreen acColorValues.rgb16Green
# define acBlue acColorValues.rgb16Blue
struct ColorAllocator;
typedef int (*SystemAllocator)( AllocatorColor * ac,
struct ColorAllocator * ca,
unsigned int r,
unsigned int g,
unsigned int b );
typedef struct ColorAllocator
{
AllocatorColor ca222Colors[64];
AllocatorColor * caColors;
int caColorCount;
int caDepth;
unsigned int caRedApproxShift;
unsigned int caGreenApproxShift;
unsigned int caBlueApproxShift;
unsigned int caRedPixelShift;
unsigned int caGreenPixelShift;
unsigned int caBluePixelShift;
unsigned int caRedMask;
unsigned int caGreenMask;
unsigned int caBlueMask;
int caAllocationType;
void * caSystemPrivate;
SystemAllocator caSystemAllocator;
} ColorAllocator;
/************************************************************************/
/* */
/* Macros for indexing colors in an array of colors, usually in an */
/* ColorAllocator structure. */
/* */
/************************************************************************/
# define C555(r,g,b) ( ( ( (r) << 7 ) & 0x7c00 ) | \
( ( (g) << 2 ) & 0x03e0 ) | \
( ( (b) >> 3 ) & 0x001f ) )
# define C332(r,g,b) ( ( ( (r) >> 0 ) & 0xe0 ) | \
( ( (g) >> 3 ) & 0x1c ) | \
( ( (b) >> 6 ) & 0x03 ) )
# define C222(r,g,b) ( ( ( (r) >> 2 ) & 0x30 ) | \
( ( (g) >> 4 ) & 0x0c ) | \
( ( (b) >> 6 ) & 0x03 ) )
# define C111(r,g,b) ( ( ( (r) >> 5 ) & 0x04 ) | \
( ( (g) >> 6 ) & 0x02 ) | \
( ( (b) >> 7 ) & 0x01 ) )
# define bmColorRgbDirect( ac, ca, r, g, b ) \
{ \
unsigned int rr= (r) >> (ca)->caRedApproxShift; \
unsigned int gg= (g) >> (ca)->caGreenApproxShift; \
unsigned int bb= (b) >> (ca)->caBlueApproxShift; \
\
(ac)->acRed= ( 65535* rr )/ (ca)->caRedMask; \
(ac)->acGreen= ( 65535* gg )/ (ca)->caGreenMask; \
(ac)->acBlue= ( 65535* bb )/ (ca)->caBlueMask; \
\
(ac)->acColorNumber= ( rr << (ca)->caRedPixelShift ) + \
( gg << (ca)->caGreenPixelShift ) + \
( bb << (ca)->caBluePixelShift ) ; \
}
/************************************************************************/
/* */
/* Routine declarations: */
/* */
/************************************************************************/
extern void bmSetCalculatedShifts( ColorAllocator * ca,
unsigned long redMask,
unsigned long greenMask,
unsigned long blueMask );
extern void bmInitColorAllocator( ColorAllocator * ca );
extern void bmCleanColorAllocator( ColorAllocator * ca );
# endif /* BMCOLOR_H */
|