~ubuntu-branches/ubuntu/maverick/mtasc/maverick

« back to all changes in this revision

Viewing changes to ocaml/swflib/swf.ml

  • Committer: Bazaar Package Importer
  • Author(s): Paul Wise
  • Date: 2006-03-25 17:15:45 UTC
  • Revision ID: james.westby@ubuntu.com-20060325171545-zjh6rxeqehxiv4v2
Tags: upstream-1.12
ImportĀ upstreamĀ versionĀ 1.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(*
 
2
 *  This file is part of SwfLib
 
3
 *  Copyright (c)2004 Nicolas Cannasse
 
4
 *
 
5
 *  This program is free software; you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation; either version 2 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *)
 
19
type float16 = int
 
20
 
 
21
type unknown = string
 
22
 
 
23
type action_count = int
 
24
 
 
25
type rgb = {
 
26
        cr : int;
 
27
        cg : int;
 
28
        cb : int;
 
29
}
 
30
 
 
31
type rgba = {
 
32
        r : int;
 
33
        g : int;
 
34
        b : int;
 
35
        a : int;
 
36
}
 
37
 
 
38
type color =
 
39
        | ColorRGB of rgb
 
40
        | ColorRGBA of rgba
 
41
 
 
42
type gradient =
 
43
        | GradientRGB of ((int * rgb) list * int)
 
44
        | GradientRGBA of ((int * rgba) list * int) 
 
45
 
 
46
type rect = {
 
47
        rect_nbits : int;
 
48
        left : int;
 
49
        right : int;
 
50
        top : int; 
 
51
        bottom : int;
 
52
}
 
53
 
 
54
type big_rect = {
 
55
        brect_nbits : int;
 
56
        bleft : int list;
 
57
        bright : int list;
 
58
        btop : int list; 
 
59
        bbottom : int list;
 
60
}
 
61
 
 
62
type matrix_part = {
 
63
        m_nbits : int;
 
64
        mx : int;
 
65
        my : int;
 
66
}
 
67
 
 
68
type matrix = {
 
69
        scale : matrix_part option;
 
70
        rotate : matrix_part option;
 
71
        trans : matrix_part;
 
72
}
 
73
 
 
74
type color_transform_alpha = {
 
75
        cxa_nbits : int;
 
76
        cxa_add : rgba option;
 
77
        cxa_mult : rgba option;
 
78
}
 
79
 
 
80
type function_decl = {
 
81
        f_name : string;
 
82
        f_args : string list;
 
83
        mutable f_codelen : action_count;
 
84
}
 
85
 
 
86
type func2_flags =
 
87
        | ThisRegister
 
88
        | ThisNoVar
 
89
        | ArgumentsRegister
 
90
        | ArgumentsNoVar
 
91
        | SuperRegister
 
92
        | SuperNoVar
 
93
        | RootRegister
 
94
        | ParentRegister
 
95
        | GlobalRegister
 
96
 
 
97
type function_decl2 = {
 
98
        f2_name : string;
 
99
        f2_flags : func2_flags list;
 
100
        f2_args : (int * string) list;
 
101
        mutable f2_nregs : int;
 
102
        mutable f2_codelen : action_count;
 
103
}
 
104
 
 
105
type try_style =
 
106
        | TryRegister of int
 
107
        | TryVariable of string
 
108
 
 
109
type try_block = {
 
110
        tr_style : try_style;
 
111
        mutable tr_trylen : action_count;
 
112
        mutable tr_catchlen : action_count option;
 
113
        mutable tr_finallylen : action_count option
 
114
}
 
115
 
 
116
type push_item =
 
117
        | PString of string
 
118
        | PFloat of int32
 
119
        | PNull
 
120
        | PUndefined
 
121
        | PReg of int
 
122
        | PBool of bool
 
123
        | PDouble of float
 
124
        | PInt of int32
 
125
        | PStack of int
 
126
        | PStack2 of int
 
127
 
 
128
type property =
 
129
        | PX
 
130
        | PY
 
131
        | PXScale
 
132
        | PYScale
 
