util: Add test case for PIPE_FORMAT_DXT1_RGB.

This commit is contained in:
José Fonseca 2010-04-01 13:34:24 +01:00
parent 9899ebd2fc
commit ca6aacf842
2 changed files with 69 additions and 5 deletions

View file

@ -28,9 +28,28 @@
#include <stdlib.h>
#include <stdio.h>
#include <float.h>
#include "util/u_format.h"
#include "util/u_format_tests.h"
#include "util/u_format_s3tc.h"
static boolean
compare_float(float x, float y)
{
float error = y - x;
if (error < 0.0f)
error = -error;
if (error > FLT_EPSILON) {
printf("error = %g\n", error);
return FALSE;
}
return TRUE;
}
static void
@ -126,7 +145,7 @@ test_format_fetch_float(const struct util_format_description *format_desc,
for (j = 0; j < format_desc->block.width; ++j) {
format_desc->fetch_float(unpacked[i][j], test->packed, j, i);
for (k = 0; k < 4; ++k) {
if (test->unpacked[i][j][k] != unpacked[i][j][k]) {
if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) {
success = FALSE;
}
}
@ -156,7 +175,7 @@ test_format_unpack_float(const struct util_format_description *format_desc,
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
for (k = 0; k < 4; ++k) {
if (test->unpacked[i][j][k] != unpacked[i][j][k]) {
if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) {
success = FALSE;
}
}
@ -313,15 +332,26 @@ test_one(test_func_t func, const char *suffix)
for (i = 0; i < util_format_nr_test_cases; ++i) {
const struct util_format_test_case *test = &util_format_test_cases[i];
const struct util_format_description *format_desc;
bool skip = FALSE;
format_desc = util_format_description(test->format);
if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC &&
!util_format_s3tc_enabled) {
skip = TRUE;
}
if (test->format != last_format) {
printf("Testing util_format_%s_%s ...\n", format_desc->short_name, suffix);
printf("%s util_format_%s_%s ...\n",
skip ? "Skipping" : "Testing", format_desc->short_name, suffix);
last_format = test->format;
}
if (!func(format_desc, &util_format_test_cases[i]))
success = FALSE;
if (!skip) {
if (!func(format_desc, &util_format_test_cases[i])) {
success = FALSE;
}
}
}
return success;
@ -356,6 +386,8 @@ int main(int argc, char **argv)
{
boolean success;
util_format_s3tc_init();
success = test_all();
return success ? 0 : 1;

View file

@ -38,6 +38,7 @@
#define PACKED_2x8(x, y) {x, y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
#define PACKED_3x8(x, y, z) {x, y, z, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
#define PACKED_4x8(x, y, z, w) {x, y, z, w, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
#define PACKED_8x8(a, b, c, d, e, f, g, h) {a, b, c, d, e, f, g, h, 0, 0, 0, 0, 0, 0, 0, 0}
#define PACKED_1x16(x) {(x) & 0xff, (x) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
#define PACKED_2x16(x, y) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
@ -207,6 +208,37 @@ util_format_test_cases[] =
* TODO: Compressed formats
*/
{
PIPE_FORMAT_DXT1_RGB,
PACKED_8x8(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff),
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
},
{
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,
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
}
}
},
/*
* Standard 8-bit integer formats