util: Add dedicated depth-stencil packing/unpacking functions.
[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 #elif defined(__APPLE__)
34 #define DXTN_LIBNAME "libtxc_dxtn.dylib"
35 #else
36 #define DXTN_LIBNAME "libtxc_dxtn.so"
37 #endif
38
39
40 static void
41 util_format_dxt1_rgb_fetch_stub(int src_stride,
42 const uint8_t *src,
43 int col, int row,
44 uint8_t *dst)
45 {
46 assert(0);
47 }
48
49
50 static void
51 util_format_dxt1_rgba_fetch_stub(int src_stride,
52 const uint8_t *src,
53 int col, int row,
54 uint8_t *dst )
55 {
56 assert(0);
57 }
58
59
60 static void
61 util_format_dxt3_rgba_fetch_stub(int src_stride,
62 const uint8_t *src,
63 int col, int row,
64 uint8_t *dst )
65 {
66 assert(0);
67 }
68
69
70 static void
71 util_format_dxt5_rgba_fetch_stub(int src_stride,
72 const uint8_t *src,
73 int col, int row,
74 uint8_t *dst )
75 {
76 assert(0);
77 }
78
79
80 static void
81 util_format_dxtn_pack_stub(int src_comps,
82 int width, int height,
83 const uint8_t *src,
84 enum util_format_dxtn dst_format,
85 uint8_t *dst,
86 int dst_stride)
87 {
88 assert(0);
89 }
90
91
92 boolean util_format_s3tc_enabled = FALSE;
93
94 util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch = util_format_dxt1_rgb_fetch_stub;
95 util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch = util_format_dxt1_rgba_fetch_stub;
96 util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch = util_format_dxt3_rgba_fetch_stub;
97 util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch = util_format_dxt5_rgba_fetch_stub;
98
99 util_format_dxtn_pack_t util_format_dxtn_pack = util_format_dxtn_pack_stub;
100
101
102 void
103 util_format_s3tc_init(void)
104 {
105 static boolean first_time = TRUE;
106 struct util_dl_library *library = NULL;
107 util_dl_proc fetch_2d_texel_rgb_dxt1;
108 util_dl_proc fetch_2d_texel_rgba_dxt1;
109 util_dl_proc fetch_2d_texel_rgba_dxt3;
110 util_dl_proc fetch_2d_texel_rgba_dxt5;
111 util_dl_proc tx_compress_dxtn;
112
113 if (!first_time)
114 return;
115 first_time = FALSE;
116
117 if (util_format_s3tc_enabled)
118 return;
119
120 library = util_dl_open(DXTN_LIBNAME);
121 if (!library) {
122 debug_printf("couldn't open " DXTN_LIBNAME ", software DXTn "
123 "compression/decompression unavailable");
124 return;
125 }
126
127 fetch_2d_texel_rgb_dxt1 =
128 util_dl_get_proc_address(library, "fetch_2d_texel_rgb_dxt1");
129 fetch_2d_texel_rgba_dxt1 =
130 util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt1");
131 fetch_2d_texel_rgba_dxt3 =
132 util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt3");
133 fetch_2d_texel_rgba_dxt5 =
134 util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt5");
135 tx_compress_dxtn =
136 util_dl_get_proc_address(library, "tx_compress_dxtn");
137
138 if (!util_format_dxt1_rgb_fetch ||
139 !util_format_dxt1_rgba_fetch ||
140 !util_format_dxt3_rgba_fetch ||
141 !util_format_dxt5_rgba_fetch ||
142 !util_format_dxtn_pack) {
143 debug_printf("couldn't reference all symbols in " DXTN_LIBNAME
144 ", software DXTn compression/decompression "
145 "unavailable");
146 util_dl_close(library);
147 return;
148 }
149
150 util_format_dxt1_rgb_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgb_dxt1;
151 util_format_dxt1_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt1;
152 util_format_dxt3_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt3;
153 util_format_dxt5_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt5;
154 util_format_dxtn_pack = (util_format_dxtn_pack_t)tx_compress_dxtn;
155 util_format_s3tc_enabled = TRUE;
156 }
157
158
159 /*
160 * Pixel fetch.
161 */
162
163 void
164 util_format_dxt1_rgb_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
165 {
166 util_format_dxt1_rgb_fetch(0, src, i, j, dst);
167 }
168
169 void
170 util_format_dxt1_rgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
171 {
172 util_format_dxt1_rgba_fetch(0, src, i, j, dst);
173 }
174
175 void
176 util_format_dxt3_rgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
177 {
178 util_format_dxt3_rgba_fetch(0, src, i, j, dst);
179 }
180
181 void
182 util_format_dxt5_rgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
183 {
184 util_format_dxt5_rgba_fetch(0, src, i, j, dst);
185 }
186
187 void
188 util_format_dxt1_rgb_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
189 {
190 uint8_t tmp[4];
191 util_format_dxt1_rgb_fetch(0, src, i, j, tmp);
192 dst[0] = ubyte_to_float(tmp[0]);
193 dst[1] = ubyte_to_float(tmp[1]);
194 dst[2] = ubyte_to_float(tmp[2]);
195 dst[3] = 1.0;
196 }
197
198 void
199 util_format_dxt1_rgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
200 {
201 uint8_t tmp[4];
202 util_format_dxt1_rgba_fetch(0, src, i, j, tmp);
203 dst[0] = ubyte_to_float(tmp[0]);
204 dst[1] = ubyte_to_float(tmp[1]);
205 dst[2] = ubyte_to_float(tmp[2]);
206 dst[3] = ubyte_to_float(tmp[3]);
207 }
208
209 void
210 util_format_dxt3_rgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
211 {
212 uint8_t tmp[4];
213 util_format_dxt3_rgba_fetch(0, src, i, j, tmp);
214 dst[0] = ubyte_to_float(tmp[0]);
215 dst[1] = ubyte_to_float(tmp[1]);
216 dst[2] = ubyte_to_float(tmp[2]);
217 dst[3] = ubyte_to_float(tmp[3]);
218 }
219
220 void
221 util_format_dxt5_rgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
222 {
223 uint8_t tmp[4];
224 util_format_dxt5_rgba_fetch(0, src, i, j, tmp);
225 dst[0] = ubyte_to_float(tmp[0]);
226 dst[1] = ubyte_to_float(tmp[1]);
227 dst[2] = ubyte_to_float(tmp[2]);
228 dst[3] = ubyte_to_float(tmp[3]);
229 }
230
231
232 /*
233 * Block decompression.
234 */
235
236 void
237 util_format_dxt1_rgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
238 {
239 unsigned x, y, i, j;
240 for(y = 0; y < height; y += 4) {
241 const uint8_t *src = src_row;
242 for(x = 0; x < width; x += 4) {
243 for(j = 0; j < 4; ++j) {
244 for(i = 0; i < 4; ++i) {
245 uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
246 util_format_dxt1_rgb_fetch(0, src, i, j, dst);
247 }
248 }
249 src += 8;
250 }
251 src_row += src_stride;
252 }
253 }
254
255 void
256 util_format_dxt1_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
257 {
258 unsigned x, y, i, j;
259 for(y = 0; y < height; y += 4) {
260 const uint8_t *src = src_row;
261 for(x = 0; x < width; x += 4) {
262 for(j = 0; j < 4; ++j) {
263 for(i = 0; i < 4; ++i) {
264 uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
265 util_format_dxt1_rgba_fetch(0, src, i, j, dst);
266 }
267 }
268 src += 8;
269 }
270 src_row += src_stride;
271 }
272 }
273
274 void
275 util_format_dxt3_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
276 {
277 unsigned x, y, i, j;
278 for(y = 0; y < height; y += 4) {
279 const uint8_t *src = src_row;
280 for(x = 0; x < width; x += 4) {
281 for(j = 0; j < 4; ++j) {
282 for(i = 0; i < 4; ++i) {
283 uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
284 util_format_dxt3_rgba_fetch(0, src, i, j, dst);
285 }
286 }
287 src += 16;
288 }
289 src_row += src_stride;
290 }
291 }
292
293 void
294 util_format_dxt5_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
295 {
296 unsigned x, y, i, j;
297 for(y = 0; y < height; y += 4) {
298 const uint8_t *src = src_row;
299 for(x = 0; x < width; x += 4) {
300 for(j = 0; j < 4; ++j) {
301 for(i = 0; i < 4; ++i) {
302 uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
303 util_format_dxt5_rgba_fetch(0, src, i, j, dst);
304 }
305 }
306 src += 16;
307 }
308 src_row += src_stride;
309 }
310 }
311
312 void
313 util_format_dxt1_rgb_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
314 {
315 unsigned x, y, i, j;
316 for(y = 0; y < height; y += 4) {
317 const uint8_t *src = src_row;
318 for(x = 0; x < width; x += 4) {
319 for(j = 0; j < 4; ++j) {
320 for(i = 0; i < 4; ++i) {
321 float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
322 uint8_t tmp[4];
323 util_format_dxt1_rgb_fetch(0, src, i, j, tmp);
324 dst[0] = ubyte_to_float(tmp[0]);
325 dst[1] = ubyte_to_float(tmp[1]);
326 dst[2] = ubyte_to_float(tmp[2]);
327 dst[3] = 1.0;
328 }
329 }
330 src += 8;
331 }
332 src_row += src_stride;
333 }
334 }
335
336 void
337 util_format_dxt1_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
338 {
339 unsigned x, y, i, j;
340 for(y = 0; y < height; y += 4) {
341 const uint8_t *src = src_row;
342 for(x = 0; x < width; x += 4) {
343 for(j = 0; j < 4; ++j) {
344 for(i = 0; i < 4; ++i) {
345 float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
346 uint8_t tmp[4];
347 util_format_dxt1_rgba_fetch(0, src, i, j, tmp);
348 dst[0] = ubyte_to_float(tmp[0]);
349 dst[1] = ubyte_to_float(tmp[1]);
350 dst[2] = ubyte_to_float(tmp[2]);
351 dst[3] = ubyte_to_float(tmp[3]);
352 }
353 }
354 src += 8;
355 }
356 src_row += src_stride;
357 }
358 }
359
360 void
361 util_format_dxt3_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
362 {
363 unsigned x, y, i, j;
364 for(y = 0; y < height; y += 4) {
365 const uint8_t *src = src_row;
366 for(x = 0; x < width; x += 4) {
367 for(j = 0; j < 4; ++j) {
368 for(i = 0; i < 4; ++i) {
369 float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
370 uint8_t tmp[4];
371 util_format_dxt3_rgba_fetch(0, src, i, j, tmp);
372 dst[0] = ubyte_to_float(tmp[0]);
373 dst[1] = ubyte_to_float(tmp[1]);
374 dst[2] = ubyte_to_float(tmp[2]);
375 dst[3] = ubyte_to_float(tmp[3]);
376 }
377 }
378 src += 16;
379 }
380 src_row += src_stride;
381 }
382 }
383
384 void
385 util_format_dxt5_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
386 {
387 unsigned x, y, i, j;
388 for(y = 0; y < height; y += 4) {
389 const uint8_t *src = src_row;
390 for(x = 0; x < width; x += 4) {
391 for(j = 0; j < 4; ++j) {
392 for(i = 0; i < 4; ++i) {
393 float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
394 uint8_t tmp[4];
395 util_format_dxt5_rgba_fetch(0, src, i, j, tmp);
396 dst[0] = ubyte_to_float(tmp[0]);
397 dst[1] = ubyte_to_float(tmp[1]);
398 dst[2] = ubyte_to_float(tmp[2]);
399 dst[3] = ubyte_to_float(tmp[3]);
400 }
401 }
402 src += 16;
403 }
404 src_row += src_stride;
405 }
406 }
407
408
409 /*
410 * Block compression.
411 */
412
413 void
414 util_format_dxt1_rgb_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
415 {
416 unsigned x, y, i, j, k;
417 for(y = 0; y < height; y += 4) {
418 const uint8_t *src = src_row;
419 uint8_t *dst = dst_row;
420 for(x = 0; x < width; x += 4) {
421 uint8_t tmp[4][4][3];
422 for(j = 0; j < 4; ++j) {
423 for(i = 0; i < 4; ++i) {
424 for(k = 0; k < 3; ++k) {
425 tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + i*4 + k];
426 }
427 }
428 }
429 util_format_dxtn_pack(3, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGB, dst, dst_stride);
430 src += 4*4;
431 dst += 8;
432 }
433 src_row += src_stride;
434 dst_row += 4*dst_stride/sizeof(*dst_row);
435 }
436 }
437
438 void
439 util_format_dxt1_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
440 {
441 unsigned x, y, i, j, k;
442 for(y = 0; y < height; y += 4) {
443 const uint8_t *src = src_row;
444 uint8_t *dst = dst_row;
445 for(x = 0; x < width; x += 4) {
446 uint8_t tmp[4][4][4];
447 for(j = 0; j < 4; ++j) {
448 for(i = 0; i < 4; ++i) {
449 for(k = 0; k < 4; ++k) {
450 tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + i*4 + k];
451 }
452 }
453 }
454 util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGBA, dst, dst_stride);
455 src += 4*4;
456 dst += 8;
457 }
458 src_row += src_stride;
459 dst_row += 4*dst_stride/sizeof(*dst_row);
460 }
461 }
462
463 void
464 util_format_dxt3_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
465 {
466 unsigned x, y, i, j, k;
467 for(y = 0; y < height; y += 4) {
468 const uint8_t *src = src_row;
469 uint8_t *dst = dst_row;
470 for(x = 0; x < width; x += 4) {
471 uint8_t tmp[4][4][4];
472 for(j = 0; j < 4; ++j) {
473 for(i = 0; i < 4; ++i) {
474 for(k = 0; k < 4; ++k) {
475 tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + i*4 + k];
476 }
477 }
478 }
479 util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT3_RGBA, dst, dst_stride);
480 src += 4*4;
481 dst += 16;
482 }
483 src_row += src_stride;
484 dst_row += 4*dst_stride/sizeof(*dst_row);
485 }
486 }
487
488 void
489 util_format_dxt5_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
490 {
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_DXT5_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 void
514 util_format_dxt1_rgb_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
515 {
516 unsigned x, y, i, j, k;
517 for(y = 0; y < height; y += 4) {
518 const float *src = src_row;
519 uint8_t *dst = dst_row;
520 for(x = 0; x < width; x += 4) {
521 uint8_t tmp[4][4][3];
522 for(j = 0; j < 4; ++j) {
523 for(i = 0; i < 4; ++i) {
524 for(k = 0; k < 3; ++k) {
525 tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
526 }
527 }
528 }
529 util_format_dxtn_pack(3, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGB, dst, dst_stride);
530 src += 4*4;
531 dst += 8;
532 }
533 src_row += src_stride;
534 dst_row += 4*dst_stride/sizeof(*dst_row);
535 }
536 }
537
538 void
539 util_format_dxt1_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
540 {
541 unsigned x, y, i, j, k;
542 for(y = 0; y < height; y += 4) {
543 const float *src = src_row;
544 uint8_t *dst = dst_row;
545 for(x = 0; x < width; x += 4) {
546 uint8_t tmp[4][4][4];
547 for(j = 0; j < 4; ++j) {
548 for(i = 0; i < 4; ++i) {
549 for(k = 0; k < 4; ++k) {
550 tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
551 }
552 }
553 }
554 util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGBA, dst, dst_stride);
555 src += 4*4;
556 dst += 8;
557 }
558 src_row += src_stride;
559 dst_row += 4*dst_stride/sizeof(*dst_row);
560 }
561 }
562
563 void
564 util_format_dxt3_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
565 {
566 unsigned x, y, i, j, k;
567 for(y = 0; y < height; y += 4) {
568 const float *src = src_row;
569 uint8_t *dst = dst_row;
570 for(x = 0; x < width; x += 4) {
571 uint8_t tmp[4][4][4];
572 for(j = 0; j < 4; ++j) {
573 for(i = 0; i < 4; ++i) {
574 for(k = 0; k < 4; ++k) {
575 tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
576 }
577 }
578 }
579 util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT3_RGBA, dst, dst_stride);
580 src += 4*4;
581 dst += 16;
582 }
583 src_row += src_stride;
584 dst_row += 4*dst_stride/sizeof(*dst_row);
585 }
586 }
587
588 void
589 util_format_dxt5_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
590 {
591 unsigned x, y, i, j, k;
592 for(y = 0; y < height; y += 4) {
593 const float *src = src_row;
594 uint8_t *dst = dst_row;
595 for(x = 0; x < width; x += 4) {
596 uint8_t tmp[4][4][4];
597 for(j = 0; j < 4; ++j) {
598 for(i = 0; i < 4; ++i) {
599 for(k = 0; k < 4; ++k) {
600 tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
601 }
602 }
603 }
604 util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT5_RGBA, dst, dst_stride);
605 src += 4*4;
606 dst += 16;
607 }
608 src_row += src_stride;
609 dst_row += 4*dst_stride/sizeof(*dst_row);
610 }
611 }
612
613
614 /*
615 * SRGB variants.
616 *
617 * FIXME: shunts to RGB for now
618 */
619
620 void
621 util_format_dxt1_srgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
622 {
623 util_format_dxt1_rgb_unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
624 }
625
626 void
627 util_format_dxt1_srgb_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
628 {
629 util_format_dxt1_rgb_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
630 }
631
632 void
633 util_format_dxt1_srgb_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
634 {
635 util_format_dxt1_rgb_fetch_rgba_8unorm(dst, src, i, j);
636 }
637
638 void
639 util_format_dxt1_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
640 {
641 util_format_dxt1_rgba_unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
642 }
643
644 void
645 util_format_dxt1_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
646 {
647 util_format_dxt1_rgba_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
648 }
649
650 void
651 util_format_dxt1_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
652 {
653 util_format_dxt1_rgba_fetch_rgba_8unorm(dst, src, i, j);
654 }
655
656 void
657 util_format_dxt3_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
658 {
659 util_format_dxt3_rgba_unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
660 }
661
662 void
663 util_format_dxt3_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
664 {
665 util_format_dxt3_rgba_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
666 }
667
668 void
669 util_format_dxt3_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
670 {
671 util_format_dxt3_rgba_fetch_rgba_8unorm(dst, src, i, j);
672 }
673
674 void
675 util_format_dxt5_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
676 {
677 util_format_dxt5_rgba_unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
678 }
679
680 void
681 util_format_dxt5_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
682 {
683 util_format_dxt5_rgba_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
684 }
685
686 void
687 util_format_dxt5_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
688 {
689 util_format_dxt5_rgba_fetch_rgba_8unorm(dst, src, i, j);
690 }
691
692 void
693 util_format_dxt1_srgb_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
694 {
695 util_format_dxt1_rgb_unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
696 }
697
698 void
699 util_format_dxt1_srgb_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
700 {
701 util_format_dxt1_rgb_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
702 }
703
704 void
705 util_format_dxt1_srgb_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
706 {
707 util_format_dxt1_rgb_fetch_rgba_float(dst, src, i, j);
708 }
709
710 void
711 util_format_dxt1_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
712 {
713 util_format_dxt1_rgba_unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
714 }
715
716 void
717 util_format_dxt1_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
718 {
719 util_format_dxt1_rgba_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
720 }
721
722 void
723 util_format_dxt1_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
724 {
725 util_format_dxt1_rgba_fetch_rgba_float(dst, src, i, j);
726 }
727
728 void
729 util_format_dxt3_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
730 {
731 util_format_dxt3_rgba_unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
732 }
733
734 void
735 util_format_dxt3_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
736 {
737 util_format_dxt3_rgba_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
738 }
739
740 void
741 util_format_dxt3_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
742 {
743 util_format_dxt3_rgba_fetch_rgba_float(dst, src, i, j);
744 }
745
746 void
747 util_format_dxt5_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
748 {
749 util_format_dxt5_rgba_unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
750 }
751
752 void
753 util_format_dxt5_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
754 {
755 util_format_dxt5_rgba_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
756 }
757
758 void
759 util_format_dxt5_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
760 {
761 util_format_dxt5_rgba_fetch_rgba_float(dst, src, i, j);
762 }
763