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