implements png buffer decoder (progress #35)

fixes memory leaks with encoder.
changes structure of encoder.