6 #include "../gfxtools.h"
9 #include "renderpoly.h"
11 gfxline_t*mkstar(int x1, int y1, int x2, int y2)
13 gfxline_t*l=0,*line = 0;
15 for(x=x1;x<=x2;x+=50) {
16 l = rfx_calloc(sizeof(gfxline_t));
19 line = gfxline_append(line, l);
21 l = rfx_calloc(sizeof(gfxline_t));
23 l->x = x2-x;l->y = y2;
24 line = gfxline_append(line, l);
31 gfxline_t*box1 = gfxline_makerectangle(50,50,150,150);
32 // put box2 and box3 on top of each other *snicker*
33 gfxline_t*box2 = gfxline_makerectangle(100,100,200,200);
34 gfxline_t*box3 = gfxline_makerectangle(100,100,200,200);
35 gfxline_t*star = mkstar(50,50, 150,150);
37 b = gfxline_append(b, box1);
38 b = gfxline_append(b, box2);
39 b = gfxline_append(b, box3);
40 b = gfxline_append(b, star);
43 memset(&matrix, 0, sizeof(gfxmatrix_t));
45 matrix.m00=cos(ua);matrix.m10=sin(ua);
46 matrix.m01=-sin(ua);matrix.m11=cos(ua);
48 gfxline_transform(b, &matrix);
49 gfxpoly_t*poly = gfxpoly_fillToPoly(b, 0.05);
56 gfxpoly_process(poly, &windrule_evenodd);
59 int test_square(int width, int height, int num, double gridsize, char bitmaptest)
62 gfxline_t* line = malloc(sizeof(gfxline_t)*num);
64 line[t].type = t?gfx_lineTo:gfx_moveTo;
65 line[t].x = (lrand48()%width);
66 line[t].y = (lrand48()%height);
67 line[t].next = &line[t+1];
69 line[num-1].x = line[0].x;
70 line[num-1].y = line[0].y;
73 windrule_t*rule = &windrule_circular;
75 gfxpoly_t*poly = gfxpoly_fillToPoly(line, gridsize);
76 gfxpoly_t*poly2 = gfxpoly_process(poly, rule);
80 intbbox_t bbox = intbbox_new(0, 0, width, height);
81 unsigned char*bitmap1 = render_polygon(poly, &bbox, 1.0, rule);
82 unsigned char*bitmap2 = render_polygon(poly2, &bbox, 1.0, &windrule_evenodd);
83 if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) {
84 save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
85 assert(!"bitmaps don't match");
89 gfxpoly_destroy(poly);
90 gfxpoly_destroy(poly2);
95 test_square(400,400, 3, 0.05, 1);
99 test_square(400,400, 50, 0.05, 1);
100 test_square(200,3, 1000, 1.0, 0);
101 test_square(3,200, 1000, 1.0, 0);
102 test_square(10,10, 200, 1.0, 0);
106 #include "../rfxswf.h"
115 gfxline_t* line = malloc(sizeof(gfxline_t)*N*2);
117 line[i].type = i?gfx_lineTo:gfx_moveTo;
118 line[i].x = lrand48()%RANGE - RANGE/2;
119 line[i].y = lrand48()%RANGE - RANGE/2;
120 line[i].next = &line[i+1];
121 line[N*2-i-1].type = gfx_lineTo;
122 line[N*2-i-1].x = line[i].x;
123 line[N*2-i-1].y = line[i].y;
124 line[N*2-i-1].next = &line[N*2-i];
126 line[N*2-1].next = 0;
128 line[N-1].x = line[0].x;
129 line[N-1].y = line[0].y;
133 memset(&m, 0, sizeof(m));
136 memset(&swf, 0, sizeof(SWF));
137 swf.movieSize.xmax = RANGE*20*1.41;
138 swf.movieSize.ymax = RANGE*20*1.41;
140 swf.frameRate = 25*0x100;
141 TAG * tag = swf.firstTag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
148 m.m00 = cos(t*M_PI/180.0);
149 m.m01 = sin(t*M_PI/180.0);
150 m.m10 = -sin(t*M_PI/180.0);
151 m.m11 = cos(t*M_PI/180.0);
154 gfxline_t*l = gfxline_clone(line);
155 gfxline_transform(l, &m);
157 gfxpoly_t*poly = gfxpoly_fillToPoly(l, 0.05);
158 gfxpoly_t*poly2 = gfxpoly_process(poly, &windrule_circular);
160 tag = swf_InsertTag(tag, ST_DEFINESHAPE);
164 rgb.r = rgb.g = 0x00; rgb.b = 0xff;
166 int fs = swf_ShapeAddSolidFillStyle(s,&rgb);
167 int ls = swf_ShapeAddLineStyle(s,20,&rgb);
169 swf_SetRect(tag,&swf.movieSize);
170 swf_SetShapeHeader(tag,s);
174 swf_ShapeSetAll(tag,s,0,0,0,fs,0);
175 edge_t*e = poly2->edges;
177 swf_ShapeSetMove(tag, s, e->a.x, e->a.y);
178 swf_ShapeSetLine(tag, s, e->b.x - e->a.x, e->b.y - e->a.y);
182 swf_ShapeSetAll(tag,s,0,0,ls,0,0);
183 edge_t*e = poly2->edges;
185 swf_ShapeSetMove(tag, s, e->a.x, e->a.y);
186 swf_ShapeSetLine(tag, s, e->b.x - e->a.x, e->b.y - e->a.y);
188 swf_ShapeSetCircle(tag, s, e->a.x, e->a.y, 5*20, 5*20);
189 swf_ShapeSetCircle(tag, s, e->b.x, e->b.y, 5*20, 5*20);
194 swf_ShapeSetEnd(tag);
197 gfxpoly_destroy(poly);
198 gfxpoly_destroy(poly2);
203 tag = swf_InsertTag(tag,ST_REMOVEOBJECT2);
206 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
207 swf_ObjectPlace(tag,t+1,t+1,NULL,NULL,NULL);
209 tag = swf_InsertTag(tag, ST_SHOWFRAME);
211 tag = swf_InsertTag(tag, ST_END);
213 swf_SaveSWF(&swf, "test.swf");