Decode part of JPEG file
Asked Answered
S

2

5

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?

Sheeran answered 18/8, 2012 at 22:25 Comment(0)
F
1

Partial JPEG decoding was implemented in jpeglib-turbo one year ago. I didn't try it, but I guess it should work.

Check it:

Add further partial decoding optimization #34

Fernand answered 29/5, 2017 at 8:27 Comment(0)
M
2

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.

Mantelpiece answered 18/8, 2012 at 22:30 Comment(2)
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
F
1

Partial JPEG decoding was implemented in jpeglib-turbo one year ago. I didn't try it, but I guess it should work.

Check it:

Add further partial decoding optimization #34

Fernand answered 29/5, 2017 at 8:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.