Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about Partial Decode #208

Closed
william-silversmith opened this issue Feb 10, 2022 · 4 comments
Closed

Question about Partial Decode #208

william-silversmith opened this issue Feb 10, 2022 · 4 comments
Labels
question Further information is requested

Comments

@william-silversmith
Copy link

Hi Randy,

This isn't exactly a feature request, I just don't have a firm grasp of the PNG format yet and was wondering if the following is possible.

I’ve been interested in getting the image formats I work with to allow for as close to random access as possible. The regular PNG format is based on deflate, and so is not random access. However, ordinary (not interlaced) Progressive PNG allows for skipping the decoding of trailing scanlines. Is it at all possible to skip decoding some leading scanlines to achieve a vertical crop? Is it possible to do this horizontally as well?

I recently introduced the spng decoder into google/neuroglancer#370 which is a scientific viewer for petascale 3d neuroscience data when I realized PNG beats gzipping raw arrays by about 25% on storage. A significant fraction of researchers in my field are paranoid about lossy compression, so I've been trying to find ways to accommodate this desire. I've been trying to optimize the ability to make rapid queries of large datasets by partially decoding images. It's not essential to do this, but it would be interesting if it is possible.

Thanks for the wonderful library Randy!

@randy408
Copy link
Owner

Image data is always encoded as a single DEFLATE stream, interlacing doesn't change that.

I have a proposed specification for subdividing image data which would allow random access: https://github.com/libspng/png-restart-marker

And to leverage that for multi-threading (#192) but all of this would need funding to implement.

@william-silversmith
Copy link
Author

Thanks again for the quick reply Randy! I think I am confused on a point. Isn't the purpose of progressive PNG to allow dynamic loading over a slow connection? Doesn't that imply the existence of multiple DEFLATE encoded sections that can be accessed independently? Or is it that you can start decoding the single DEFLATE stream in an on-line fashion and extract each scanline?

Thanks for pointing me to the work you've been considering. If I am correct about the on-line decoding of the deflate stream, I can see the benefit of the restart markers.

I haven't applied for this myself, but I've heard good things about this grant program for essential open-source imaging software: https://chanzuckerberg.com/eoss/ I think a new funding cycle should start within a few months though I'm not tapped into their internal conversations. Check back in periodically and you might be able to apply. This is certainly a very useful library. I would suspect you'd have a competitive application.

@randy408
Copy link
Owner

Interlacing just rearranges the order of pixels to allow for "better" progressive display, you get a lower resolution preview early on as opposed to loading the full resolution image from top to bottom. It's still a single DEFLATE stream that is decompressed linearly. See the wikipedia page on Adam7 interlacing for an illustration (.GIF's don't embed here).

@william-silversmith
Copy link
Author

Thank you so much Randy! That explanation makes it clear. Please feel free to close this issue unless it is otherwise helpful for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants