ATF comes as a byteArray, here some utilities to verify its ATF, get the width, height and file format, as well as overall size (in case the byteArray contains more than ATF)
So here the ATF spec:
ATF Field Type Comment Signature U8[3] Always ‘ATF’. Length U24 Size of ATF file in bytes, does include signature bytes and this length field. Cubemap UB[1] 0 = normal texture 1 = cube map texture Format UB[7] 0 = RGB888 1 = RGBA88888 2 = Compressed Log2Width U8 Width of texture expressed as 2^Log2Width. Maximum value allowed is 11. Log2Height U8 Height of texture expressed as 2^Log2Height. Maximum value allowed is 11.
Our ATF class util:
final public class ATFUtils { static public function isATF( byteArray:ByteArray):Boolean { //65:'A' 84:'T' 70:'F' return byteArray.length>10 && byteArray[0]==65 && byteArray[1]==84 && byteArray[2]==70; } static public function getATFWidth( byteArray:ByteArray):int { return 1<<(int(byteArray[7])); } static public function getATFHeight( byteArray:ByteArray):int { return 1<<(int(byteArray[8])); } static public function getATFFormat( byteArray:ByteArray):String { var format:int = int(byteArray[6]) switch (format) { case 0: case 1: return Context3DTextureFormat.BGRA; break; case 2: case 3: return Context3DTextureFormat.COMPRESSED; break; case 4: case 5: return "compressedAlpha"; break; // explicit string to stay compatible default: //new formats? .. please add } return null; } static public function getATFLength(byteArray:ByteArray):int { var u24_1:int = byteArray[3]; var u24_2:int = byteArray[4]; var u24_3:int = byteArray[5]; var length:int = (u24_1<<16)+(u24_2<<8)+(u24_3)+6; return length; } }
Leave a Reply