X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fgfxpoly%2Ftest.c;h=888e4d6ab79e01e315980633d96d36aca775429b;hb=33e9461da6b886671749d6cbabd80b355ab1f6d9;hp=aff9208ede9b49ae9ed7e00065706a2bebff5f40;hpb=ae7c92fe5721f97e786a8bbe9153eadbf292460d;p=swftools.git diff --git a/lib/gfxpoly/test.c b/lib/gfxpoly/test.c index aff9208..888e4d6 100644 --- a/lib/gfxpoly/test.c +++ b/lib/gfxpoly/test.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include "../gfxtools.h" @@ -53,13 +52,13 @@ gfxline_t* mkchessboard() unsigned int r = 0; int spacing = 20; - //int num_caros = 40; - //int l = 5; - //char do_centerpiece=1; + int num_caros = 40; + int l = 5; + char do_centerpiece=1; - int num_caros = 4; - int l=1; - char do_centerpiece=0; + //int num_caros = 4; + //int l=1; + //char do_centerpiece=0; for(x=-l;x<=l;x++) for(y=-l;y<=l;y++) { @@ -138,7 +137,7 @@ int test0() gfxpoly_destroy(poly); } -int test1() +int test1(int argn, char*argv[]) { gfxline_t*box1 = gfxline_makerectangle(50,50,150,150); // put box2 and box3 on top of each other *snicker* @@ -203,7 +202,7 @@ int test_square(int width, int height, int num, double gridsize, char bitmaptest gfxpoly_destroy(poly); } -int test2() +int test2(int argn, char*argv[]) { test_square(400,400, 3, 0.05, 1); @@ -217,7 +216,7 @@ int test2() } #include "../rfxswf.h" -void test3() +void test3(int argn, char*argv[]) { #undef N #undef RANGE @@ -251,7 +250,6 @@ void test3() m.m11 = cos(t*M_PI/180.0); m.tx = RANGE*1.41/2; m.ty = RANGE*1.41/2; - printf("%d\n", t); gfxline_t*l = gfxline_clone(line); gfxline_transform(l, &m); @@ -322,7 +320,7 @@ void test3() } #include -void test4() +void test4(int argn, char*argv[]) { char*dir = "ps"; DIR*_dir = opendir(dir); @@ -335,10 +333,18 @@ void test4() if(!strstr(file->d_name, ".ps")) continue; - char* filename = allocprintf("%s/%s", dir, file->d_name); + char* filename; + + if(argn<2) + filename = allocprintf("%s/%s", dir, file->d_name); + else + filename = argv[1]; + windrule_t*rule = &windrule_evenodd; - gfxpoly_t*poly = gfxpoly_from_file(filename, 0.01); - free(filename); + gfxpoly_t*poly = 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); @@ -359,8 +365,14 @@ void test4() save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png"); assert(!"bitmaps don't match"); } + free(bitmap1); + free(bitmap2); + gfxpoly_destroy(poly); gfxpoly_destroy(poly2); + if(argn==2) + break; } + closedir(_dir); } #include "../gfxdevice.h" @@ -378,16 +390,16 @@ void extract_polygons_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color) } windrule_t*rule = &windrule_evenodd; - gfxpoly_t*poly2 = gfxpoly_process(poly, rule); double zoom = 1.0; intbbox_t bbox = intbbox_from_polygon(poly, zoom); unsigned char*bitmap1 = render_polygon(poly, &bbox, zoom, rule); - unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd); if(!bitmap_ok(&bbox, bitmap1)) { printf("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); if(!bitmap_ok(&bbox, bitmap2)) { save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png"); assert(!"error in bitmap"); @@ -396,6 +408,8 @@ void extract_polygons_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color) save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png"); assert(!"bitmaps don't match"); } + free(bitmap1); + free(bitmap2); gfxpoly_destroy(poly); gfxpoly_destroy(poly2); @@ -456,8 +470,9 @@ finish: 0, internal: 0 }; -void test5() +void test5(int argn, char*argv[]) { + gfxsource_t*driver = gfxsource_pdf_create(); char*dir = "pdfs"; DIR*_dir = opendir(dir); if(!_dir) return; @@ -470,7 +485,6 @@ void test5() continue; char* filename = allocprintf("%s/%s", dir, file->d_name); - gfxsource_t*driver = gfxsource_pdf_create(); gfxdocument_t*doc = driver->open(driver, filename); gfxdevice_t*out = &extract_polygons; int t; @@ -479,13 +493,15 @@ void test5() gfxpage_t* page = doc->getpage(doc, t); page->render(page, out); page->destroy(page); - break; } + doc->destroy(doc); free(filename); } + closedir(_dir); + driver->destroy(driver); } -int main() +int main(int argn, char*argv[]) { - test0(); + test5(argn, argv); }