Unknown PNG chunks

95 views
Skip to first unread message

mattl...@live.com

unread,
Aug 15, 2022, 6:05:06 PM8/15/22
to skia-discuss
Hi folks, I am trying to have a look at supporting PNG chunks when decoding images. As far as I can tell, I need to compile with the "PNG_READ_UNKNOWN_CHUNKS_SUPPORTED" flag set, and then this code is enabled:


        png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_ALWAYS, (png_byte*)"", 0);
        png_set_read_user_chunk_fn(png_ptr, (png_voidp) chunkReader, sk_read_user_chunk);


This seems to work from a logic perspective, but at runtime, the "png_ptr->num_chunk_list" value is 0, so it just skips over. When I step through, I see it reach the "png_handle_as_unknown" in "png.c", and then it just return with a value of "0".

Are chunks supported? Should I even be going down this path?

Thanks!

Leon Scroggins

unread,
Aug 16, 2022, 3:13:04 PM8/16/22
to skia-d...@googlegroups.com
I'm not sure what's going on with the png_ptr->num_chunk_list value, but you should be able to handle these with SkPngChunkReader. You can look at an example implementation here.


--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/768af1fa-0f9b-467a-a80d-139560c642c5n%40googlegroups.com.


--

 •  Leon Scroggins

 •  scr...@google.com


李華斯

unread,
Aug 16, 2022, 3:16:11 PM8/16/22
to skia-d...@googlegroups.com
--

mattl...@live.com

unread,
Aug 16, 2022, 3:37:08 PM8/16/22
to skia-discuss
I am using the reader - and that is where I noticed it did not pick up the iTXt or pHYs chunks. 

Does the reader only work with some types?

Leon Scroggins

unread,
Aug 16, 2022, 4:02:22 PM8/16/22
to skia-d...@googlegroups.com
It's been a while since I've looked at this very deeply. I think this only supports unknown chunks - iTXt and pHYs are standard chunks, which are handled directly by libpng. (There might be a way to tell libpng to let you handle known chunks, but I'm not sure.)

There are standard libpng methods for retrieving the data from pHYs:
png_get_pixels_per_meter
png_get_x_pixels_per_meter
png_get_y_pixels_per_meter

I don't remember how to get iTXt.

The Skia API doesn't give you a way to get those chunks (or their data), though, and I'm not sure it should.

mattl...@live.com

unread,
Aug 16, 2022, 5:00:35 PM8/16/22
to skia-discuss
Thanks! This makes a bunch of sense.
Reply all
Reply to author
Forward
0 new messages