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 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
* Types, macros, etc for the GLchan datatype.
26
* The swrast module is kind of hard-coded for 8bpp color channels but
27
* may be recompiled to use 16- or 32-bit color channels. But that
28
* feature is seldom used and is likely broken in various ways.
35
#include "main/config.h"
39
* Color channel data type.
42
typedef GLubyte GLchan;
44
#define CHAN_MAXF 255.0F
45
#define CHAN_TYPE GL_UNSIGNED_BYTE
47
typedef GLushort GLchan;
48
#define CHAN_MAX 65535
49
#define CHAN_MAXF 65535.0F
50
#define CHAN_TYPE GL_UNSIGNED_SHORT
52
typedef GLfloat GLchan;
54
#define CHAN_MAXF 1.0F
55
#define CHAN_TYPE GL_FLOAT
57
#error "illegal number of color channel bits"
63
#define CHAN_TO_UBYTE(c) (c)
64
#define CHAN_TO_USHORT(c) (((c) << 8) | (c))
65
#define CHAN_TO_SHORT(c) (((c) << 7) | ((c) >> 1))
66
#define CHAN_TO_FLOAT(c) UBYTE_TO_FLOAT(c)
68
#define CLAMPED_FLOAT_TO_CHAN(c, f) CLAMPED_FLOAT_TO_UBYTE(c, f)
69
#define UNCLAMPED_FLOAT_TO_CHAN(c, f) UNCLAMPED_FLOAT_TO_UBYTE(c, f)
71
#define COPY_CHAN4(DST, SRC) COPY_4UBV(DST, SRC)
75
#define CHAN_TO_UBYTE(c) ((c) >> 8)
76
#define CHAN_TO_USHORT(c) (c)
77
#define CHAN_TO_SHORT(c) ((c) >> 1)
78
#define CHAN_TO_FLOAT(c) ((GLfloat) ((c) * (1.0 / CHAN_MAXF)))
80
#define CLAMPED_FLOAT_TO_CHAN(c, f) CLAMPED_FLOAT_TO_USHORT(c, f)
81
#define UNCLAMPED_FLOAT_TO_CHAN(c, f) UNCLAMPED_FLOAT_TO_USHORT(c, f)
83
#define COPY_CHAN4(DST, SRC) COPY_4V(DST, SRC)
87
#define CHAN_TO_UBYTE(c) FLOAT_TO_UBYTE(c)
88
#define CHAN_TO_USHORT(c) ((GLushort) (CLAMP((c), 0.0f, 1.0f) * 65535.0))
89
#define CHAN_TO_SHORT(c) ((GLshort) (CLAMP((c), 0.0f, 1.0f) * 32767.0))
90
#define CHAN_TO_FLOAT(c) (c)
92
#define CLAMPED_FLOAT_TO_CHAN(c, f) c = (f)
93
#define UNCLAMPED_FLOAT_TO_CHAN(c, f) c = (f)
95
#define COPY_CHAN4(DST, SRC) COPY_4V(DST, SRC)
99
#error unexpected CHAN_BITS size
105
* Convert 4 floats to GLchan values.
106
* \param dst pointer to destination GLchan[4] array.
107
* \param f pointer to source GLfloat[4] array.
109
#define UNCLAMPED_FLOAT_TO_RGBA_CHAN(dst, f) \
111
UNCLAMPED_FLOAT_TO_CHAN((dst)[0], (f)[0]); \
112
UNCLAMPED_FLOAT_TO_CHAN((dst)[1], (f)[1]); \
113
UNCLAMPED_FLOAT_TO_CHAN((dst)[2], (f)[2]); \
114
UNCLAMPED_FLOAT_TO_CHAN((dst)[3], (f)[3]); \
119
#endif /* U_CHAN_H */