made gfxpoly_check test for correct circular filling
[swftools.git] / lib / gfxpoly / test.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <memory.h>
4 #include <math.h>
5 #include "../gfxtools.h"
6 #include "poly.h"
7 #include "convert.h"
8 #include "renderpoly.h"
9 #include "stroke.h"
10
11 gfxline_t*mkstar(int x1, int y1, int x2, int y2)
12 {
13     gfxline_t*l=0,*line = 0;
14     int x;
15     for(x=x1;x<=x2;x+=50) {
16         l = rfx_calloc(sizeof(gfxline_t));
17         l->type = gfx_moveTo;
18         l->x = x;l->y = y1;
19         line = gfxline_append(line, l);
20
21         l = rfx_calloc(sizeof(gfxline_t));
22         l->type = gfx_lineTo;
23         l->x = x2-x;l->y = y2;
24         line = gfxline_append(line, l);
25     }
26     return line;
27 }
28
29 gfxline_t* mkrandomshape(int range, int n)
30 {
31     int i;
32     gfxline_t* line = malloc(sizeof(gfxline_t)*n);
33     for(i=0;i<n;i++) {
34         line[i].type = i?gfx_lineTo:gfx_moveTo;
35         line[i].x = lrand48()%range - range/2;
36         line[i].y = lrand48()%range - range/2;
37         line[i].next = &line[i+1];
38     }
39     line[n-1].x = line[0].x;
40     line[n-1].y = line[0].y;
41     line[n-1].next = 0;
42     return line;
43 }
44
45 gfxline_t* mkchessboard()
46 {
47     gfxline_t*b = 0;
48     int x,y;
49     unsigned int r = 0;
50     int spacing = 20;
51
52     int num_caros = 40;
53     int l = 5;
54     char do_centerpiece=1;
55
56     //int num_caros = 4;
57     //int l=1;
58     //char do_centerpiece=0;
59
60     for(x=-l;x<=l;x++) 
61     for(y=-l;y<=l;y++) {
62         /* pseudo random */ 
63         r = crc32_add_byte(r, x);r = crc32_add_byte(r, y);
64         if(r&1) {
65             gfxline_t*box;
66             if(r&2) {
67                 box = gfxline_makerectangle(x*spacing,y*spacing,(x+1)*spacing,(y+1)*spacing);
68             } else {
69                 box = gfxline_makerectangle((x+1)*spacing,y*spacing,x*spacing,(y+1)*spacing);
70             }
71             b = gfxline_append(b, box);
72         }
73     }
74
75     int t;
76     for(t=0;t<num_caros;t++) {
77         r = crc32_add_byte(r, t);
78         int x=(r%10-5)*spacing;
79         int y=((r>>4)%10-5)*spacing;
80         int sizex = ((r>>8)%4)*spacing;
81         int sizey = sizex;
82         if(r&65536)
83             sizex = -sizex;
84         gfxline_t*l = malloc(sizeof(gfxline_t)*5);
85         l[0].type = gfx_moveTo;l[0].next = &l[1];
86         l[1].type = gfx_lineTo;l[1].next = &l[2];
87         l[2].type = gfx_lineTo;l[2].next = &l[3];
88         l[3].type = gfx_lineTo;l[3].next = &l[4];
89         l[4].type = gfx_lineTo;l[4].next = 0;
90         l[0].x = x;
91         l[0].y = y-sizey;
92         l[1].x = x+sizex;
93         l[1].y = y;
94         l[2].x = x;
95         l[2].y = y+sizey;
96         l[3].x = x-sizex;
97         l[3].y = y;
98         l[4].x = x;
99         l[4].y = y-sizey;
100         gfxline_append(b, l);
101     }
102     if(do_centerpiece) {
103         for(t=0;t<5;t++) {
104             gfxline_t*l = gfxline_makerectangle(-9*spacing,-10,9*spacing,10);
105             gfxmatrix_t matrix;
106             memset(&matrix, 0, sizeof(gfxmatrix_t));
107             double ua=t*0.43;
108             matrix.m00=cos(ua);matrix.m10=sin(ua);
109             matrix.m01=-sin(ua);matrix.m11=cos(ua);
110             gfxline_transform(l, &matrix);
111             gfxline_append(b, l);
112         }
113         gfxline_append(b, gfxline_makecircle(100,100,100,100));
114     }
115     return b;
116 }
117
118 gfxline_t* make_circles(int n)
119 {
120     gfxline_t*b = 0;
121     unsigned int c = 0;
122     int t;
123     for(t=0;t<n;t++) {
124         c = crc32_add_byte(c, t);
125         int x = c%200;
126         c = crc32_add_byte(c, t);
127         int y = c%200;;
128         c = crc32_add_byte(c, t^0x55);
129         int r = c%100;
130         gfxline_t*c = gfxline_makecircle(x,y,r,r);
131         b = gfxline_append(b, c);
132         //b = gfxline_append(b, gfxline_makerectangle(10,10,100,100));
133     }
134     return b;
135 }
136
137 static windcontext_t onepolygon = {1};
138 static windcontext_t twopolygons = {2};
139
140 int test_speed()
141 {
142     //gfxline_t* b = mkchessboard();
143     //gfxline_t* b = mkrandomshape(100,7);
144     gfxline_t* b = make_circles(30);
145
146     gfxmatrix_t m;
147     memset(&m, 0, sizeof(gfxmatrix_t));
148     int t;
149     for(t=0;t<360;t++) {
150         printf("%d\n", t);
151         m.m00 = cos(t*M_PI/180.0);
152         m.m01 = sin(t*M_PI/180.0);
153         m.m10 = -sin(t*M_PI/180.0);
154         m.m11 = cos(t*M_PI/180.0);
155         m.tx = 400*1.41/2;
156         m.ty = 400*1.41/2;
157         gfxline_t*l = gfxline_clone(b);
158         gfxline_transform(l, &m);
159         gfxpoly_t*poly = gfxpoly_from_fill(b, 0.05);
160
161         gfxpoly_t*poly2 = gfxpoly_process(poly, 0, &windrule_evenodd, &onepolygon);
162         gfxpoly_destroy(poly);
163         gfxpoly_destroy(poly2);
164         gfxline_free(l);
165     }
166     gfxline_free(b);
167 }
168
169 int test0(int argn, char*argv[])
170 {
171     gfxline_t*box1 = gfxline_makerectangle(-100,-100,100,100);
172     gfxline_t*box2 = gfxline_makerectangle(-100,-100,100,100);
173     gfxline_t*box3 = gfxline_makerectangle(-100,-100,100,100);
174     //gfxline_append(box2, box3);
175
176     gfxpoly_check(gfxpoly_from_stroke(box1, 2.0, gfx_capRound, gfx_joinRound, 0, 0.05), 1);
177
178     gfxmatrix_t matrix;
179     memset(&matrix, 0, sizeof(gfxmatrix_t));
180     double ua=M_PI/4;
181     matrix.m00=cos(ua);matrix.m10=sin(ua);
182     matrix.m01=-sin(ua);matrix.m11=cos(ua);
183     gfxline_transform(box1, &matrix);
184     
185     //gfxline_t*b = 0;
186     //b = gfxline_append(b, box1);
187     //b = gfxline_append(b, box2);
188     //gfxline_dump(b, stderr, "");
189
190     gfxpoly_t*poly1 = gfxpoly_from_fill(box1, 0.05);
191     gfxpoly_t*poly2 = gfxpoly_from_fill(box2, 0.05);
192     
193     gfxline_free(box1);
194     gfxline_free(box2);
195     
196     //gfxpoly_t*poly3 = gfxpoly_process(poly1, poly2, &windrule_intersect, &twopolygons);
197     gfxpoly_t*poly3 = gfxpoly_process(poly1, poly2, &windrule_intersect, &twopolygons);
198     gfxpoly_dump(poly3);
199     
200     gfxline_t*line = gfxline_from_gfxpoly(poly3);
201
202     gfxline_dump(line, stdout, "");
203     gfxline_free(line);
204     gfxpoly_destroy(poly1);
205     gfxpoly_destroy(poly2);
206     gfxpoly_destroy(poly3);
207 }
208
209
210 int test1(int argn, char*argv[])
211 {
212     gfxline_t*box1 = gfxline_makerectangle(50,50,150,150);
213     gfxline_t*box2 = gfxline_makerectangle(100,100,200,200);
214     gfxline_t*box3 = gfxline_makerectangle(200,100,300,200);
215     gfxline_t*box4 = gfxline_makerectangle(300,200,400,400);
216     gfxline_t* board = mkchessboard();
217     gfxline_t*star = mkstar(50,50, 150,150);
218     gfxline_t*b = 0;
219     b = gfxline_append(b, box1);
220     b = gfxline_append(b, box2);
221     b = gfxline_append(b, box3);
222     b = gfxline_append(b, box4);
223
224     gfxmatrix_t matrix;
225     memset(&matrix, 0, sizeof(gfxmatrix_t));
226     matrix.m00 = 1.0;
227     matrix.m11 = 1.0;
228     matrix.tx = 200;
229     matrix.ty = 200;
230     gfxline_transform(board, &matrix);
231     b = gfxline_append(b, board);
232
233     //gfxline_transform(b, &matrix);
234
235     //gfxline_dump(b, stderr, "");
236     gfxpoly_t*poly = gfxpoly_from_fill(b, 0.05);
237     
238     gfxline_free(box1);
239     gfxline_free(box2);
240     gfxline_free(box3);
241     gfxline_free(star);
242
243     //gfxpoly_dump(poly);
244     gfxpoly_t*poly2 = gfxpoly_process(poly, 0, &windrule_evenodd, &onepolygon);
245     //gfxpoly_dump(poly2);
246     gfxpoly_save_arrows(poly2, "test.ps");
247     gfxpoly_destroy(poly);
248     gfxpoly_destroy(poly2);
249 }
250
251 int test_square(int width, int height, int num, double gridsize, char bitmaptest)
252 {
253     int t;
254     gfxline_t* line = malloc(sizeof(gfxline_t)*num);
255     for(t=0;t<num;t++) {
256         line[t].type = t?gfx_lineTo:gfx_moveTo;
257         line[t].x = (lrand48()%width);
258         line[t].y = (lrand48()%height);
259         line[t].next = &line[t+1];
260     }
261     line[num-1].x = line[0].x;
262     line[num-1].y = line[0].y;
263     line[num-1].next = 0;
264
265     gfxpoly_t*poly1 = gfxpoly_from_fill(line, gridsize);
266     gfxline_free(line);
267
268     windrule_t*rule = &windrule_circular;
269     gfxpoly_t*poly2 = gfxpoly_process(poly1, 0, rule, &onepolygon);
270     if(bitmaptest) {
271         intbbox_t bbox = intbbox_new(0, 0, width, height);
272         unsigned char*bitmap1 = render_polygon(poly1, &bbox, 1.0, rule, &onepolygon);
273         assert(bitmap_ok(&bbox, bitmap1));
274         unsigned char*bitmap2 = render_polygon(poly2, &bbox, 1.0, &windrule_evenodd, &onepolygon);
275         assert(bitmap_ok(&bbox, bitmap2));
276         if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) {
277             save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
278             assert(!"bitmaps don't match");
279         }
280     }
281     gfxpoly_destroy(poly1);
282     gfxpoly_destroy(poly2);
283 }
284
285 int test2(int argn, char*argv[])
286 {
287     test_square(400,400, 3, 0.05, 1);
288
289     int t;
290     for(t=0;t<400;t++) {
291         fprintf(stderr, "%d\n", t);
292         test_square(400,400, 50, 0.05, 1);
293         test_square(200,3, 1000, 1.0, 0);
294         test_square(3,200, 1000, 1.0, 0);
295         test_square(10,10, 200, 1.0, 0);
296     }
297 }
298
299 #include "../rfxswf.h"
300 void test3(int argn, char*argv[])
301 {
302 #undef N
303 #undef RANGE
304 #define N 100
305 #define RANGE 400
306
307     //gfxline_t*line = mkrandomshape(RANGE, N);
308     //windrule_t*rule = &windrule_circular;
309     //gfxline_t*line = mkchessboard();
310     gfxline_t*line = make_circles(30);
311     windrule_t*rule = &windrule_evenodd;
312     //windrule_t*rule = &windrule_circular;
313
314     gfxmatrix_t m;
315     memset(&m, 0, sizeof(m));
316
317     SWF swf;
318     memset(&swf, 0, sizeof(SWF));
319     swf.movieSize.xmax = RANGE*20*1.41;
320     swf.movieSize.ymax = RANGE*20*1.41;
321     swf.fileVersion = 9;
322     swf.frameRate = 25*0x100;
323     TAG * tag = swf.firstTag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
324     swf_SetU8(tag, 0);
325     swf_SetU8(tag, 0);
326     swf_SetU8(tag, 0);
327
328     int t;
329     for(t=0;t<360;t++) {
330         fprintf(stderr, "%d\n", t);
331         m.m00 = cos(t*M_PI/180.0);
332         m.m01 = sin(t*M_PI/180.0);
333         m.m10 = -sin(t*M_PI/180.0);
334         m.m11 = cos(t*M_PI/180.0);
335         m.tx = RANGE*1.41/2;
336         m.ty = RANGE*1.41/2;
337
338         gfxline_t*l = gfxline_clone(line);
339         gfxline_transform(l, &m);
340
341         gfxpoly_t*poly1 = gfxpoly_from_fill(l, 0.05);
342
343         gfxpoly_t*poly2 = gfxpoly_process(poly1, 0, rule, &onepolygon);
344
345         tag = swf_InsertTag(tag, ST_DEFINESHAPE);
346         SHAPE* s;
347         swf_ShapeNew(&s);
348         RGBA rgb;
349         rgb.r = rgb.g = 0x00; rgb.b = 0xff;
350         rgb.a = 255;
351         int fs = swf_ShapeAddSolidFillStyle(s,&rgb);
352         int ls = swf_ShapeAddLineStyle(s,20,&rgb);
353         swf_SetU16(tag,t+1);
354         swf_SetRect(tag,&swf.movieSize);
355         swf_SetShapeHeader(tag,s);
356
357 #define FILL
358 #ifdef FILL
359         swf_ShapeSetAll(tag,s,UNDEFINED_COORD,UNDEFINED_COORD,0,fs,0);
360
361         int i,j;
362         gfxpolystroke_t*stroke = poly2->strokes;
363         for(;stroke;stroke=stroke->next) {
364             for(j=0;j<stroke->num_points-1;j++) {
365                 point_t a = stroke->points[j];
366                 point_t b = stroke->points[j+1];
367 #define ROTATE
368 #ifdef ROTATE
369                 swf_ShapeSetMove(tag, s, a.y, a.x);
370                 swf_ShapeSetLine(tag, s, b.y - a.y, b.x - a.x);
371 #else
372                 swf_ShapeSetMove(tag, s, a.x, a.y);
373                 swf_ShapeSetLine(tag, s, b.x - a.x, b.y - a.y);
374 #endif
375             }
376         }
377 #else
378         swf_ShapeSetAll(tag,s,0,0,ls,0,0);
379         edge_t*e = poly2->edges;
380         while(e) {
381             swf_ShapeSetMove(tag, s, e->a.x, e->a.y);
382             swf_ShapeSetLine(tag, s, e->b.x - e->a.x, e->b.y - e->a.y);
383             
384             swf_ShapeSetCircle(tag, s, e->a.x, e->a.y, 5*20, 5*20);
385             swf_ShapeSetCircle(tag, s, e->b.x, e->b.y, 5*20, 5*20);
386             e = e->next;
387         }
388 #endif
389
390         swf_ShapeSetEnd(tag);
391         swf_ShapeFree(s);
392
393         gfxpoly_destroy(poly1);
394         gfxpoly_destroy(poly2);
395
396         gfxline_free(l);
397    
398         if(t) {
399             tag = swf_InsertTag(tag,ST_REMOVEOBJECT2);
400             swf_SetU16(tag, t);
401         }
402         tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
403         swf_ObjectPlace(tag,t+1,t+1,NULL,NULL,NULL);
404
405         tag = swf_InsertTag(tag, ST_SHOWFRAME);
406     }
407     tag = swf_InsertTag(tag, ST_END);
408
409     swf_SaveSWF(&swf, "test.swf");
410 }
411
412 void rotate90(gfxpoly_t*poly)
413 {
414     int i,j;
415     gfxpolystroke_t*stroke = poly->strokes;
416     for(;stroke;stroke=stroke->next) {
417         for(j=0;j<stroke->num_points;j++) {
418             point_t a = stroke->points[j];
419             stroke->points[j].x = a.y;
420             stroke->points[j].y = a.x;
421         }
422     }
423 }
424
425 #include <dirent.h>
426 void test4(int argn, char*argv[])
427 {
428     char*dir = "ps";
429     DIR*_dir = opendir(dir);
430     if(!_dir) return;
431     struct dirent*file;
432     while(1) {
433         file = readdir(_dir);
434         if (!file) 
435             break;
436         if(!strstr(file->d_name, ".ps")) 
437             continue;
438
439         char* filename;
440
441         if(argn<2)
442             filename = allocprintf("%s/%s", dir, file->d_name);
443         else
444             filename = argv[1];
445
446         windrule_t*rule = &windrule_evenodd;
447         gfxpoly_t*poly1 = gfxpoly_from_file(filename, 1.0);//0.01);
448
449         if(argn!=2)
450             free(filename);
451
452         double zoom = 1.0;
453
454         if(!gfxpoly_check(poly1, 0)) {
455             printf("bad polygon\n");
456             continue;
457         }
458
459         gfxpoly_t*poly2 = gfxpoly_process(poly1, 0, rule, &onepolygon);
460         assert(gfxpoly_check(poly2, 1));
461
462         int pass;
463         for(pass=0;pass<2;pass++) {
464             intbbox_t bbox = intbbox_from_polygon(poly1, zoom);
465             unsigned char*bitmap1 = render_polygon(poly1, &bbox, zoom, rule, &onepolygon);
466             unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_circular, &onepolygon);
467             if(!bitmap_ok(&bbox, bitmap1) || !bitmap_ok(&bbox, bitmap2)) {
468                 save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
469                 assert(!"error in bitmaps");
470             }
471             if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) {
472                 save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
473                 assert(!"bitmaps don't match");
474             }
475             free(bitmap1);
476             free(bitmap2);
477
478             // second pass renders the 90° rotated version
479             rotate90(poly1);
480             rotate90(poly2);
481         }
482
483         gfxpoly_destroy(poly1);
484         gfxpoly_destroy(poly2);
485         if(argn==2) 
486             break;
487     }
488     closedir(_dir);
489 }
490
491 #include "../gfxdevice.h"
492 #include "../pdf/pdf.h"
493
494 static int max_segments = 0;
495 static int max_any_segments = 0;
496 void extract_polygons_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color) 
497 {
498     //gfxpoly_t*c = gfxpoly_from_fill(line, 0.05);
499     //gfxpoly_free(c);
500
501     //gfxpoly_t*poly1 = gfxpoly_from_fill(line, 0.05);
502     gfxpoly_t*poly1 = gfxpoly_from_fill(line, 0.05);
503
504     //gfxline_dump(line, stderr, "");
505     //gfxpoly_dump(poly);
506
507     int size = gfxpoly_size(poly1);
508     if(size == 4) {
509         //rectangles are boring.
510         gfxpoly_destroy(poly1);
511         return;
512     }
513
514     max_any_segments = size > max_any_segments? size : max_any_segments;
515     if(size>100000) {
516         fprintf(stderr, "%d segments (skipping)\n", size);
517         return;
518     } else {
519         max_segments = size > max_segments? size : max_segments;
520         fprintf(stderr, "%d segments (max so far: %d/%d)\n", size, max_segments, max_any_segments);
521     }
522
523     if(!gfxpoly_check(poly1, 0)) {
524         gfxpoly_destroy(poly1);
525         fprintf(stderr, "bad polygon\n");
526         return;
527     }
528
529     windrule_t*rule = &windrule_evenodd;
530
531     double zoom = 1.0;
532     intbbox_t bbox = intbbox_from_polygon(poly1, zoom);
533     unsigned char*bitmap1 = render_polygon(poly1, &bbox, zoom, rule, &onepolygon);
534     if(!bitmap_ok(&bbox, bitmap1)) {
535         fprintf(stderr, "bad polygon or error in renderer\n");
536         return;
537     }
538     gfxpoly_t*poly2 = gfxpoly_process(poly1, 0, rule, &onepolygon);
539     unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd, &onepolygon);
540     if(!bitmap_ok(&bbox, bitmap2)) {
541         save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
542         assert(!"error in bitmap");
543     }
544     if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) {
545         save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
546         assert(!"bitmaps don't match");
547     }
548     free(bitmap1);
549     free(bitmap2);
550
551     gfxpoly_destroy(poly1);
552     gfxpoly_destroy(poly2);
553 }
554 int extract_polygons_setparameter(gfxdevice_t*dev, const char*key, const char*value) {
555     return 0;
556 }
557 void extract_polygons_startclip(gfxdevice_t*dev, gfxline_t*line) 
558 {
559     extract_polygons_fill(dev, line, 0);
560 }
561 void extract_polygons_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*imgcoord2devcoord, gfxcxform_t*cxform)
562 {
563     extract_polygons_fill(dev, line, 0);
564 }
565 void extract_polygons_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*gradcoord2devcoord)
566 {
567     extract_polygons_fill(dev, line, 0);
568 }
569 void extract_polygons_drawlink(gfxdevice_t*dev, gfxline_t*line, const char*action)
570 {
571     extract_polygons_fill(dev, line, 0);
572 }
573 void extract_polygons_addfont(gfxdevice_t*dev, gfxfont_t*font)
574 {
575     int t;
576     for(t=0;t<font->num_glyphs;t++) {
577         //extract_polygons_fill(dev, font->glyphs[t].line, 0);
578     }
579 }
580 void extract_polygons_endclip(gfxdevice_t*dev)
581 {
582 }
583 void extract_polygons_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit)
584 {
585 }
586 void extract_polygons_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix)
587 {
588 }
589     
590 gfxdevice_t extract_polygons = 
591 {
592 name: "extract polygons",
593 setparameter:extract_polygons_setparameter,
594 startclip: extract_polygons_startclip,
595 endclip: extract_polygons_endclip,
596 stroke: extract_polygons_stroke,
597 fill: extract_polygons_fill,
598 fillbitmap: extract_polygons_fillbitmap,
599 fillgradient: extract_polygons_fillgradient,
600 addfont: extract_polygons_addfont,
601 drawchar: extract_polygons_drawchar,
602 drawlink: extract_polygons_drawlink,
603 startpage: 0,
604 endpage: 0,
605 geterror: 0,
606 finish: 0,
607 internal: 0
608 };
609
610 #if 0
611 void test5(int argn, char*argv[])
612 {
613     gfxsource_t*driver = gfxsource_pdf_create();
614     char*dir = "pdfs";
615     DIR*_dir = opendir(dir);
616     if(!_dir) return;
617     struct dirent*file;
618     while(1) {
619         file = readdir(_dir);
620         if (!file) 
621             break;
622         if(!strstr(file->d_name, ".pdf")) 
623             continue;
624         char* filename = allocprintf("%s/%s", dir, file->d_name);
625
626         if(argn>1) 
627             filename = argv[1];
628
629         gfxdocument_t*doc = driver->open(driver, filename);
630         gfxdevice_t*out = &extract_polygons;
631         int t;
632         for(t=1;t<=doc->num_pages;t++) {
633             fprintf(stderr, "%s (page %d)\n", filename, t);
634             gfxpage_t* page = doc->getpage(doc, t);
635             page->render(page, out);
636             page->destroy(page);
637         }
638         doc->destroy(doc);
639         if(argn>1) 
640             break;
641         free(filename);
642     }
643     closedir(_dir);
644     driver->destroy(driver);
645 }
646 #endif
647
648 int main(int argn, char*argv[])
649 {
650     test4(argn, argv);
651 }
652