`
gouxychina
  • 浏览: 33086 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

(swf file format spec v10)swf文件格式中英文说明书v10,定点数浮点数,笔记3

阅读更多
Fixed-point numbers
The SWF file format supports two types of fixed-point numbers: 32-bit and 16-bit.
The 32-bit fixed-point numbers are 16.16. 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.
FIXED values are stored like 32-bit integers in the SWF file (using little-endian byte order)
and must be byte aligned.
For example: The real value 7.5 is equivalent to: 0x0007.8000.
This value is stored in the SWF file as: 00 80 07 00.
SWF 8 and later supports 16-bit 8.8 signed, fixed-point numbers. The high 8 bits represent
the number before the decimal point, and the low 8 bits represent the number after the
decimal point. FIXED8 values are stored like 16-bit integers in the SWF file (using littleendian
byte order) and must be byte aligned.
定点数
swf文件格式支持两种类型的定点数:32位定点数和16位定点数。32位定点数的格式是16.16格式的,小数点前面是高16位,小数点后面低16位。定点值存在SWF文件里,像32位整数形式,采用了little-endian的字节顺序,必须字节对齐。
例如:一个实数:7.5相当于0x0007.8000(10进制转换为16进制可知:7x16^0 . 8*16^-1)。
这个值在SWF文件中是以00 80 07 00的形式存储的。
SWF8或更高版本中,16位的定点数采用8.8格式,小数点前高8位,低8位在小数点后。在SWF文件里FIXED8数据存储时就像16位整数一样使用little-endian字节序,并且必须字节对齐。

Fixed-Point Types
Type Comment
FIXED 32-bit 16.16 fixed-point number 32定点数
FIXED8 16-bit 8.8 fixed-point number 16位定点数

Floating-point numbers
SWF 8 and later supports the use of IEEE Standard 754 compatible floating-point types.
Three types of floating-point numbers are supported.

浮点数
SWF8或更高版本中支持使用IEEE标准754兼容浮点类型。
三种类型的浮点数都支持。


Floating-Point Types
Type Comment
FLOAT16 Half-precision (16-bit) floating-point number (16-bit)半精度
FLOAT Single-precision (32-bit) IEEE Standard 754 compatible (32-bit)单精度
DOUBLE Double-precision (64-bit) IEEE Standard 754 compatible (64-bit)双精度


FLOAT16 is identical to the characteristics of FLOAT except for changes to the number of
bits allocated to the exponent and mantissa:
■ 1 bit for the sign
■ 5 bits for the exponent, with an exponent bias of 16
■ 10 bits for the mantissa

FLOAT16是和IEEE Standard 754类似的,只是改变了标准中分配给尾数和指数的位数。
■1位作为符号位
■5位是分配给指数部分,实际的指数是5位数表示的数和16的差值;
■10位用来表示尾数


Encoded integers
SWF 9 and later supports the use of integers encoded with a variable number of bytes. One
type of encoded integer is supported.
This is a 32-bit unsigned integer value encoded with a variable number of bytes to save space.
All EncodedU32's are encoded as 1-5 bytes depending on the value (larger values need more
space). The encoding method is if the hi bit in the current byte is set, then the next byte is also
part of the value. Each bit in a byte contributes 7 bits to the value, with the hi bit telling us
whether to use the next byte, or if this is the last byte for the value.
This is the algorithm for parsing an EncodedU32:

编码的整数
SWF 9或更高版本支持与一个可变数目字节编码的整数使用。一整数类型的编码支持。
这是一个32位无符号的可变字节编码的整数,以节省空间。
所有EncodedU32的编码为1-5个字节取决于值(较大的值需要更多空间)。该编码方法是,如果在当前字节高位被设置,那么下一个字节也是值的一部分。字节中的每一位都有价值包括高位,告诉我们是否使用下一个字节,或者说明这是最后一个字节的值。

这是分析EncodedU32算法:(此步翻译略)


int GetEncodedU32(unsigned char*& pos)
{
int result = pos[0];
if (!(result & 0x00000080))
{
pos++;
return result;
}
result = (result & 0x0000007f) | pos[1]<<7;
if (!(result & 0x00004000))
{
pos += 2;
return result;
}
result = (result & 0x00003fff) | pos[2]<<14;
if (!(result & 0x00200000))
{
pos += 3;
return result;
}
result = (result & 0x001fffff) | pos[3]<<21;
if (!(result & 0x10000000))
{
pos += 4;
return result;
}
result = (result & 0x0fffffff) | pos[4]<<28;
pos += 5;
return result;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics