X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fgfxpoly%2Frenderpoly.c;h=c1a428f6c39d1546799f24e099e655e21a22d774;hp=9ec6abfd0fbe677ca25f791a3db75a58bfd6a932;hb=336f6de943b8c0bbeb0f64b7e35dd9511147a20a;hpb=002f2ed7c404339e11d669aa86ec998d8dd473a5 diff --git a/lib/gfxpoly/renderpoly.c b/lib/gfxpoly/renderpoly.c index 9ec6abf..c1a428f 100644 --- a/lib/gfxpoly/renderpoly.c +++ b/lib/gfxpoly/renderpoly.c @@ -8,6 +8,7 @@ typedef struct _renderpoint double x; segment_dir_t dir; fillstyle_t*fs; + edge_t*e; //only for debugging int polygon_nr; } renderpoint_t; @@ -27,16 +28,18 @@ typedef struct _renderbuf renderline_t*lines; } renderbuf_t; -static inline void add_pixel(renderbuf_t*buf, double x, int y, segment_dir_t dir, fillstyle_t*fs, int polygon_nr) +static inline void add_pixel(renderbuf_t*buf, double x, int y, segment_dir_t dir, fillstyle_t*fs, int polygon_nr, edge_t*e) { renderpoint_t p; p.x = x; p.dir = dir; p.fs = fs; + p.e = e; p.polygon_nr = polygon_nr; - - if(x >= buf->bbox.xmax || y >= buf->bbox.ymax || y < buf->bbox.ymin) + + if(y >= buf->bbox.ymax || y < buf->bbox.ymin) return; + renderline_t*l = &buf->lines[y-buf->bbox.ymin]; if(l->num == l->size) { @@ -47,8 +50,7 @@ static inline void add_pixel(renderbuf_t*buf, double x, int y, segment_dir_t dir l->num++; } #define CUT 0.5 -#define INT(x) ((int)((x)+16)-16) -static void add_line(renderbuf_t*buf, double x1, double y1, double x2, double y2, fillstyle_t*fs, int polygon_nr) +static void add_line(renderbuf_t*buf, double x1, double y1, double x2, double y2, fillstyle_t*fs, int polygon_nr, edge_t*e) { x1 *= buf->zoom; y1 *= buf->zoom; @@ -65,14 +67,14 @@ static void add_line(renderbuf_t*buf, double x1, double y1, double x2, double y2 } diffx = x2 - x1; diffy = y2 - y1; - ny1 = INT(y1)+CUT; - ny2 = INT(y2)+CUT; + ny1 = floor(y1)+CUT; + ny2 = floor(y2)+CUT; if(ny1 < y1) { - ny1 = INT(y1) + 1.0 + CUT; + ny1 = floor(y1) + 1.0 + CUT; } if(ny2 >= y2) { - ny2 = INT(y2) - 1.0 + CUT; + ny2 = floor(y2) - 1.0 + CUT; } if(ny1 > ny2) return; @@ -81,14 +83,14 @@ static void add_line(renderbuf_t*buf, double x1, double y1, double x2, double y2 x1 = x1 + (ny1-y1)*stepx; x2 = x2 + (ny2-y2)*stepx; - int posy=INT(ny1); - int endy=INT(ny2); + int posy=floor(ny1); + int endy=floor(ny2); double posx=0; double startx = x1; while(posy<=endy) { double xx = startx + posx; - add_pixel(buf, xx, posy, dir, fs, polygon_nr); + add_pixel(buf, xx, posy, dir, fs, polygon_nr, e); posx+=stepx; posy++; } @@ -118,7 +120,7 @@ static void fill_bitwise(unsigned char*line, int x1, int x2) } } -unsigned char* render_polygon(gfxpoly_t*polygon, intbbox_t*bbox, double zoom, windrule_t*rule) +unsigned char* render_polygon(gfxpoly_t*polygon, intbbox_t*bbox, double zoom, windrule_t*rule, windcontext_t*context) { renderbuf_t _buf, *buf=&_buf; buf->width = (bbox->xmax - bbox->xmin); @@ -126,9 +128,10 @@ unsigned char* render_polygon(gfxpoly_t*polygon, intbbox_t*bbox, double zoom, wi buf->bbox = *bbox; buf->zoom = zoom * polygon->gridsize; int width8 = (buf->width+7) >> 3; + char bleeding = 0; unsigned char* image = (unsigned char*)malloc(width8*buf->height); memset(image, 0, width8*buf->height); - + buf->lines = (renderline_t*)rfx_alloc(buf->height*sizeof(renderline_t)); int y; for(y=0;yheight;y++) { @@ -140,7 +143,7 @@ unsigned char* render_polygon(gfxpoly_t*polygon, intbbox_t*bbox, double zoom, wi edge_t*e; int polygon_nr = 0; for(e=polygon->edges;e;e=e->next) { - add_line(buf, e->a.x, e->a.y, e->b.x, e->b.y, e->style, polygon_nr); + add_line(buf, e->a.x, e->a.y, e->b.x, e->b.y, e->style, polygon_nr, e); } for(y=0;yheight;y++) { @@ -150,28 +153,29 @@ unsigned char* render_polygon(gfxpoly_t*polygon, intbbox_t*bbox, double zoom, wi int num = buf->lines[y].num; qsort(points, num, sizeof(renderpoint_t), compare_renderpoints); int lastx = 0; - - windstate_t fill = rule->start(1); + + windstate_t fill = rule->start(context); for(n=0;nx - bbox->xmin); - + if(x < lastx) - x = lastx; - if(x > buf->width) { - break; - } - if(fill.is_filled && x!=lastx) { + x = lastx; + if(x > buf->width) + x = buf->width; + + if(fill.is_filled && lastxadd(fill, p->fs, p->dir, p->polygon_nr); + fill = rule->add(context, fill, p->fs, p->dir, p->polygon_nr); lastx = x; } if(fill.is_filled && lastx!=buf->width) { - - return 0;// return an error, we're bleeding - - fill_bitwise(line, lastx, buf->width); + /* we're bleeding, fill over padding, too. */ + fprintf(stderr, "Polygon %08x is bleeding in line %d\n", polygon, y); + fill_bitwise(line, lastx, width8*8); + assert(line[width8-1]&0x01); + bleeding = 1; } } @@ -181,6 +185,9 @@ unsigned char* render_polygon(gfxpoly_t*polygon, intbbox_t*bbox, double zoom, wi } memset(&buf->lines[y], 0, sizeof(renderline_t)); } + if(bleeding) { + assert(!bitmap_ok(bbox, image)); + } free(buf->lines);buf->lines=0; return image; } @@ -191,6 +198,14 @@ unsigned char* render_polygon(gfxpoly_t*polygon, intbbox_t*bbox, double zoom, wi static inline max(double a, double b) {return a>b?a:b;} static inline min(double a, double b) {return aedges; - zoom *= polygon->gridsize; + double g = zoom*polygon->gridsize; if(e) { - b.xmin = e->a.x*zoom; - b.ymin = e->a.y*zoom; - b.xmax = e->a.x*zoom; - b.ymax = e->a.y*zoom; + b.xmin = e->a.x*g; + b.ymin = e->a.y*g; + b.xmax = e->a.x*g; + b.ymax = e->a.y*g; } for(e=polygon->edges;e;e=e->next) { - double x_min = min(e->a.x,e->b.x)*zoom; - double y_min = min(e->a.y,e->b.y)*zoom; - double x_max = max(e->a.x,e->b.x)*zoom; - double y_max = max(e->a.y,e->b.y)*zoom; + double x_min = min(e->a.x,e->b.x)*g; + double y_min = min(e->a.y,e->b.y)*g; + double x_max = max(e->a.x,e->b.x)*g; + double y_max = max(e->a.y,e->b.y)*g; int x1 = floor(x_min); int y1 = floor(y_min); int x2 = ceil(x_max); @@ -229,8 +245,9 @@ intbbox_t intbbox_from_polygon(gfxpoly_t*polygon, double zoom) if(x1 < b.xmin) b.xmin = x1; if(y1 < b.ymin) b.ymin = y1; if(x2 > b.xmax) b.xmax = x2; - if(y2 > b.xmax) b.ymax = y2; + if(y2 > b.ymax) b.ymax = y2; } + if(b.xmax > (int)(MAX_WIDTH*zoom)) b.xmax = (int)(MAX_WIDTH*zoom); if(b.ymax > (int)(MAX_HEIGHT*zoom)) @@ -244,6 +261,8 @@ intbbox_t intbbox_from_polygon(gfxpoly_t*polygon, double zoom) b.xmin = b.xmax; if(b.ymin > b.ymax) b.ymin = b.ymax; + + b.xmax = adjust_x(b.xmin, b.xmax); b.width = b.xmax - b.xmin; b.height = b.ymax - b.ymin; @@ -269,8 +288,22 @@ intbbox_t intbbox_from_polygon(gfxpoly_t*polygon, double zoom) #define B00000010 0x02 #define B00000001 0x01 +int bitmap_ok(intbbox_t*bbox, unsigned char*data) +{ + int y; + int width8 = (bbox->width+7) >> 3; + for(y=0;yheight;y++) { + if(data[width8-1]&0x01) + return 0; //bleeding + data += width8; + } + return 1; +} + int compare_bitmaps(intbbox_t*bbox, unsigned char*data1, unsigned char*data2) { + if(!data1 || !data2) + return 0; int x,y; int height = bbox->height; int width = bbox->width;