133
        | PCurrentFrame
 
134
        | PTotalFrames
 
135
        | PAlpha
 
136
        | PVisible
 
137
        | PWidth
 
138
        | PHeight
 
139
        | PRotation
 
140
        | PTarget
 
141
        | PFramesLoaded
 
142
        | PName
 
143
        | PDropTarget
 
144
        | PUrl
 
145
        | PHighQuality
 
146
        | PFocusRect
 
147
        | PSoundBufTime
 
148
        | PQuality
 
149
        | PXMouse
 
150
        | PYMouse
 
151
 
 
152
type action =
 
153
        | AEnd
 
154
 
 
155
        | ANextFrame
 
156
        | APrevFrame
 
157
        | APlay
 
158
        | AStop
 
159
        | AToggleHighQuality
 
160
        | AStopSounds
 
161
        | AAddNum
 
162
        | ASubtract
 
163
        | AMultiply
 
164
        | ADivide
 
165
        | ACompareNum
 
166
        | AEqualNum
 
167
        | ALogicalAnd
 
168
        | ALogicalOr
 
169
        | ANot
 
170
        | AStringEqual
 
171
        | AStringLength
 
172
        | ASubString
 
173
        | APop
 
174
        | AToInt
 
175
        | AEval
 
176
        | ASet
 
177
        | ATellTarget
 
178
        | AStringAdd
 
179
        | AGetProperty
 
180
        | ASetProperty
 
181
        | ADuplicateMC
 
182
        | ARemoveMC
 
183
        | ATrace
 
184
        | AStartDrag
 
185
        | AStopDrag
 
186
        | AThrow
 
187
        | ACast
 
188
        | AImplements
 
189
        | AFSCommand2
 
190
        | ARandom
 
191
        | AMBStringLength
 
192
        | AOrd
 
193
        | AChr
 
194
        | AGetTimer
 
195
        | AMBStringSub
 
196
        | AMBOrd
 
197
        | AMBChr
 
198
        | ADeleteObj
 
199
        | ADelete
 
200
        | ALocalAssign
 
201
        | ACall
 
202
        | AReturn
 
203
        | AMod
 
204
        | ANew
 
205
        | ALocalVar
 
206
        | AInitArray
 
207
        | AObject
 
208
        | ATypeOf
 
209
        | ATargetPath
 
210
        | AEnum
 
211
        | AAdd
 
212
        | ACompare
 
213
        | AEqual
 
214
        | AToNumber
 
215
        | AToString
 
216
        | ADup
 
217
        | ASwap
 
218
        | AObjGet
 
219
        | AObjSet
 
220
        | AIncrement
 
221
        | ADecrement
 
222
        | AObjCall
 
223
        | ANewMethod
 
224
        | AInstanceOf
 
225
        | AEnum2
 
226
        | AAnd
 
227
        | AOr
 
228
        | AXor
 
229
        | AShl
 
230
        | AShr
 
231
        | AAsr
 
232
        | APhysEqual
 
233
        | AGreater
 
234
        | AStringGreater
 
235
        | AExtends
 
236
 
 
237
        | AGotoFrame of int
 
238
        | AGetURL of string * string
 
239
        | ASetReg of int
 
240
        | AStringPool of string list
 
241
        | AWaitForFrame of int * int
 
242
        | ASetTarget of string
 
243
        | AGotoLabel of string
 
244
        | AWaitForFrame2 of int
 
245
        | AFunction2 of function_decl2
 
246
        | ATry of try_block
 
247
        | AWith of int
 
248
        | APush of push_item list
 
249
        | AJump of action_count
 
250
        | AGetURL2 of int
 
251
        | AFunction of function_decl
 
252
        | ACondJump of action_count
 
253
        | ACallFrame (* no data *)
 
254
        | AGotoFrame2 of bool * int option
 
255
 
 
256
        | AUnknown of int * unknown
 
257
 
 
258
type actions = action DynArray.t
 
