OSDN Git Service

401d9d0e676acc2663b42b2dc25de89321b67bf6
[happyabc/happyabc.git] / swflib / swfOut.ml
1 open Base
2 open SwfType
3
4 module type TagType = sig
5   type t
6   val to_base : t -> int * SwfBaseOut.s list
7 end
8
9 module Make(Tag : TagType) = struct
10   let char c =
11     `Ui8 (Char.code c)
12
13   let of_rect {top; bottom; left; right} =
14     `Rect(left,right,top,bottom)
15
16   let of_tag tag =
17     let make_type t size =
18       if size < 0x3F then
19         [`Ui16 ((t lsl 6) lor size)]
20       else
21         [`Ui16 ((t lsl 6) lor 0x3F); `Si32 (Int32.of_int size)] in
22     let t,data' =
23       Tag.to_base tag in
24       [`Size(make_type t, data')]
25
26   let to_base t : SwfBaseOut.t list = [
27     (* signature *)
28     char 'F'; char 'W'; char 'S';
29     (* version *)
30     `Ui8 t.version;
31     (* file length *)
32     `Ui32Size;
33     (* frame size *)
34     of_rect t.frame_size;
35     (* frame rate *)
36     `Fixed8 t.frame_rate;
37     (* frame count *)
38     `Ui16 t.frame_count
39   ] @ HList.concat_map of_tag t.tags
40
41 end