Merge branch 'horizontals'
[swftools.git] / lib / gfxpoly / renderpoly.c
index 240859d..989dfc8 100644 (file)
@@ -7,7 +7,7 @@ typedef struct _renderpoint
 {
     double x;
     segment_dir_t dir;
-    fillstyle_t*fs;
+    edgestyle_t*fs;
     int polygon_nr;
 } renderpoint_t;
 
@@ -27,7 +27,7 @@ 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, edgestyle_t*fs, int polygon_nr)
 {
     renderpoint_t p;
     p.x = x;
@@ -48,7 +48,7 @@ static inline void add_pixel(renderbuf_t*buf, double x, int y, segment_dir_t dir
     l->num++;
 }
 #define CUT 0.5
-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, edgestyle_t*fs, segment_dir_t dir, int polygon_nr)
 {
     x1 *= buf->zoom;
     y1 *= buf->zoom;
@@ -56,13 +56,14 @@ static void add_line(renderbuf_t*buf, double x1, double y1, double x2, double y2
     y2 *= buf->zoom;
     double diffx, diffy;
     double ny1, ny2, stepx;
-    segment_dir_t dir = DIR_DOWN;
+
     if(y2 < y1) {
-        dir = DIR_UP;
+        dir ^= DIR_UP^DIR_DOWN;
         double x,y;
        x = x1;x1 = x2;x2=x;
        y = y1;y1 = y2;y2=y;
     }
+
     diffx = x2 - x1;
     diffy = y2 - y1;
     ny1 = floor(y1)+CUT;
@@ -86,6 +87,8 @@ static void add_line(renderbuf_t*buf, double x1, double y1, double x2, double y2
     double posx=0;
     double startx = x1;
 
+    //printf("line %d from %f to %f dir=%s\n", polygon_nr, y1, y2, dir==DIR_UP?"up":"down");
+
     while(posy<=endy) {
         double xx = startx + posx;
         add_pixel(buf, xx, posy, dir, fs, polygon_nr);
@@ -145,7 +148,7 @@ unsigned char* render_polygon(gfxpoly_t*polygon, intbbox_t*bbox, double zoom, wi
        for(t=0;t<stroke->num_points-1;t++) {
            point_t a = stroke->points[t];
            point_t b = stroke->points[t+1];
-           add_line(buf, a.x, a.y, b.x, b.y, stroke->fs, polygon_nr);
+           add_line(buf, a.x, a.y, b.x, b.y, stroke->fs, stroke->dir, polygon_nr);
        }
     }
 
@@ -175,10 +178,12 @@ unsigned char* render_polygon(gfxpoly_t*polygon, intbbox_t*bbox, double zoom, wi
         }
         if(fill.is_filled && lastx!=buf->width) {
             /* we're bleeding, fill over padding, too. */
-            fprintf(stderr, "Polygon %08x is bleeding in line %d\n", (int)polygon, y);
+            fprintf(stderr, "Polygon %p is bleeding in line %d\n", polygon, y);
             fill_bitwise(line, lastx, width8*8);
            assert(line[width8-1]&0x01);
            bleeding = 1;
+           exit(1);
+
         }
     }