Add the level bias we're supposed to have.
authorsgunderson@bigfoot.com <>
Sun, 31 May 2009 14:45:26 +0000 (16:45 +0200)
committersgunderson@bigfoot.com <>
Sun, 31 May 2009 14:45:26 +0000 (16:45 +0200)
idct_float.c
idct_imprecise_int.c
idct_reference.c
idct_test.c

index c8bde1b..ede97cd 100644 (file)
@@ -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);
                        }
                }
        }
index 6dd6983..7048a66 100644 (file)
@@ -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))
 
index e710de3..f74ad0b 100644 (file)
@@ -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) {
index d7b543c..bd39c74 100644 (file)
@@ -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);