Is there an image library available that allows a user to extract pixels from a png file that has been loaded onto disk without decompressing it?
So I have 100k 8bit images of size 512×512 where each one is about 10kb when in png format. This means that I would only need 1GB of RAM to store all the images at runtime for a program Im writing.
Is it possible to efficiently retrieve pixels from an image like this?
I.e. lets say I have an array images where images[i] references a png image that has been loaded but not uncompressed to RAM (is this what happens when you load a png image?)
Then ideally I would like to write something like
pixel = images[i].getPixel(x,y);
Anyone know if this is possible? Which library? Where my assumptions are false?
I don’t think you’ll be able to get a pixel without decompressing at least the preceding part of the image. When you open a file, it will just point to the compressed data on disk. When you run it through a PNG library, it will be decompressed.
Your best bet, I think, and the canonical library for reading and writing PNGs, is libpng. It provides great low-level access to image data and metadata, and is probably going to be the fastest/most efficient option. It allows you to decompress the data row by row (and perhaps chunk by chunk–I can’t remember), so you can probably decompress until you get your pixel, then toss the decompressed data and move to the next image.
The downside is that it’s probably not as programmer friendly as some other options. The documentation is comprehensive to the point of being tedious, IMO, but there may be simpler tutorials out there. On the other hand, you’ll probably need all the details in the manual to accomplish what the minimal decompression you’re going for. It will also help explain the PNG file format so you can better manage data down to the chunk level.