Sorry never tried to actually save a PNG. Little i know about 256 palettes with PNG either, most use true colors that don't really take any more space, but is it possible to set pixels alpha value to 0 when color is #0? That would help for the mask problem, assuming you had all colors correctly. I realize this might add extra data to image if you did not have alpha channel previously.