1 #include "pipe/p_compiler.h"
2 #include "util/u_debug.h"
3 #include "util/u_math.h"
4 #include "util/format/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
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)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
util_format_etc1_rgb8_pack_rgba_8unorm(UNUSED uint8_t * dst_row,UNUSED unsigned dst_stride,UNUSED const uint8_t * src_row,UNUSED unsigned src_stride,UNUSED unsigned width,UNUSED unsigned height)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
util_format_etc1_rgb8_unpack_rgba_float(void * dst_row,unsigned dst_stride,const uint8_t * src_row,unsigned src_stride,unsigned width,unsigned height)28 util_format_etc1_rgb8_unpack_rgba_float(void *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 = (float *)((uint8_t *)dst_row + (y + j) * dst_stride + x * comps * 4);
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
util_format_etc1_rgb8_pack_rgba_float(UNUSED uint8_t * dst_row,UNUSED unsigned dst_stride,UNUSED const float * src_row,UNUSED unsigned src_stride,UNUSED unsigned width,UNUSED unsigned height)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
util_format_etc1_rgb8_fetch_rgba(void * in_dst,const uint8_t * src,unsigned i,unsigned j)70 util_format_etc1_rgb8_fetch_rgba(void *in_dst, const uint8_t *src, unsigned i, unsigned j)
71 {
72 float *dst = in_dst;
73 struct etc1_block block;
74 uint8_t tmp[3];
75
76 assert(i < 4 && j < 4); /* check i, j against 4x4 block size */
77
78 etc1_parse_block(&block, src);
79 etc1_fetch_texel(&block, i, j, tmp);
80
81 dst[0] = ubyte_to_float(tmp[0]);
82 dst[1] = ubyte_to_float(tmp[1]);
83 dst[2] = ubyte_to_float(tmp[2]);
84 dst[3] = 1.0f;
85 }
86