Path: blob/21.2-virgl/src/util/format/u_format_etc.c
7129 views
#include "pipe/p_compiler.h"1#include "util/u_debug.h"2#include "util/u_math.h"3#include "util/format/u_format_etc.h"45/* define etc1_parse_block and etc. */6#define UINT8_TYPE uint8_t7#define TAG(x) x8#include "../../mesa/main/texcompress_etc_tmp.h"9#undef TAG10#undef UINT8_TYPE1112void13util_format_etc1_rgb8_unpack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)14{15etc1_unpack_rgba8888(dst_row, dst_stride, src_row, src_stride, width, height);16}1718void19util_format_etc1_rgb8_pack_rgba_8unorm(UNUSED uint8_t *restrict dst_row, UNUSED unsigned dst_stride,20UNUSED const uint8_t *restrict src_row, UNUSED unsigned src_stride,21UNUSED unsigned width, UNUSED unsigned height)22{23assert(0);24}2526void27util_format_etc1_rgb8_unpack_rgba_float(void *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)28{29const unsigned bw = 4, bh = 4, bs = 8, comps = 4;30struct etc1_block block;31unsigned x, y, i, j;3233for (y = 0; y < height; y += bh) {34const uint8_t *src = src_row;3536for (x = 0; x < width; x+= bw) {37etc1_parse_block(&block, src);3839for (j = 0; j < bh; j++) {40float *dst = (float *)((uint8_t *)dst_row + (y + j) * dst_stride + x * comps * 4);41uint8_t tmp[3];4243for (i = 0; i < bw; i++) {44etc1_fetch_texel(&block, i, j, tmp);45dst[0] = ubyte_to_float(tmp[0]);46dst[1] = ubyte_to_float(tmp[1]);47dst[2] = ubyte_to_float(tmp[2]);48dst[3] = 1.0f;49dst += comps;50}51}5253src += bs;54}5556src_row += src_stride;57}58}5960void61util_format_etc1_rgb8_pack_rgba_float(UNUSED uint8_t *restrict dst_row, UNUSED unsigned dst_stride,62UNUSED const float *restrict src_row, UNUSED unsigned src_stride,63UNUSED unsigned width, UNUSED unsigned height)64{65assert(0);66}6768void69util_format_etc1_rgb8_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, unsigned i, unsigned j)70{71float *dst = in_dst;72struct etc1_block block;73uint8_t tmp[3];7475assert(i < 4 && j < 4); /* check i, j against 4x4 block size */7677etc1_parse_block(&block, src);78etc1_fetch_texel(&block, i, j, tmp);7980dst[0] = ubyte_to_float(tmp[0]);81dst[1] = ubyte_to_float(tmp[1]);82dst[2] = ubyte_to_float(tmp[2]);83dst[3] = 1.0f;84}858687