2 * Mesa 3-D graphics library
4 * Copyright (C) 2011 VMware, Inc. All Rights Reserved.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
26 * Types, macros, etc for the GLchan datatype.
27 * The swrast module is kind of hard-coded for 8bpp color channels but
28 * may be recompiled to use 16- or 32-bit color channels. But that
29 * feature is seldom used and is likely broken in various ways.
36 #include "main/config.h"
40 * Default bits per color channel: 8, 16 or 32
48 * Color channel data type.
51 typedef GLubyte GLchan
;
53 #define CHAN_MAXF 255.0F
54 #define CHAN_TYPE GL_UNSIGNED_BYTE
56 typedef GLushort GLchan
;
57 #define CHAN_MAX 65535
58 #define CHAN_MAXF 65535.0F
59 #define CHAN_TYPE GL_UNSIGNED_SHORT
61 typedef GLfloat GLchan
;
63 #define CHAN_MAXF 1.0F
64 #define CHAN_TYPE GL_FLOAT
66 #error "illegal number of color channel bits"
72 #define CHAN_TO_UBYTE(c) (c)
73 #define CHAN_TO_USHORT(c) (((c) << 8) | (c))
74 #define CHAN_TO_SHORT(c) (((c) << 7) | ((c) >> 1))
75 #define CHAN_TO_FLOAT(c) UBYTE_TO_FLOAT(c)
77 #define CLAMPED_FLOAT_TO_CHAN(c, f) CLAMPED_FLOAT_TO_UBYTE(c, f)
78 #define UNCLAMPED_FLOAT_TO_CHAN(c, f) UNCLAMPED_FLOAT_TO_UBYTE(c, f)
80 #define COPY_CHAN4(DST, SRC) COPY_4UBV(DST, SRC)
84 #define CHAN_TO_UBYTE(c) ((c) >> 8)
85 #define CHAN_TO_USHORT(c) (c)
86 #define CHAN_TO_SHORT(c) ((c) >> 1)
87 #define CHAN_TO_FLOAT(c) ((GLfloat) ((c) * (1.0 / CHAN_MAXF)))
89 #define CLAMPED_FLOAT_TO_CHAN(c, f) CLAMPED_FLOAT_TO_USHORT(c, f)
90 #define UNCLAMPED_FLOAT_TO_CHAN(c, f) UNCLAMPED_FLOAT_TO_USHORT(c, f)
92 #define COPY_CHAN4(DST, SRC) COPY_4V(DST, SRC)
96 #define CHAN_TO_UBYTE(c) FLOAT_TO_UBYTE(c)
97 #define CHAN_TO_USHORT(c) ((GLushort) (CLAMP((c), 0.0f, 1.0f) * 65535.0))
98 #define CHAN_TO_SHORT(c) ((GLshort) (CLAMP((c), 0.0f, 1.0f) * 32767.0))
99 #define CHAN_TO_FLOAT(c) (c)
101 #define CLAMPED_FLOAT_TO_CHAN(c, f) c = (f)
102 #define UNCLAMPED_FLOAT_TO_CHAN(c, f) c = (f)
104 #define COPY_CHAN4(DST, SRC) COPY_4V(DST, SRC)
108 #error unexpected CHAN_BITS size
114 * Convert 4 floats to GLchan values.
115 * \param dst pointer to destination GLchan[4] array.
116 * \param f pointer to source GLfloat[4] array.
118 #define UNCLAMPED_FLOAT_TO_RGBA_CHAN(dst, f) \
120 UNCLAMPED_FLOAT_TO_CHAN((dst)[0], (f)[0]); \
121 UNCLAMPED_FLOAT_TO_CHAN((dst)[1], (f)[1]); \
122 UNCLAMPED_FLOAT_TO_CHAN((dst)[2], (f)[2]); \
123 UNCLAMPED_FLOAT_TO_CHAN((dst)[3], (f)[3]); \
128 #endif /* U_CHAN_H */