]> git.imager.perl.org - imager.git/blobdiff - imgdouble.c
Initial version
[imager.git] / imgdouble.c
index 0afd3dc2b2c8000e517bc7d9ffc817eddf63659b..8dc4ccc6f85e1ac52b702b8f66071bf5afb58f9b 100644 (file)
@@ -32,9 +32,9 @@ static int i_gpixf_ddoub(i_img *im, int x, int y, i_fcolor *val);
 static int i_glinf_ddoub(i_img *im, int l, int r, int y, i_fcolor *vals);
 static int i_plinf_ddoub(i_img *im, int l, int r, int y, i_fcolor *vals);
 static int i_gsamp_ddoub(i_img *im, int l, int r, int y, i_sample_t *samps, 
-                       int *chans, int chan_count);
+                       int const *chans, int chan_count);
 static int i_gsampf_ddoub(i_img *im, int l, int r, int y, i_fsample_t *samps, 
-                        int *chans, int chan_count);
+                        int const *chans, int chan_count);
 
 /*
 =item IIM_base_16bit_direct
@@ -86,14 +86,30 @@ Creates a new double per sample image.
 =cut
 */
 i_img *i_img_double_new_low(i_img *im, int x, int y, int ch) {
+  int bytes;
+
   mm_log((1,"i_img_double_new(x %d, y %d, ch %d)\n", x, y, ch));
+
+  if (x < 1 || y < 1) {
+    i_push_error(0, "Image sizes must be positive");
+    return NULL;
+  }
+  if (ch < 1 || ch > MAXCHANNELS) {
+    i_push_errorf(0, "channels must be between 1 and %d", MAXCHANNELS);
+    return NULL;
+  }
+  bytes = x * y * ch * sizeof(double);
+  if (bytes / y / ch / sizeof(double) != x) {
+    i_push_errorf(0, "integer overflow calculating image allocation");
+    return NULL;
+  }
   
   *im = IIM_base_double_direct;
   i_tags_new(&im->tags);
   im->xsize = x;
   im->ysize = y;
   im->channels = ch;
-  im->bytes = x * y * ch * sizeof(double);
+  im->bytes = bytes;
   im->ext_data = NULL;
   im->idata = mymalloc(im->bytes);
   if (im->idata) {
@@ -110,6 +126,8 @@ i_img *i_img_double_new_low(i_img *im, int x, int y, int ch) {
 i_img *i_img_double_new(int x, int y, int ch) {
   i_img *im;
 
+  i_clear_error();
+
   im = mymalloc(sizeof(i_img));
   if (im) {
     if (!i_img_double_new_low(im, x, y, ch)) {
@@ -260,7 +278,7 @@ static int i_plinf_ddoub(i_img *im, int l, int r, int y, i_fcolor *vals) {
 }
 
 static int i_gsamp_ddoub(i_img *im, int l, int r, int y, i_sample_t *samps, 
-                       int *chans, int chan_count) {
+                       int const *chans, int chan_count) {
   int ch, count, i, w;
   int off;
 
@@ -305,7 +323,7 @@ static int i_gsamp_ddoub(i_img *im, int l, int r, int y, i_sample_t *samps,
 }
 
 static int i_gsampf_ddoub(i_img *im, int l, int r, int y, i_fsample_t *samps, 
-                        int *chans, int chan_count) {
+                        int const *chans, int chan_count) {
   int ch, count, i, w;
   int off;