Fix crash due to uninitialized variable

png_get_tRNS doesn't initialize supplied variables when no transparency chunk is found (see http://sourceforge.net/p/png-mng/mailman/message/27133707/).
In that case the trans_alpha variable still has its initial (indeterminate) value which leads to the crash when using it in set_pixel_bgra() later on.
We now check if the transparency chunk is valid before accessing it.

Commit licensed under MIT/X11.
Use correct type for variable

This was changed in PR#8, but the correct variable type is png_charp according to a clang warning and the documentation (http://refspecs.linuxfoundation.org/LSB_3.1.0/LSB-Desktop-generic/LSB-Desktop-generic/libpng12.png.get.iccp.1.html).

Commit licensed under MIT/X11.
Move the call to png_get_PLTE() up so it initializes the png_palette and num_palette variables in all cases.
This fixes accessing an uninitialized variable e.g. in the 2bpp case.

Commit licensed under MIT/X11.