123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678 |
- (*
- * This file is part of SwfLib
- * Copyright (c)2004 Nicolas Cannasse
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- *)
- type float16 = int
- type unknown = string
- type binary = string
- type action_count = int
- type rgb = {
- cr : int;
- cg : int;
- cb : int;
- }
- type rgba = {
- r : int;
- g : int;
- b : int;
- a : int;
- }
- type color =
- | ColorRGB of rgb
- | ColorRGBA of rgba
- type gradient =
- | GradientRGB of ((int * rgb) list * int)
- | GradientRGBA of ((int * rgba) list * int)
- type rect = {
- rect_nbits : int;
- left : int;
- right : int;
- top : int;
- bottom : int;
- }
- type big_rect = {
- brect_nbits : int;
- bleft : int list;
- bright : int list;
- btop : int list;
- bbottom : int list;
- }
- type matrix_part = {
- m_nbits : int;
- mx : int;
- my : int;
- }
- type matrix = {
- scale : matrix_part option;
- rotate : matrix_part option;
- trans : matrix_part;
- }
- type color_transform_alpha = {
- cxa_nbits : int;
- cxa_add : rgba option;
- cxa_mult : rgba option;
- }
- type function_decl = {
- f_name : string;
- f_args : string list;
- mutable f_codelen : action_count;
- }
- type func2_flags =
- | ThisRegister
- | ThisNoVar
- | ArgumentsRegister
- | ArgumentsNoVar
- | SuperRegister
- | SuperNoVar
- | RootRegister
- | ParentRegister
- | GlobalRegister
- type function_decl2 = {
- f2_name : string;
- f2_flags : func2_flags list;
- f2_args : (int * string) list;
- mutable f2_nregs : int;
- mutable f2_codelen : action_count;
- }
- type try_style =
- | TryRegister of int
- | TryVariable of string
- type try_block = {
- tr_style : try_style;
- mutable tr_trylen : action_count;
- mutable tr_catchlen : action_count option;
- mutable tr_finallylen : action_count option
- }
- type push_item =
- | PString of string
- | PFloat of int32
- | PNull
- | PUndefined
- | PReg of int
- | PBool of bool
- | PDouble of float
- | PInt of int32
- | PStack of int
- | PStack2 of int
- type property =
- | PX
- | PY
- | PXScale
- | PYScale
- | PCurrentFrame
- | PTotalFrames
- | PAlpha
- | PVisible
- | PWidth
- | PHeight
- | PRotation
- | PTarget
- | PFramesLoaded
- | PName
- | PDropTarget
- | PUrl
- | PHighQuality
- | PFocusRect
- | PSoundBufTime
- | PQuality
- | PXMouse
- | PYMouse
- type action =
- | AEnd
- | ANextFrame
- | APrevFrame
- | APlay
- | AStop
- | AToggleHighQuality
- | AStopSounds
- | AAddNum
- | ASubtract
- | AMultiply
- | ADivide
- | ACompareNum
- | AEqualNum
- | ALogicalAnd
- | ALogicalOr
- | ANot
- | AStringEqual
- | AStringLength
- | ASubString
- | APop
- | AToInt
- | AEval
- | ASet
- | ATellTarget
- | AStringAdd
- | AGetProperty
- | ASetProperty
- | ADuplicateMC
- | ARemoveMC
- | ATrace
- | AStartDrag
- | AStopDrag
- | AThrow
- | ACast
- | AImplements
- | AFSCommand2
- | ARandom
- | AMBStringLength
- | AOrd
- | AChr
- | AGetTimer
- | AMBStringSub
- | AMBOrd
- | AMBChr
- | ADeleteObj
- | ADelete
- | ALocalAssign
- | ACall
- | AReturn
- | AMod
- | ANew
- | ALocalVar
- | AInitArray
- | AObject
- | ATypeOf
- | ATargetPath
- | AEnum
- | AAdd
- | ACompare
- | AEqual
- | AToNumber
- | AToString
- | ADup
- | ASwap
- | AObjGet
- | AObjSet
- | AIncrement
- | ADecrement
- | AObjCall
- | ANewMethod
- | AInstanceOf
- | AEnum2
- | AAnd
- | AOr
- | AXor
- | AShl
- | AShr
- | AAsr
- | APhysEqual
- | AGreater
- | AStringGreater
- | AExtends
- | AGotoFrame of int
- | AGetURL of string * string
- | ASetReg of int
- | AStringPool of string list
- | AWaitForFrame of int * int
- | ASetTarget of string
- | AGotoLabel of string
- | AWaitForFrame2 of int
- | AFunction2 of function_decl2
- | ATry of try_block
- | AWith of int
- | APush of push_item list
- | AJump of action_count
- | AGetURL2 of int
- | AFunction of function_decl
- | ACondJump of action_count
- | ACallFrame (* no data *)
- | AGotoFrame2 of bool * int option
- | AUnknown of int * unknown
- type actions = action DynArray.t
- type header = {
- mutable h_version : int;
- mutable h_size : rect;
- mutable h_fps : float16;
- mutable h_frame_count : int;
- mutable h_compressed : bool;
- }
- type export = {
- mutable exp_id : int;
- exp_name : string;
- }
- type import = {
- mutable imp_id : int;
- imp_name : string;
- }
- type do_init_action = {
- mutable dia_id : int;
- dia_actions : actions;
- }
- type sound = {
- mutable so_id : int;
- so_flags : int;
- so_samples : int;
- so_data : unknown;
- }
- type start_sound = {
- mutable sts_id : int;
- sts_data : unknown;
- }
- type sfs_bitmap = {
- sfb_repeat : bool;
- sfb_smooth : bool;
- mutable sfb_cid : int;
- sfb_mpos : matrix;
- }
- type shape_fill_style =
- | SFSSolid of rgb
- | SFSSolid3 of rgba
- | SFSLinearGradient of matrix * gradient
- | SFSRadialGradient of matrix * gradient * int option
- | SFSBitmap of sfs_bitmap
- type shape_line_style = {
- sls_width : int;
- sls_color : color;
- sls_flags : int option;
- sls_fill : shape_fill_style option;
- sls_miter : int option;
- }
- type shape_new_styles = {
- sns_fill_styles : shape_fill_style list;
- sns_line_styles : shape_line_style list;
- sns_nlbits : int;
- sns_nfbits : int;
- }
- type shape_change_style_record = {
- scsr_move : (int * int * int) option;
- scsr_fs0 : int option;
- scsr_fs1 : int option;
- scsr_ls : int option;
- scsr_new_styles : shape_new_styles option;
- }
- type shape_curved_edge_record = {
- scer_nbits : int;
- scer_cx : int;
- scer_cy : int;
- scer_ax : int;
- scer_ay : int;
- }
- type shape_straight_edge_record = {
- sser_nbits : int;
- sser_line : int option * int option;
- }
- type shape_record =
- | SRStyleChange of shape_change_style_record
- | SRCurvedEdge of shape_curved_edge_record
- | SRStraightEdge of shape_straight_edge_record
- type shape_records = {
- srs_nlbits : int;
- srs_nfbits : int;
- srs_records : shape_record list;
- }
- type shape_with_style = {
- sws_fill_styles : shape_fill_style list;
- sws_line_styles : shape_line_style list;
- sws_records : shape_records;
- }
- type shape = {
- mutable sh_id : int;
- sh_bounds : rect;
- sh_bounds2 : (rect * int) option;
- sh_style : shape_with_style;
- }
- type filter_gradient = {
- fgr_colors : (rgba * int) list;
- fgr_data : unknown;
- }
- type filter =
- | FDropShadow of unknown
- | FBlur of unknown
- | FGlow of unknown
- | FBevel of unknown
- | FGradientGlow of filter_gradient
- | FAdjustColor of unknown
- | FGradientBevel of filter_gradient
- type bitmap_jpg = {
- mutable jpg_id : int;
- jpg_data : binary;
- }
- type bitmap_data = {
- mutable bd_id : int;
- bd_table : binary option;
- bd_data : binary;
- bd_alpha : binary option;
- bd_deblock : int option;
- }
- type bitmap_lossless = {
- mutable bll_id : int;
- bll_format : int;
- bll_width : int;
- bll_height : int;
- bll_data : unknown;
- }
- type morph_shape = {
- mutable msh_id : int;
- msh_start_bounds : rect;
- msh_end_bounds : rect;
- msh_data : unknown;
- }
- type cid_data = {
- mutable cd_id : int;
- cd_data : binary;
- }
- type text_glyph = {
- txg_index : int;
- txg_advanced : int;
- }
- type text_record = {
- mutable txr_font : (int * int) option;
- txr_color : color option;
- txr_dx : int option;
- txr_dy : int option;
- txr_glyphs : text_glyph list;
- }
- type text = {
- mutable txt_id : int;
- txt_bounds : big_rect;
- txt_matrix : matrix;
- txt_ngbits : int;
- txt_nabits : int;
- txt_records : text_record list;
- }
- type button_record = {
- btr_flags : int;
- mutable btr_cid : int;
- btr_depth : int;
- btr_mpos : matrix;
- btr_color : color_transform_alpha option;
- btr_filters : filter list option;
- btr_blendmode : int option;
- }
- type button_action = {
- bta_flags : int;
- bta_actions : actions;
- }
- type button2 = {
- mutable bt2_id : int;
- bt2_track_as_menu : bool;
- bt2_records : button_record list;
- bt2_actions : button_action list;
- }
- type remove_object = {
- mutable rmo_id : int;
- rmo_depth : int;
- }
- type edit_text_layout = {
- edtl_align : int;
- edtl_left_margin : int;
- edtl_right_margin : int;
- edtl_indent : int;
- edtl_leading : int;
- }
- type edit_text = {
- mutable edt_id : int;
- edt_bounds : rect;
- mutable edt_font : (int * int) option;
- edt_color : rgba option;
- edt_maxlen : int option;
- edt_layout : edit_text_layout option;
- edt_variable : string;
- edt_text : string option;
- edt_wordwrap : bool;
- edt_multiline : bool;
- edt_password : bool;
- edt_readonly : bool;
- edt_autosize : bool;
- edt_noselect : bool;
- edt_border : bool;
- edt_html : bool;
- edt_outlines : bool;
- }
- type f9class = {
- mutable f9_cid : int option;
- f9_classname : string;
- }
- type files_attrib = {
- fa_network : bool;
- fa_as3 : bool;
- fa_metadata : bool;
- fa_gpu : bool;
- fa_direct_blt : bool;
- }
- type tag_data =
- | TEnd
- | TShowFrame
- | TShape of shape
- | TRemoveObject of remove_object
- | TBitsJPEG of bitmap_jpg
- | TJPEGTables of binary
- | TSetBgColor of rgb
- | TFont of cid_data
- | TText of text
- | TDoAction of actions
- | TFontInfo of cid_data
- | TSound of sound
- | TStartSound of start_sound
- | TBitsLossless of bitmap_lossless
- | TBitsJPEG2 of bitmap_data
- | TShape2 of shape
- | TProtect
- | TPlaceObject2 of place_object
- | TRemoveObject2 of int
- | TShape3 of shape
- | TText2 of text
- | TButton2 of button2
- | TBitsJPEG3 of bitmap_data
- | TBitsLossless2 of bitmap_lossless
- | TEditText of edit_text
- | TClip of clip
- | TProductInfo of unknown
- | TFrameLabel of string * char option
- | TSoundStreamHead2 of unknown
- | TMorphShape of morph_shape
- | TFont2 of cid_data
- | TExport of export list
- | TImport of string * import list
- | TDoInitAction of do_init_action
- | TVideoStream of cid_data
- | TVideoFrame of cid_data
- | TFontInfo2 of cid_data
- | TDebugID of unknown
- | TEnableDebugger2 of int * string
- | TScriptLimits of int * int
- | TFilesAttributes of files_attrib
- | TPlaceObject3 of place_object
- | TImport2 of string * import list
- | TFontAlignZones of cid_data
- | TCSMSettings of cid_data
- | TFont3 of cid_data
- | TF9Classes of f9class list
- | TMetaData of string
- | TScale9 of int * rect
- | TActionScript3 of (int * string) option * As3.as3_tag
- | TShape4 of shape
- | TMorphShape2 of morph_shape
- | TScenes of (int * string) list * (int * string) list
- | TBinaryData of int * binary
- | TBigBinaryData of int * binary list
- | TFontName of cid_data
- | TBitsJPEG4 of bitmap_data
- | TFont4 of cid_data
- | TUnknown of int * unknown
- and tag = {
- mutable tid : int;
- mutable textended : bool;
- mutable tdata : tag_data;
- }
- and clip_event = {
- cle_events : int;
- cle_key : char option;
- cle_actions : actions;
- }
- and place_object = {
- po_depth : int;
- po_move : bool;
- mutable po_cid : int option;
- po_matrix : matrix option;
- po_color : color_transform_alpha option;
- po_ratio : float16 option;
- po_inst_name : string option;
- po_clip_depth : int option;
- po_events : clip_event list option;
- po_filters : filter list option;
- po_blend : int option;
- po_bcache : int option;
- }
- and clip = {
- mutable c_id : int;
- c_frame_count : int;
- c_tags : tag list;
- }
- type font_language_code =
- | LCNone (*0*)
- | LCLatin (*1*)
- | LCJapanese (*2*)
- | LCKorean (*3*)
- | LCSimplifiedChinese (*4*)
- | LCTraditionalChinese (*5*)
- type font_glyph_data = {
- font_char_code: int;
- font_shape: shape_records;
- }
- type font_layout_glyph_data = {
- font_advance: int;
- font_bounds: rect;
- }
- type font_kerning_data = {
- font_char_code1: int;
- font_char_code2: int;
- font_adjust: int;
- }
- type font_layout_data = {
- font_ascent: int;
- font_descent: int;
- font_leading: int;
- font_glyphs_layout: font_layout_glyph_data array;
- font_kerning: font_kerning_data list;
- }
- type font2_data = {
- font_shift_jis: bool;
- font_is_small: bool;
- font_is_ansi: bool;
- font_wide_codes: bool;
- font_wide_offsets: bool;
- font_is_italic: bool;
- font_is_bold: bool;
- font_language: font_language_code;
- font_name: string;
- font_glyphs: font_glyph_data array;
- font_layout: font_layout_data;
- }
- type swf = header * tag list
- let __deflate = ref (fun (_:unit IO.output) -> assert false)
- let __inflate = ref (fun _ -> assert false)
- let __parser = ref (fun _ -> assert false)
- let __printer = ref (fun (_:unit IO.output) _ -> ())
- exception Error of string
- let error msg = raise (Error msg)
- let warnings = ref true
- let to_float16 f =
- let sign , f = (if f < 0. then true , 0. -. f else false , f) in
- let high = int_of_float f in
- let low = int_of_float ((f -. (float high)) *. 256.) in
- if high > 127 then failwith "to_float16";
- (high lsl 8) lor (if sign then low lor (1 lsl 15) else low)
- let parse (ch : IO.input) =
- (!__parser ch : swf)
- let write (ch : 'a IO.output) (data : swf) =
- !__printer (Obj.magic ch) data
- let deflate (ch : 'a IO.output) =
- (Obj.magic (!__deflate (Obj.magic ch) : unit IO.output) : 'a IO.output)
- let inflate (ch : IO.input) =
- (!__inflate ch : IO.input)
|