]> git.imager.perl.org - imager.git/blobdiff - palimg.c
- samples/gifscale.pl sourced the base value for gif_top from
[imager.git] / palimg.c
index 261325954f2025d5546ff5518c3562a130caee0e..6bae01c3ebc6561ebf2cf9b773b8bbcef31c3cb2 100644 (file)
--- a/palimg.c
+++ b/palimg.c
@@ -71,18 +71,28 @@ static i_img IIM_base_8bit_pal =
   i_setcolors_p, /* i_f_setcolors */
 
   i_destroy_p, /* i_f_destroy */
+
+  i_gsamp_bits_fb,
+  NULL, /* i_f_psamp_bits */
 };
 
 /*
-=item i_img_pal_new_low(im, x, y, channels, maxpal)
+=item i_img_pal_new(x, y, channels, maxpal)
 
-Creates a new paletted image.
+=category Image creation/destruction
+=synopsis i_img *img = i_img_pal_new(width, height, channels, max_palette_size)
+
+Creates a new paletted image of the supplied dimensions.
 
-Currently 0 < maxpal <= 256
+I<maxpal> is the maximum palette size and should normally be 256.
+
+Returns a new image or NULL on failure.
 
 =cut
 */
-i_img *i_img_pal_new_low(i_img *im, int x, int y, int channels, int maxpal) {
+i_img *
+i_img_pal_new(int x, int y, int channels, int maxpal) {
+  i_img *im;
   i_img_pal_ext *palext;
   int bytes, line_bytes;
 
@@ -114,6 +124,7 @@ i_img *i_img_pal_new_low(i_img *im, int x, int y, int channels, int maxpal) {
     return NULL;
   }
 
+  im = i_img_alloc();
   memcpy(im, &IIM_base_8bit_pal, sizeof(i_img));
   palext = mymalloc(sizeof(i_img_pal_ext));
   palext->pal = mymalloc(sizeof(i_color) * maxpal);
@@ -128,31 +139,9 @@ i_img *i_img_pal_new_low(i_img *im, int x, int y, int channels, int maxpal) {
   memset(im->idata, 0, im->bytes);
   im->xsize = x;
   im->ysize = y;
-  
-  return im;
-}
-
-/*
-=item i_img_pal_new(x, y, channels, maxpal)
-
-=category Image creation
-
-Creates a new paletted image of the supplied dimensions.
-
-Returns a new image or NULL on failure.
-
-=cut
-*/
-
-i_img *i_img_pal_new(int x, int y, int channels, int maxpal) {
-  i_img *im;
-  mm_log((1, "i_img_pal_new(x %d, y %d, channels %d, maxpal %d)\n", x, y, channels, maxpal));
-  im = mymalloc(sizeof(i_img));
-  if (!i_img_pal_new_low(im, x, y, channels, maxpal)) {
-    myfree(im);
-    im = NULL;
-  }
 
+  i_img_init(im);
+  
   return im;
 }
 
@@ -423,6 +412,11 @@ static int i_gsamp_p(i_img *im, int l, int r, int y, i_sample_t *samps,
       }
     }
     else {
+      if (chan_count <= 0 || chan_count > im->channels) {
+       i_push_errorf(0, "chan_count %d out of range, must be >0, <= channels", 
+                     chan_count);
+       return 0;
+      }
       for (i = 0; i < w; ++i) {
         i_palidx which = *data++;
         if (which < palsize) {