]> git.imager.perl.org - imager.git/blobdiff - draw.c
bump Imager::Font version
[imager.git] / draw.c
diff --git a/draw.c b/draw.c
index 2aa28ffd73ea4f840bf3204d48cf3905f891060e..1c04efbf9be2861ef18011470ea3dfa031e3d17d 100644 (file)
--- a/draw.c
+++ b/draw.c
@@ -346,7 +346,7 @@ arc_poly(int *count, double **xvals, double **yvals,
 =category Drawing
 =synopsis i_arc_aa(im, 50, 50, 35, 90, 135, &color);
 
-Antialias fills an arc centered at (x,y) with radius I<rad> covering
+Anti-alias fills an arc centered at (x,y) with radius I<rad> covering
 the range of angles in degrees from d1 to d2, with the color.
 
 =cut
@@ -372,7 +372,7 @@ i_arc_aa(i_img *im, double x, double y, double rad, double d1, double d2,
 =category Drawing
 =synopsis i_arc_aa_cfill(im, 50, 50, 35, 90, 135, fill);
 
-Antialias fills an arc centered at (x,y) with radius I<rad> covering
+Anti-alias fills an arc centered at (x,y) with radius I<rad> covering
 the range of angles in degrees from d1 to d2, with the fill object.
 
 =cut
@@ -478,7 +478,7 @@ i_pixel_coverage(i_mmarray *dot, int x, int y) {
 =category Drawing
 =synopsis i_circle_aa(im, 50, 50, 45, &color);
 
-Antialias fills a circle centered at (x,y) for radius I<rad> with
+Anti-alias fills a circle centered at (x,y) for radius I<rad> with
 color.
 
 =cut
@@ -1076,9 +1076,50 @@ Fills the box from (x1,y1) to (x2,y2) inclusive with color.
 
 void
 i_box_filled(i_img *im,int x1,int y1,int x2,int y2, const i_color *val) {
-  int x,y;
+  i_img_dim x, y, width;
+  i_palidx index;
+
   mm_log((1,"i_box_filled(im* 0x%x,x1 %d,y1 %d,x2 %d,y2 %d,val 0x%x)\n",im,x1,y1,x2,y2,val));
-  for(x=x1;x<x2+1;x++) for (y=y1;y<y2+1;y++) i_ppix(im,x,y,val);
+
+  if (x1 > x2 || y1 > y2
+      || x2 < 0 || y2 < 0
+      || x1 >= im->xsize || y1 > im->ysize)
+    return;
+
+  if (x1 < 0)
+    x1 = 0;
+  if (x2 >= im->xsize)
+    x2 = im->xsize - 1;
+  if (y1 < 0)
+    y1 = 0;
+  if (y2 >= im->ysize)
+    y2 = im->ysize - 1;
+
+  width = x2 - x1 + 1;
+
+  if (im->type == i_palette_type
+      && i_findcolor(im, val, &index)) {
+    i_palidx *line = mymalloc(sizeof(i_palidx) * width);
+
+    for (x = 0; x < width; ++x)
+      line[x] = index;
+
+    for (y = y1; y <= y2; ++y)
+      i_ppal(im, x1, x2+1, y, line);
+
+    myfree(line);
+  }
+  else {
+    i_color *line = mymalloc(sizeof(i_color) * width);
+
+    for (x = 0; x < width; ++x)
+      line[x] = *val;
+
+    for (y = y1; y <= y2; ++y)
+      i_plin(im, x1, x2+1, y, line);
+
+    myfree(line);
+  }
 }
 
 /*
@@ -1118,19 +1159,21 @@ i_box_cfill(i_img *im,int x1,int y1,int x2,int y2,i_fill_t *fill) {
 }
 
 /* 
-=item i_line(im, x1, y1, x2, y2, val, endp)
+=item i_line(C<im>, C<x1>, C<y1>, C<x2>, C<y2>, C<color>, C<endp>)
 
 =category Drawing
 
-Draw a line to image using bresenhams linedrawing algorithm
+=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
-   val  - color to write to image
-   endp - endpoint flag (boolean)
+   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
 */
@@ -1238,13 +1281,13 @@ i_line_dda(i_img *im, int x1, int y1, int x2, int y2, i_color *val) {
 }
 
 /*
-=item i_line_aa(im, x1, x2, y1, y2, color, endp)
+=item i_line_aa(C<im>, C<x1>, C<x2>, C<y1>, C<y2>, C<color>, C<endp>)
 
 =category Drawing
 
-Antialias draws a line from (x1,y1) to (x2, y2) in color.
+Anti-alias draws a line from (x1,y1) to (x2, y2) in color.
 
-The point (x2, y2) is drawn only if endp is set.
+The point (x2, y2) is drawn only if C<endp> is set.
 
 =cut
 */
@@ -1607,6 +1650,8 @@ i_flood_fill_low(i_img *im,int seedx,int seedy,
   ltx = i_lspan(im, seedx, seedy, seed, cmpfunc);
   rtx = i_rspan(im, seedx, seedy, seed, cmpfunc);
   for(tx=ltx; tx<=rtx; tx++) SET(tx, seedy);
+  bxmin = ltx;
+  bxmax = rtx;
 
   ST_PUSH(ltx, rtx, ltx, rtx, seedy+1,  1);
   ST_PUSH(ltx, rtx, ltx, rtx, seedy-1, -1);
@@ -1633,7 +1678,7 @@ i_flood_fill_low(i_img *im,int seedx,int seedy,
     if ( lx >= 0 && (wasIn = INSIDE(lx, y, seed)) ) {
       SET(lx, y);
       lx--;
-      while(INSIDE(lx, y, seed) && lx > 0) {
+      while(lx >= 0 && INSIDE(lx, y, seed)) {
        SET(lx,y);
        lx--;
       }
@@ -1687,15 +1732,15 @@ i_flood_fill_low(i_img *im,int seedx,int seedy,
 }
 
 /*
-=item i_flood_fill(im, seedx, seedy, color)
+=item i_flood_fill(C<im>, C<seedx>, C<seedy>, C<color>)
 
 =category Drawing
 =synopsis i_flood_fill(im, 50, 50, &color);
 
-Flood fills the 4-connected region starting from the point (seedx,
-seedy) with I<color>.
+Flood fills the 4-connected region starting from the point (C<seedx>,
+C<seedy>) with I<color>.
 
-Returns false if (seedx, seedy) are outside the image.
+Returns false if (C<seedx>, C<seedy>) are outside the image.
 
 =cut
 */
@@ -1729,15 +1774,15 @@ i_flood_fill(i_img *im, int seedx, int seedy, const i_color *dcol) {
 }
 
 /*
-=item i_flood_cfill(im, seedx, seedy, fill)
+=item i_flood_cfill(C<im>, C<seedx>, C<seedy>, C<fill>)
 
 =category Drawing
 =synopsis i_flood_cfill(im, 50, 50, fill);
 
-Flood fills the 4-connected region starting from the point (seedx,
-seedy) with I<fill>.
+Flood fills the 4-connected region starting from the point (C<seedx>,
+C<seedy>) with C<fill>.
 
-Returns false if (seedx, seedy) are outside the image.
+Returns false if (C<seedx>, C<seedy>) are outside the image.
 
 =cut
 */
@@ -1769,16 +1814,16 @@ i_flood_cfill(i_img *im, int seedx, int seedy, i_fill_t *fill) {
 }
 
 /*
-=item i_flood_fill_border(im, seedx, seedy, color, border)
+=item i_flood_fill_border(C<im>, C<seedx>, C<seedy>, C<color>, C<border>)
 
 =category Drawing
 =synopsis i_flood_fill_border(im, 50, 50, &color, &border);
 
-Flood fills the 4-connected region starting from the point (seedx,
-seedy) with I<color>, fill stops when the fill reaches a pixels with
-color I<border>.
+Flood fills the 4-connected region starting from the point (C<seedx>,
+C<seedy>) with C<color>, fill stops when the fill reaches a pixels
+with color C<border>.
 
-Returns false if (seedx, seedy) are outside the image.
+Returns false if (C<seedx>, C<seedy>) are outside the image.
 
 =cut
 */
@@ -1809,16 +1854,16 @@ i_flood_fill_border(i_img *im, int seedx, int seedy, const i_color *dcol,
 }
 
 /*
-=item i_flood_cfill_border(im, seedx, seedy, fill, border)
+=item i_flood_cfill_border(C<im>, C<seedx>, C<seedy>, C<fill>, C<border>)
 
 =category Drawing
 =synopsis i_flood_cfill_border(im, 50, 50, fill, border);
 
-Flood fills the 4-connected region starting from the point (seedx,
-seedy) with I<fill>, the fill stops when it reaches pixels of color
-I<border>.
+Flood fills the 4-connected region starting from the point (C<seedx>,
+C<seedy>) with C<fill>, the fill stops when it reaches pixels of color
+C<border>.
 
-Returns false if (seedx, seedy) are outside the image.
+Returns false if (C<seedx>, C<seedy>) are outside the image.
 
 =cut
 */