电竞比分网-中国电竞赛事及体育赛事平台

分享

swf文件格式說(shuō)明書(shū)(中文+英文)

 quasiceo 2015-01-12

swf文件格式說(shuō)明書(shū)(中文+英文)

 

SWF文件頭

 

字段                類型                     備注

 

標(biāo)識(shí)                8                   標(biāo)識(shí)字節(jié):

 

                                          F代表未壓縮

 

                                          C代表已壓縮(SWF6以后的版本特有)

 

標(biāo)識(shí)                 8                  代表W

 

標(biāo)識(shí)                 8                  代表S

 

版本號(hào)               8                  代表SWF文件的版本,比如0x06代表SWF6

 

文件長(zhǎng)度            32                 整個(gè)文件的所占的字節(jié)數(shù)

 

幀大小              RECT                 結(jié)構(gòu)SWF場(chǎng)景的大小,單位為1twip1/20像素)

幀速度               16

幀數(shù)                16                 影片總的幀數(shù)目

The header begins with a three-byte Signature of either 0x46, 0x57, 0x53 (“FWS”) or 0x46,

0x57, 0x43 (“CWS”). An FWS signature indicates an uncompressed SWF file; CWS indicates

that the entire file after the first 8 bytes (that is, after the FileLength field) has been compressed using the open standard ZLIB. The data format used by the ZLIB library is described by Request for Comments (RFCs) documents 1950 to 1952. CWS file compression is only permitted in SWF version 6 or later.

 

 

文件頭以三個(gè)標(biāo)識(shí)符開(kāi)始,他們不是0x46, 0x57, 0x53 (FWS)就是0x46,0x57, 0x43 (CWS).一個(gè)FWS標(biāo)識(shí)表示該文件是未壓縮文件.CWS標(biāo)識(shí)表示整個(gè)文件,在前八個(gè)字節(jié),也就是文件長(zhǎng)度字段之后所有的內(nèi)容,都是開(kāi)放標(biāo)準(zhǔn)ZLIB壓縮過(guò)的.用ZLIB庫(kù)的數(shù)據(jù)格式,在1950 1952年的Request for Comments (RFCs)文檔中有所描述.CWS僅在SWF6以后才允許使用.

 

 

A one-byte Version number follows the signature. The version number is not an ASCII character,but an 8-bit number. For example, for SWF 4 the version byte is 0x04, not the ASCII character‘4’ (0x35).

 

 

在標(biāo)識(shí)符之后的一個(gè)字節(jié)是版本號(hào).這個(gè)版本號(hào)不是一個(gè)ASCII字符,而是一個(gè)8位的數(shù)字.例如,SWF4文件的版本號(hào)是0x04,不是ASCII字符”4(0x35)

 

 

The FileLength field is the total length of the SWF file including the header. If this is an

uncompressed SWF (FWS signature), the FileLength field should exactly match the file size. If

this is a compressed SWF (CWS signature), the FileLength field indicates the total length of the

file after decompression, and thus will generally not match the file size. Having the uncompressed size available can make the decompression process more efficient.

 

 

 

文件長(zhǎng)度字段代表包括文件頭整個(gè)文件的總長(zhǎng)度.如果是一個(gè)未壓縮的SWF文件(FWS標(biāo)識(shí)符),文件長(zhǎng)度字段表示文件的精確大小;如果是一個(gè)壓縮的SWF文件(CWS標(biāo)識(shí)),文件長(zhǎng)度字段表示解壓后文件的大小,這樣一般就不是實(shí)際文件的大小了.讓未壓縮(解壓后)的大小可見(jiàn),則可以使解壓過(guò)程更加有效.

 

 

The FrameSize field defines the width and height of the movie. This is stored as a RECT

structure, meaning that its size may vary according to the number of bits needed to encode the

coordinates. The FrameSize RECT always has Xmin and Ymin of 0; the Xmax and Ymax

members define the width and height (see Using Bit Values).

 

 

 

幀大小字段表示影片的寬度和高度.它存在一個(gè)RECT結(jié)構(gòu)中,表示它的大小可以根據(jù)坐標(biāo)(四個(gè)點(diǎn)的坐標(biāo))數(shù)值的變化而變化.文件大小RECT通常是這樣的形式:XminYmin成員都為0XmaxYmax成員聲明寬度和高度.(參考Using Bit Values一節(jié))

 

 

The FrameRate is the desired playback rate in frames per second. This rate is not guaranteed if the

SWF file contains streaming sound data, or Flash Player is running on a slow CPU.

 

 

幀速率表示理想的每秒播放幀數(shù).如果SWF文件包含聲音流數(shù)據(jù),或者Flash播放器運(yùn)行在一個(gè)慢的CPU上,這個(gè)速率是不能保證的.

 

 

The FrameCount is the total number of frames in this SWF movie.

