if the channdesc is not CY, then the calculated size in png is wrong by a factor of the number of bytes per pixel. a more invasive but perhaps better patch would create a function chantobpp and use that where required.