问题
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?
回答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
回答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.
来源:https://stackoverflow.com/questions/12022675/decode-part-of-jpeg-file