lvandeve / lodepng

PNG encoder and decoder in C and C++.
zlib License
2.07k stars 422 forks source link

Is the sTER Chunk supported? #22

Open MarcusJohnson91 opened 8 years ago

MarcusJohnson91 commented 8 years ago

It's an extension for stereoscopic support in PNG.

lvandeve commented 8 years ago

It is not directly supported.

However, there are some helper functions that allow using it. It could be done as follows:

  1. decode the image as normal and have the result in one big image
  2. back from the beginning of the file, use "lodepng_chunk_next_const" and "lodepng_chunk_type_equals" to navigate to the sTER chunk (or stop once IDAT, IEND or end of file is reached, then there is none)
  3. read the one byte called "mode" from the chunk
  4. allocate two new image buffers, and write a 2D for loop through the big image with y from 0 to height, x from 0 to width, and follow the spec in point 3.6 at http://www.libpng.org/pub/png/spec/register/pngext-1.4.0-pdg.html to output pixels in one or the other output image buffer
  5. if needed to get the pHYs information for the pixel ratio, use in step 1. a decoding function that outputs information to a LodePNGState, then it will have phys_x, phys_y and phys_unit in the LodePNGInfo.

I hope this helps

MarcusJohnson91 commented 8 years ago

If I wanted to add support for the sTER chunk, how would I go about doing that?

I could probably get it done within a day, but I only know C, not C++. so classes are magic to me.

lvandeve commented 8 years ago

I would prefer to not have it in LodePNG, I would like to keep the library focused on one thing, the pure PNG spec.

But it could be implemented as a utility function in lodepng_util.cpp. Thanks to the lodepngchunk... functions, and preprocessing/postprocessing of the image, it doesn't need to be inside the core library.