Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4358 | Serge | 1 | /* |
2 | * Mesa 3-D graphics library |
||
3 | * |
||
4 | * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. |
||
5 | * |
||
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
7 | * copy of this software and associated documentation files (the "Software"), |
||
8 | * to deal in the Software without restriction, including without limitation |
||
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
10 | * and/or sell copies of the Software, and to permit persons to whom the |
||
11 | * Software is furnished to do so, subject to the following conditions: |
||
12 | * |
||
13 | * The above copyright notice and this permission notice shall be included |
||
14 | * in all copies or substantial portions of the Software. |
||
15 | * |
||
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||
17 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
||
20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
||
21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
||
22 | * OTHER DEALINGS IN THE SOFTWARE. |
||
23 | */ |
||
24 | |||
25 | |||
26 | /** |
||
27 | * \file colormac.h |
||
28 | * Color-related macros |
||
29 | */ |
||
30 | |||
31 | |||
32 | #ifndef COLORMAC_H |
||
33 | #define COLORMAC_H |
||
34 | |||
35 | |||
36 | #include "config.h" |
||
37 | #include "macros.h" |
||
38 | #include "mtypes.h" |
||
39 | |||
40 | |||
41 | /** |
||
42 | * Convert four float values in [0,1] to ubytes in [0,255] with clamping. |
||
43 | */ |
||
44 | static inline void |
||
45 | _mesa_unclamped_float_rgba_to_ubyte(GLubyte dst[4], const GLfloat src[4]) |
||
46 | { |
||
47 | int i; |
||
48 | for (i = 0; i < 4; i++) |
||
49 | UNCLAMPED_FLOAT_TO_UBYTE(dst[i], src[i]); |
||
50 | } |
||
51 | |||
52 | |||
53 | /** |
||
54 | * \name Generic color packing macros. All inputs should be GLubytes. |
||
55 | * |
||
56 | * \todo We may move these into texstore.h at some point. |
||
57 | */ |
||
58 | /*@{*/ |
||
59 | |||
60 | #define PACK_COLOR_8888( X, Y, Z, W ) \ |
||
61 | (((X) << 24) | ((Y) << 16) | ((Z) << 8) | (W)) |
||
62 | |||
63 | #define PACK_COLOR_8888_REV( X, Y, Z, W ) \ |
||
64 | (((W) << 24) | ((Z) << 16) | ((Y) << 8) | (X)) |
||
65 | |||
66 | #define PACK_COLOR_888( X, Y, Z ) \ |
||
67 | (((X) << 16) | ((Y) << 8) | (Z)) |
||
68 | |||
69 | #define PACK_COLOR_565( X, Y, Z ) \ |
||
70 | ((((X) & 0xf8) << 8) | (((Y) & 0xfc) << 3) | (((Z) & 0xf8) >> 3)) |
||
71 | |||
72 | #define PACK_COLOR_565_REV( X, Y, Z ) \ |
||
73 | (((X) & 0xf8) | ((Y) & 0xe0) >> 5 | (((Y) & 0x1c) << 11) | (((Z) & 0xf8) << 5)) |
||
74 | |||
75 | #define PACK_COLOR_5551( R, G, B, A ) \ |
||
76 | ((((R) & 0xf8) << 8) | (((G) & 0xf8) << 3) | (((B) & 0xf8) >> 2) | \ |
||
77 | ((A) >> 7)) |
||
78 | |||
79 | #define PACK_COLOR_1555( A, B, G, R ) \ |
||
80 | ((((B) & 0xf8) << 7) | (((G) & 0xf8) << 2) | (((R) & 0xf8) >> 3) | \ |
||
81 | (((A) & 0x80) << 8)) |
||
82 | |||
83 | #define PACK_COLOR_1555_REV( A, B, G, R ) \ |
||
84 | ((((B) & 0xf8) >> 1) | (((G) & 0xc0) >> 6) | (((G) & 0x38) << 10) | (((R) & 0xf8) << 5) | \ |
||
85 | ((A) ? 0x80 : 0)) |
||
86 | |||
87 | #define PACK_COLOR_2101010_UB( A, B, G, R ) \ |
||
88 | (((B) << 22) | ((G) << 12) | ((R) << 2) | \ |
||
89 | (((A) & 0xc0) << 24)) |
||
90 | |||
91 | #define PACK_COLOR_2101010_US( A, B, G, R ) \ |
||
92 | ((((B) >> 6) << 20) | (((G) >> 6) << 10) | ((R) >> 6) | \ |
||
93 | (((A) >> 14) << 30)) |
||
94 | |||
95 | #define PACK_COLOR_4444( R, G, B, A ) \ |
||
96 | ((((R) & 0xf0) << 8) | (((G) & 0xf0) << 4) | ((B) & 0xf0) | ((A) >> 4)) |
||
97 | |||
98 | #define PACK_COLOR_4444_REV( R, G, B, A ) \ |
||
99 | ((((B) & 0xf0) << 8) | (((A) & 0xf0) << 4) | ((R) & 0xf0) | ((G) >> 4)) |
||
100 | |||
101 | #define PACK_COLOR_44( L, A ) \ |
||
102 | (((L) & 0xf0) | (((A) & 0xf0) >> 4)) |
||
103 | |||
104 | #define PACK_COLOR_88( L, A ) \ |
||
105 | (((L) << 8) | (A)) |
||
106 | |||
107 | #define PACK_COLOR_88_REV( L, A ) \ |
||
108 | (((A) << 8) | (L)) |
||
109 | |||
110 | #define PACK_COLOR_1616( L, A ) \ |
||
111 | (((L) << 16) | (A)) |
||
112 | |||
113 | #define PACK_COLOR_1616_REV( L, A ) \ |
||
114 | (((A) << 16) | (L)) |
||
115 | |||
116 | #define PACK_COLOR_332( R, G, B ) \ |
||
117 | (((R) & 0xe0) | (((G) & 0xe0) >> 3) | (((B) & 0xc0) >> 6)) |
||
118 | |||
119 | #define PACK_COLOR_233( B, G, R ) \ |
||
120 | (((B) & 0xc0) | (((G) & 0xe0) >> 2) | (((R) & 0xe0) >> 5)) |
||
121 | |||
122 | /*@}*/ |
||
123 | |||
124 | |||
125 | #endif /* COLORMAC_H */><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>> |