Maybe base it on: load_image_png in https://github.com/pts/pts-swiggle/blob/master/pts-swiggle.c . This uses only a fraction of the libpng library, probably it can be inlined (also zlib, see https://github.com/pts/pdfsizeopt-jbig2).
Maybe base it on: https://gist.github.com/niw/5963798. Which libpng version does it need?
Alpha channel (transparency) handling can get tricky.
Add fast processing for 8-bit RGB, 8-bit grayscale and 8-bit palette, without gamma correction: just memcpy.