259
 
 
260
type header = {
 
261
        mutable h_version : int;
 
262
        mutable h_size : rect;
 
263
        mutable h_fps : float16;
 
264
        mutable h_frame_count : int; 
 
265
        mutable h_compressed : bool;
 
266
}
 
267
 
 
268
type export = {
 
269
        mutable exp_id : int;
 
270
        exp_name : string;
 
271
}
 
272
 
 
273
type do_init_action = {
 
274
        mutable dia_id : int;
 
275
        dia_actions : actions;
 
276
}
 
277
 
 
278
type sound = {
 
279
        mutable so_id : int;
 
280
        so_flags : int;
 
281
        so_samples : int;
 
282
        so_data : unknown;
 
283
}
 
284
 
 
285
type start_sound = {
 
286
        mutable sts_id : int;
 
287
        sts_data : unknown;
 
288
}
 
289
 
 
290
type sfs_bitmap = {
 
291
        sfb_repeat : bool;
 
292
        sfb_smooth : bool;
 
293
        mutable sfb_cid : int;
 
294
        sfb_mpos : matrix;
 
295
}
 
296
 
 
297
type shape_fill_style = 
 
298
        | SFSSolid of rgb
 
299
        | SFSSolid3 of rgba
 
300
        | SFSLinearGradient of matrix * gradient
 
301
        | SFSRadialGradient of matrix * gradient * int option
 
302
        | SFSBitmap of sfs_bitmap
 
303
 
 
304
type shape_line_style = {
 
305
        sls_width : int;
 
306
        sls_color : color;
 
307
        sls_unk : int option;
 
308
}
 
309
 
 
310
type shape_new_styles = {
 
311
        sns_fill_styles : shape_fill_style list;
 
312
        sns_line_styles : shape_line_style list;
 
313
        sns_nlbits : int;
 
314
        sns_nfbits : int;
 
315
}
 
316
 
 
317
type shape_change_style_record = {
 
318
        scsr_move : (int * int * int) option;
 
319
        scsr_fs0 : int option;
 
320
        scsr_fs1 : int option;
 
321
        scsr_ls : int option;
 
322
        scsr_new_styles : shape_new_styles option;
 
323
}
 
324
 
 
325
type shape_curved_edge_record = {
 
326
        scer_nbits : int;
 
327
        scer_cx : int;
 
328
        scer_cy : int;
 
329
        scer_ax : int;
 
330
        scer_ay : int;
 
331
}
 
332
 
 
333
type shape_straight_edge_record = {
 
334
        sser_nbits : int;
 
335
        sser_line : int option * int option;
 
336
}
 
337
 
 
338
type shape_record = 
 
339
        | SRStyleChange of shape_change_style_record
 
340
        | SRCurvedEdge of shape_curved_edge_record
 
341
        | SRStraightEdge of shape_straight_edge_record
 
342
 
 
343
type shape_records = {
 
344
        srs_nlbits : int;
 
345
        srs_nfbits : int;
 
346
        srs_records : shape_record list;
 
347
}
 
348
 
 
349
type shape_with_style = {
 
350
        sws_fill_styles : shape_fill_style list;
 
351
        sws_line_styles : shape_line_style list;
 
352
        sws_records : shape_records;
 
353
}
 
354
 
 
355
type shape = {
 
356
        mutable sh_id : int;
 
357
        sh_bounds : rect;
 
358
        sh_bounds2 : (rect * int) option;
 
359
        sh_style : shape_with_style;
 
360
}
 
361
 
 
362
type filter_gradient = {
 
363
        fgr_colors : (rgba * int) list;
 
364
        fgr_data : unknown;
 
365
}
 
366
 
 
367
type filter =
 
368
        | FDropShadow of unknown
 
369
        | FBlur of unknown
 
370
        | FGlow of unknown
 
371
        | FBevel of unknown
 
372
        | FGradientGlow of filter_gradient
 
373
        | FAdjustColor of unknown
 
374
        | FGradientBevel of filter_gradient
 
375
 
 
376
type bitmap_jpg = {
 
377
        mutable jpg_id : int;
 
378
        jpg_data : string;
 
379
}
 
