1、swf文件结构中的大体数据类型CHAPTER 4Basic Data TypesThis section describes the basic data types that make up the more complex data structures in the Macromedia Flash (SWF) file format. All other structures in the SWF file format are built on these fundamental types.这章节描述大体数据类型在SWF文件里能够创建更多复杂数据结构。所有在SWF文件里的其它结构都
2、是由这些大体类型创建的。Coordinates and twips坐标和缇The SWF file format stores all x-y coordinates as integers, usually in a unit of measurement called a twip. In the SWF format, a twip is 1/20th of a logical pixel. A logical pixel is the same as a screen pixel when the file is played at 100%that is, without scali
3、ng.For example, a rectangle 800 twips wide by 400 twips high is rendered as 40 by 20 logical pixels. Fractional pixel sizes are approximated with anti-aliasing. A rectangle 790 by 390 twips by pixels) appears to have slightly blurred edges.Twips are a good compromise between size and precision. They
4、 provide sub-pixel accuracy for zooming and precise placement of objects, while consuming very few bits per in the SWF file format use the traditional graphics axes: x is horizontal and proceeds from minimum values at the left to maximum values at the right, and y is vertical and proceeds from minim
5、umvalues at the top to maximumvalues at the bottom. swf文件格式用整数来存储X-Y坐标,它的单位默许的是缇(twip),20 twip=1 pixel。在没有缩放的情形下,确实是100%播放时,swf中的一个逻辑像素和屏幕上的一个像素是对应的。利用缇的益处确实是能够取得比利用像素更高的精度。比如,一个800twips宽,400twips高的矩形,就会被说明成4020像素的大小,这时矩形的边缘是没有锯齿的。若是是790390twips( 像素)的话,它的就会有轻微的模糊边缘。Twips一个大小与精度之间好的折衷方案。当处置少数坐标位时,它们规
6、定支持了缩放的亚像素的精准度(sub-pixel)和对象放置的精度。在swf的坐标系里面,它采纳的是传统的图像的坐标,x轴是水平方向,而且是从左到右值是增大的;y轴是垂直方向的,而且从下到上是增加的。Integer types and byte order整数类型和字节顺序The SWF file format uses 8-bit, 16-bit, 32-bit, 64-bit, signed, and unsigned integer types. All integer values are stored in the SWF file by using little-endian by
7、te order: the least significant byte is stored first, and the most significant byte is stored last, in the same way as the Intel x86 architecture. The bit order within bytes in the SWF file format is big-endian: the most significant bit is stored first, and the least significant bit is stored last.s
8、wf文件中利用的8位、16位、32位、64位有符号和无符号的整数。这些整数在swf文件中是以little-endian的顺序来存储的:低字节在前,高字节在后,一样方式应用于Intel X86体系结构。而每一个字节的每一名那么是按big-endian的顺序来排列的:即高位在先,低位在后。For example:The 32-bit value 0x456e7120 is stored as 20 71 6e 45. The 16-bit value 0xe712 is stored as 12 e7.All integer types must be byte aligned. That is,
9、 the first bit of an integer value must be stored in the first bit of a byte in the SWF file. 比如一个32位的整数:0x456e7120 ,它在文件中确实是以 20 71 6e 45的格式存储的。一个16位的整数:0xe712,它在文件中确实是以 12 e7的格式存储的。这种方式就称为little-endian。在SWF文件中,所有整数类型必需是字节对齐的。也确实是,一个整数值的第一名必需存储在一个字节的第一名。little-endian要紧用在咱们此刻的PC的CPU中,big-endian那么应用在
10、目前的Mac机械中(是指Power系列处置器)。Signed integers are represented by using traditional 2s-complement bit patterns. These are the signed integer representations used on most modern computer platforms. In the 2s complement system, negative numbers have 1 as the first bit, and zero and positive numbers have 0 as
11、 the first bit. A negative number, -n, is represented as the bitwise opposite of the positive-zero number n-1.符号整数通过利用2补数位形式(2s-complement bit patterns)来描述的。这种符号整数表示法用于大多数现代微机平台。在2s complement系统里,负数第一名设为1,而且0和正数第一名设为0.一个负数,-n,描述成那个数的正数n-1的 反数(取反)。Integer TypesType CommentSI8 Signed 8-bit integer val
12、ue 带符号8位整数SI16 Signed 16-bit integer value带符号16位整数SI32 Signed 32-bit integer value带符号32位整数SI8n Signed 8-bit arrayn is the numberof array elements带符号8位数组,n是数组元素个数SI16n Signed 16-bit arrayn is the is number of array elements带符号16位数组,n是数组元素个数UI8 Unsigned 8-bit integer value不带符号8位整数UI16 Unsigned 16-bit
13、integer value不带符号16位整数UI32 Unsigned 32-bit integer value不带符号32位整数UI8n Unsigned 8-bit arrayn is the number of array elements不带符号8位数组,n是数组元素个数UI16n Unsigned 16-bit arrayn is the number of array elements不带符号16位数组,n是数组元素个数UI24n Unsigned 24-bit arrayn is the number of array elements不带符号24位数组,n是数组元素个数UI32
14、n Unsigned 32-bit arrayn isthe number ofarray elements不带符号32位数组,n是数组元素个数UI64n Unsigned 64-bit arrayn is thenumber of array elements不带符号64位数组,n是数组元素个数Fixed-point numbersThe SWF file format supports two types of fixed-point numbers: 32 bit and 16 32-bit fixed-point numbers are . That is, the high 16 b
15、its represent the number before the decimal point, and the low 16 bits represent the number after the decimal point. swf文件格式支持两种类型的定点数:32位定点数和16位定点数。32位定点数的格式是格式的,小数点前面和小数点后面的每一部份各占2个字节(16位)。FIXED values are stored like 32-bit integers in the SWF file (using little-endian byte order) and must be byt
16、e aligned.而且在SWF文件里,也是采纳了little-endian的形式定点数像32位整数一样存储,必需字节对齐。For example:The real value is equivalent to: 。This value is stored in the SWF file as: 00 80 07 00SWF 8 and later supports 16-bit signed, fixed-point numbers. The high 8 bits represent the number before the decimal point, and the low 8 bi
17、ts represent the number after the decimal point. FIXED8 values are stored like 16-bit integers in the SWF file (using little-endian byte order) and must be byte aligned.比如一个32位的实数:=。在文件中确实是以00 80 07 00的形式存储的。16位的定点数和32位的是类似的,采纳格式,也是little-endian的形式。16位的定点数是在Flash8及其以后版本中才被支持的。在SWF文件里FIXED8数据存储时就像16位
18、整数一样利用little-endian字节序,而且必需字节对齐。Fixed-Point TypesType CommentFIXED 32-bit fixed-point number 32位定点数FIXED8 16-bit fixed-point number16位定点数Floating-point numbersSWF 8 and later supports the use of IEEE Standard 754 compatible floating-point types. Three types of floating-point numbers are supported.Fl
19、oating-Point TypesType Comment FLOAT16 Half-precision (16-bit) floating-point numberFLOAT Single-precision (32-bit)IEEE Standard 754 compatibleDOUBLE Double-precision (64-bit) IEEE Standard 754 compatibleFLOAT16 is identical to the characteristics of FLOAT except for changes to the number of bits al
20、located to the exponent and mantissa:1 bit for the sign 1位作为符号位5 bits for the exponent, with an exponent bias of 16 5位是分派给指数部份,实际的指数是5位数表示的数和16的差值;10 bits for the mantissa 10位用来表示尾数 swf8及其后续的版本中支持和IEEE Standard 754兼容的浮点数类型。一共有三种类型,别离是:Half-precision (16-bit)floating-point number半精度、Single-precision(
21、32-bit)单精度、Double-precision (64-bit)双精度。除半精度的这种浮点型数据之外,其它两种都符合IEEE Standard 754的标准。半精度的也是和IEEE Standard 754类似的,只是改变了标准中分派给尾数和指数的位数。在半精度型的浮点数中,一名作为符号位;5位是分派给指数部份,实际的指数是5位数表示的数和16的差值;剩余的10位用来表示尾数。Bit values Bit values are variable-length bit fields that can represent three types of numbers: 1. Unsigne
22、d integers 2. Signed integers 3. Signed fixed-point values. 位值是用多少位来表示一个数值是不确信的,也确实是说,表示值的时候,位数是可变的。它能够表示三种类型的数值:无符号整数、有符号整数和有符号的格式的定点数。位值不是位齐的,而其它一些数据类型,比如前面提到过的无符号整数等都是必需位齐的。若是一个位齐的数据类型后面随着一个位值,那么最后几位若是不能填满的话,应该用0补齐。 而且以上这些数若是需要扩展的话,是按符号扩展来进行扩展的。Bit values 位值. 一个字节由8位组成,为了节约存储空间,swf文件中很多的flag都利用位作
23、为记录空间,比如UBn,确实是由n位组成的一个unsigned integer or long数据,在利用bit values时,若是一个结构(Record struct)已经描述完成,但bit位指针不是8的倍数,需要利用到fill bits(0)将数据补足为8的倍数,进行字节对齐的操作.Bit values are variable-length bit fields that can represent three types of numbers: integers integers fixed-point values.Bit values do not have to be byte
24、 aligned. Other types (such as UI8 and UI16) are always byte aligned. If a byte-aligned type follows a bit value, the last byte that contains the bit value is padded with zeros. 位值是一个变长位域,能描述三种数值:一、不带符号整数;二、符号整数;3、带符号 定点数Bit值不用字节对齐。其它类型(诸如UI8 和 UI16)常常字节对齐。若是一个字节对齐类型跟从一个位值,那最后一个字节包括位值,必需用0填充。The fol
25、lowing example is a stream of 64 bits, made up of 9-bit values of varying length, followed by a UI16 value:下面那个例子是一个64位的数据流,由9个变长的位值组成,后面紧跟一个UI16值: The bit stream begins with a 6-bit value (BV1), followed by a 5-bit value (BV2) that is spread across Byte1 and Byte2. BV3 is spread across Byte2 and By
26、te3, while BV4 is wholly contained within Byte3. Byte 5 contains two bit values: BV7 and BV8. BV9 is followed by a byte-aligned type (UI16), so the last four bits of Byte 6 are padded with zeros.那个位数据流从一个6位值开始,紧接着5位值,那个值跨度Byte1和Byte2两个字节之间。BV3跨度在Byte2和Byte3两个字节之间。而BV4整个包括在Byte3中。Byte5包括两个位值:BV7和BV8。
27、BV9后面紧接一个字节对齐的UI16。因此,第六个字节的最后四位要被0填充补齐。Bit Values Type CommentSBnBits Signed-bit value (nBits is the number of bits used to store the value) UBnBits Unsigned-bit value (nBits is the number of bits used to store the value) FBnBits Signed, fixed-point bit value (nBits is the number of bits used to st
28、ore the value)SBnBits 带符号的位值(nBits表示那个值有nBits位被存储)UBnBits 无符号位值(nBits表示那个值有nBits位被存储)FBnBits 带符号,定点小数位值(nBits表示那个值有nBits位被存储)When an unsigned-bit value is expanded into a larger word size, the leftmost bits are filled with zeros. When a signed-bit value is expanded into a larger word size, the high
29、bit is copied to the leftmost bits. 当一个无符号的位值被扩展到一个larger word 大小,最左侧的位所有被0填充。当一个带符号的位值被扩展到一个larger word 大小,最高位被复制到最左侧的所有位。This expansion is called sign extension. For example, the 4-bit unsigned value UB4 = 1110 would be expanded to a 16-bit value like this: 0000000000001110 = 14. The same value in
30、terpreted as a signed value, SB4 = 1110 would be expanded to 110 = 2. Signed-bit values are similar but must take account of the sign bit. The signed value of 35 is represented as SB7 = 0100011. The extra zero bit is required; otherwise the high bit is sign extended and the value is interpreted as n
31、egative.这种扩展被称为 符号扩展。例如:一个4-bit 无符号值UB4=1110,将被扩展成一个 16-bit 的值,像如此:0000000000001110=14。一样的值被说明成一个带符号的值,SB4=1110 将被扩展成110=-2。符号位的值是相似的,但必需与符号位相同。带符号的值35被描述成SB7=0100011。扩展位0是必需的;不然,最高位被扩展置位,那个值就被描述成负数了。 Fixed-point bit values are 32-bit signed, fixed-point numbers. That is, the high 16 bits represent
32、the number before the decimal point, and the low 16 bits represent the number after the decimal point. A fixed-point bit value is identical to a signed-bit value, but the interpretation is different. For example, a 19-bit, signed-bit value of 0x30000 is interpreted as 196608 decimal. The 19-bit, fixed-point bit value 0x30000 is interpreted as . The format of this value is effectively rather than .定
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1