summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r--src/gallium/auxiliary/util/u_format_s3tc.c683
1 files changed, 349 insertions, 334 deletions
diff --git a/src/gallium/auxiliary/util/u_format_s3tc.c b/src/gallium/auxiliary/util/u_format_s3tc.c
index 268f0e8dfa..06cfdcfa8e 100644
--- a/src/gallium/auxiliary/util/u_format_s3tc.c
+++ b/src/gallium/auxiliary/util/u_format_s3tc.c
@@ -35,58 +35,121 @@
#endif
+static void
+util_format_dxt1_rgb_fetch_stub(int src_stride,
+ const uint8_t *src,
+ int col, int row,
+ uint8_t *dst)
+{
+ assert(0);
+}
+
+
+static void
+util_format_dxt1_rgba_fetch_stub(int src_stride,
+ const uint8_t *src,
+ int col, int row,
+ uint8_t *dst )
+{
+ assert(0);
+}
+
+
+static void
+util_format_dxt3_rgba_fetch_stub(int src_stride,
+ const uint8_t *src,
+ int col, int row,
+ uint8_t *dst )
+{
+ assert(0);
+}
+
+
+static void
+util_format_dxt5_rgba_fetch_stub(int src_stride,
+ const uint8_t *src,
+ int col, int row,
+ uint8_t *dst )
+{
+ assert(0);
+}
+
+
+static void
+util_format_dxtn_pack_stub(int src_comps,
+ int width, int height,
+ const uint8_t *src,
+ enum util_format_dxtn dst_format,
+ uint8_t *dst,
+ int dst_stride)
+{
+ assert(0);
+}
+
+
boolean util_format_s3tc_enabled = FALSE;
-util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch = NULL;
-util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch = NULL;
-util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch = NULL;
-util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch = NULL;
+util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch = util_format_dxt1_rgb_fetch_stub;
+util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch = util_format_dxt1_rgba_fetch_stub;
+util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch = util_format_dxt3_rgba_fetch_stub;
+util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch = util_format_dxt5_rgba_fetch_stub;
-util_format_dxtn_pack_t util_format_dxtn_pack = NULL;
+util_format_dxtn_pack_t util_format_dxtn_pack = util_format_dxtn_pack_stub;
void
util_format_s3tc_init(void)
{
- static struct util_dl_library *
- library = NULL;
+ static boolean first_time = TRUE;
+ struct util_dl_library *library = NULL;
+ util_dl_proc fetch_2d_texel_rgb_dxt1;
+ util_dl_proc fetch_2d_texel_rgba_dxt1;
+ util_dl_proc fetch_2d_texel_rgba_dxt3;
+ util_dl_proc fetch_2d_texel_rgba_dxt5;
+ util_dl_proc tx_compress_dxtn;
+
+ if (!first_time)
+ return;
+ first_time = FALSE;
if (util_format_s3tc_enabled)
return;
+ library = util_dl_open(DXTN_LIBNAME);
if (!library) {
- library = util_dl_open(DXTN_LIBNAME);
- if (!library) {
- debug_printf("couldn't open " DXTN_LIBNAME ", software DXTn "
- "compression/decompression unavailable");
- }
- else {
- util_format_dxt1_rgb_fetch = (util_format_dxtn_fetch_t)
- util_dl_get_proc_address(library, "fetch_2d_texel_rgb_dxt1");
- util_format_dxt1_rgba_fetch = (util_format_dxtn_fetch_t)
- util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt1");
- util_format_dxt3_rgba_fetch = (util_format_dxtn_fetch_t)
- util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt3");
- util_format_dxt5_rgba_fetch = (util_format_dxtn_fetch_t)
- util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt5");
- util_format_dxtn_pack = (util_format_dxtn_pack_t)
- util_dl_get_proc_address(library, "tx_compress_dxtn");
-
- if (util_format_dxt1_rgb_fetch ||
- util_format_dxt1_rgba_fetch ||
- util_format_dxt3_rgba_fetch ||
- util_format_dxt5_rgba_fetch ||
- util_format_dxtn_pack) {
- util_format_s3tc_enabled = TRUE;
- debug_printf("software DXTn compression/decompression available");
-
- } else {
- debug_printf("couldn't reference all symbols in "
- DXTN_LIBNAME ", software DXTn compression/decompression "
- "unavailable");
- }
- }
+ debug_printf("couldn't open " DXTN_LIBNAME ", software DXTn "
+ "compression/decompression unavailable");
+ return;
+ }
+
+ fetch_2d_texel_rgb_dxt1 =
+ util_dl_get_proc_address(library, "fetch_2d_texel_rgb_dxt1");
+ fetch_2d_texel_rgba_dxt1 =
+ util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt1");
+ fetch_2d_texel_rgba_dxt3 =
+ util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt3");
+ fetch_2d_texel_rgba_dxt5 =
+ util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt5");
+ tx_compress_dxtn =
+ util_dl_get_proc_address(library, "tx_compress_dxtn");
+
+ if (!util_format_dxt1_rgb_fetch ||
+ !util_format_dxt1_rgba_fetch ||
+ !util_format_dxt3_rgba_fetch ||
+ !util_format_dxt5_rgba_fetch ||
+ !util_format_dxtn_pack) {
+ debug_printf("couldn't reference all symbols in " DXTN_LIBNAME
+ ", software DXTn compression/decompression "
+ "unavailable");
+ return;
}
+
+ util_format_dxt1_rgb_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgb_dxt1;
+ util_format_dxt1_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt1;
+ util_format_dxt3_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt3;
+ util_format_dxt5_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt5;
+ util_format_dxtn_pack = (util_format_dxtn_pack_t)tx_compress_dxtn;
+ util_format_s3tc_enabled = TRUE;
}
@@ -97,85 +160,69 @@ util_format_s3tc_init(void)
void
util_format_dxt1_rgb_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
{
- if (util_format_dxt1_rgb_fetch) {
- util_format_dxt1_rgb_fetch(0, src, i, j, dst);
- }
+ util_format_dxt1_rgb_fetch(0, src, i, j, dst);
}
void
util_format_dxt1_rgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
{
- if (util_format_dxt1_rgba_fetch) {
- util_format_dxt1_rgba_fetch(0, src, i, j, dst);
- }
+ util_format_dxt1_rgba_fetch(0, src, i, j, dst);
}
void
util_format_dxt3_rgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
{
- if (util_format_dxt3_rgba_fetch) {
- util_format_dxt3_rgba_fetch(0, src, i, j, dst);
- }
+ util_format_dxt3_rgba_fetch(0, src, i, j, dst);
}
void
util_format_dxt5_rgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
{
- if (util_format_dxt5_rgba_fetch) {
- util_format_dxt5_rgba_fetch(0, src, i, j, dst);
- }
+ util_format_dxt5_rgba_fetch(0, src, i, j, dst);
}
void
util_format_dxt1_rgb_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
- if (util_format_dxt1_rgb_fetch) {
- uint8_t tmp[4];
- util_format_dxt1_rgb_fetch(0, src, i, j, tmp);
- dst[0] = ubyte_to_float(tmp[0]);
- dst[1] = ubyte_to_float(tmp[1]);
- dst[2] = ubyte_to_float(tmp[2]);
- dst[3] = 1.0;
- }
+ uint8_t tmp[4];
+ util_format_dxt1_rgb_fetch(0, src, i, j, tmp);
+ dst[0] = ubyte_to_float(tmp[0]);
+ dst[1] = ubyte_to_float(tmp[1]);
+ dst[2] = ubyte_to_float(tmp[2]);
+ dst[3] = 1.0;
}
void
util_format_dxt1_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
- if (util_format_dxt1_rgba_fetch) {
- uint8_t tmp[4];
- util_format_dxt1_rgba_fetch(0, src, i, j, tmp);
- dst[0] = ubyte_to_float(tmp[0]);
- dst[1] = ubyte_to_float(tmp[1]);
- dst[2] = ubyte_to_float(tmp[2]);
- dst[3] = ubyte_to_float(tmp[3]);
- }
+ uint8_t tmp[4];
+ util_format_dxt1_rgba_fetch(0, src, i, j, tmp);
+ dst[0] = ubyte_to_float(tmp[0]);
+ dst[1] = ubyte_to_float(tmp[1]);
+ dst[2] = ubyte_to_float(tmp[2]);
+ dst[3] = ubyte_to_float(tmp[3]);
}
void
util_format_dxt3_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
- if (util_format_dxt3_rgba_fetch) {
- uint8_t tmp[4];
- util_format_dxt3_rgba_fetch(0, src, i, j, tmp);
- dst[0] = ubyte_to_float(tmp[0]);
- dst[1] = ubyte_to_float(tmp[1]);
- dst[2] = ubyte_to_float(tmp[2]);
- dst[3] = ubyte_to_float(tmp[3]);
- }
+ uint8_t tmp[4];
+ util_format_dxt3_rgba_fetch(0, src, i, j, tmp);
+ dst[0] = ubyte_to_float(tmp[0]);
+ dst[1] = ubyte_to_float(tmp[1]);
+ dst[2] = ubyte_to_float(tmp[2]);
+ dst[3] = ubyte_to_float(tmp[3]);
}
void
util_format_dxt5_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
- if (util_format_dxt5_rgba_fetch) {
- uint8_t tmp[4];
- util_format_dxt5_rgba_fetch(0, src, i, j, tmp);
- dst[0] = ubyte_to_float(tmp[0]);
- dst[1] = ubyte_to_float(tmp[1]);
- dst[2] = ubyte_to_float(tmp[2]);
- dst[3] = ubyte_to_float(tmp[3]);
- }
+ uint8_t tmp[4];
+ util_format_dxt5_rgba_fetch(0, src, i, j, tmp);
+ dst[0] = ubyte_to_float(tmp[0]);
+ dst[1] = ubyte_to_float(tmp[1]);
+ dst[2] = ubyte_to_float(tmp[2]);
+ dst[3] = ubyte_to_float(tmp[3]);
}
@@ -186,188 +233,172 @@ util_format_dxt5_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, un
void
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)
{
- if (util_format_dxt1_rgb_fetch) {
- unsigned x, y, i, j;
- for(y = 0; y < height; y += 4) {
- const uint8_t *src = src_row;
- for(x = 0; x < width; x += 4) {
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
- util_format_dxt1_rgb_fetch(0, src, i, j, dst);
- }
+ unsigned x, y, i, j;
+ for(y = 0; y < height; y += 4) {
+ const uint8_t *src = src_row;
+ for(x = 0; x < width; x += 4) {
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
+ util_format_dxt1_rgb_fetch(0, src, i, j, dst);
}
- src += 8;
}
- src_row += src_stride;
+ src += 8;
}
+ src_row += src_stride;
}
}
void
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)
{
- if (util_format_dxt1_rgba_fetch) {
- unsigned x, y, i, j;
- for(y = 0; y < height; y += 4) {
- const uint8_t *src = src_row;
- for(x = 0; x < width; x += 4) {
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
- util_format_dxt1_rgba_fetch(0, src, i, j, dst);
- }
+ unsigned x, y, i, j;
+ for(y = 0; y < height; y += 4) {
+ const uint8_t *src = src_row;
+ for(x = 0; x < width; x += 4) {
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
+ util_format_dxt1_rgba_fetch(0, src, i, j, dst);
}
- src += 8;
}
- src_row += src_stride;
+ src += 8;
}
+ src_row += src_stride;
}
}
void
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)
{
- if (util_format_dxt3_rgba_fetch) {
- unsigned x, y, i, j;
- for(y = 0; y < height; y += 4) {
- const uint8_t *src = src_row;
- for(x = 0; x < width; x += 4) {
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
- util_format_dxt3_rgba_fetch(0, src, i, j, dst);
- }
+ unsigned x, y, i, j;
+ for(y = 0; y < height; y += 4) {
+ const uint8_t *src = src_row;
+ for(x = 0; x < width; x += 4) {
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
+ util_format_dxt3_rgba_fetch(0, src, i, j, dst);
}
- src += 16;
}
- src_row += src_stride;
+ src += 16;
}
+ src_row += src_stride;
}
}
void
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)
{
- if (util_format_dxt5_rgba_fetch) {
- unsigned x, y, i, j;
- for(y = 0; y < height; y += 4) {
- const uint8_t *src = src_row;
- for(x = 0; x < width; x += 4) {
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
- util_format_dxt5_rgba_fetch(0, src, i, j, dst);
- }
+ unsigned x, y, i, j;
+ for(y = 0; y < height; y += 4) {
+ const uint8_t *src = src_row;
+ for(x = 0; x < width; x += 4) {
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
+ util_format_dxt5_rgba_fetch(0, src, i, j, dst);
}
- src += 16;
}
- src_row += src_stride;
+ src += 16;
}
+ src_row += src_stride;
}
}
void
util_format_dxt1_rgb_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
- if (util_format_dxt1_rgb_fetch) {
- unsigned x, y, i, j;
- for(y = 0; y < height; y += 4) {
- const uint8_t *src = src_row;
- for(x = 0; x < width; x += 4) {
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
- uint8_t tmp[4];
- util_format_dxt1_rgb_fetch(0, src, i, j, tmp);
- dst[0] = ubyte_to_float(tmp[0]);
- dst[1] = ubyte_to_float(tmp[1]);
- dst[2] = ubyte_to_float(tmp[2]);
- dst[3] = 1.0;
- }
+ unsigned x, y, i, j;
+ for(y = 0; y < height; y += 4) {
+ const uint8_t *src = src_row;
+ for(x = 0; x < width; x += 4) {
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
+ uint8_t tmp[4];
+ util_format_dxt1_rgb_fetch(0, src, i, j, tmp);
+ dst[0] = ubyte_to_float(tmp[0]);
+ dst[1] = ubyte_to_float(tmp[1]);
+ dst[2] = ubyte_to_float(tmp[2]);
+ dst[3] = 1.0;
}
- src += 8;
}
- src_row += src_stride;
+ src += 8;
}
+ src_row += src_stride;
}
}
void
util_format_dxt1_rgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
- if (util_format_dxt1_rgba_fetch) {
- unsigned x, y, i, j;
- for(y = 0; y < height; y += 4) {
- const uint8_t *src = src_row;
- for(x = 0; x < width; x += 4) {
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
- uint8_t tmp[4];
- util_format_dxt1_rgba_fetch(0, src, i, j, tmp);
- dst[0] = ubyte_to_float(tmp[0]);
- dst[1] = ubyte_to_float(tmp[1]);
- dst[2] = ubyte_to_float(tmp[2]);
- dst[3] = ubyte_to_float(tmp[3]);
- }
+ unsigned x, y, i, j;
+ for(y = 0; y < height; y += 4) {
+ const uint8_t *src = src_row;
+ for(x = 0; x < width; x += 4) {
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
+ uint8_t tmp[4];
+ util_format_dxt1_rgba_fetch(0, src, i, j, tmp);
+ dst[0] = ubyte_to_float(tmp[0]);
+ dst[1] = ubyte_to_float(tmp[1]);
+ dst[2] = ubyte_to_float(tmp[2]);
+ dst[3] = ubyte_to_float(tmp[3]);
}
- src += 8;
}
- src_row += src_stride;
+ src += 8;
}
+ src_row += src_stride;
}
}
void
util_format_dxt3_rgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
- if (util_format_dxt3_rgba_fetch) {
- unsigned x, y, i, j;
- for(y = 0; y < height; y += 4) {
- const uint8_t *src = src_row;
- for(x = 0; x < width; x += 4) {
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
- uint8_t tmp[4];
- util_format_dxt3_rgba_fetch(0, src, i, j, tmp);
- dst[0] = ubyte_to_float(tmp[0]);
- dst[1] = ubyte_to_float(tmp[1]);
- dst[2] = ubyte_to_float(tmp[2]);
- dst[3] = ubyte_to_float(tmp[3]);
- }
+ unsigned x, y, i, j;
+ for(y = 0; y < height; y += 4) {
+ const uint8_t *src = src_row;
+ for(x = 0; x < width; x += 4) {
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
+ uint8_t tmp[4];
+ util_format_dxt3_rgba_fetch(0, src, i, j, tmp);
+ dst[0] = ubyte_to_float(tmp[0]);
+ dst[1] = ubyte_to_float(tmp[1]);
+ dst[2] = ubyte_to_float(tmp[2]);
+ dst[3] = ubyte_to_float(tmp[3]);
}
- src += 16;
}
- src_row += src_stride;
+ src += 16;
}
+ src_row += src_stride;
}
}
void
util_format_dxt5_rgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
- if (util_format_dxt5_rgba_fetch) {
- unsigned x, y, i, j;
- for(y = 0; y < height; y += 4) {
- const uint8_t *src = src_row;
- for(x = 0; x < width; x += 4) {
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
- uint8_t tmp[4];
- util_format_dxt5_rgba_fetch(0, src, i, j, tmp);
- dst[0] = ubyte_to_float(tmp[0]);
- dst[1] = ubyte_to_float(tmp[1]);
- dst[2] = ubyte_to_float(tmp[2]);
- dst[3] = ubyte_to_float(tmp[3]);
- }
+ unsigned x, y, i, j;
+ for(y = 0; y < height; y += 4) {
+ const uint8_t *src = src_row;
+ for(x = 0; x < width; x += 4) {
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
+ uint8_t tmp[4];
+ util_format_dxt5_rgba_fetch(0, src, i, j, tmp);
+ dst[0] = ubyte_to_float(tmp[0]);
+ dst[1] = ubyte_to_float(tmp[1]);
+ dst[2] = ubyte_to_float(tmp[2]);
+ dst[3] = ubyte_to_float(tmp[3]);
}
- src += 16;
}
- src_row += src_stride;
+ src += 16;
}
+ src_row += src_stride;
}
}
@@ -379,216 +410,200 @@ util_format_dxt5_rgba_unpack_float(float *dst_row, unsigned dst_stride, const ui
void
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)
{
- if (util_format_dxtn_pack) {
- unsigned x, y, i, j, k;
- for(y = 0; y < height; y += 4) {
- const uint8_t *src = src_row;
- uint8_t *dst = dst_row;
- for(x = 0; x < width; x += 4) {
- uint8_t tmp[4][4][3];
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- for(k = 0; k < 3; ++k) {
- tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + i*4 + k];
- }
+ unsigned x, y, i, j, k;
+ for(y = 0; y < height; y += 4) {
+ const uint8_t *src = src_row;
+ uint8_t *dst = dst_row;
+ for(x = 0; x < width; x += 4) {
+ uint8_t tmp[4][4][3];
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ for(k = 0; k < 3; ++k) {
+ tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + i*4 + k];
}
}
- util_format_dxtn_pack(3, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGB, dst, dst_stride);
- src += 4*4;
- dst += 8;
}
- src_row += src_stride;
- dst_row += 4*dst_stride/sizeof(*dst_row);
+ util_format_dxtn_pack(3, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGB, dst, dst_stride);
+ src += 4*4;
+ dst += 8;
}
+ src_row += src_stride;
+ dst_row += 4*dst_stride/sizeof(*dst_row);
}
}
void
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)
{
- if (util_format_dxtn_pack) {
- unsigned x, y, i, j, k;
- for(y = 0; y < height; y += 4) {
- const uint8_t *src = src_row;
- uint8_t *dst = dst_row;
- for(x = 0; x < width; x += 4) {
- uint8_t tmp[4][4][4];
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- for(k = 0; k < 4; ++k) {
- tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + i*4 + k];
- }
+ unsigned x, y, i, j, k;
+ for(y = 0; y < height; y += 4) {
+ const uint8_t *src = src_row;
+ uint8_t *dst = dst_row;
+ for(x = 0; x < width; x += 4) {
+ uint8_t tmp[4][4][4];
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ for(k = 0; k < 4; ++k) {
+ tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + i*4 + k];
}
}
- util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGBA, dst, dst_stride);
- src += 4*4;
- dst += 8;
}
- src_row += src_stride;
- dst_row += 4*dst_stride/sizeof(*dst_row);
+ util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGBA, dst, dst_stride);
+ src += 4*4;
+ dst += 8;
}
+ src_row += src_stride;
+ dst_row += 4*dst_stride/sizeof(*dst_row);
}
}
void
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)
{
- if (util_format_dxtn_pack) {
- unsigned x, y, i, j, k;
- for(y = 0; y < height; y += 4) {
- const uint8_t *src = src_row;
- uint8_t *dst = dst_row;
- for(x = 0; x < width; x += 4) {
- uint8_t tmp[4][4][4];
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- for(k = 0; k < 4; ++k) {
- tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + i*4 + k];
- }
+ unsigned x, y, i, j, k;
+ for(y = 0; y < height; y += 4) {
+ const uint8_t *src = src_row;
+ uint8_t *dst = dst_row;
+ for(x = 0; x < width; x += 4) {
+ uint8_t tmp[4][4][4];
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ for(k = 0; k < 4; ++k) {
+ tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + i*4 + k];
}
}
- util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT3_RGBA, dst, dst_stride);
- src += 4*4;
- dst += 16;
}
- src_row += src_stride;
- dst_row += 4*dst_stride/sizeof(*dst_row);
+ util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT3_RGBA, dst, dst_stride);
+ src += 4*4;
+ dst += 16;
}
+ src_row += src_stride;
+ dst_row += 4*dst_stride/sizeof(*dst_row);
}
}
void
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)
{
- if (util_format_dxtn_pack) {
- unsigned x, y, i, j, k;
- for(y = 0; y < height; y += 4) {
- const uint8_t *src = src_row;
- uint8_t *dst = dst_row;
- for(x = 0; x < width; x += 4) {
- uint8_t tmp[4][4][4];
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- for(k = 0; k < 4; ++k) {
- tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + i*4 + k];
- }
+ unsigned x, y, i, j, k;
+ for(y = 0; y < height; y += 4) {
+ const uint8_t *src = src_row;
+ uint8_t *dst = dst_row;
+ for(x = 0; x < width; x += 4) {
+ uint8_t tmp[4][4][4];
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ for(k = 0; k < 4; ++k) {
+ tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + i*4 + k];
}
}
- util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT5_RGBA, dst, dst_stride);
- src += 4*4;
- dst += 16;
}
- src_row += src_stride;
- dst_row += 4*dst_stride/sizeof(*dst_row);
+ util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT5_RGBA, dst, dst_stride);
+ src += 4*4;
+ dst += 16;
}
+ src_row += src_stride;
+ dst_row += 4*dst_stride/sizeof(*dst_row);
}
}
void
util_format_dxt1_rgb_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
{
- if (util_format_dxtn_pack) {
- unsigned x, y, i, j, k;
- for(y = 0; y < height; y += 4) {
- const float *src = src_row;
- uint8_t *dst = dst_row;
- for(x = 0; x < width; x += 4) {
- uint8_t tmp[4][4][3];
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- for(k = 0; k < 3; ++k) {
- tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
- }
+ unsigned x, y, i, j, k;
+ for(y = 0; y < height; y += 4) {
+ const float *src = src_row;
+ uint8_t *dst = dst_row;
+ for(x = 0; x < width; x += 4) {
+ uint8_t tmp[4][4][3];
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ for(k = 0; k < 3; ++k) {
+ tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
}
}
- util_format_dxtn_pack(3, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGB, dst, dst_stride);
- src += 4*4;
- dst += 8;
}
- src_row += src_stride;
- dst_row += 4*dst_stride/sizeof(*dst_row);
+ util_format_dxtn_pack(3, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGB, dst, dst_stride);
+ src += 4*4;
+ dst += 8;
}
+ src_row += src_stride;
+ dst_row += 4*dst_stride/sizeof(*dst_row);
}
}
void
util_format_dxt1_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
{
- if (util_format_dxtn_pack) {
- unsigned x, y, i, j, k;
- for(y = 0; y < height; y += 4) {
- const float *src = src_row;
- uint8_t *dst = dst_row;
- for(x = 0; x < width; x += 4) {
- uint8_t tmp[4][4][4];
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- for(k = 0; k < 4; ++k) {
- tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
- }
+ unsigned x, y, i, j, k;
+ for(y = 0; y < height; y += 4) {
+ const float *src = src_row;
+ uint8_t *dst = dst_row;
+ for(x = 0; x < width; x += 4) {
+ uint8_t tmp[4][4][4];
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ for(k = 0; k < 4; ++k) {
+ tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
}
}
- util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGBA, dst, dst_stride);
- src += 4*4;
- dst += 8;
}
- src_row += src_stride;
- dst_row += 4*dst_stride/sizeof(*dst_row);
+ util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGBA, dst, dst_stride);
+ src += 4*4;
+ dst += 8;
}
+ src_row += src_stride;
+ dst_row += 4*dst_stride/sizeof(*dst_row);
}
}
void
util_format_dxt3_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
{
- if (util_format_dxtn_pack) {
- unsigned x, y, i, j, k;
- for(y = 0; y < height; y += 4) {
- const float *src = src_row;
- uint8_t *dst = dst_row;
- for(x = 0; x < width; x += 4) {
- uint8_t tmp[4][4][4];
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- for(k = 0; k < 4; ++k) {
- tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
- }
+ unsigned x, y, i, j, k;
+ for(y = 0; y < height; y += 4) {
+ const float *src = src_row;
+ uint8_t *dst = dst_row;
+ for(x = 0; x < width; x += 4) {
+ uint8_t tmp[4][4][4];
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ for(k = 0; k < 4; ++k) {
+ tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
}
}
- util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT3_RGBA, dst, dst_stride);
- src += 4*4;
- dst += 16;
}
- src_row += src_stride;
- dst_row += 4*dst_stride/sizeof(*dst_row);
+ util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT3_RGBA, dst, dst_stride);
+ src += 4*4;
+ dst += 16;
}
+ src_row += src_stride;
+ dst_row += 4*dst_stride/sizeof(*dst_row);
}
}
void
util_format_dxt5_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
{
- if (util_format_dxtn_pack) {
- unsigned x, y, i, j, k;
- for(y = 0; y < height; y += 4) {
- const float *src = src_row;
- uint8_t *dst = dst_row;
- for(x = 0; x < width; x += 4) {
- uint8_t tmp[4][4][4];
- for(j = 0; j < 4; ++j) {
- for(i = 0; i < 4; ++i) {
- for(k = 0; k < 4; ++k) {
- tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
- }
+ unsigned x, y, i, j, k;
+ for(y = 0; y < height; y += 4) {
+ const float *src = src_row;
+ uint8_t *dst = dst_row;
+ for(x = 0; x < width; x += 4) {
+ uint8_t tmp[4][4][4];
+ for(j = 0; j < 4; ++j) {
+ for(i = 0; i < 4; ++i) {
+ for(k = 0; k < 4; ++k) {
+ tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + i*4 + k]);
}
}
- util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT5_RGBA, dst, dst_stride);
- src += 4*4;
- dst += 16;
}
- src_row += src_stride;
- dst_row += 4*dst_stride/sizeof(*dst_row);
+ util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT5_RGBA, dst, dst_stride);
+ src += 4*4;
+ dst += 16;
}
+ src_row += src_stride;
+ dst_row += 4*dst_stride/sizeof(*dst_row);
}
}