]> git.imager.perl.org - imager.git/commitdiff
image fills with images with channels not at 4 were broken
authorTony Cook <tony@develop=help.com>
Wed, 25 Jun 2003 03:22:14 +0000 (03:22 +0000)
committerTony Cook <tony@develop=help.com>
Wed, 25 Jun 2003 03:22:14 +0000 (03:22 +0000)
Changes
fills.c

diff --git a/Changes b/Changes
index ef63b77305592a0b057136c65ce9ba1926011a28..63a29956905bc17b4872c62398adc3a065d41151 100644 (file)
--- a/Changes
+++ b/Changes
@@ -718,6 +718,9 @@ Revision history for Perl extension Imager.
           which we use, define it if freetype doesn't.
         - Added extra options to rubthrough() so only a subpart of
           source image is used.
+        - the image fills didn't handle filling with source images of
+          less than four channels correctly
+
 =================================================================
 
         For latest versions check the Imager-devel pages:
diff --git a/fills.c b/fills.c
index de9f1628ecb6762ac7f0ad11a9181d72cc8382fd..9d54639bd4ee5378f0241c8703df6d38c2f6d6ad 100644 (file)
--- a/fills.c
+++ b/fills.c
@@ -727,6 +727,7 @@ static void fill_image(i_fill_t *fill, int x, int y, int width, int channels,
   struct i_fill_image_t *f = (struct i_fill_image_t *)fill;
   int i = 0;
   i_color c;
+  i_color *out = data;
   
   if (f->has_matrix) {
     /* the hard way */
@@ -761,7 +762,7 @@ static void fill_image(i_fill_t *fill, int x, int y, int width, int channels,
         }
         c2[dy] = interp_i_color(c[dy][0], c[dy][1], rx, f->src->channels);
       }
-      *data++ = interp_i_color(c2[0], c2[1], ry, f->src->channels);
+      *out++ = interp_i_color(c2[0], c2[1], ry, f->src->channels);
       ++i;
     }
   }
@@ -784,11 +785,34 @@ static void fill_image(i_fill_t *fill, int x, int y, int width, int channels,
       }
       rx -= ix * f->src->xsize;
       ry -= iy * f->src->ysize;
-      i_gpix(f->src, rx, ry, data);
-      ++data;
+      i_gpix(f->src, rx, ry, out);
+      ++out;
       ++i;
     }
   }
+  if (f->src->channels == 3) {
+    /* just set the alpha */
+    for (i = 0; i <  width; ++i) {
+      data->channel[3] = 255;
+      data++;
+    }
+  }
+  else if (f->src->channels == 2) {
+    /* copy the alpha to channel 3, duplicate the grey value */
+    for (i = 0; i <  width; ++i) {
+      data->channel[3] = data->channel[1];
+      data->channel[1] = data->channel[2] = data->channel[0];
+      data++;
+    }
+  }
+  else if (f->src->channels == 1) {
+    /* set the alpha, duplicate grey */
+    for (i = 0; i <  width; ++i) {
+      data->channel[3] = 255;
+      data->channel[1] = data->channel[2] = data->channel[0];
+      data++;
+    }
+  }
 }
 
 /*
@@ -863,6 +887,29 @@ static void fill_imagef(i_fill_t *fill, int x, int y, int width, int channels,
       ++i;
     }
   }
+  if (f->src->channels == 3) {
+    /* just set the alpha */
+    for (i = 0; i <  width; ++i) {
+      data->channel[3] = 1.0;
+      data++;
+    }
+  }
+  else if (f->src->channels == 2) {
+    /* copy the alpha to channel 3, duplicate the grey value */
+    for (i = 0; i <  width; ++i) {
+      data->channel[3] = data->channel[1];
+      data->channel[1] = data->channel[2] = data->channel[0];
+      data++;
+    }
+  }
+  else if (f->src->channels == 1) {
+    /* set the alpha, duplicate grey */
+    for (i = 0; i <  width; ++i) {
+      data->channel[3] = 1.0;
+      data->channel[1] = data->channel[2] = data->channel[0];
+      data++;
+    }
+  }
 }
 
 static void combine_replace(i_color *, i_color *, int, int);