summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/util/u_format_s3tc.c
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2010-04-01 15:07:14 +0100
committerJosé Fonseca <jfonseca@vmware.com>2010-04-01 15:07:14 +0100
commit08eb07bc83c9ba81ad5b497b8991d1069e17f4d7 (patch)
tree44df2dab1721b138b029985037526be836bb34d1 /src/gallium/auxiliary/util/u_format_s3tc.c
parent8548efbe1d2ebc9cfe5636d3e0f3064958ad0644 (diff)
util: Add support for other DXTn RGBA formats.
Diffstat (limited to 'src/gallium/auxiliary/util/u_format_s3tc.c')
-rw-r--r--src/gallium/auxiliary/util/u_format_s3tc.c192
1 files changed, 187 insertions, 5 deletions
diff --git a/src/gallium/auxiliary/util/u_format_s3tc.c b/src/gallium/auxiliary/util/u_format_s3tc.c
index bb1d6d5ee0..268f0e8dfa 100644
--- a/src/gallium/auxiliary/util/u_format_s3tc.c
+++ b/src/gallium/auxiliary/util/u_format_s3tc.c
@@ -181,8 +181,6 @@ util_format_dxt5_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, un
/*
* Block decompression.
- *
- * FIXME
*/
void
@@ -230,11 +228,43 @@ util_format_dxt1_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const
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);
+ }
+ }
+ 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);
+ }
+ }
+ src += 16;
+ }
+ src_row += src_stride;
+ }
+ }
}
void
@@ -344,8 +374,6 @@ util_format_dxt5_rgba_unpack_float(float *dst_row, unsigned dst_stride, const ui
/*
* Block compression.
- *
- * FIXME
*/
void
@@ -365,7 +393,7 @@ util_format_dxt1_rgb_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const ui
}
}
}
- util_format_dxtn_pack(3, 4, 4, src, UTIL_FORMAT_DXT1_RGB, dst, dst_stride);
+ util_format_dxtn_pack(3, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGB, dst, dst_stride);
src += 4*4;
dst += 8;
}
@@ -378,36 +406,190 @@ util_format_dxt1_rgb_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const ui
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];
+ }
+ }
+ }
+ 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];
+ }
+ }
+ }
+ 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];
+ }
+ }
+ }
+ 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]);
+ }
+ }
+ }
+ 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]);
+ }
+ }
+ }
+ 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]);
+ }
+ }
+ }
+ 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]);
+ }
+ }
+ }
+ 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);
+ }
+ }
}