initial revision
[swftools.git] / src / swfrender.c
1 #include "../config.h"
2 #include <stdio.h>
3 #include <stdarg.h>
4 #include <assert.h>
5 #include <unistd.h>
6 #include <fcntl.h>
7 #include "../lib/rfxswf.h"
8
9 // swfrender.c
10
11 typedef struct RENDERBUF 
12 {
13     int width;
14     int height;
15     void*internal;
16 } RENDERBUF;
17
18 typedef struct heap_t
19 {
20 };
21
22 typedef struct _renderbuf_internal
23 {
24     heap_t* lines;
25 } renderbuf_internal;
26
27
28 void swf_RenderShape(RENDERBUF*dest, SHAPE2*shape)
29 {
30     renderbuf_internal*i = (renderbuf_internal)dest->internal;
31
32     SHAPELINE*line = shape->lines;
33     int x=0,y=0;
34
35     while(line)
36     {
37         if(line->type == moveTo) {
38             /* max 31 bits + sign */
39             x = line->x;
40             y = line->y;
41         } else if(line->type == lineTo) {
42             /* max 17 bits + sign */
43             int diffx = line->x - x;
44             int diffy = line->y - y;
45             int stepx,posx=0,posy=0;
46             if(diffy<0) {
47                 x = line->x;
48                 y = line->y;
49                 diffx = -diffx;
50                 diffy = -diffy;
51             }
52             stepx = (diffx*0x1000) / diffy;
53
54             while(posy<diffy) {
55                 int xx = x + ((posx)/0x1000);
56                 int yy = posy;
57                 // TODO: add pixel to dest
58                 posx+=stepx;
59                 posy++;
60             }
61
62             x = line->x;
63             y = line->y;
64         } else if(line->type == splineTo) {
65         }
66
67         line = line->next;
68     }
69 }
70
71 int main()
72 {
73     char*filename = "output.swf";
74     fi = open(filename, O_RDONLY|O_BINARY);
75     if (fi<=0) { 
76         fprintf(stderr,"Couldn't open %s\n", filename);
77         perror(argv[1]);
78         exit(1);
79     }
80
81     if(swf_ReadSWF(fi,&swf)<0) { 
82         fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",argv[1]);
83         close(fi);
84     }
85
86     tag = swf.firstTag;
87     while(tag) {
88         if(tag.id == ST_DEFINESHAPE3) {
89             SHAPE2 shape;
90             swf_ParseDefineShape(tag, &shape);
91             swf_RenderShape(tag, MATRIX m);
92         }
93     }
94 }