5 #include "idct_reference.h"
7 void* idct_reference_alloc(const uint32_t* quant_table)
9 uint32_t* qt_copy = (uint32_t*)malloc(DCTSIZE2 * sizeof(uint32_t));
10 // FIXME: check for NULL return
12 memcpy(qt_copy, quant_table, DCTSIZE2 * sizeof(uint32_t));
17 void idct_reference_free(void* userdata)
22 void idct_reference(const int16_t* input, const void* userdata, uint8_t* output)
24 const uint32_t* quant_table = (const uint32_t*)userdata;
25 double temp[DCTSIZE2];
27 for (unsigned y = 0; y < 8; ++y) {
28 for (unsigned x = 0; x < 8; ++x) {
30 for (unsigned u = 0; u < 8; ++u) {
31 for (unsigned v = 0; v < 8; ++v) {
32 double c_u = (u == 0) ? 1/sqrt(2.0) : 1.0;
33 double c_v = (v == 0) ? 1/sqrt(2.0) : 1.0;
35 * input[u * DCTSIZE + v] * quant_table[u * DCTSIZE + v]
36 * cos((2 * x + 1) * v * M_PI / 16.0)
37 * cos((2 * y + 1) * u * M_PI / 16.0);
40 temp[y * DCTSIZE + x] = 0.25 * acc;
44 for (unsigned y = 0; y < 8; ++y) {
45 for (unsigned x = 0; x < 8; ++x) {
46 double val = temp[y * DCTSIZE + x] + 128.0;
48 output[y * DCTSIZE + x] = 0;
49 } else if (val >= 255.0) {
50 output[y * DCTSIZE + x] = 255;
52 output[y * DCTSIZE + x] = (uint8_t)(val + 0.5);