幀數(shù)表示SWF影片總的幀數(shù)目.

SWF File Structure

 

SWF文件結(jié)構(gòu)

 

Following the header is a series of tagged data blocks. All tags share a common format, so any

program parsing a SWF file can skip over blocks it does not understand. Data inside the block can

point to offsets within the block, but can never point to an offset in another block. This enables

tags to be removed, inserted, or modified by tools that process a SWF file.

 

在文件頭后面的是一些標(biāo)簽化的數(shù)據(jù)塊。所有的標(biāo)簽都是用一種通用格式。所以任何程序在解析一個(gè)SWF文件時(shí),都可以跳過(guò)那些還不明確的塊。在每個(gè)塊中的數(shù)據(jù)可以指向這個(gè)塊中的偏移量,但絕不能指向另外一個(gè)塊的偏移量。這樣,在用工具處理SWF文件的時(shí)候就任意可以刪除、插入和修改(SWF文件不會(huì)被破壞)

 

 

 

Tag Format

 

標(biāo)簽格式

08ac4758c64f4f929e035063b98e5d54.gif

 

Each tag begins with a tag type and a length. There are two tag header formats, short and long.

Short tag headers are used for tags with 62 bytes of data or less. Long tag headers can be used for

any tag size up to 4GB, far larger than is presently practical.

 

每個(gè)標(biāo)簽都以標(biāo)簽類型和長(zhǎng)度開(kāi)頭。標(biāo)簽頭格式有兩種,短型和長(zhǎng)型。短型標(biāo)簽頭用在數(shù)據(jù)不超過(guò)62字節(jié)的標(biāo)簽;長(zhǎng)型標(biāo)簽頭則可用在比實(shí)際用到的大小大得多的4GB之內(nèi)的任何標(biāo)簽中。

 

 

 

標(biāo)簽頭(短型)

 

字段                                         類型                        備注

 

TagCodeAndLength(標(biāo)簽類型和長(zhǎng)度)          16                  10位:標(biāo)簽類型

                                                                  6位:標(biāo)簽長(zhǎng)度

 

 

 

 

 

Note: The TagCodeAndLength field is a two-byte word, not a bitfield of 10 bits followed by a bitfield

 

of 6 bits. The little-endian byte ordering of SWF makes these two layouts different.

 

The length specified in the TagCodeAndLength field does not include the RECORDHEADER

 

that starts a tag.

 

TagCodeAndLength字段是一個(gè)占兩字節(jié)的字,而不是一個(gè)10位二進(jìn)制字段后面跟著6位二進(jìn)制字段。

 

If the tag is 63 bytes or longer, it is stored in a long tag header. The long tag header consists of a

 

short tag header with a length of 0x3f, followed by a 32-bit length.

 

假如標(biāo)簽是63字節(jié)或者更長(zhǎng),它具有長(zhǎng)型標(biāo)簽頭。長(zhǎng)型標(biāo)簽頭就好像一個(gè)以0x3f開(kāi)頭的短型標(biāo)簽頭,后面跟著一個(gè)32位長(zhǎng)度。

 

標(biāo)簽頭(長(zhǎng)型)

 

字段                                     類型                     備注

 

TagCodeAndLength(標(biāo)簽類型和長(zhǎng)度)      16               標(biāo)簽類型和標(biāo)簽長(zhǎng)度(這兒的標(biāo)簽長(zhǎng)度不是真實(shí)                                                               )合起來(lái)是0x3f,包裝起來(lái)像短型標(biāo)簽頭

 

長(zhǎng)度                                   32                  標(biāo)簽長(zhǎng)度

 

 

 

 

 

Definition and Control Tags

 

定義型標(biāo)簽和控制型標(biāo)簽

 

There are two categories of tags in SWF:

 

Definition Tags These tags define the content of the SWF movie – the shapes, text, bitmaps,

 

sounds, and so on. Each definition tag assigns a unique ID called a character ID to the content it

 

defines. Flash Player then stores the character in a repository called the dictionary. Definition

 

tags, by themselves, do not cause anything to be rendered.

 

Control Tags These tags create and manipulate rendered instances of characters in the

 

dictionary, and control the flow of the movie.

 

SWF有兩種類類型的標(biāo)簽:

 

定義型標(biāo)簽:這類標(biāo)簽定義SWF影片的內(nèi)容,如各種形狀,文字,位圖,聲音等等。每個(gè)定義型標(biāo)簽在內(nèi)容被定義都分配了一個(gè)唯一的標(biāo)識(shí)號(hào)給它,這叫做角色標(biāo)識(shí)(character ID).flash播放器則把這些角色放到一個(gè)存儲(chǔ)空間里面,這個(gè)存儲(chǔ)空間我們一般叫它字典。用定義型tag是不會(huì)繪制任何圖形的,不會(huì)產(chǎn)生任何動(dòng)畫(huà)的。

 

