Skip to content

Commit

Permalink
Bug fixes for the polygon rendering code where naming the same pixel …
Browse files Browse the repository at this point in the history
…twice

would result in an entire line being wrong.
  • Loading branch information
Arnar Mar Hrafnkelsson committed Nov 12, 2001
1 parent 22e6c99 commit 24acc1a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 14 deletions.
35 changes: 28 additions & 7 deletions Imager/polygon.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,26 @@ ss_scanline_exorcise(ss_scanline *ss) {

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++) {
Expand Down Expand Up @@ -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);
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;

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)
);

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);
Expand All @@ -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) {
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) {
Expand Down
34 changes: 27 additions & 7 deletions Imager/t/t75polyaa.t
Original file line number Diff line number Diff line change
Expand Up @@ -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.)

BEGIN { $| = 1; print "1..6\n"; }
BEGIN { $| = 1; print "1..7\n"; }
END {print "not ok 1\n" unless $loaded;}
use Imager qw(:all);

Expand Down Expand Up @@ -68,20 +68,40 @@ $img->write(file=>"testout/t75big.ppm") or die $img->errstr;

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 => [
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();

$img->write(file=>"testout/t75wave.ppm") or die $img->errstr;

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();


Expand Down

0 comments on commit 24acc1a

Please sign in to comment.