bitbank2 / JPEGDEC

An optimized JPEG decoder for Arduino
Apache License 2.0
364 stars 47 forks source link

JPEG_DECODE_ERROR on a large epaper screen #77

Open countrysideboy opened 5 days ago

countrysideboy commented 5 days ago

doraemon IMG_6080 Large jpegdec_debug.zip I use JPEGDEC to decode the jpeg file on a large 7 color e-ink screen(800x480), but I cannot show the whole and get a JPEG_DECODE_ERROR. I try to add some debug code, and find the JPEGDecodeMCU function throw an error in the area of the code below.

 // get the DC component
    pucFast = &pJPEG->ucHuffDC[pJPEG->ucDCTable * DC_TABLE_SIZE];
    ulCode = (ulBits >> (REGISTER_WIDTH - 12 - ulBitOff)) & 0xfff; // get as lower 12 bits
    if (ulCode >= 0xf80) // it's a long code
        ulCode = (ulCode & 0xff); // point to long table and trim to 7-bits + 0x80 offset into long table
    else
        ulCode >>= 6; // it's a short code, use first 6 bits only
    ucHuff = pucFast[ulCode];
    cCoeff = (signed char)pucFast[ulCode+512]; // get pre-calculated extra bits for "small" values
    if (ucHuff == 0) {// invalid code
        Serial.println("invalid code1");//【Where the error occurred】
        return -1;
    }

The same code works well with the 2.9 inch black and white epaper.The difference of the bw and 7 color screen maybe the display buffer(800x480 use more ram).Esp32 and rp2040 get the same result. I try to use another lib, TJpg_Decoder, which can decode without error on my 7 clolor screen.

countrysideboy commented 5 days ago

I tried to submit the same problem in that issue, and I'm sorry for sending the code so late.

countrysideboy commented 1 day ago

The batman.jpg is also throw the decode error on the 7 clolor screen of gxepd2 driver.