Skip to content

Issue #346: Import and export safe-to-copy PNG chunks

Alx Sa requested to merge alxsa-png-save-safe-chunks into master

This patch attempts to resolve issue #346 (closed).

PNGs can contain other data chunks besides image-related ones. Currently, we ignore these and only use chunks with named functions in libpng (such as png_get_IHDR ()).

This patch uses the function png_set_read_user_chunk_fn () to set up a callback to access these additional chunks. If they are marked as safe to copy (the last byte of the 4-byte long name is lowercase), it stores as a parasite. On export, the parasite data is retrieved and exported before the image data using png_write_chunk ().

@Wormnest Hi! Since this is metadata-related, I'm bothering you as usual. 😄 If and when you have time, any feedback, suggestions, or other sample files with safe-to-copy chunks that you're aware of would be appreciated. Either way, thanks!

Edit: Adding a real-world sample file. ZDoom adds a 'grAb' chunk which stores sprite offsets. With this patch, GIMP now loads and saves the chunk correctly. hehea0

Edited by Alx Sa

Merge request reports