控制型標(biāo)簽:這類標(biāo)簽用來(lái)產(chǎn)生和操作字典中的角色實(shí)例的渲染,并且控制影片的流程。

 

Tag Ordering in SWF

 

SWF標(biāo)簽的排序

 

Generally speaking, tags in a SWF can occur in any order. However, there are a few rules that

 

must be observed:

 

1 A tag should only depend on tags that come before it. A tag should never depend on a tag that

 

comes later in the file.

 

2 A definition tag that defines a character must occur before any control tag that refers to that

 

character.

 

3 Streaming sound tags must be in order. Out-of-order streaming sound tags will result in the

 

sound being played out of order.

 

4 The End tag is always the last tag in the SWF file.

 

總的來(lái)說(shuō),標(biāo)簽可以出現(xiàn)任何情況的排序方法,但也不是隨便亂排, 它遵循一些規(guī)則:

 

1.一個(gè)標(biāo)簽只能依靠在它之前的標(biāo)簽,不能依靠在它之后的標(biāo)簽.

 

2.一個(gè)定義了角色的定義型標(biāo)簽必須在引用這個(gè)角色的控制型標(biāo)簽之前。

 

3.流媒體標(biāo)簽必須有順序,沒(méi)有順序的流媒體播放起來(lái)也是沒(méi)有順序的

 

4.結(jié)束標(biāo)簽(tag)應(yīng)該在SWF文件的最后。

 

 

 

The Dictionary

 

字典

 

The dictionary is a repository of characters that have been defined, and are available for use by Control Tags. The process of building and using the dictionary is as follows: 1 A definition tag defines some content, such as a shape, font, bitmap, or sound. 2 A unique CharacterId is assigned to the content by the definition tag. 3 The content is saved in the dictionary under the CharacterId. 4 A control tag retrieves the content from the dictionary using the CharacterId, and performs some action on the content, such as displaying a shape, or playing a sound. Every definition tag must specify a unique ID. Duplicate IDs are not allowed. Typically, the first CharacterId is 1, the second CharacterId is 2, and so on. Character zero is special and considered a null character. Control tags are not the only tags that reference the dictionary. Definition tags can use characters from the dictionary to define more complex characters. For example, the DefineButton and DefineSprite tags refer to other characters to define their contents. The DefineText tag can refer to font characters to select different fonts for the text.

 

字典是已經(jīng)定義好的所有角色的倉(cāng)庫(kù),并且可以通過(guò)控制型標(biāo)簽來(lái)使用它。建立和使用字典的過(guò)程是以下這樣的:1.一個(gè)定義型標(biāo)簽定義了一些內(nèi)容,如形體,字體,位圖或者聲音。2.定義型標(biāo)簽給該內(nèi)容賦上一個(gè)唯一的角色標(biāo)識(shí)(CharacterID)。3.依據(jù)角色標(biāo)識(shí)把內(nèi)容存到字典中。4. 一個(gè)控制型標(biāo)簽根據(jù)角色標(biāo)識(shí)從字典中找出相應(yīng)的內(nèi)容,然后給這個(gè)內(nèi)容執(zhí)行一些動(dòng)作,比如顯示一個(gè)形體,或者播放一個(gè)聲音。每個(gè)控制型標(biāo)簽都只指定一個(gè)唯一的標(biāo)識(shí)。相同的標(biāo)識(shí)是不允許的。舉個(gè)象征性的例子,第一個(gè)角色的標(biāo)識(shí)是1,第二個(gè)角色的標(biāo)識(shí)是2,依次類推。角色標(biāo)識(shí)為0的是一個(gè)特殊的標(biāo)識(shí),被看作是空角色??刂菩蜆?biāo)簽并不是唯一指向字典的標(biāo)簽。定義型標(biāo)簽也可以指向多個(gè)角色來(lái)定義一些更復(fù)雜的角色。例如,定義按鈕(DefineButton)和定義精靈(DefineSprite)標(biāo)簽都是根據(jù)其它角色來(lái)定義它們的內(nèi)容的。定義文字(DefineText)標(biāo)簽可以指向字體角色來(lái)為文字選擇不同的字體。

 

附:Sprite一般都翻譯為精靈,解釋可以查相關(guān)的書(shū)籍,flash ,director等都有這個(gè)概念。

 

The following diagram illustrates a typical interaction between definition tags, control tags and the dictionary:

 

以下的圖示展示了定義型標(biāo)簽,控制型標(biāo)簽和字典之間的一個(gè)象征性的交互:

image002.gif

 

 

Processing a SWF File

 

處理一個(gè)SWF文件

 

