X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fgfxpoly%2Ftest.c;h=a04f7792a8edfb7201efe70ee5d4797b4e8b09c8;hp=888e4d6ab79e01e315980633d96d36aca775429b;hb=8d76501168e44398feb36ae4d378178a676d8f2c;hpb=64cbdc0d10e611af20d4d375ff6319793da8e6f5 diff --git a/lib/gfxpoly/test.c b/lib/gfxpoly/test.c index 888e4d6..a04f779 100644 --- a/lib/gfxpoly/test.c +++ b/lib/gfxpoly/test.c @@ -28,21 +28,17 @@ gfxline_t*mkstar(int x1, int y1, int x2, int y2) gfxline_t* mkrandomshape(int range, int n) { int i; - gfxline_t* line = malloc(sizeof(gfxline_t)*n*2); + gfxline_t* line = malloc(sizeof(gfxline_t)*n); for(i=0;iedges; - while(e) { + + int i,j; + for(i=0;inum_strokes;i++) { + gfxpolystroke_t*stroke = &poly2->strokes[i]; + for(j=0;jnum_points-1;j++) { + point_t a = stroke->points[j]; + point_t b = stroke->points[j+1]; #define ROTATE #ifdef ROTATE - swf_ShapeSetMove(tag, s, e->a.y, e->a.x); - swf_ShapeSetLine(tag, s, e->b.y - e->a.y, e->b.x - e->a.x); + swf_ShapeSetMove(tag, s, a.y, a.x); + swf_ShapeSetLine(tag, s, b.y - a.y, b.x - a.x); #else - swf_ShapeSetMove(tag, s, e->a.x, e->a.y); - swf_ShapeSetLine(tag, s, e->b.x - e->a.x, e->b.y - e->a.y); + swf_ShapeSetMove(tag, s, a.x, a.y); + swf_ShapeSetLine(tag, s, b.x - a.x, b.y - a.y); #endif - e = e->next; - } + } + } #else swf_ShapeSetAll(tag,s,0,0,ls,0,0); edge_t*e = poly2->edges; @@ -300,7 +337,7 @@ void test3(int argn, char*argv[]) swf_ShapeSetEnd(tag); swf_ShapeFree(s); - gfxpoly_destroy(poly); + gfxpoly_destroy(poly1); gfxpoly_destroy(poly2); gfxline_free(l); @@ -319,6 +356,19 @@ void test3(int argn, char*argv[]) swf_SaveSWF(&swf, "test.swf"); } +void rotate90(gfxpoly_t*poly) +{ + int i,j; + for(i=0;inum_strokes;i++) { + gfxpolystroke_t*stroke = &poly->strokes[i]; + for(j=0;jnum_points;j++) { + point_t a = stroke->points[j]; + stroke->points[j].x = a.y; + stroke->points[j].y = a.x; + } + } +} + #include void test4(int argn, char*argv[]) { @@ -341,33 +391,42 @@ void test4(int argn, char*argv[]) filename = argv[1]; windrule_t*rule = &windrule_evenodd; - gfxpoly_t*poly = gfxpoly_from_file(filename, 1.0);//0.01); + gfxpoly_t*poly1 = gfxpoly_from_file(filename, 1.0);//0.01); if(argn!=2) free(filename); double zoom = 1.0; - intbbox_t bbox = intbbox_from_polygon(poly, zoom); - if(!gfxpoly_check(poly)) { + if(!gfxpoly_check(poly1)) { printf("bad polygon\n"); continue; } - gfxpoly_t*poly2 = gfxpoly_process(poly, rule); - unsigned char*bitmap1 = render_polygon(poly, &bbox, zoom, rule); - unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd); - if(!bitmap_ok(&bbox, bitmap1) || !bitmap_ok(&bbox, bitmap2)) { - save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png"); - assert(!"error in bitmaps"); - } - if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) { - save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png"); - assert(!"bitmaps don't match"); - } - free(bitmap1); - free(bitmap2); - gfxpoly_destroy(poly); + gfxpoly_t*poly2 = gfxpoly_process(poly1, rule, &onepolygon); + + int pass; + for(pass=0;pass<2;pass++) { + intbbox_t bbox = intbbox_from_polygon(poly1, zoom); + unsigned char*bitmap1 = render_polygon(poly1, &bbox, zoom, rule, &onepolygon); + unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd, &onepolygon); + if(!bitmap_ok(&bbox, bitmap1) || !bitmap_ok(&bbox, bitmap2)) { + save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png"); + assert(!"error in bitmaps"); + } + if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) { + save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png"); + assert(!"bitmaps don't match"); + } + free(bitmap1); + free(bitmap2); + + // second pass renders the 90° rotated version + rotate90(poly1); + rotate90(poly2); + } + + gfxpoly_destroy(poly1); gfxpoly_destroy(poly2); if(argn==2) break; @@ -380,26 +439,38 @@ void test4(int argn, char*argv[]) void extract_polygons_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color) { - gfxpoly_t*poly = gfxpoly_from_gfxline(line, 0.05); - printf("%d segments\n", gfxpoly_size(poly)); + //gfxpoly_t*c = gfxpoly_from_gfxline(line, 0.05); + //gfxpoly_free(c); + + gfxpoly_t*poly1 = gfxpoly_from_gfxline(line, 0.05); + + //gfxline_dump(line, stderr, ""); + //gfxpoly_dump(poly); - if(!gfxpoly_check(poly)) { - gfxpoly_destroy(poly); - printf("bad polygon\n"); + if(gfxpoly_size(poly1)>100000) { + fprintf(stderr, "%d segments (skipping)\n", gfxpoly_size(poly1)); + return; + } else { + //fprintf(stderr, "%d segments\n", gfxpoly_size(poly)); + } + + if(!gfxpoly_check(poly1)) { + gfxpoly_destroy(poly1); + fprintf(stderr, "bad polygon\n"); return; } windrule_t*rule = &windrule_evenodd; - + double zoom = 1.0; - intbbox_t bbox = intbbox_from_polygon(poly, zoom); - unsigned char*bitmap1 = render_polygon(poly, &bbox, zoom, rule); + intbbox_t bbox = intbbox_from_polygon(poly1, zoom); + unsigned char*bitmap1 = render_polygon(poly1, &bbox, zoom, rule, &onepolygon); if(!bitmap_ok(&bbox, bitmap1)) { - printf("bad polygon or error in renderer\n"); + fprintf(stderr, "bad polygon or error in renderer\n"); return; } - gfxpoly_t*poly2 = gfxpoly_process(poly, rule); - unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd); + gfxpoly_t*poly2 = gfxpoly_process(poly1, rule, &onepolygon); + unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd, &onepolygon); if(!bitmap_ok(&bbox, bitmap2)) { save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png"); assert(!"error in bitmap"); @@ -411,7 +482,7 @@ void extract_polygons_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color) free(bitmap1); free(bitmap2); - gfxpoly_destroy(poly); + gfxpoly_destroy(poly1); gfxpoly_destroy(poly2); } int extract_polygons_setparameter(gfxdevice_t*dev, const char*key, const char*value) { @@ -485,16 +556,21 @@ void test5(int argn, char*argv[]) continue; char* filename = allocprintf("%s/%s", dir, file->d_name); + if(argn>1) + filename = argv[1]; + gfxdocument_t*doc = driver->open(driver, filename); gfxdevice_t*out = &extract_polygons; int t; for(t=1;t<=doc->num_pages;t++) { - printf("%s (page %d)\n", filename, t); + fprintf(stderr, "%s (page %d)\n", filename, t); gfxpage_t* page = doc->getpage(doc, t); page->render(page, out); page->destroy(page); } doc->destroy(doc); + if(argn>1) + break; free(filename); } closedir(_dir); @@ -503,5 +579,6 @@ void test5(int argn, char*argv[]) int main(int argn, char*argv[]) { - test5(argn, argv); + test4(argn, argv); } +