X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fgfxtools.c;h=9975e6d28650c51635b55760c15ee8181ed7fab9;hb=ecd7c7248b9a93163090bfe7512b2a53d8da6d95;hp=a206e57db897d8a7153d581b17a495f1fae7e4d6;hpb=3c6c2c2a98a273483285119b9cc0b782aa8a79c8;p=swftools.git diff --git a/lib/gfxtools.c b/lib/gfxtools.c index a206e57..9975e6d 100644 --- a/lib/gfxtools.c +++ b/lib/gfxtools.c @@ -28,12 +28,14 @@ #include #include "gfxtools.h" #include "gfxfont.h" +#include "jpeg.h" typedef struct _linedraw_internal { gfxline_t*start; gfxline_t*next; gfxcoord_t x0,y0; + char has_moveto; } linedraw_internal_t; static void linedraw_moveTo(gfxdrawer_t*d, gfxcoord_t x, gfxcoord_t y) @@ -41,12 +43,7 @@ static void linedraw_moveTo(gfxdrawer_t*d, gfxcoord_t x, gfxcoord_t y) linedraw_internal_t*i = (linedraw_internal_t*)d->internal; gfxline_t*l = (gfxline_t*)rfx_alloc(sizeof(gfxline_t)); l->type = gfx_moveTo; - if((int)((d->x * 5120) == (int)(x * 5120)) && - (int)((d->y * 5120) == (int)(y * 5120))) { - /* never mind- we're already there */ - return; - - } + i->has_moveto = 1; i->x0 = x; i->y0 = y; l->sx = l->sy = 0; @@ -62,15 +59,14 @@ static void linedraw_moveTo(gfxdrawer_t*d, gfxcoord_t x, gfxcoord_t y) static void linedraw_lineTo(gfxdrawer_t*d, gfxcoord_t x, gfxcoord_t y) { linedraw_internal_t*i = (linedraw_internal_t*)d->internal; - gfxline_t*l = (gfxline_t*)rfx_alloc(sizeof(gfxline_t)); - - if(!i->start) { + if(!i->has_moveto) { /* starts with a line, not with a moveto. As this is the first entry in the list, this is probably *meant* to be a moveto */ linedraw_moveTo(d, x, y); return; } - + + gfxline_t*l = (gfxline_t*)rfx_alloc(sizeof(gfxline_t)); l->type = gfx_lineTo; d->x = l->x = x; d->y = l->y = y; @@ -85,14 +81,12 @@ static void linedraw_lineTo(gfxdrawer_t*d, gfxcoord_t x, gfxcoord_t y) static void linedraw_splineTo(gfxdrawer_t*d, gfxcoord_t sx, gfxcoord_t sy, gfxcoord_t x, gfxcoord_t y) { linedraw_internal_t*i = (linedraw_internal_t*)d->internal; - gfxline_t*l = (gfxline_t*)rfx_alloc(sizeof(gfxline_t)); - - if(!i->start) { - fprintf(stderr, "Error: drawing startpoint is a spline\n"); + if(!i->has_moveto) { linedraw_moveTo(d, x, y); return; } + gfxline_t*l = (gfxline_t*)rfx_alloc(sizeof(gfxline_t)); l->type = gfx_splineTo; d->x = l->x = x; d->y = l->y = y; @@ -105,10 +99,15 @@ static void linedraw_splineTo(gfxdrawer_t*d, gfxcoord_t sx, gfxcoord_t sy, gfxco if(!i->start) i->start = l; } -static void* linedraw_close(gfxdrawer_t*d) +static void linedraw_close(gfxdrawer_t*d) { linedraw_internal_t*i = (linedraw_internal_t*)d->internal; + if(!i->has_moveto) + return; linedraw_lineTo(d, i->x0, i->y0); + i->has_moveto = 0; + i->x0 = 0; + i->y0 = 0; } static void* linedraw_result(gfxdrawer_t*d) { @@ -833,7 +832,7 @@ void gfxfontlist_free(gfxfontlist_t*list, char deletefonts) } } -gfxline_t*gfxline_makerectangle(int x1,int y1,int x2, int y2) +gfxline_t*gfxline_makerectangle(double x1,double y1,double x2, double y2) { gfxline_t* line = (gfxline_t*)rfx_calloc(sizeof(gfxline_t)*5); line[0].x = x1;line[0].y = y1;line[0].type = gfx_moveTo;line[0].next = &line[1]; @@ -989,3 +988,18 @@ void gfxline_dump(gfxline_t*line, FILE*fi, char*prefix) } } +void gfximage_save_jpeg(gfximage_t*img, char*filename, int quality) +{ + unsigned char*data = malloc(img->width*img->height*3); + int t; + int size = img->width*img->height; + int s = 0; + for(t=0;tdata[t].r; + data[s+1] = img->data[t].g; + data[s+2] = img->data[t].b; + s+=3; + } + jpeg_save(data, img->width, img->height, quality, filename); +} +