Flash Player processes all the tags in a SWF file until a ShowFrame tag is encountered. At this point, the display list is copied to the screen and Flash Player is idle until it is time to process the next frame. The contents of the first frame are the cumulative effect of performing all the control tag operations before the first ShowFrame tag. The contents of the second frame are the cumulative effect of performing all the control tag operations from the beginning of the file to the second ShowFrame tag, and so on.

 

Flash播放器在一個(gè)顯示幀標(biāo)簽到來(lái)之前會(huì)處理顯示幀標(biāo)簽之前SWF文件的所有標(biāo)簽。在這個(gè)時(shí)候,播放列表被復(fù)制到屏幕上面,與此同時(shí)Flash播放器在處理下一幀之前是空閑的。第一幀所顯示的內(nèi)容,是在第一個(gè)顯示幀標(biāo)簽之前的所有控制型標(biāo)簽操作產(chǎn)生的累積效果。第二幀所顯示的內(nèi)容,是從文件開(kāi)始到第二個(gè)顯示幀標(biāo)簽所有控制型標(biāo)簽操作產(chǎn)生的累積效果。以此類推。

 

File Compression Strategy

 

文件壓縮策略

 

Since SWF files are frequently delivered over a network connection, it is important that they be as

 

compact as possible. There are several techniques that are used to accomplish this. Here are some

 

things to look out for:

 

既然SWF文件在網(wǎng)絡(luò)連接中傳輸?shù)梅浅nl繁,那它們當(dāng)然是越緊湊越好。有很多技術(shù)可以實(shí)現(xiàn)這點(diǎn)。這是我們選中的幾種有效的策略:

 

 

 

Reuse The structure of the character dictionary makes it very easy to reuse elements in a SWF

file. For example, a shape, button, sound, font, or bitmap can be stored in a file once and

referenced many times.

 

重用 角色字典的結(jié)構(gòu)使得重用SWF文件元素非常容易。例如,一個(gè)形體、按鈕、聲音、字體或者位圖,可以在文件中只存一次,但用到很多次。

 

 

 

Compression Shapes are compressed using a very efficient delta encoding scheme, often the

first coordinate of a line is assumed to be the last coordinate of the previous one. Distances are

also often expressed relative to the last position.

 

壓縮 形體使用了非常有效的差值編碼方法來(lái)壓縮,經(jīng)常直線的開(kāi)始坐標(biāo)是上一條直線的最終坐標(biāo)。距離經(jīng)常由上一個(gè)位置的坐標(biāo)來(lái)表達(dá)。

 

 

 

Default values Some structures like matrices and color transforms have common fields that are

used more often than others. For example, for a matrix, the most common field is the translation

field. Scaling and rotation are less common. Therefore if the scaling field is not present, it is

assumed to be 100%. If the rotation field is not present, it is assumed that there is no rotation.

This use of default values helps to minimize file sizes.

 

默認(rèn)值 有一些結(jié)構(gòu)像矩陣和色彩變換都有一些共同的屬性用得比其它的多。比如一個(gè)矩陣,最常用的屬性就是平移屬性,而縮放與旋轉(zhuǎn)則用得相對(duì)少點(diǎn)。因此如果沒(méi)有定義縮放屬性,就假定它的值為100%,如果沒(méi)有定義旋轉(zhuǎn)屬性,就假定它的值為沒(méi)有旋轉(zhuǎn)。使用默認(rèn)值可以使文件大小最小化。

 

Change Encoding As a rule, SWF files only store the changes between states. This is reflected

in shape data structures and in the place/move/remove model used by the display list.

 

變化編碼 作為一種規(guī)則,SWF文件只存儲(chǔ)兩種狀態(tài)之間的變化。它由形體數(shù)據(jù)結(jié)構(gòu)和播放列表中使用的定位/移動(dòng)/移除模塊反映出來(lái)。

 

 

Shape Data Structure The shape data structure uses a unique structure to minimize the size of

shapes and to render anti-aliased shapes very efficiently on the screen.

 

形體數(shù)據(jù)結(jié)構(gòu) 形體數(shù)據(jù)結(jié)構(gòu)使用了一種獨(dú)特的結(jié)構(gòu),使得形體的文件大小最小化,并且使得形體在屏幕上的平滑抗鋸齒處理非常有效。

 

 

 

Summary

 

小結(jié)

 

A SWF file is made up of a header, followed by a number of tags. There are two types of tags,

 

Definition Tags and Control Tags. Definition Tags define the objects known as characters,

 

which are stored in the Dictionary. Control Tags manipulate characters, and control the flow

 

of the movie.

 

一個(gè)SWF文件是由一個(gè)文件頭,跟著一系列的標(biāo)簽組成的。標(biāo)簽類型有兩種:定義型標(biāo)簽和控制型標(biāo)簽。定義型標(biāo)簽把所有物體定義成一個(gè)個(gè)角色,這些角色存在字典里面??刂菩蜆?biāo)簽操作這些角色,并且控制影片的流程。

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多