slyrus / opticl

An image processing library for Common Lisp
Other
182 stars 35 forks source link

PNG input conversion rewrite for better transparency/alpha support. #2

Closed akovalenko closed 12 years ago

akovalenko commented 12 years ago

There are two possible representations of transparency in PNG files: alpha channel for :truecolor-alpha and :greyscale-alpha colour types, and a separate transparency map in a tRNS ancillary chunk. PNG-READ retains the difference by keeping data from tRNS as a separate TRANSPARENCY property of png-state.

New version of OPTICL:READ-PNG-STREAM uses transparency data for OPTICL alpha channel when reading a PNG with no "native" alpha channel implied by colour-type. Additionally, as OPTICL has no equivalent for :greyscale-alpha, greyscale images with (any kind of) transparency data are converted to RGBA.

Due to a bug in PNG-READ (fix committed on pull request https://github.com/Ramarren/png-read/pull/3), PNG-READ::TRANPARENCY property contained a raw representation of tRNS ancillary chunk instead of 2D 8-bit transparency data (that's how it was intended to work). A workaround for unfixed PNG-READ was added to this version of OPTICL:READ-PNG-STREAM: If TRANSPARENCY is not a 2D-array, its content is ignored (as if there were no alpha channel). Warning or error could be more appropriate here.

Turning :greyscale-alpha colour type to RGBA is an example of new use cases supported by rewritten READ-PNG-STREAM, even with older PNG-READ.

slyrus commented 12 years ago

Merged. Thanks for the patch and sorry for the lengthy delay.