util: remove stray debug code
[mesa.git] / src / gallium / auxiliary / util / u_format_latc.c
1 /**************************************************************************
2 *
3 * Copyright (C) 2011 Red Hat Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 **************************************************************************/
23
24 #include <stdio.h>
25 #include "u_math.h"
26 #include "u_format.h"
27 #include "u_format_rgtc.h"
28 #include "u_format_latc.h"
29
30 static void u_format_unsigned_encode_rgtc_ubyte(uint8_t *blkaddr, uint8_t srccolors[4][4],
31 int numxpixels, int numypixels);
32
33 static void u_format_unsigned_fetch_texel_rgtc(unsigned srcRowStride, const uint8_t *pixdata,
34 unsigned i, unsigned j, uint8_t *value, unsigned comps);
35
36 static void u_format_signed_encode_rgtc_ubyte(int8_t *blkaddr, int8_t srccolors[4][4],
37 int numxpixels, int numypixels);
38
39 static void u_format_signed_fetch_texel_rgtc(unsigned srcRowStride, const int8_t *pixdata,
40 unsigned i, unsigned j, int8_t *value, unsigned comps);
41
42 void
43 util_format_latc1_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
44 {
45 /* Fix warnings here: */
46 (void) u_format_unsigned_encode_rgtc_ubyte;
47 (void) u_format_signed_encode_rgtc_ubyte;
48
49 u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 1);
50 }
51
52 void
53 util_format_latc1_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
54 {
55 util_format_rgtc1_unorm_unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
56 }
57
58 void
59 util_format_latc1_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row,
60 unsigned src_stride, unsigned width, unsigned height)
61 {
62 util_format_rgtc1_unorm_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
63 }
64
65 void
66 util_format_latc1_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
67 {
68 unsigned x, y, i, j;
69 int block_size = 8;
70
71 for(y = 0; y < height; y += 4) {
72 const uint8_t *src = src_row;
73 for(x = 0; x < width; x += 4) {
74 for(j = 0; j < 4; ++j) {
75 for(i = 0; i < 4; ++i) {
76 float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
77 uint8_t tmp_r;
78 u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);
79 dst[0] =
80 dst[1] =
81 dst[2] = ubyte_to_float(tmp_r);
82 dst[3] = 1.0;
83 }
84 }
85 src += block_size;
86 }
87 src_row += src_stride;
88 }
89 }
90
91 void
92 util_format_latc1_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
93 {
94 util_format_rgtc1_unorm_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
95 }
96
97 void
98 util_format_latc1_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
99 {
100 uint8_t tmp_r;
101
102 u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);
103 dst[0] =
104 dst[1] =
105 dst[2] = ubyte_to_float(tmp_r);
106 dst[3] = 1.0;
107 }
108
109 void
110 util_format_latc1_snorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
111 {
112 fprintf(stderr,"%s\n", __func__);
113 }
114
115 void
116 util_format_latc1_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
117 {
118 fprintf(stderr,"%s\n", __func__);
119 }
120
121 void
122 util_format_latc1_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
123 {
124 fprintf(stderr,"%s\n", __func__);
125 }
126
127 void
128 util_format_latc1_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
129 {
130 util_format_rgtc1_snorm_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
131 }
132
133 void
134 util_format_latc1_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
135 {
136 unsigned x, y, i, j;
137 int block_size = 8;
138
139 for(y = 0; y < height; y += 4) {
140 const int8_t *src = (int8_t *)src_row;
141 for(x = 0; x < width; x += 4) {
142 for(j = 0; j < 4; ++j) {
143 for(i = 0; i < 4; ++i) {
144 float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
145 int8_t tmp_r;
146 u_format_signed_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);
147 dst[0] =
148 dst[1] =
149 dst[2] = byte_to_float_tex(tmp_r);
150 dst[3] = 1.0;
151 }
152 }
153 src += block_size;
154 }
155 src_row += src_stride;
156 }
157 }
158
159 void
160 util_format_latc1_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
161 {
162 int8_t tmp_r;
163
164 u_format_signed_fetch_texel_rgtc(0, (int8_t *)src, i, j, &tmp_r, 1);
165 dst[0] =
166 dst[1] =
167 dst[2] = byte_to_float_tex(tmp_r);
168 dst[3] = 1.0;
169 }
170
171
172 void
173 util_format_latc2_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
174 {
175 u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 2);
176 u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, dst + 1, 2);
177 }
178
179 void
180 util_format_latc2_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
181 {
182 util_format_rgtc2_unorm_unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
183 }
184
185 void
186 util_format_latc2_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
187 {
188 util_format_rgtc2_unorm_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
189 }
190
191 void
192 util_format_latc2_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
193 {
194 util_format_rxtc2_unorm_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height, 3);
195 }
196
197 void
198 util_format_latc2_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
199 {
200 unsigned x, y, i, j;
201 int block_size = 16;
202
203 for(y = 0; y < height; y += 4) {
204 const uint8_t *src = src_row;
205 for(x = 0; x < width; x += 4) {
206 for(j = 0; j < 4; ++j) {
207 for(i = 0; i < 4; ++i) {
208 float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
209 uint8_t tmp_r, tmp_g;
210 u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);
211 u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);
212 dst[0] =
213 dst[1] =
214 dst[2] = ubyte_to_float(tmp_r);
215 dst[3] = ubyte_to_float(tmp_g);
216 }
217 }
218 src += block_size;
219 }
220 src_row += src_stride;
221 }
222 }
223
224 void
225 util_format_latc2_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
226 {
227 uint8_t tmp_r, tmp_g;
228
229 u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);
230 u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);
231 dst[0] =
232 dst[1] =
233 dst[2] = ubyte_to_float(tmp_r);
234 dst[3] = ubyte_to_float(tmp_g);
235 }
236
237
238 void
239 util_format_latc2_snorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
240 {
241 fprintf(stderr,"%s\n", __func__);
242 }
243
244 void
245 util_format_latc2_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
246 {
247 fprintf(stderr,"%s\n", __func__);
248 }
249
250 void
251 util_format_latc2_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
252 {
253 fprintf(stderr,"%s\n", __func__);
254 }
255
256 void
257 util_format_latc2_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
258 {
259 unsigned x, y, i, j;
260 int block_size = 16;
261
262 for(y = 0; y < height; y += 4) {
263 const int8_t *src = (int8_t *)src_row;
264 for(x = 0; x < width; x += 4) {
265 for(j = 0; j < 4; ++j) {
266 for(i = 0; i < 4; ++i) {
267 float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
268 int8_t tmp_r, tmp_g;
269 u_format_signed_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);
270 u_format_signed_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);
271 dst[0] =
272 dst[1] =
273 dst[2] = byte_to_float_tex(tmp_r);
274 dst[3] = byte_to_float_tex(tmp_g);
275 }
276 }
277 src += block_size;
278 }
279 src_row += src_stride;
280 }
281 }
282
283 void
284 util_format_latc2_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
285 {
286 util_format_rxtc2_snorm_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height, 3);
287 }
288
289 void
290 util_format_latc2_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
291 {
292 int8_t tmp_r, tmp_g;
293
294 u_format_signed_fetch_texel_rgtc(0, (int8_t *)src, i, j, &tmp_r, 2);
295 u_format_signed_fetch_texel_rgtc(0, (int8_t *)src + 8, i, j, &tmp_g, 2);
296 dst[0] =
297 dst[1] =
298 dst[2] = byte_to_float_tex(tmp_r);
299 dst[3] = byte_to_float_tex(tmp_g);
300 }
301
302
303 #define TAG(x) u_format_unsigned_##x
304 #define TYPE uint8_t
305 #define T_MIN 0
306 #define T_MAX 255
307
308 #include "../../../mesa/main/texcompress_rgtc_tmp.h"
309
310 #undef TYPE
311 #undef TAG
312 #undef T_MIN
313 #undef T_MAX
314
315
316 #define TAG(x) u_format_signed_##x
317 #define TYPE int8_t
318 #define T_MIN (int8_t)-128
319 #define T_MAX (int8_t)127
320
321 #include "../../../mesa/main/texcompress_rgtc_tmp.h"
322
323 #undef TYPE
324 #undef TAG
325 #undef T_MIN
326 #undef T_MAX