2 Copyright 2004 John Tsiombikas <nuclear@siggraph.org>
4 This file is part of the graphics core library.
6 The graphics core library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 The graphics core library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with the graphics core library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* color bit shift and mask values for color packing/unpacking
22 * in a cross-endianess manner.
24 * author: John Tsiombikas 2004
26 #ifndef _COLOR_BITS_H_
27 #define _COLOR_BITS_H_
29 #include "common/types.h"
30 #include "common/byteorder.h"
32 /* 32bit color shift values */
34 #define ALPHA_SHIFT32 24
35 #define RED_SHIFT32 16
36 #define GREEN_SHIFT32 8
37 #define BLUE_SHIFT32 0
38 #else /* BIG_ENDIAN */
39 #define ALPHA_SHIFT32 0
41 #define GREEN_SHIFT32 16
42 #define BLUE_SHIFT32 24
43 #endif /* LITTLE_ENDIAN */
45 /* 32bit color mask values */
46 #define ALPHA_MASK32 0xff
47 #define RED_MASK32 0xff
48 #define GREEN_MASK32 0xff
49 #define BLUE_MASK32 0xff
51 /* 16bit color shift values */
53 #define RED_SHIFT16 11
54 #define GREEN_SHIFT16 5
55 #define BLUE_SHIFT16 0
56 #else /* BIG_ENDIAN */
58 #define GREEN_SHIFT16 5
59 #define BLUE_SHIFT16 11
60 #endif /* LITTLE_ENDIAN */
62 /* 16bit color mask values */
63 #define RED_MASK16 0x1f
64 #define GREEN_MASK16 0x3f
65 #define BLUE_MASK16 0x1f
67 /* 15bit color shift values */
69 #define RED_SHIFT15 10
70 #define GREEN_SHIFT15 5
71 #define BLUE_SHIFT15 0
72 #else /* BIG_ENDIAN */
74 #define GREEN_SHIFT15 5
75 #define BLUE_SHIFT15 10
76 #endif /* LITTLE_ENDIAN */
78 /* 15bit color mask values */
79 #define RED_MASK15 0x1f
80 #define GREEN_MASK15 0x1f
81 #define BLUE_MASK15 0x1f
84 /* color packing macros */
85 #define PACK_COLOR32(a,r,g,b) \
86 ((((unsigned long)(a) & ALPHA_MASK32) << ALPHA_SHIFT32) | \
87 (((unsigned long)(r) & RED_MASK32) << RED_SHIFT32) | \
88 (((unsigned long)(g) & GREEN_MASK32) << GREEN_SHIFT32) | \
89 (((unsigned long)(b) & BLUE_MASK32) << BLUE_SHIFT32))
91 #define PACK_COLOR24(r,g,b) PACK_COLOR32(0xff,r,g,b)
93 #define PACK_COLOR16(r,g,b) \
94 ((((unsigned short)(r) & RED_MASK16) << RED_SHIFT16) | \
95 (((unsigned short)(g) & GREEN_MASK16) << GREEN_SHIFT16) | \
96 (((unsigned short)(b) & BLUE_MASK16) << BLUE_SHIFT16))
98 #define PACK_COLOR15(r,g,b) \
99 ((((unsigned short)(r) & RED_MASK15) << RED_SHIFT15) | \
100 (((unsigned short)(g) & GREEN_MASK15) << GREEN_SHIFT15) | \
101 (((unsigned short)(b) & BLUE_MASK15) << BLUE_SHIFT15))
103 #endif /* _COLOR_BITS_H_ */