From: sgunderson@bigfoot.com <> Date: Sun, 31 May 2009 14:45:26 +0000 (+0200) Subject: Add the level bias we're supposed to have. X-Git-Url: https://git.sesse.net/?p=fjl;a=commitdiff_plain;h=0e688f0b5db93745648802bdf1c96d0d526eb9ff Add the level bias we're supposed to have. --- diff --git a/idct_float.c b/idct_float.c index c8bde1b..ede97cd 100644 --- a/idct_float.c +++ b/idct_float.c @@ -157,12 +157,12 @@ void idct_float(const int16_t* input, const void* userdata, uint8_t* output) temp2); for (unsigned x = 0; x < DCTSIZE; ++x) { const double val = temp2[x]; - if (val < 0.0) { + if (val < -128.0) { output[y * DCTSIZE + x] = 0; - } else if (val >= 255.0) { + } else if (val >= 127.0) { output[y * DCTSIZE + x] = 255; } else { - output[y * DCTSIZE + x] = (uint8_t)(val + 0.5); + output[y * DCTSIZE + x] = (uint8_t)(val + 128.5); } } } diff --git a/idct_imprecise_int.c b/idct_imprecise_int.c index 6dd6983..7048a66 100644 --- a/idct_imprecise_int.c +++ b/idct_imprecise_int.c @@ -14,7 +14,7 @@ struct idct_imprecise_int_userdata { }; #define PRECISION 12 -#define ROUND_BIAS (1LL << (PRECISION - 1)) +#define ROUND_BIAS (257LL << (PRECISION - 1)) #define FIX(x) ((int32_t)((x) * (1LL << PRECISION) + 0.5)) diff --git a/idct_reference.c b/idct_reference.c index e710de3..f74ad0b 100644 --- a/idct_reference.c +++ b/idct_reference.c @@ -43,7 +43,7 @@ void idct_reference(const int16_t* input, const void* userdata, uint8_t* output) for (unsigned y = 0; y < 8; ++y) { for (unsigned x = 0; x < 8; ++x) { - double val = temp[y * DCTSIZE + x]; + double val = temp[y * DCTSIZE + x] + 128.0; if (val < 0.0) { output[y * DCTSIZE + x] = 0; } else if (val >= 255.0) { diff --git a/idct_test.c b/idct_test.c index d7b543c..bd39c74 100644 --- a/idct_test.c +++ b/idct_test.c @@ -76,8 +76,13 @@ void test_dc_becomes_spread_out(idct_alloc_t* idct_alloc, idct_free_t* idct_free void* userdata = idct_alloc(quant); - for (unsigned i = 0; i < 255*8; ++i) { - uint32_t reference_value = i / 8; + for (unsigned i = -255*8; i < 255*16; ++i) { + int reference_value = i / 8 + 128; + if (reference_value < 0) { + reference_value = 0; + } else if (reference_value > 255) { + reference_value = 255; + } coeff[0] = i; (*idct)(coeff, userdata, output);