380
 
 
381
type bitmap_jpg2 = {
 
382
        mutable jp2_id : int;
 
383
        jp2_table : string;
 
384
        jp2_data : string;
 
385
}
 
386
 
 
387
type bitmap_jpg3 = {
 
388
        mutable jp3_id : int;
 
389
        jp3_table : string;
 
390
        jp3_data : string;
 
391
        jp3_alpha_data : string;
 
392
}
 
393
 
 
394
type bitmap_lossless = {
 
395
        mutable bll_id : int;
 
396
        bll_format : int;
 
397
        bll_width : int;
 
398
        bll_height : int;
 
399
        bll_data : unknown;
 
400
}
 
401
 
 
402
type morph_shape = {
 
403
        mutable msh_id : int;
 
404
        msh_start_bounds : rect;
 
405
        msh_end_bounds : rect;
 
406
        msh_data : unknown;
 
407
}
 
408
 
 
409
type font2 = {
 
410
        mutable ft2_id : int;
 
411
        ft2_data : unknown;
 
412
}
 
413
 
 
414
type font3 = {
 
415
        mutable ft3_id : int;
 
416
        ft3_data : unknown;
 
417
}
 
418
 
 
419
type font_glyphs = {
 
420
        mutable fgl_id : int;
 
421
        fgl_data : unknown;
 
422
}
 
423
 
 
424
type text_glyph = {
 
425
        txg_index : int;
 
426
        txg_advanced : int;
 
427
}
 
428
 
 
429
type text_record = {
 
430
        mutable txr_font : (int * int) option;
 
431
        txr_color : color option;
 
432
        txr_dx : int option;
 
433
        txr_dy : int option;
 
434
        txr_glyphs : text_glyph list;
 
435
}
 
436
 
 
437
type text = {
 
438
        mutable txt_id : int;
 
439
        txt_bounds : big_rect;
 
440
        txt_matrix : matrix;
 
441
        txt_ngbits : int;
 
442
        txt_nabits : int;
 
443
        txt_records : text_record list;
 
444
}
 
445
 
 
446
type button_record = {
 
447
        btr_flags : int;
 
448
        mutable btr_cid : int;
 
449
        btr_depth : int;
 
450
        btr_mpos : matrix;
 
451
        btr_color : color_transform_alpha option;
 
452
}
 
453
 
 
454
type button_action = {
 
455
        bta_flags : int;
 
456
        bta_actions : actions;
 
457
}
 
458
 
 
459
type button2 = {
 
460
        mutable bt2_id : int;
 
461
        bt2_track_as_menu : bool;
 
462
        bt2_records : button_record list;
 
463
        bt2_actions : button_action list;
 
464
}
 
465
 
 
466
type remove_object = {
 
467
        mutable rmo_id : int;
 
468
        rmo_depth : int;
 
469
}
 
470
 
 
471
type edit_text_layout = {
 
472
        edtl_align : int;
 
473
        edtl_left_margin : int;
 
474
        edtl_right_margin : int;
 
475
        edtl_indent : int;
 
476
        edtl_leading : int;
 
477
}
 
478
 
 
479
type edit_text = {
 
480
        mutable edt_id : int;
 
481
        edt_bounds : rect;
 
482
        mutable edt_font : (int * int) option;
 
483
        edt_color : rgba option;
 
484
        edt_maxlen : int option;
 
485
        edt_layout : edit_text_layout option;
 
486
        edt_variable : string;
 
487
        edt_text : string option;
 
488
        edt_wordwrap : bool;
 
489
        edt_multiline : bool;
 
490
        edt_password : bool;
 
491
        edt_readonly : bool;
 
492
        edt_autosize : bool;
 
493
        edt_noselect : bool;
 
494
        edt_border : bool;
 
495
        edt_html : bool;
 
496
        edt_outlines : bool;
 
497
}
 
498
 
 
499
type tag_data =
 
500
        | TEnd
 
501
        | TShowFrame
 
502
        | TShape of shape
 
503
        | TRemoveObject of remove_object
 
504
        | TBitsJPEG of bitmap_jpg
 
