1 /**************************************************************************
3 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
4 * Copyright (c) 2008 VMware, Inc.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
23 **************************************************************************/
28 #include "u_format_s3tc.h"
31 #if defined(_WIN32) || defined(WIN32)
32 #define DXTN_LIBNAME "dxtn.dll"
34 #define DXTN_LIBNAME "libtxc_dxtn.so"
38 util_format_dxt1_rgb_fetch_stub( int src_stride
,
43 util_format_s3tc_init();
44 util_format_dxt1_rgb_fetch(src_stride
, src
, col
, row
, dst
);
48 util_format_dxt1_rgba_fetch_stub( int src_stride
,
53 util_format_s3tc_init();
54 util_format_dxt1_rgba_fetch(src_stride
, src
, col
, row
, dst
);
58 util_format_dxt3_rgba_fetch_stub( int src_stride
,
63 util_format_s3tc_init();
64 util_format_dxt3_rgba_fetch(src_stride
, src
, col
, row
, dst
);
68 util_format_dxt5_rgba_fetch_stub( int src_stride
,
73 util_format_s3tc_init();
74 util_format_dxt5_rgba_fetch(src_stride
, src
, col
, row
, dst
);
78 void util_format_dxtn_pack_stub( int src_comps
,
79 int width
, int height
,
81 enum util_format_dxtn dst_format
,
85 util_format_s3tc_init();
86 util_format_dxtn_pack_stub(src_comps
, width
, height
, src
, dst_format
, dst
, dst_stride
);
89 boolean util_format_s3tc_inited
= FALSE
;
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
;
96 util_format_dxtn_pack_t util_format_dxtn_pack
= util_format_dxtn_pack_stub
;
102 #define is_nop(f) ((void*)(f) == (void*)nop)
105 get_proc_address_or_nop(struct util_dl_library
*library
,
106 const char *procname
)
109 util_dl_proc proc
= util_dl_get_proc_address(library
, procname
);
113 return (util_dl_proc
)nop
;
117 util_format_s3tc_do_init(void)
119 struct util_dl_library
*library
;
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");
134 debug_printf("couldn't open " DXTN_LIBNAME
", software DXTn "
135 "compression/decompression unavailable\n");
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");
144 debug_printf("couldn't reference all symbols in "
145 DXTN_LIBNAME
", software DXTn compression/decompression "
146 "unavailable or partially available\n");
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);
168 util_format_dxt1_rgb_fetch_8unorm(uint8_t *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
170 util_format_dxt1_rgb_fetch(0, src
, i
, j
, dst
);
174 util_format_dxt1_rgba_fetch_8unorm(uint8_t *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
176 util_format_dxt1_rgba_fetch(0, src
, i
, j
, dst
);
180 util_format_dxt3_rgba_fetch_8unorm(uint8_t *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
182 util_format_dxt3_rgba_fetch(0, src
, i
, j
, dst
);
186 util_format_dxt5_rgba_fetch_8unorm(uint8_t *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
188 util_format_dxt5_rgba_fetch(0, src
, i
, j
, dst
);
192 util_format_dxt1_rgb_fetch_float(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
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]);
203 util_format_dxt1_rgba_fetch_float(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
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]);
214 util_format_dxt3_rgba_fetch_float(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
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]);
225 util_format_dxt5_rgba_fetch_float(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
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]);
237 * Block decompression.
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
)
243 if (!is_nop(util_format_dxt1_rgb_fetch
)) {
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
);
256 src_row
+= src_stride
;
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
)
264 if (!is_nop(util_format_dxt1_rgba_fetch
)) {
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
);
277 src_row
+= src_stride
;
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
)
285 if (!is_nop(util_format_dxt3_rgba_fetch
)) {
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
);
298 src_row
+= src_stride
;
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
)
306 if (is_nop(util_format_dxt5_rgba_fetch
)) {
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
);
319 src_row
+= src_stride
;
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
)
327 if (is_nop(util_format_dxt1_rgb_fetch
)) {
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;
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]);
345 src_row
+= src_stride
;
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
)
353 if (!is_nop(util_format_dxt1_rgba_fetch
)) {
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;
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]);
371 src_row
+= src_stride
;
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
)
379 if (!is_nop(util_format_dxt3_rgba_fetch
)) {
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;
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]);
397 src_row
+= src_stride
;
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
)
405 if (!is_nop(util_format_dxt5_rgba_fetch
)) {
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;
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]);
423 src_row
+= src_stride
;
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
)
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
];
450 util_format_dxtn_pack(3, 4, 4, &tmp
[0][0][0], UTIL_FORMAT_DXT1_RGB
, dst
, dst_stride
);
454 src_row
+= src_stride
;
455 dst_row
+= 4*dst_stride
/sizeof(*dst_row
);
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
)
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
];
477 util_format_dxtn_pack(4, 4, 4, &tmp
[0][0][0], UTIL_FORMAT_DXT1_RGBA
, dst
, dst_stride
);
481 src_row
+= src_stride
;
482 dst_row
+= 4*dst_stride
/sizeof(*dst_row
);
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
)
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
];
504 util_format_dxtn_pack(4, 4, 4, &tmp
[0][0][0], UTIL_FORMAT_DXT3_RGBA
, dst
, dst_stride
);
508 src_row
+= src_stride
;
509 dst_row
+= 4*dst_stride
/sizeof(*dst_row
);
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
)
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
];
531 util_format_dxtn_pack(4, 4, 4, &tmp
[0][0][0], UTIL_FORMAT_DXT5_RGBA
, dst
, dst_stride
);
535 src_row
+= src_stride
;
536 dst_row
+= 4*dst_stride
/sizeof(*dst_row
);
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
)
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
]);
558 util_format_dxtn_pack(3, 4, 4, &tmp
[0][0][0], UTIL_FORMAT_DXT1_RGB
, dst
, dst_stride
);
562 src_row
+= src_stride
;
563 dst_row
+= 4*dst_stride
/sizeof(*dst_row
);
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
)
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
]);
585 util_format_dxtn_pack(4, 4, 4, &tmp
[0][0][0], UTIL_FORMAT_DXT1_RGBA
, dst
, dst_stride
);
589 src_row
+= src_stride
;
590 dst_row
+= 4*dst_stride
/sizeof(*dst_row
);
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
)
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
]);
612 util_format_dxtn_pack(4, 4, 4, &tmp
[0][0][0], UTIL_FORMAT_DXT3_RGBA
, dst
, dst_stride
);
616 src_row
+= src_stride
;
617 dst_row
+= 4*dst_stride
/sizeof(*dst_row
);
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
)
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
]);
639 util_format_dxtn_pack(4, 4, 4, &tmp
[0][0][0], UTIL_FORMAT_DXT5_RGBA
, dst
, dst_stride
);
643 src_row
+= src_stride
;
644 dst_row
+= 4*dst_stride
/sizeof(*dst_row
);
653 * FIXME: shunts to RGB for now
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
)
659 util_format_dxt1_rgb_unpack_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
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
)
665 util_format_dxt1_rgb_pack_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
669 util_format_dxt1_srgb_fetch_8unorm(uint8_t *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
671 util_format_dxt1_rgb_fetch_8unorm(dst
, src
, i
, j
);
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
)
677 util_format_dxt1_rgba_unpack_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
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
)
683 util_format_dxt1_rgba_pack_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
687 util_format_dxt1_srgba_fetch_8unorm(uint8_t *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
689 util_format_dxt1_rgba_fetch_8unorm(dst
, src
, i
, j
);
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
)
695 util_format_dxt3_rgba_unpack_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
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
)
701 util_format_dxt3_rgba_pack_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
705 util_format_dxt3_srgba_fetch_8unorm(uint8_t *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
707 util_format_dxt3_rgba_fetch_8unorm(dst
, src
, i
, j
);
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
)
713 util_format_dxt5_rgba_unpack_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
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
)
719 util_format_dxt5_rgba_pack_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
723 util_format_dxt5_srgba_fetch_8unorm(uint8_t *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
725 util_format_dxt5_rgba_fetch_8unorm(dst
, src
, i
, j
);
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
)
731 util_format_dxt1_rgb_unpack_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
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
)
737 util_format_dxt1_rgb_pack_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
741 util_format_dxt1_srgb_fetch_float(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
743 util_format_dxt1_rgb_fetch_float(dst
, src
, i
, j
);
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
)
749 util_format_dxt1_rgba_unpack_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
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
)
755 util_format_dxt1_rgba_pack_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
759 util_format_dxt1_srgba_fetch_float(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
761 util_format_dxt1_rgba_fetch_float(dst
, src
, i
, j
);
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
)
767 util_format_dxt3_rgba_unpack_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
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
)
773 util_format_dxt3_rgba_pack_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
777 util_format_dxt3_srgba_fetch_float(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
779 util_format_dxt3_rgba_fetch_float(dst
, src
, i
, j
);
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
)
785 util_format_dxt5_rgba_unpack_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
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
)
791 util_format_dxt5_rgba_pack_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
795 util_format_dxt5_srgba_fetch_float(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
797 util_format_dxt5_rgba_fetch_float(dst
, src
, i
, j
);