Browse Source

util: Add support for other DXTn RGBA formats.

tags/mesa-7.9-rc1
José Fonseca 15 years ago
parent
commit
08eb07bc83

+ 2
- 2
progs/gallium/unit/u_format_test.c View File

@@ -200,7 +200,7 @@ test_format_pack_float(const struct util_format_description *format_desc,
unsigned i, j, k;
boolean success;

if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
if (test->format == PIPE_FORMAT_DXT1_RGBA) {
/*
* Skip S3TC as packed representation is not canonical.
*
@@ -300,7 +300,7 @@ test_format_pack_8unorm(const struct util_format_description *format_desc,
unsigned i;
boolean success;

if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
if (test->format == PIPE_FORMAT_DXT1_RGBA) {
/*
* Skip S3TC as packed representation is not canonical.
*

+ 187
- 5
src/gallium/auxiliary/util/u_format_s3tc.c View File

@@ -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);
}
}
}



+ 111
- 17
src/gallium/auxiliary/util/u_format_tests.c View File

@@ -205,7 +205,7 @@ util_format_test_cases[] =
*/

/*
* TODO: Compressed formats
* Compressed formats
*/

{
@@ -214,31 +214,125 @@ util_format_test_cases[] =
PACKED_8x8(0xf2, 0xd7, 0xb0, 0x20, 0xae, 0x2c, 0x6f, 0x97),
{
{
0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0,
0x5d/255.0, 0x62/255.0, 0x89/255.0, 0xff/255.0,
0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0,
0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0
{0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0},
{0x5d/255.0, 0x62/255.0, 0x89/255.0, 0xff/255.0},
{0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0},
{0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0}
},
{
0xd6/255.0, 0xff/255.0, 0x94/255.0, 0xff/255.0,
0x5d/255.0, 0x62/255.0, 0x89/255.0, 0xff/255.0,
0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0,
0xd6/255.0, 0xff/255.0, 0x94/255.0, 0xff/255.0
{0xd6/255.0, 0xff/255.0, 0x94/255.0, 0xff/255.0},
{0x5d/255.0, 0x62/255.0, 0x89/255.0, 0xff/255.0},
{0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0},
{0xd6/255.0, 0xff/255.0, 0x94/255.0, 0xff/255.0}
},
{
0x5d/255.0, 0x62/255.0, 0x89/255.0, 0xff/255.0,
0x5d/255.0, 0x62/255.0, 0x89/255.0, 0xff/255.0,
0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0,
0x21/255.0, 0x14/255.0, 0x84/255.0, 0xff/255.0
{0x5d/255.0, 0x62/255.0, 0x89/255.0, 0xff/255.0},
{0x5d/255.0, 0x62/255.0, 0x89/255.0, 0xff/255.0},
{0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0},
{0x21/255.0, 0x14/255.0, 0x84/255.0, 0xff/255.0}
},
{
0x5d/255.0, 0x62/255.0, 0x89/255.0, 0xff/255.0,
0x21/255.0, 0x14/255.0, 0x84/255.0, 0xff/255.0,
0x21/255.0, 0x14/255.0, 0x84/255.0, 0xff/255.0,
0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0
{0x5d/255.0, 0x62/255.0, 0x89/255.0, 0xff/255.0},
{0x21/255.0, 0x14/255.0, 0x84/255.0, 0xff/255.0},
{0x21/255.0, 0x14/255.0, 0x84/255.0, 0xff/255.0},
{0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0}
}
}
},
{
PIPE_FORMAT_DXT1_RGBA,
PACKED_8x8(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff),
PACKED_8x8(0xff, 0x2f, 0xa4, 0x72, 0xeb, 0xb2, 0xbd, 0xbe),
{
{
{0x00/255.0, 0x00/255.0, 0x00/255.0, 0x00/255.0},
{0x4e/255.0, 0xaa/255.0, 0x90/255.0, 0xff/255.0},
{0x4e/255.0, 0xaa/255.0, 0x90/255.0, 0xff/255.0},
{0x00/255.0, 0x00/255.0, 0x00/255.0, 0x00/255.0}
},
{
{0x4e/255.0, 0xaa/255.0, 0x90/255.0, 0xff/255.0},
{0x29/255.0, 0xff/255.0, 0xff/255.0, 0xff/255.0},
{0x00/255.0, 0x00/255.0, 0x00/255.0, 0x00/255.0},
{0x4e/255.0, 0xaa/255.0, 0x90/255.0, 0xff/255.0}
},
{
{0x73/255.0, 0x55/255.0, 0x21/255.0, 0xff/255.0},
{0x00/255.0, 0x00/255.0, 0x00/255.0, 0x00/255.0},
{0x00/255.0, 0x00/255.0, 0x00/255.0, 0x00/255.0},
{0x4e/255.0, 0xaa/255.0, 0x90/255.0, 0xff/255.0}
},
{
{0x4e/255.0, 0xaa/255.0, 0x90/255.0, 0xff/255.0},
{0x00/255.0, 0x00/255.0, 0x00/255.0, 0x00/255.0},
{0x00/255.0, 0x00/255.0, 0x00/255.0, 0x00/255.0},
{0x4e/255.0, 0xaa/255.0, 0x90/255.0, 0xff/255.0}
}
}
},
{
PIPE_FORMAT_DXT3_RGBA,
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
{0xe7, 0x4a, 0x8f, 0x96, 0x5b, 0xc1, 0x1c, 0x84, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a},
{
{
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x77/255.0},
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xee/255.0},
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xaa/255.0},
{0x8c/255.0, 0xff/255.0, 0xb5/255.0, 0x44/255.0}
},
{
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xff/255.0},
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x88/255.0},
{0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x66/255.0},
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x99/255.0}
},
{
{0x31/255.0, 0x55/255.0, 0x5a/255.0, 0xbb/255.0},
{0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x55/255.0},
{0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x11/255.0},
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xcc/255.0}
},
{
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xcc/255.0},
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x11/255.0},
{0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x44/255.0},
{0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x88/255.0}
}
}
},
{
PIPE_FORMAT_DXT5_RGBA,
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
{0xf8, 0x11, 0xc5, 0x0c, 0x9a, 0x73, 0xb4, 0x9c, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a},
{
{
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x74/255.0},
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xf8/255.0},
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xb6/255.0},
{0x8c/255.0, 0xff/255.0, 0xb5/255.0, 0x53/255.0}
},
{
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xf8/255.0},
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x95/255.0},
{0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x53/255.0},
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x95/255.0}
},
{
{0x31/255.0, 0x55/255.0, 0x5a/255.0, 0xb6/255.0},
{0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x53/255.0},
{0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x11/255.0},
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xd7/255.0}
},
{
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xb6/255.0},
{0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x11/255.0},
{0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x32/255.0},
{0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x95/255.0}
}
}
},


/*
* Standard 8-bit integer formats

Loading…
Cancel
Save