(swf file format spec v10)swf文件格式中英文说明书v10,位值部分,笔记4

Bit values
Bit values are variable-length bit fields that can represent three types of numbers:
1. Unsigned integers
2. Signed integers
3. Signed 16.16 fixed-point values.
Bit values do not have to be byte 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.
位值
位值是用多少位来表示一个数值长度是不确定的,它可以表示三种类型的数值:无符号整数、有符号整数和有符号的16.16格式的定点数。
位值不是位齐的,而其它一些数据类型,比如前面提到过的(Unsigned integers8/16)等都是必须位齐的。如果一个位齐的数据类型后面跟着一个位值,那么后几位如果不能填满的话,应该用0补齐。

The following example is a stream of 64 bits. The 64 bits represent 9 values of varying bit
length, followed by a UI16 value:(图)
下面这个例子是一个64位的数据流,由9个变长的位值组成,后面紧跟一个UI16值:
[img]http://dl.iteye.com/upload/attachment/330453/5af58e5d-e5fa-3439-a7c1-bc0a46d8962f.png[/img]

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 Byte3, while BV4 is wholly contained
within Byte3. Byte 5 contains two bit values: BV7 and BV8. BV9 is followed by a bytealigned
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。BV9后面紧接一个字节对齐的UI16。因此,第六个字节的最后四位要被0填充补齐。


Bit Values
Type Comment
SB[nBits] Signed-bit value (nBits is the number of bits used to store the value)
UB[nBits] Unsigned-bit value (nBits is the number of bits used to store the value)
FB[nBits] Signed, fixed-point bit value (nBits is the number of bits used to store the value)


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 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 UB[4] = 1110
would be expanded to a 16-bit value like this: 0000000000001110 = 14. The same value
interpreted as a signed value, SB[4] = 1110 would be expanded to 1111111111111110 = –2.
Signed-bit values are similar but must take account of the sign bit. The signed value of 35 is
represented as SB[7] = 0100011. The extra zero bit is required; otherwise the high bit is sign
extended and the value is interpreted as negative.
这种扩展被称为 符号扩展。例如,一个4-bit 无符号值UB[4]=1110,将被扩展成一个 16-bit 的值,像:0000000000001110=14。同样的值被解释成一个带符号的值,SB[4]=1110 将被扩展成1111111111111110=-2。符号位的值是类似的,但必须与符号位相同。带符号的值35被描述成SB[7]=0100011。扩展位0是必须的;否则,最高位扩展置位,这个值就被描述成负数了。

Fixed-point bit values are 32-bit 16.16 signed, fixed-point numbers. That is, the high 16 bits
represent 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 3.0. The format
of this value is effectively 3.16 rather than 16.16.
定点位值是一个32-bit 16.16格式的带符号的值,定点数。高16位表示小数点前面的数,且低16位表示小数点后面的数。一个定点位值是一个带符号的位值,但是解释是不同的。例如,一个19位有符号位的值0x30000被解释为196608。这个19位定点位值0x30000被描述成3.0。格式这个值是3.16远比16.16有效得多。

Using bit values
Bit values are stored by using the minimum number of bits possible for the range needed.
Most bit value fields use a fixed number of bits. Some use a variable number of bits, but in all
such cases, the number of bits to be used is explicitly stated in another field in the same
structure. In these variable-length cases, applications that generate SWF files must determine
the minimum number of bits necessary to represent the actual values that will be specified.
For signed-bit values, if the number to be encoded is positive, an extra bit is necessary to
preserve the leading 0; otherwise sign extension changes the bit value into a negative number.
As an example of variable-sized bit values, consider the RECT structure:
使用位值
位值用于为尽可能所需要的值范围存储最小数量的位。大部分位域使用固定大小的位。许多使用变长的位,但在诸如此类情况,在相同结构中,这个位的长度明确定义其它域的状态。在其它位变长情况下,SWF文件程序必须确定所需的最小长度位,用于描述指定的实际值。对于带符号的位值,如果这个编码长度能够确定,一个扩展位必须保留第一位是0;否则,符号扩展将改变这个位值为负数。
RECT结构就是使用变长位值的例子:(下翻译略)

RECT
Field Type Comment
Nbits UB[5] Bits in each rect value field
Xmin SB[Nbits] x minimum position for rect
Xmax SB[Nbits] x maximum position for rect
Ymin SB[Nbits] y minimum position for rect
Ymax SB[Nbits] y maximum position for rect


The Nbits field determines the number of bits used to store the coordinate values Xmin,
Xmax, Ymin, and Ymax. Say the coordinates of the rectangle are as follows:
Xmin = 127 decimal = 1111111 binary
Xmax = 260 decimal = 100000100 binary
Ymin = 15 decimal = 1111 binary
Ymax = 514 decimal = 1000000010 binary
这个Nbits域决定了用于存储坐标值的形式:Xmin, Xmax, Ymin, and Ymax。矩形的四个坐标如下:
Xmin = 127 decimal = 1111111 binary
Xmax = 260 decimal = 100000100 binary
Ymin = 15 decimal = 1111 binary
Ymax = 514 decimal = 1000000010 binary

Nbits is calculated by finding the coordinate that requires the most bits to represent. In this case, that value is 514 (01000000010 binary) which requires 11 bits to represent. The rectangle is stored as the following table shows:
计算得出Nbits:找出坐标中所需要的最大位长度。在这种情况下,这个值是514(01000000010 二进制位)需要11位去描述。那么个矩形通过下面的表述表进行存储:
RECT
Field Type and Value Comment
Nbits UB[5] = 01011 Bits required (11)
Xmin SB[11] = 00001111111 x minimum in twips (127)
Xmax SB[11] = 00100000100 x maximum in twips (260)
Ymin SB[11] = 00000001111 y minimum in twips (15)
Ymax SB[11] = 01000000010 y maximum in twips (514)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值