Imager
view release on metacpan or search on metacpan
myfree(line);
}
return 1;
}
/*
=item i_box_cfill(im, x1, y1, x2, y2, fill)
=category Drawing
=synopsis i_box_cfill(im, 0, 0, im->xsize-1, im->ysize-1, fill);
Fills the box from (x1,y1) to (x2,y2) inclusive with fill.
=cut
*/
void
i_box_cfill(i_img *im,i_img_dim x1,i_img_dim y1,i_img_dim x2,i_img_dim y2,i_fill_t *fill) {
i_render r;
dIMCTXim(im);
im_log((aIMCTX,1,"i_box_cfill(im* %p, p1(" i_DFp "), p2(" i_DFp "), fill %p)\n",
im, i_DFcp(x1, y1), i_DFcp(x2,y2), fill));
++x2;
if (x1 < 0)
x1 = 0;
if (y1 < 0)
y1 = 0;
if (x2 > im->xsize)
x2 = im->xsize;
if (y2 >= im->ysize)
y2 = im->ysize-1;
if (x1 >= x2 || y1 > y2)
return;
i_render_init(&r, im, x2-x1);
while (y1 <= y2) {
i_render_fill(&r, x1, y1, x2-x1, NULL, fill);
++y1;
}
i_render_done(&r);
}
/*
=item i_line(C<im>, C<x1>, C<y1>, C<x2>, C<y2>, C<color>, C<endp>)
=category Drawing
=for stopwords Bresenham's
Draw a line to image using Bresenham's line drawing algorithm
im - image to draw to
x1 - starting x coordinate
y1 - starting x coordinate
x2 - starting x coordinate
y2 - starting x coordinate
color - color to write to image
endp - endpoint flag (boolean)
=cut
*/
void
i_line(i_img *im, i_img_dim x1, i_img_dim y1, i_img_dim x2, i_img_dim y2, const i_color *val, int endp) {
i_img_dim x, y;
i_img_dim dx, dy;
i_img_dim p;
dx = x2 - x1;
dy = y2 - y1;
/* choose variable to iterate on */
if (i_abs(dx) > i_abs(dy)) {
i_img_dim dx2, dy2, cpy;
/* sort by x */
if (x1 > x2) {
i_img_dim t;
t = x1; x1 = x2; x2 = t;
t = y1; y1 = y2; y2 = t;
}
dx = i_abs(dx);
dx2 = dx*2;
dy = y2 - y1;
if (dy<0) {
dy = -dy;
cpy = -1;
} else {
cpy = 1;
}
dy2 = dy*2;
p = dy2 - dx;
y = y1;
for(x=x1; x<x2-1; x++) {
if (p<0) {
p += dy2;
} else {
y += cpy;
p += dy2-dx2;
}
i_ppix(im, x+1, y, val);
}
} else {
i_img_dim dy2, dx2, cpx;
/* sort bx y */
if (y1 > y2) {
i_img_dim t;
t = x1; x1 = x2; x2 = t;
t = y1; y1 = y2; y2 = t;
}
dy = i_abs(dy);
( run in 1.207 second using v1.01-cache-2.11-cpan-524268b4103 )