Bodmer / JPEGDecoder

A JPEG decoder library
Other
220 stars 64 forks source link

skipping mcu blocks inside JpegDec.read() #54

Closed vult-r closed 3 years ago

vult-r commented 3 years ago

Hi,

Is there any support / function to skip entire mcu's inside the .read() loop?

in my case im not looking to decode the entire picture, but just a small box inside a byte-buffer.

( detecting motion in an area )

i tried manipulating mcu_x and mcu_y , but the order of decoding still seems to go from begin to end without a skip.

(this is the mod i tried to add, but it doesnt seem to skip at all)

void JPEGDecoder::skipToMcu(int x,int y)
{
    // how many mcu's did we move?
    int mcu_delta = (x-mcu_x) + ((y-mcu_y)*(image_info.m_MCUSPerRow));

    // moved-mcu's x pixels
    int pointer_delta = mcu_delta  * (image_info.m_MCUWidth * image_info.m_MCUHeight);

    // manipulate vars

    (*pImage) += pointer_delta;
    mcu_x = x;
    mcu_y = y;
}
Bodmer commented 3 years ago

Due to the Jpeg compression format supported it is not possible to skip decoding blocks. Block must be decoded fromthe start. It is possible to stop decoding if the blocks are below the required image block range using JpegDec.abort();