I'm trying to load part of big JPEG file (hundreds of megapixels) with a limited memory footprint. I need only about a 1000 scanlines of 20000. It seems that current implementation of libjpeg (as well as its fork libjpeg-turbo) doesn't provide a way to skip unneeded 19k scanlines without decoding them. Is there a workaround for it without digging into libjpeg internals?
Decode part of JPEG file
Partial JPEG decoding was implemented in jpeglib-turbo one year ago. I didn't try it, but I guess it should work.
Check it:
You can't avoid having to decode the scan lines you want to skip, but you can avoid storing them anywhere. When you get the callback from libjpeg for each row, just wait until the row number matches the section of scanlines you want.
Why can't I do that? AFAIU JPEG is stored in 8x8 blocks, thus if I need only 1000 bottom scanlines I can skip top blocks (19k/8) and decode only ones I need. Do I miss something? (Let's not consider progressive compression atm) –
Sheeran
It's been a long time since I've had to work with the JPEG internals, but isn't the Huffmann compression applied after the DCT transform on the 8x8 blocks? That means the top blocks are a variable amount of data so you don't know how much to skip without at least doing the Huffmann decoding. I suppose you could do that and avoid doing the DCT reconstruction, but as you say that would land you deep in the libjpeg internals. –
Mantelpiece
Partial JPEG decoding was implemented in jpeglib-turbo one year ago. I didn't try it, but I guess it should work.
Check it:
© 2022 - 2024 — McMap. All rights reserved.