505
        | TJPEGTables of string
 
506
        | TSetBgColor of rgb
 
507
        | TText of text
 
508
        | TDoAction of actions
 
509
        | TSound of sound
 
510
        | TStartSound of start_sound
 
511
        | TBitsLossless of bitmap_lossless
 
512
        | TBitsJPEG2 of bitmap_jpg2
 
513
        | TShape2 of shape
 
514
        | TProtect
 
515
        | TPlaceObject2 of place_object
 
516
        | TRemoveObject2 of int
 
517
        | TShape3 of shape
 
518
        | TText2 of text
 
519
        | TButton2 of button2
 
520
        | TBitsJPEG3 of bitmap_jpg3
 
521
        | TBitsLossless2 of bitmap_lossless
 
522
        | TEditText of edit_text
 
523
        | TClip of clip
 
524
        | TFrameLabel of string * char option
 
525
        | TSoundStreamHead2 of unknown
 
526
        | TMorphShape of morph_shape
 
527
        | TFont2 of font2
 
528
        | TExport of export list
 
529
        | TDoInitAction of do_init_action
 
530
        | TVideoStream of unknown
 
531
        | TVideoFrame of unknown
 
532
        | TFlash8 of unknown
 
533
        | TPlaceObject3 of place_object
 
534
        | TFontGlyphs of font_glyphs
 
535
        | TTextInfo of unknown
 
536
        | TFont3 of font3
 
537
        | TShape4 of shape
 
538
        | TShape5 of int * string
 
539
        | TUnknown of int * unknown
 
540
 
 
541
and tag = {
 
542
        mutable tid : int;
 
543
        mutable textended : bool;
 
544
        mutable tdata : tag_data;
 
545
}
 
546
 
 
547
and clip_event = {
 
548
        cle_events : int;
 
549
        cle_key : char option;
 
550
        cle_actions : actions;
 
551
}
 
552
 
 
553
and place_object = {
 
554
        po_depth : int;
 
555
        po_move : bool;
 
556
        mutable po_cid : int option;
 
557
        po_matrix : matrix option;
 
558
        po_color : color_transform_alpha option;
 
559
        po_ratio : float16 option;
 
560
        po_inst_name : string option;
 
561
        po_clip_depth : int option;
 
562
        po_events : clip_event list option;
 
563
        po_filters : filter list option;
 
564
        po_blend : int option;
 
565
        po_bcache : int option;
 
566
}
 
567
 
 
568
and clip = {
 
569
        mutable c_id : int;
 
570
        c_frame_count : int;
 
571
        c_tags : tag list;
 
572
}
 
573
 
 
574
type swf = header * tag list
 
575
 
 
576
let __deflate = ref (fun (_:unit IO.output) -> assert false)
 
577
let __inflate = ref (fun _ -> assert false)
 
578
let __parser = ref (fun _ -> assert false)
 
579
let __printer = ref (fun (_:unit IO.output) _ -> ())
 
580
 
 
581
exception Error of string
 
582
 
 
583
let error msg = raise (Error msg)
 
584
 
 
585
let warnings = ref true
 
586
 
 
587
let to_float16 f =
 
588
        let sign , f = (if f < 0. then true , 0. -. f else false , f) in
 
589
        let high = int_of_float f in
 
590
        let low = int_of_float ((f -. (float high)) *. 256.) in
 
591
        if high > 127 then failwith "to_float16";
 
592
        (high lsl 8) lor (if sign then low lor (1 lsl 15) else low)
 
593
 
 
594
let parse (ch : IO.input) =
 
595
        (!__parser ch : swf)
 
596
 
 
597
let write (ch : 'a IO.output) (data : swf) =
 
598
        !__printer (Obj.magic ch) data
 
599
 
 
600
let deflate (ch : 'a IO.output) =
 
601
        (Obj.magic (!__deflate (Obj.magic ch) : unit IO.output) : 'a IO.output)
 
602
 
 
603
let inflate (ch : IO.input) =
 
604
        (!__inflate ch : IO.input)