]> git.imager.perl.org - imager.git/commitdiff
allow box() to accept floating colors for filling areas
authorTony Cook <tony@develop-help.com>
Mon, 16 May 2011 12:51:32 +0000 (22:51 +1000)
committerTony Cook <tony@develop-help.com>
Mon, 16 May 2011 12:54:14 +0000 (22:54 +1000)
Imager.pm
Imager.xs
draw.c
imager.h
lib/Imager/LargeSamples.pod

index 3b689b4a4da0ad81d4bef1dd394427447a667e42..b2575c13830bab71b3fc6647525aea2f28590f83 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -2681,7 +2681,12 @@ sub box {
       $color = i_color_new(255,255,255,255);
     }
 
-    i_box_filled($raw, $xmin, $ymin,$xmax, $ymax, $color);
+    if ($color->isa("Imager::Color")) {
+      i_box_filled($raw, $xmin, $ymin,$xmax, $ymax, $color);
+    }
+    else {
+      i_box_filledf($raw, $xmin, $ymin,$xmax, $ymax, $color);
+    }
   }
   elsif ($opts{fill}) {
     unless (UNIVERSAL::isa($opts{fill}, 'Imager::Fill')) {
index 8aa49d4d8dc3586a9afe41f55eb06c137aa33599..d6e8471a066e03857aaf7b184040056d837ef157 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -1453,6 +1453,15 @@ i_box_filled(im,x1,y1,x2,y2,val)
               int     y2
           Imager::Color    val
 
+int
+i_box_filledf(im,x1,y1,x2,y2,val)
+    Imager::ImgRaw     im
+              int     x1
+              int     y1
+              int     x2
+              int     y2
+          Imager::Color::Float    val
+
 void
 i_box_cfill(im,x1,y1,x2,y2,fill)
     Imager::ImgRaw     im
diff --git a/draw.c b/draw.c
index 1c04efbf9be2861ef18011470ea3dfa031e3d17d..58239edcfe37649dd21457476249efb7284e64be 100644 (file)
--- a/draw.c
+++ b/draw.c
@@ -1122,6 +1122,65 @@ i_box_filled(i_img *im,int x1,int y1,int x2,int y2, const i_color *val) {
   }
 }
 
+/*
+=item i_box_filledf(im, x1, y1, x2, y2, color)
+
+=category Drawing
+=synopsis i_box_filledf(im, 0, 0, im->xsize-1, im->ysize-1, &fcolor);
+
+Fills the box from (x1,y1) to (x2,y2) inclusive with a floating point
+color.
+
+=cut
+*/
+
+int
+i_box_filledf(i_img *im,int x1,int y1,int x2,int y2, const i_fcolor *val) {
+  i_img_dim x, y, width;
+  i_palidx index;
+
+  mm_log((1,"i_box_filledf(im* 0x%x,x1 %d,y1 %d,x2 %d,y2 %d,val 0x%x)\n",im,x1,y1,x2,y2,val));
+
+  if (x1 > x2 || y1 > y2
+      || x2 < 0 || y2 < 0
+      || x1 >= im->xsize || y1 > im->ysize)
+    return 0;
+
+  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->bits <= 8) {
+    i_color c;
+    c.rgba.r = SampleFTo8(val->rgba.r);
+    c.rgba.g = SampleFTo8(val->rgba.g);
+    c.rgba.b = SampleFTo8(val->rgba.b);
+    c.rgba.a = SampleFTo8(val->rgba.a);
+
+    i_box_filled(im, x1, y1, x2, y2, &c);
+  }
+  else {
+    i_fcolor *line = mymalloc(sizeof(i_fcolor) * width);
+    
+    for (x = 0; x < width; ++x)
+      line[x] = *val;
+    
+    for (y = y1; y <= y2; ++y)
+      i_plinf(im, x1, x2+1, y, line);
+    
+    myfree(line);
+  }
+  
+  return 1;
+}
+
 /*
 =item i_box_cfill(im, x1, y1, x2, y2, fill)
 
index 5e9669e32d45062a9806cb6e8b857c083e0486e1..944c97f640296f436aaea94f62374982e72929a7 100644 (file)
--- a/imager.h
+++ b/imager.h
@@ -164,6 +164,7 @@ float i_gpix_pch(i_img *im,int x,int y,int ch);
 
 void i_box         (i_img *im,int x1,int y1,int x2,int y2,const i_color *val);
 void i_box_filled  (i_img *im,int x1,int y1,int x2,int y2,const i_color *val);
+int i_box_filledf  (i_img *im,int x1,int y1,int x2,int y2,const i_fcolor *val);
 void i_box_cfill(i_img *im, int x1, int y1, int x2, int y2, i_fill_t *fill);
 void i_line        (i_img *im,int x1,int y1,int x2,int y2,const i_color *val, int endp);
 void i_line_aa     (i_img *im,int x1,int y1,int x2,int y2,const i_color *val, int endp);
index fe2f8f027ad745153fdf5ccc3a578f73779d3d93..5e462299e240e40d38e0c002e85e8d2012b00582 100644 (file)
@@ -26,7 +26,7 @@ don't, for future improvements.
   Method       Support    Notes
   ------       -------    -----
   arc          Partial    [1]
-  box          Partial    [1]
+  box          Partial    [2]
   circle       Partial    [1]
   convert      Full
   copy         Full
@@ -64,6 +64,9 @@ don't, for future improvements.
 [1] filling an area using the fill parameter works at the full depth
 of the image, using filled => 1 and color works at 8-bits/sample
 
+[2] box() will fill the area at the supplied color, but outline at
+8-bits/sample.
+
 =head1 File format large sample support
 
   Format    Format samples    Imager support