Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / auxiliary / util / u_format.h
1 /**************************************************************************
2 *
3 * Copyright 2009 Vmware, Inc.
4 * 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
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #ifndef U_FORMAT_H
30 #define U_FORMAT_H
31
32
33 #include "pipe/p_format.h"
34
35
36 /**
37 * Describe how to best pack/unpack pixels into/from the prescribed format.
38 *
39 * These are used for automatic code generation of pixel packing and unpacking
40 * routines (in compile time, e.g., u_format_access.py, or in runtime, like
41 * llvmpipe does).
42 *
43 * Thumb rule is: if you're not code generating pixel packing/unpacking then
44 * these are irrelevant for you.
45 *
46 * Note that this can be deduced from other values in util_format_description
47 * structure. This is by design, to make code generation of pixel
48 * packing/unpacking/sampling routines simple and efficient.
49 *
50 * XXX: This should be renamed to something like util_format_pack.
51 */
52 enum util_format_layout {
53 /**
54 * Single scalar component.
55 */
56 UTIL_FORMAT_LAYOUT_SCALAR = 0,
57
58 /**
59 * One or more components of mixed integer formats, arithmetically encoded
60 * in a word up to 32bits.
61 */
62 UTIL_FORMAT_LAYOUT_ARITH = 1,
63
64 /**
65 * One or more components, no mixed formats, each with equal power of two
66 * number of bytes.
67 */
68 UTIL_FORMAT_LAYOUT_ARRAY = 2,
69
70 /**
71 * XXX: Not used yet. These might go away and be replaced by a single entry,
72 * for formats where multiple pixels have to be
73 * read in order to determine a single pixel value (i.e., block.width > 1
74 * || block.height > 1)
75 */
76 UTIL_FORMAT_LAYOUT_YUV = 3,
77 UTIL_FORMAT_LAYOUT_DXT = 4
78 };
79
80
81 struct util_format_block
82 {
83 /** Block width in pixels */
84 unsigned width;
85
86 /** Block height in pixels */
87 unsigned height;
88
89 /** Block size in bits */
90 unsigned bits;
91 };
92
93
94 enum util_format_type {
95 UTIL_FORMAT_TYPE_VOID = 0,
96 UTIL_FORMAT_TYPE_UNSIGNED = 1,
97 UTIL_FORMAT_TYPE_SIGNED = 2,
98 UTIL_FORMAT_TYPE_FIXED = 3,
99 UTIL_FORMAT_TYPE_FLOAT = 4
100 };
101
102
103 enum util_format_swizzle {
104 UTIL_FORMAT_SWIZZLE_X = 0,
105 UTIL_FORMAT_SWIZZLE_Y = 1,
106 UTIL_FORMAT_SWIZZLE_Z = 2,
107 UTIL_FORMAT_SWIZZLE_W = 3,
108 UTIL_FORMAT_SWIZZLE_0 = 4,
109 UTIL_FORMAT_SWIZZLE_1 = 5,
110 UTIL_FORMAT_SWIZZLE_NONE = 6
111 };
112
113
114 enum util_format_colorspace {
115 UTIL_FORMAT_COLORSPACE_RGB = 0,
116 UTIL_FORMAT_COLORSPACE_SRGB = 1,
117 UTIL_FORMAT_COLORSPACE_YUV = 2,
118 UTIL_FORMAT_COLORSPACE_ZS = 3,
119 };
120
121
122 struct util_format_channel_description
123 {
124 unsigned type:6;
125 unsigned normalized:1;
126 unsigned size:9;
127 };
128
129
130 struct util_format_description
131 {
132 enum pipe_format format;
133 const char *name;
134 struct util_format_block block;
135 enum util_format_layout layout;
136 struct util_format_channel_description channel[4];
137 unsigned char swizzle[4];
138 enum util_format_colorspace colorspace;
139 };
140
141
142 extern const struct util_format_description
143 util_format_description_table[];
144
145
146 const struct util_format_description *
147 util_format_description(enum pipe_format format);
148
149
150 void
151 util_format_read_4f(enum pipe_format format,
152 float *dst, unsigned dst_stride,
153 const void *src, unsigned src_stride,
154 unsigned x, unsigned y, unsigned w, unsigned h);
155
156 void
157 util_format_write_4f(enum pipe_format format,
158 const float *src, unsigned src_stride,
159 void *dst, unsigned dst_stride,
160 unsigned x, unsigned y, unsigned w, unsigned h);
161
162 void
163 util_format_read_4ub(enum pipe_format format,
164 uint8_t *dst, unsigned dst_stride,
165 const void *src, unsigned src_stride,
166 unsigned x, unsigned y, unsigned w, unsigned h);
167
168 void
169 util_format_write_4ub(enum pipe_format format,
170 const uint8_t *src, unsigned src_stride,
171 void *dst, unsigned dst_stride,
172 unsigned x, unsigned y, unsigned w, unsigned h);
173
174 #endif /* ! U_FORMAT_H */