Details
-
Task
-
Resolution: Won't Do
-
P2: Important
-
None
-
5.10
-
None
Description
When atlassing output file format may or may not need alpha, depending on the images stored in each atlas image. (It's a per-atlas-image decision). Might also be wise to allow to specify the output format e.g. masks can use a single channel format.
The specific texture compression format to use changes whether alpha is required or not. When atlassing, this information needs to be passed to the compressor per each image.
If alpha is used with a compressed format then we need to premultiply it because that's what QQ2 expects when it samples from textures with alpha. Since noone of the compressors I've found actually premultiplies alpha (because, I think, OpenGL lacks a premultiplied alpha format), then we must do it as a preprocessing step, before feeding images to texture compressors.
(Note that if we are atlassing AND compressing, this "preprocessing" could be done by the atlassing tool itself).
Writing such a preprocessor is not possible using QtGui facilities at the moment, because none of the Qt image writes can write premulitplied alpha:
- the PNG format does not support premultiplied alpha. Qt correctly saves PNG with non-premultiplied alpha.
- Random note: the pngcrush binary shipped with the iOS SDK generates non-compliant PNGs which are premultiplied: http://www.jongware.com/pngdefry.html
- BMP supports it, but Qt doesn't save BMPs with alpha
- TIFF might support it, but anyhow Qt doesn't save TIFFs with alpha
- ...
The only workaround to this problem that I've found is saving to PNG, then resorting to imagemagick and premultiply alpha manually, saving the result in BMP. Handy command line:
for i in *png; do convert "$i" \( +clone -alpha Extract \) -channel RGB -compose Multiply -composite "$(basename "$i" .png).bmp" done