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
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(uint8_t * dst_row,unsigned dst_stride,const uint8_t * src_row,unsigned src_stride,unsigned width,unsigned height)20 util_format_etc1_rgb8_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
21 {
22    assert(0);
23 }
24 
25 void
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)26 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)
27 {
28    const unsigned bw = 4, bh = 4, bs = 8, comps = 4;
29    struct etc1_block block;
30    unsigned x, y, i, j;
31 
32    for (y = 0; y < height; y += bh) {
33       const uint8_t *src = src_row;
34 
35       for (x = 0; x < width; x+= bw) {
36          etc1_parse_block(&block, src);
37 
38          for (j = 0; j < bh; j++) {
39             float *dst = dst_row + (y + j) * dst_stride / sizeof(*dst_row) + x * comps;
40             uint8_t tmp[3];
41 
42             for (i = 0; i < bw; i++) {
43                etc1_fetch_texel(&block, i, j, tmp);
44                dst[0] = ubyte_to_float(tmp[0]);
45                dst[1] = ubyte_to_float(tmp[1]);
46                dst[2] = ubyte_to_float(tmp[2]);
47                dst[3] = 1.0f;
48                dst += comps;
49             }
50          }
51 
52          src += bs;
53       }
54 
55       src_row += src_stride;
56    }
57 }
58 
59 void
util_format_etc1_rgb8_pack_rgba_float(uint8_t * dst_row,unsigned dst_stride,const float * src_row,unsigned src_stride,unsigned width,unsigned height)60 util_format_etc1_rgb8_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
61 {
62    assert(0);
63 }
64 
65 void
util_format_etc1_rgb8_fetch_rgba_float(float * dst,const uint8_t * src,unsigned i,unsigned j)66 util_format_etc1_rgb8_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
67 {
68    const unsigned bw = 4, bh = 4;
69    struct etc1_block block;
70    uint8_t tmp[3];
71 
72    assert(i < bw && j < bh);
73 
74    etc1_parse_block(&block, src);
75    etc1_fetch_texel(&block, i, j, tmp);
76 
77    dst[0] = ubyte_to_float(tmp[0]);
78    dst[1] = ubyte_to_float(tmp[1]);
79    dst[2] = ubyte_to_float(tmp[2]);
80    dst[3] = 1.0f;
81 }
82