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