Is there a problem with DCT or quantization when encoding JPEG files?

53 Views Asked by At

When I make my own BMP to JPEG encoder, I found that the resulting JPEG image was very different from the original. After comparing RGB images to YUV images, I found that the two images were exactly the same. Instead of optimizing DCT transformation, I chose the simplest way to conduct one-dimensional DCT transformation for rows and columns of the MCU matrix. I stored the coefficients of DCT matrix in dct_tbl and dct_tblt. Does this approach lose accuracy in calculations? In addition, when I quantized, I didn't round the result. this is picture : Encode JPEG file BMP file

This is the DCT&Quantizztion code:

    void FdctAndQuant(char *block,u8 const* std_quan_tabl,short *data)
{
   double dblock_1[64];
   double dblock_2[64];

    memset(dblock_1, 0, sizeof(dblock_1));
    memset(dblock_2, 0, sizeof(dblock_2));


    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
            for (int k = 0; k < 8; k++)
                dblock_1[i * 8 + j] += (dct_tbl[i * 8 + k] * (double)block[8 * k + j]);
        }
    }

    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
            for (int k = 0; k < 8; k++)
                dblock_2[i * 8 + j] +=  (dblock_1[i * 8 + k] * dct_tblt[8 * k + j]);
        }
    }

//Zig-zig
    for (int i = 0; i < 64; i++) {
        data[zigzag[i]] = (short)(dblock_2[i]/((double)(std_quan_tabl[i])));
    }

}
0

There are 0 best solutions below