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);
}
}
}
};
#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))
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) {
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);