]> git.imager.perl.org - imager.git/commitdiff
Bug fixes for the polygon rendering code where naming the same pixel twice
authorArnar Mar Hrafnkelsson <addi@cpan.org>
Mon, 12 Nov 2001 18:46:47 +0000 (18:46 +0000)
committerArnar Mar Hrafnkelsson <addi@cpan.org>
Mon, 12 Nov 2001 18:46:47 +0000 (18:46 +0000)
would result in an entire line being wrong.

polygon.c
t/t75polyaa.t

index 9a2a64d26aba41739c905f4c9e54f65948f41113..b6338902947858722d061d7c43976b294e96c4eb 100644 (file)
--- a/polygon.c
+++ b/polygon.c
@@ -162,7 +162,26 @@ ss_scanline_exorcise(ss_scanline *ss) {
 
 static
 int
 
 static
 int
-lines_in_interval(p_line *lset, int l, p_slice *tllist, pcord cc) {
+lines_in_interval(p_line *lset, int l, p_slice *tllist, pcord minc, pcord maxc) {
+  int k;
+  int count = 0;
+  for(k=0; k<l; k++) {
+    if (lset[k].maxy > minc && lset[k].miny < maxc) {
+      if (lset[k].miny == lset[k].maxy) {
+       POLY_DEB( printf(" HORIZONTAL - skipped\n") );
+      } else {
+       tllist[count].x=p_eval_aty(&lset[k],(minc+maxc)/2.0 );
+       tllist[count].n=k;
+       count++;
+      }
+    }
+  }
+  return count;
+}
+
+static
+int
+lines_in_interval_old(p_line *lset, int l, p_slice *tllist, pcord cc) {
   int k;
   int count = 0;
   for(k=0; k<l; k++) {
   int k;
   int count = 0;
   for(k=0; k<l; k++) {
@@ -559,20 +578,21 @@ i_poly_aa(i_img *im, int l, double *x, double *y, i_color *val) {
   /* loop on intervals */
   for(i=0; i<l-1; i++) {
     int startscan = max( coarse(pset[i].y), 0);
   /* loop on intervals */
   for(i=0; i<l-1; i++) {
     int startscan = max( coarse(pset[i].y), 0);
-    int stopscan = min( coarse(pset[i+1].y+15), im->ysize-1);
+    int stopscan = min( coarse(pset[i+1].y+15), im->ysize);
     pcord cc = (pset[i].y + pset[i+1].y)/2;
 
     pcord cc = (pset[i].y + pset[i+1].y)/2;
 
+    if (pset[i].y == pset[i+1].y) {
+      POLY_DEB( printf("current slice thickness = 0 => skipping\n") );
+      continue;
+    }
+
     POLY_DEB(
             printf("current slice is %d: %d to %d ( cpoint %d ) scanlines %d to %d\n", 
                    i, pset[i].y, pset[i+1].y, cc, startscan, stopscan)
             );
     
     POLY_DEB(
             printf("current slice is %d: %d to %d ( cpoint %d ) scanlines %d to %d\n", 
                    i, pset[i].y, pset[i+1].y, cc, startscan, stopscan)
             );
     
-    if (pset[i].y == pset[i+1].y) {
-      POLY_DEB( printf("current slice thickness = 0 => skipping\n") );
-      continue;
-    }
     
     
-    clc = lines_in_interval(lset, l, tllist, cc);
+    clc = lines_in_interval(lset, l, tllist, pset[i].y, pset[i+1].y);
     qsort(tllist, clc, sizeof(p_slice), (int(*)(const void *,const void *))p_compx);
 
     mark_updown_slices(lset, tllist, clc);
     qsort(tllist, clc, sizeof(p_slice), (int(*)(const void *,const void *))p_compx);
 
     mark_updown_slices(lset, tllist, clc);
@@ -596,6 +616,7 @@ i_poly_aa(i_img *im, int l, double *x, double *y, i_color *val) {
       tempy = min(cscl*16+16, pset[i+1].y);
       POLY_DEB( printf("evaluating scan line %d \n", cscl) );
       for(k=0; k<clc-1; k+=2) {
       tempy = min(cscl*16+16, pset[i+1].y);
       POLY_DEB( printf("evaluating scan line %d \n", cscl) );
       for(k=0; k<clc-1; k+=2) {
+       POLY_DEB( printf("evaluating slice %d\n", k) );
        render_slice_scanline(&templine, cscl, lset+tllist[k].n, lset+tllist[k+1].n);
       }
       if (16*coarse(tempy) == tempy) {
        render_slice_scanline(&templine, cscl, lset+tllist[k].n, lset+tllist[k+1].n);
       }
       if (16*coarse(tempy) == tempy) {
index ddae831658d0b0f2fc127e23051cafb5f0c87dbd..6c180523f43af65eef9f7daaa54c585e7f950997 100644 (file)
@@ -6,7 +6,7 @@
 # Change 1..1 below to 1..last_test_to_print .
 # (It may become useful if the test is moved to ./t subdirectory.)
 
 # Change 1..1 below to 1..last_test_to_print .
 # (It may become useful if the test is moved to ./t subdirectory.)
 
-BEGIN { $| = 1; print "1..6\n"; }
+BEGIN { $| = 1; print "1..7\n"; }
 END {print "not ok 1\n" unless $loaded;}
 use Imager qw(:all);
 
 END {print "not ok 1\n" unless $loaded;}
 use Imager qw(:all);
 
@@ -68,13 +68,13 @@ $img->write(file=>"testout/t75big.ppm") or die $img->errstr;
 
 print "ok 5\n";
 
 
 print "ok 5\n";
 
-$img = Imager->new(xsize => 200, ysize => 200);
-
-$img -> polygon(color=>$blue,
+$img = Imager->new(xsize => 300, ysize => 300);
+$img -> polygon(color=>$white,
                points => [
                points => [
-                          translate(100,100,
-                                    scale(10,10,
-                                          get_polygon('wavycircle', 32*4, sub { 8+0.5*cos(12*$_) })))
+                          translate(150,150,
+                                    rotate(45*PI/180,
+                                           scale(70,70,
+                                                 get_polygon('wavycircle', 32*8, sub { 1.2+1*cos(4*$_) }))))
                          ],
               ) or die $img->errstr();
 
                          ],
               ) or die $img->errstr();
 
@@ -82,6 +82,26 @@ $img->write(file=>"testout/t75wave.ppm") or die $img->errstr;
 
 print "ok 6\n";
 
 
 print "ok 6\n";
 
+
+$img = Imager->new(xsize=>10,ysize=>6);
+@data = translate(165,5,
+                 scale(80,80,
+                       get_polygon('wavycircle', 32*8, sub { 1+1*cos(4*$_) })));
+
+print "XXX\n";
+$img -> polygon(color=>$white,
+               points => [
+                          translate(165,5,
+                                    scale(80,80,
+                                          get_polygon('wavycircle', 32*8, sub { 1+1*cos(4*$_) })))
+                         ],
+              ) or die $img->errstr();
+
+make_zoom($img,20,\@data, $blue)->write(file=>"testout/t75wavebug.ppm") or die $img->errstr;
+
+
+print "ok 7\n";
+
 malloc_state();
 
 
 malloc_state();