cc0a6ae5a86b12a7ef927d4e4191041a7087e375
[mesa.git] / src / gallium / auxiliary / util / u_format_etc.c
1 #include "pipe/p_compiler.h"
2 #include "util/u_debug.h"
3 #include "util/u_math.h"
4 #include "u_format_etc.h"
5
6 /* define etc1_parse_block and etc. */
7 #define UINT8_TYPE uint8_t
8 #define TAG(x) x
9 #include "../../../mesa/main/texcompress_etc_tmp.h"
10 #undef TAG
11 #undef UINT8_TYPE
12
13 void
14 util_format_etc1_rgb8_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
15 {
16 etc1_unpack_rgba8888(dst_row, dst_stride, src_row, src_stride, width, height);
17 }
18
19 void
20 util_format_etc1_rgb8_pack_rgba_8unorm(UNUSED uint8_t *dst_row, UNUSED unsigned dst_stride,
21 UNUSED const uint8_t *src_row, UNUSED unsigned src_stride,
22 UNUSED unsigned width, UNUSED unsigned height)
23 {
24 assert(0);
25 }
26
27 void
28 util_format_etc1_rgb8_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
29 {
30 const unsigned bw = 4, bh = 4, bs = 8, comps = 4;
31 struct etc1_block block;
32 unsigned x, y, i, j;
33
34 for (y = 0; y < height; y += bh) {
35 const uint8_t *src = src_row;
36
37 for (x = 0; x < width; x+= bw) {
38 etc1_parse_block(&block, src);
39
40 for (j = 0; j < bh; j++) {
41 float *dst = dst_row + (y + j) * dst_stride / sizeof(*dst_row) + x * comps;
42 uint8_t tmp[3];
43
44 for (i = 0; i < bw; i++) {
45 etc1_fetch_texel(&block, i, j, tmp);
46 dst[0] = ubyte_to_float(tmp[0]);
47 dst[1] = ubyte_to_float(tmp[1]);
48 dst[2] = ubyte_to_float(tmp[2]);
49 dst[3] = 1.0f;
50 dst += comps;
51 }
52 }
53
54 src += bs;
55 }
56
57 src_row += src_stride;
58 }
59 }
60
61 void
62 util_format_etc1_rgb8_pack_rgba_float(UNUSED uint8_t *dst_row, UNUSED unsigned dst_stride,
63 UNUSED const float *src_row, UNUSED unsigned src_stride,
64 UNUSED unsigned width, UNUSED unsigned height)
65 {
66 assert(0);
67 }
68
69 void
70 util_format_etc1_rgb8_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
71 {
72 struct etc1_block block;
73 uint8_t tmp[3];
74
75 assert(i < 4 && j < 4); /* check i, j against 4x4 block size */
76
77 etc1_parse_block(&block, src);
78 etc1_fetch_texel(&block, i, j, tmp);
79
80 dst[0] = ubyte_to_float(tmp[0]);
81 dst[1] = ubyte_to_float(tmp[1]);
82 dst[2] = ubyte_to_float(tmp[2]);
83 dst[3] = 1.0f;
84 }