PNG image reader and writer without external libraries