~ubuntu-branches/ubuntu/precise/mesa/precise-updates

« back to all changes in this revision

Viewing changes to src/mesa/swrast/s_chan.h

  • Committer: Package Import Robot
  • Author(s): Robert Hooker
  • Date: 2012-02-02 12:05:48 UTC
  • mfrom: (1.7.1) (3.3.27 sid)
  • Revision ID: package-import@ubuntu.com-20120202120548-nvkma85jq0h4coix
Tags: 8.0~rc2-0ubuntu4
Drop drisearchdir handling, it is no longer needed with multiarch
and dri-alternates being removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Mesa 3-D graphics library
 
3
 *
 
4
 * Copyright (C) 2011  VMware, Inc.  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 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.
 
22
 */
 
23
 
 
24
/**
 
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.
 
29
 */
 
30
 
 
31
#ifndef U_CHAN_H
 
32
#define U_CHAN_H
 
33
 
 
34
 
 
35
#include "main/config.h"
 
36
 
 
37
 
 
38
/**
 
39
 * Color channel data type.
 
40
 */
 
41
#if CHAN_BITS == 8
 
42
   typedef GLubyte GLchan;
 
43
#define CHAN_MAX 255
 
44
#define CHAN_MAXF 255.0F
 
45
#define CHAN_TYPE GL_UNSIGNED_BYTE
 
46
#elif CHAN_BITS == 16
 
47
   typedef GLushort GLchan;
 
48
#define CHAN_MAX 65535
 
49
#define CHAN_MAXF 65535.0F
 
50
#define CHAN_TYPE GL_UNSIGNED_SHORT
 
51
#elif CHAN_BITS == 32
 
52
   typedef GLfloat GLchan;
 
53
#define CHAN_MAX 1.0
 
54
#define CHAN_MAXF 1.0F
 
55
#define CHAN_TYPE GL_FLOAT
 
56
#else
 
57
#error "illegal number of color channel bits"
 
58
#endif
 
59
 
 
60
 
 
61
#if CHAN_BITS == 8
 
62
 
 
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)
 
67
 
 
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)
 
70
 
 
71
#define COPY_CHAN4(DST, SRC)  COPY_4UBV(DST, SRC)
 
72
 
 
73
#elif CHAN_BITS == 16
 
74
 
 
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)))
 
79
 
 
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)
 
82
 
 
83
#define COPY_CHAN4(DST, SRC)  COPY_4V(DST, SRC)
 
84
 
 
85
#elif CHAN_BITS == 32
 
86
 
 
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)
 
91
 
 
92
#define CLAMPED_FLOAT_TO_CHAN(c, f)  c = (f)
 
93
#define UNCLAMPED_FLOAT_TO_CHAN(c, f)      c = (f)
 
94
 
 
95
#define COPY_CHAN4(DST, SRC)  COPY_4V(DST, SRC)
 
96
 
 
97
#else
 
98
 
 
99
#error unexpected CHAN_BITS size
 
100
 
 
101
#endif
 
102
 
 
103
 
 
104
/**
 
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.
 
108
 */
 
109
#define UNCLAMPED_FLOAT_TO_RGBA_CHAN(dst, f)    \
 
110
do {                                            \
 
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]);   \
 
115
} while (0)
 
116
 
 
117
 
 
118
 
 
119
#endif /* U_CHAN_H */