gallium/util: print \n after DXTn printf
[mesa.git] / src / gallium / auxiliary / util / u_format_s3tc.c
1 /**************************************************************************
2 *
3 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
4 * Copyright (c) 2008 VMware, Inc.
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 * BRIAN PAUL 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 #include "u_dl.h"
26 #include "u_math.h"
27 #include "u_format.h"
28 #include "u_format_s3tc.h"
29
30
31 #if defined(_WIN32) || defined(WIN32)
32 #define DXTN_LIBNAME "dxtn.dll"
33 #else
34 #define DXTN_LIBNAME "libtxc_dxtn.so"
35 #endif
36
37 static void
38 util_format_dxt1_rgb_fetch_stub( int src_stride,
39 const uint8_t *src,
40 int col, int row,
41 uint8_t *dst )
42 {
43 util_format_s3tc_init();
44 util_format_dxt1_rgb_fetch(src_stride, src, col, row, dst);
45 }
46
47 static void
48 util_format_dxt1_rgba_fetch_stub( int src_stride,
49 const uint8_t *src,
50 int col, int row,
51 uint8_t *dst )
52 {
53 util_format_s3tc_init();
54 util_format_dxt1_rgba_fetch(src_stride, src, col, row, dst);
55 }
56
57 static void
58 util_format_dxt3_rgba_fetch_stub( int src_stride,
59 const uint8_t *src,
60 int col, int row,
61 uint8_t *dst )
62 {
63 util_format_s3tc_init();
64 util_format_dxt3_rgba_fetch(src_stride, src, col, row, dst);
65 }
66
67 static void
68 util_format_dxt5_rgba_fetch_stub( int src_stride,
69 const uint8_t *src,
70 int col, int row,
71 uint8_t *dst )
72 {
73 util_format_s3tc_init();
74 util_format_dxt5_rgba_fetch(src_stride, src, col, row, dst);
75 }
76
77 static
78 void util_format_dxtn_pack_stub( int src_comps,
79 int width, int height,
80 const uint8_t *src,
81 enum util_format_dxtn dst_format,
82 uint8_t *dst,
83 int dst_stride)
84 {
85 util_format_s3tc_init();
86 util_format_dxtn_pack_stub(src_comps, width, height, src, dst_format, dst, dst_stride);
87 }
88
89 boolean util_format_s3tc_inited = FALSE;
90
91 util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch = util_format_dxt1_rgb_fetch_stub;
92 util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch = util_format_dxt1_rgba_fetch_stub;
93 util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch = util_format_dxt3_rgba_fetch_stub;
94 util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch = util_format_dxt5_rgba_fetch_stub;
95
96 util_format_dxtn_pack_t util_format_dxtn_pack = util_format_dxtn_pack_stub;
97
98 static void
99 nop(void)
100 {}
101
102 #define is_nop(f) ((void*)(f) == (void*)nop)
103
104 static util_dl_proc
105 get_proc_address_or_nop(struct util_dl_library *library,
106 const char *procname)
107 {
108 if(library) {
109 util_dl_proc proc = util_dl_get_proc_address(library, procname);
110 if(proc)
111 return proc;
112 }
113 return (util_dl_proc)nop;
114 }
115
116 void
117 util_format_s3tc_do_init(void)
118 {
119 struct util_dl_library *library;
120
121 library = util_dl_open(DXTN_LIBNAME);
122 util_format_dxt1_rgb_fetch = (util_format_dxtn_fetch_t)
123 get_proc_address_or_nop(library, "fetch_2d_texel_rgb_dxt1");
124 util_format_dxt1_rgba_fetch = (util_format_dxtn_fetch_t)
125 get_proc_address_or_nop(library, "fetch_2d_texel_rgba_dxt1");
126 util_format_dxt3_rgba_fetch = (util_format_dxtn_fetch_t)
127 get_proc_address_or_nop(library, "fetch_2d_texel_rgba_dxt3");
128 util_format_dxt5_rgba_fetch = (util_format_dxtn_fetch_t)
129 get_proc_address_or_nop(library, "fetch_2d_texel_rgba_dxt5");
130 util_format_dxtn_pack = (util_format_dxtn_pack_t)
131 get_proc_address_or_nop(library, "tx_compress_dxtn");
132
133 if (!library)
134 debug_printf("couldn't open " DXTN_LIBNAME ", software DXTn "
135 "compression/decompression unavailable\n");
136 else {
137 if (!is_nop(util_format_dxt1_rgb_fetch) &&
138 !is_nop(util_format_dxt1_rgba_fetch) &&
139 !is_nop(util_format_dxt3_rgba_fetch) &&
140 !is_nop(util_format_dxt5_rgba_fetch) &&
141 !is_nop(util_format_dxtn_pack)) {
142 debug_printf("software DXTn compression/decompression available\n");
143 } else
144 debug_printf("couldn't reference all symbols in "
145 DXTN_LIBNAME ", software DXTn compression/decompression "
146 "unavailable or partially available\n");
147 }
148
149 #define DO(n, a, A) \
150 ((struct util_format_description *)util_format_description(PIPE_FORMAT_DXT##n##_SRGB##A))->is_supported = \
151 ((struct util_format_description *)util_format_description(PIPE_FORMAT_DXT##n##_RGB##A))->is_supported = \
152 !is_nop(util_format_dxt##n##_rgb##a##_fetch);
153
154 DO(1,,);
155 DO(1,a,A);
156 DO(3,a,A);
157 DO(5,a,A);
158
159 #undef DO
160 }
161
162
163 /*
164 * Pixel fetch.
165 */
166
167 void
168 util_format_dxt1_rgb_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
169 {
170 util_format_dxt1_rgb_fetch(0, src, i, j, dst);
171 }
172
173 void
174 util_format_dxt1_rgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
175 {
176 util_format_dxt1_rgba_fetch(0, src, i, j, dst);
177 }
178
179 void
180 util_format_dxt3_rgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
181 {
182 util_format_dxt3_rgba_fetch(0, src, i, j, dst);
183 }
184
185 void
186 util_format_dxt5_rgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
187 {
188 util_format_dxt5_rgba_fetch(0, src, i, j, dst);
189 }
190
191 void
192 util_format_dxt1_rgb_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
193 {
194 uint8_t tmp[4];
195 util_format_dxt1_rgb_fetch(0, src, i, j, tmp);
196 dst[0] = ubyte_to_float(tmp[0]);
197 dst[1] = ubyte_to_float(tmp[1]);
198 dst[2] = ubyte_to_float(tmp[2]);
199 dst[3] = 1.0;
200 }
201
202 void
203 util_format_dxt1_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
204 {
205 uint8_t tmp[4];
206 util_format_dxt1_rgba_fetch(0, src, i, j, tmp);
207 dst[0] = ubyte_to_float(tmp[0]);
208 dst[1] = ubyte_to_float(tmp[1]);
209 dst[2] = ubyte_to_float(tmp[2]);
210 dst[3] = ubyte_to_float(tmp[3]);
211 }
212
213 void
214 util_format_dxt3_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
215 {
216 uint8_t tmp[4];
217 util_format_dxt3_rgba_fetch(0, src, i, j, tmp);
218 dst[0] = ubyte_to_float(tmp[0]);
219 dst[1] = ubyte_to_float(tmp[1]);
220 dst[2] = ubyte_to_float(tmp[2]);
221 dst[3] = ubyte_to_float(tmp[3]);
222 }
223
224 void
225 util_format_dxt5_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
226 {
227 uint8_t tmp[4];
228 util_format_dxt5_rgba_fetch(0, src, i, j, tmp);
229 dst[0] = ubyte_to_float(tmp[0]);
230 dst[1] = ubyte_to_float(tmp[1]);
231 dst[2] = ubyte_to_float(tmp[2]);
232 dst[3] = ubyte_to_float(tmp[3]);
233 }
234
235
236 /*
237 * Block decompression.
238 */
239
240 void
241 util_format_dxt1_rgb_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
242 {
243 if (!is_nop(util_format_dxt1_rgb_fetch)) {
244 unsigned x, y, i, j;
245 for(y = 0; y < height; y += 4) {
246 const uint8_t *src = src_row;
247 for(x = 0; x < width; x += 4) {
248 for(j = 0; j < 4; ++j) {
249 for(i = 0; i < 4; ++i) {
250 uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
251 util_format_dxt1_rgb_fetch(0, src, i, j, dst);
252 }
253 }
254 src += 8;
255 }
256 src_row += src_stride;
257 }
258 }
259 }
260
261 void
262 util_format_dxt1_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
263 {
264 if (!is_nop(util_format_dxt1_rgba_fetch)) {
265 unsigned x, y, i, j;
266 for(y = 0; y < height; y += 4) {
267 const uint8_t *src = src_row;
268 for(x = 0; x < width; x += 4) {
269 for(j = 0; j < 4; ++j) {
270 for(i = 0; i < 4; ++i) {
271 uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
272 util_format_dxt1_rgba_fetch(0, src, i, j, dst);
273 }
274 }
275 src += 8;
276 }
277 src_row += src_stride;
278 }
279 }
280 }
281
282 void
283 util_format_dxt3_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
284 {
285 if (!is_nop(util_format_dxt3_rgba_fetch)) {
286 unsigned x, y, i, j;
287 for(y = 0; y < height; y += 4) {
288 const uint8_t *src = src_row;
289 for(x = 0; x < width; x += 4) {
290 for(j = 0; j < 4; ++j) {
291 for(i = 0; i < 4; ++i) {
292 uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
293 util_format_dxt3_rgba_fetch(0, src, i, j, dst);
294 }
295 }
296 src += 16;
297 }
298 src_row += src_stride;
299 }
300 }
301 }
302
303 void
304 util_format_dxt5_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
305 {
306 if (is_nop(util_format_dxt5_rgba_fetch)) {
307 unsigned x, y, i, j;
308 for(y = 0; y < height; y += 4) {
309 const uint8_t *src = src_row;
310 for(x = 0; x < width; x += 4) {
311 for(j = 0; j < 4; ++j) {
312 for(i = 0; i < 4; ++i) {
313 uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
314 util_format_dxt5_rgba_fetch(0, src, i, j, dst);
315 }
316 }
317 src += 16;
318 }
319 src_row += src_stride;
320 }
321 }
322 }
323
324 void
325 util_format_dxt1_rgb_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
326 {
327 if (is_nop(util_format_dxt1_rgb_fetch)) {
328 unsigned x, y, i, j;
329 for(y = 0; y < height; y += 4) {
330 const uint8_t *src = src_row;
331 for(x = 0; x < width; x += 4) {
332 for(j = 0; j < 4; ++j) {
333 for(i = 0; i < 4; ++i) {
334 float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
335 uint8_t tmp[4];
336 util_format_dxt1_rgb_fetch(0, src, i, j, tmp);
337 dst[0] = ubyte_to_float(tmp[0]);
338 dst[1] = ubyte_to_float(tmp[1]);
339 dst[2] = ubyte_to_float(tmp[2]);
340 dst[3] = 1.0;
341 }
342 }
343 src += 8;
344 }
345 src_row += src_stride;
346 }
347 }
348 }
349
350 void
351 util_format_dxt1_rgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
352 {
353 if (!is_nop(util_format_dxt1_rgba_fetch)) {
354 unsigned x, y, i, j;
355 for(y = 0; y < height; y += 4) {
356 const uint8_t *src = src_row;
357 for(x = 0; x < width; x += 4) {
358 for(j = 0; j < 4; ++j) {
359 for(i = 0; i < 4; ++i) {
360 float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
361 uint8_t tmp[4];
362 util_format_dxt1_rgba_fetch(0, src, i, j, tmp);
363 dst[0] = ubyte_to_float(tmp[0]);
364 dst[1] = ubyte_to_float(tmp[1]);
365 dst[2] = ubyte_to_float(tmp[2]);
366 dst[3] = ubyte_to_float(tmp[3]);
367 }
368 }
369 src += 8;
370 }
371 src_row += src_stride;
372 }
373 }
374 }
375
376 void
377 util_format_dxt3_rgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
378 {
379 if (!is_nop(util_format_dxt3_rgba_fetch)) {
380 unsigned x, y, i, j;
381 for(y = 0; y < height; y += 4) {
382 const uint8_t *src = src_row;
383 for(x = 0; x < width; x += 4) {
384 for(j = 0; j < 4; ++j) {
385 for(i = 0; i < 4; ++i) {
386 float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
387 uint8_t tmp[4];
388 util_format_dxt3_rgba_fetch(0, src, i, j, tmp);
389 dst[0] = ubyte_to_float(tmp[0]);
390 dst[1] = ubyte_to_float(tmp[1]);
391 dst[2] = ubyte_to_float(tmp[2]);
392 dst[3] = ubyte_to_float(tmp[3]);
393 }
394 }
395 src += 16;
396 }
397 src_row += src_stride;
398 }
399 }
400 }
401
402 void
403 util_format_dxt5_rgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
404 {
405 if (!is_nop(util_format_dxt5_rgba_fetch)) {
406 unsigned x, y, i, j;
407 for(y = 0; y < height; y += 4) {
408 const uint8_t *src = src_row;
409 for(x = 0; x < width; x += 4) {
410 for(j = 0; j < 4; ++j) {
411 for(i = 0; i < 4; ++i) {
412 float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
413 uint8_t tmp[4];
414 util_format_dxt5_rgba_fetch(0, src, i, j, tmp);
415 dst[0] = ubyte_to_float(tmp[0]);
416 dst[1] = ubyte_to_float(tmp[1]);
417 dst[2] = ubyte_to_float(tmp[2]);
418 dst[3] = ubyte_to_float(tmp[3]);
419 }
420 }
421 src += 16;
422 }
423 src_row += src_stride;
424 }
425 }
426 }
427
428
429 /*
430 * Block compression.
431 */
432
433 void
434 util_format_dxt1_rgb_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
435 {
436 if (!is_nop(util_format_dxtn_pack)) {
437 unsigned x, y, i, j, k;
438 for(y = 0; y < height; y += 4) {
439 const uint8_t *src = src_row;
440 uint8_t *dst = dst_row;
441 for(x = 0; x < width; x += 4) {
442 uint8_t tmp[4][4][3];
443 for(j = 0; j < 4; ++j) {
444 for(i = 0; i < 4; ++i) {
445 for(k = 0; k < 3; ++k) {
446 tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + i*4 + k];
447 }
448 }
449 }
450 util_format_dxtn_pack(3, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGB, dst, dst_stride);
451 src += 4*4;
452 dst += 8;
453 }
454 src_row += src_stride;
455 dst_row += 4*dst_stride/sizeof(*dst_row);
456 }
457 }
458 }
459
460 void
461 util_format_dxt1_rgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
462 {
463 if (!is_nop(util_format_dxtn_pack)) {
464 unsigned x, y, i, j, k;
465 for(y = 0; y < height; y += 4) {
466 const uint8_t *src = src_row;
467 uint8_t *dst = dst_row;
468 for(x = 0; x < width; x += 4) {
469 uint8_t tmp[4][4][4];
470 for(j = 0; j < 4; ++j) {
471 for(i = 0; i < 4; ++i) {
472 for(k = 0; k < 4; ++k) {
473 tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + i*4 + k];
474 }
475 }
476 }
477 util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGBA, dst, dst_stride);
478 src += 4*4;
479 dst += 8;
480 }
481 src_row += src_stride;
482 dst_row += 4*dst_stride/sizeof(*dst_row);
483 }
484 }
485 }
486
487 void
488 util_format_dxt3_rgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
489 {
490 if (!is_nop(util_format_dxtn_pack)) {
491 unsigned x, y, i, j, k;
492 for(y = 0; y < height; y += 4) {
493 const uint8_t *src = src_row;
494 uint8_t *dst = dst_row;
495 for(x = 0; x < width; x += 4) {
496 uint8_t tmp[4][4][4];
497 for(j = 0; j < 4; ++j) {
498 for(i = 0; i < 4; ++i) {
499 for(k = 0; k < 4; ++k) {
500 tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + i*4 + k];
501 }
502 }
503 }
504 util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT3_RGBA, dst, dst_stride);
505 src += 4*4;
506 dst += 16;
507 }
508 src_row += src_stride;
509 dst_row += 4*dst_stride/sizeof(*dst_row);
510 }
511 }
512 }
513
514 void
515 util_format_dxt5_rgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
516 {
517 if (!is_nop(util_format_dxtn_pack)) {
518 unsigned x, y, i, j, k;
519 for(y = 0; y < height; y += 4) {
520 const uint8_t *src = src_row;
521 uint8_t *dst = dst_row;
522 for(x = 0; x < width; x += 4) {
523 uint8_t tmp[4][4][4];
524 for(j = 0; j < 4; ++j) {
525 for(i = 0; i < 4; ++i) {
526 for(k = 0; k < 4; ++k) {
527 tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + i*4 + k];
528 }
529 }
530 }
531 util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT5_RGBA, dst, dst_stride);
532 src += 4*4;
533 dst += 16;
534 }
535 src_row += src_stride;
536 dst_row += 4*dst_stride/sizeof(*dst_row);
537 }
538 }
539 }
540
541 void
542 util_format_dxt1_rgb_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
543 {
544 if (!is_nop(util_format_dxtn_pack)) {
545 unsigned x, y, i, j, k;
546 for(y = 0; y < height; y += 4) {
547 const float *src = src_row;
548 uint8_t *dst = dst_row;
549 for(x = 0; x < width; x += 4) {
550 uint8_t tmp[4][4][3];
551 for(j = 0; j < 4; ++j) {
552 for(i = 0; i < 4; ++i) {
553 for(k = 0; k < 3; ++k) {
554 tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
555 }
556 }
557 }
558 util_format_dxtn_pack(3, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGB, dst, dst_stride);
559 src += 4*4;
560 dst += 8;
561 }
562 src_row += src_stride;
563 dst_row += 4*dst_stride/sizeof(*dst_row);
564 }
565 }
566 }
567
568 void
569 util_format_dxt1_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
570 {
571 if (!is_nop(util_format_dxtn_pack)) {
572 unsigned x, y, i, j, k;
573 for(y = 0; y < height; y += 4) {
574 const float *src = src_row;
575 uint8_t *dst = dst_row;
576 for(x = 0; x < width; x += 4) {
577 uint8_t tmp[4][4][4];
578 for(j = 0; j < 4; ++j) {
579 for(i = 0; i < 4; ++i) {
580 for(k = 0; k < 4; ++k) {
581 tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
582 }
583 }
584 }
585 util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGBA, dst, dst_stride);
586 src += 4*4;
587 dst += 8;
588 }
589 src_row += src_stride;
590 dst_row += 4*dst_stride/sizeof(*dst_row);
591 }
592 }
593 }
594
595 void
596 util_format_dxt3_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
597 {
598 if (!is_nop(util_format_dxtn_pack)) {
599 unsigned x, y, i, j, k;
600 for(y = 0; y < height; y += 4) {
601 const float *src = src_row;
602 uint8_t *dst = dst_row;
603 for(x = 0; x < width; x += 4) {
604 uint8_t tmp[4][4][4];
605 for(j = 0; j < 4; ++j) {
606 for(i = 0; i < 4; ++i) {
607 for(k = 0; k < 4; ++k) {
608 tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
609 }
610 }
611 }
612 util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT3_RGBA, dst, dst_stride);
613 src += 4*4;
614 dst += 16;
615 }
616 src_row += src_stride;
617 dst_row += 4*dst_stride/sizeof(*dst_row);
618 }
619 }
620 }
621
622 void
623 util_format_dxt5_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
624 {
625 if (!is_nop(util_format_dxtn_pack)) {
626 unsigned x, y, i, j, k;
627 for(y = 0; y < height; y += 4) {
628 const float *src = src_row;
629 uint8_t *dst = dst_row;
630 for(x = 0; x < width; x += 4) {
631 uint8_t tmp[4][4][4];
632 for(j = 0; j < 4; ++j) {
633 for(i = 0; i < 4; ++i) {
634 for(k = 0; k < 4; ++k) {
635 tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
636 }
637 }
638 }
639 util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT5_RGBA, dst, dst_stride);
640 src += 4*4;
641 dst += 16;
642 }
643 src_row += src_stride;
644 dst_row += 4*dst_stride/sizeof(*dst_row);
645 }
646 }
647 }
648
649
650 /*
651 * SRGB variants.
652 *
653 * FIXME: shunts to RGB for now
654 */
655
656 void
657 util_format_dxt1_srgb_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
658 {
659 util_format_dxt1_rgb_unpack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
660 }
661
662 void
663 util_format_dxt1_srgb_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
664 {
665 util_format_dxt1_rgb_pack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
666 }
667
668 void
669 util_format_dxt1_srgb_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
670 {
671 util_format_dxt1_rgb_fetch_8unorm(dst, src, i, j);
672 }
673
674 void
675 util_format_dxt1_srgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
676 {
677 util_format_dxt1_rgba_unpack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
678 }
679
680 void
681 util_format_dxt1_srgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
682 {
683 util_format_dxt1_rgba_pack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
684 }
685
686 void
687 util_format_dxt1_srgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
688 {
689 util_format_dxt1_rgba_fetch_8unorm(dst, src, i, j);
690 }
691
692 void
693 util_format_dxt3_srgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
694 {
695 util_format_dxt3_rgba_unpack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
696 }
697
698 void
699 util_format_dxt3_srgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
700 {
701 util_format_dxt3_rgba_pack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
702 }
703
704 void
705 util_format_dxt3_srgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
706 {
707 util_format_dxt3_rgba_fetch_8unorm(dst, src, i, j);
708 }
709
710 void
711 util_format_dxt5_srgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
712 {
713 util_format_dxt5_rgba_unpack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
714 }
715
716 void
717 util_format_dxt5_srgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
718 {
719 util_format_dxt5_rgba_pack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
720 }
721
722 void
723 util_format_dxt5_srgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
724 {
725 util_format_dxt5_rgba_fetch_8unorm(dst, src, i, j);
726 }
727
728 void
729 util_format_dxt1_srgb_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
730 {
731 util_format_dxt1_rgb_unpack_float(dst_row, dst_stride, src_row, src_stride, width, height);
732 }
733
734 void
735 util_format_dxt1_srgb_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
736 {
737 util_format_dxt1_rgb_pack_float(dst_row, dst_stride, src_row, src_stride, width, height);
738 }
739
740 void
741 util_format_dxt1_srgb_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
742 {
743 util_format_dxt1_rgb_fetch_float(dst, src, i, j);
744 }
745
746 void
747 util_format_dxt1_srgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
748 {
749 util_format_dxt1_rgba_unpack_float(dst_row, dst_stride, src_row, src_stride, width, height);
750 }
751
752 void
753 util_format_dxt1_srgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
754 {
755 util_format_dxt1_rgba_pack_float(dst_row, dst_stride, src_row, src_stride, width, height);
756 }
757
758 void
759 util_format_dxt1_srgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
760 {
761 util_format_dxt1_rgba_fetch_float(dst, src, i, j);
762 }
763
764 void
765 util_format_dxt3_srgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
766 {
767 util_format_dxt3_rgba_unpack_float(dst_row, dst_stride, src_row, src_stride, width, height);
768 }
769
770 void
771 util_format_dxt3_srgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
772 {
773 util_format_dxt3_rgba_pack_float(dst_row, dst_stride, src_row, src_stride, width, height);
774 }
775
776 void
777 util_format_dxt3_srgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
778 {
779 util_format_dxt3_rgba_fetch_float(dst, src, i, j);
780 }
781
782 void
783 util_format_dxt5_srgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
784 {
785 util_format_dxt5_rgba_unpack_float(dst_row, dst_stride, src_row, src_stride, width, height);
786 }
787
788 void
789 util_format_dxt5_srgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
790 {
791 util_format_dxt5_rgba_pack_float(dst_row, dst_stride, src_row, src_stride, width, height);
792 }
793
794 void
795 util_format_dxt5_srgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
796 {
797 util_format_dxt5_rgba_fetch_float(dst, src, i, j);
798 }
799