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
|
# ifndef APP_COLOR_H
# define APP_COLOR_H
# include <X11/Xlib.h>
# include <X11/Intrinsic.h>
/************************************************************************/
/* */
/* Administration on colors. */
/* */
/************************************************************************/
typedef struct AppColors
{
XColor ac222Colors[64];
XColor * acColors;
int acColorCount;
Display * acDisplay;
int acDepth;
Colormap acColormap;
int acVisualClass;
unsigned int acRedApproxShift;
unsigned int acGreenApproxShift;
unsigned int acBlueApproxShift;
unsigned int acRedPixelShift;
unsigned int acGreenPixelShift;
unsigned int acBluePixelShift;
unsigned int acRedMask;
unsigned int acGreenMask;
unsigned int acBlueMask;
} AppColors;
/************************************************************************/
/* */
/* Macros for indexing colors in an array of colors, usually in an */
/* AppColors 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 appColorRgbDirect( xc, ac, r, g, b ) \
{ \
unsigned int rr= (r) >> (ac)->acRedApproxShift; \
unsigned int gg= (g) >> (ac)->acGreenApproxShift; \
unsigned int bb= (b) >> (ac)->acBlueApproxShift; \
(xc)->red= ( 65535* rr )/ (ac)->acRedMask; \
(xc)->green= ( 65535* gg )/ (ac)->acGreenMask; \
(xc)->blue= ( 65535* bb )/ (ac)->acBlueMask; \
(xc)->pixel= ( rr << (ac)->acRedPixelShift ) + \
( gg << (ac)->acGreenPixelShift ) + \
( bb << (ac)->acBluePixelShift ) ; \
}
/************************************************************************/
/* */
/* Routine declarations. */
/* */
/************************************************************************/
extern void appInitColors( AppColors * ac );
extern int appAllocateColors( Display * dis,
AppColors * ac );
extern void appCleanColors( Display * display,
AppColors * ac );
extern int appColorRgb222( XColor * xc,
AppColors * ac,
int r,
int g,
int b );
extern int appColorRgb111( XColor * xc,
AppColors * ac,
int r,
int g,
int b );
extern int appColorRgb332( XColor * xc,
AppColors * ac,
int r,
int g,
int b );
extern int appColorRgb555( XColor * xc,
AppColors * ac,
int r,
int g,
int b );
extern int appColorRgb( XColor * xc,
AppColors * ac,
int r,
int g,
int b );
extern int appColorFindRgb( XColor * xc,
AppColors * ac,
int r,
int g,
int b );
extern int appColorNamed( XColor * xc,
AppColors * ac,
char * name );
# endif
|