]> git.imager.perl.org - imager.git/blobdiff - imgdouble.c
i_test_format_probe:
[imager.git] / imgdouble.c
index 8dc4ccc6f85e1ac52b702b8f66071bf5afb58f9b..903912ba1c76054244837574dc2ebbdd369cdbe6 100644 (file)
@@ -20,17 +20,17 @@ sample image type to work with.
 =cut
 */
 
 =cut
 */
 
-#include "image.h"
-#include "imagei.h"
+#include "imager.h"
+#include "imageri.h"
 
 
-static int i_ppix_ddoub(i_img *im, int x, int y, i_color *val);
+static int i_ppix_ddoub(i_img *im, int x, int y, const i_color *val);
 static int i_gpix_ddoub(i_img *im, int x, int y, i_color *val);
 static int i_glin_ddoub(i_img *im, int l, int r, int y, i_color *vals);
 static int i_gpix_ddoub(i_img *im, int x, int y, i_color *val);
 static int i_glin_ddoub(i_img *im, int l, int r, int y, i_color *vals);
-static int i_plin_ddoub(i_img *im, int l, int r, int y, i_color *vals);
-static int i_ppixf_ddoub(i_img *im, int x, int y, i_fcolor *val);
+static int i_plin_ddoub(i_img *im, int l, int r, int y, const i_color *vals);
+static int i_ppixf_ddoub(i_img *im, int x, int y, const i_fcolor *val);
 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_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_plinf_ddoub(i_img *im, int l, int r, int y, const i_fcolor *vals);
 static int i_gsamp_ddoub(i_img *im, int l, int r, int y, i_sample_t *samps, 
                        int const *chans, int chan_count);
 static int i_gsampf_ddoub(i_img *im, int l, int r, int y, i_fsample_t *samps, 
 static int i_gsamp_ddoub(i_img *im, int l, int r, int y, i_sample_t *samps, 
                        int const *chans, int chan_count);
 static int i_gsampf_ddoub(i_img *im, int l, int r, int y, i_fsample_t *samps, 
@@ -81,6 +81,8 @@ static i_img IIM_base_double_direct =
 /*
 =item i_img_double_new(int x, int y, int ch)
 
 /*
 =item i_img_double_new(int x, int y, int ch)
 
+=category Image creation
+
 Creates a new double per sample image.
 
 =cut
 Creates a new double per sample image.
 
 =cut
@@ -141,15 +143,22 @@ i_img *i_img_double_new(int x, int y, int ch) {
   return im;
 }
 
   return im;
 }
 
-static int i_ppix_ddoub(i_img *im, int x, int y, i_color *val) {
+static int i_ppix_ddoub(i_img *im, int x, int y, const i_color *val) {
   int off, ch;
 
   if (x < 0 || x >= im->xsize || y < 0 || y > im->ysize) 
     return -1;
 
   off = (x + y * im->xsize) * im->channels;
   int off, ch;
 
   if (x < 0 || x >= im->xsize || y < 0 || y > im->ysize) 
     return -1;
 
   off = (x + y * im->xsize) * im->channels;
-  for (ch = 0; ch < im->channels; ++ch)
-    ((double*)im->idata)[off+ch] = Sample8ToF(val->channel[ch]);
+  if (I_ALL_CHANNELS_WRITABLE(im)) {
+    for (ch = 0; ch < im->channels; ++ch)
+      ((double*)im->idata)[off+ch] = Sample8ToF(val->channel[ch]);
+  }
+  else {
+    for (ch = 0; ch < im->channels; ++ch)
+      if (im->ch_mask & (1<<ch))
+       ((double*)im->idata)[off+ch] = Sample8ToF(val->channel[ch]);
+  }
 
   return 0;
 }
 
   return 0;
 }
@@ -167,15 +176,22 @@ static int i_gpix_ddoub(i_img *im, int x, int y, i_color *val) {
   return 0;
 }
 
   return 0;
 }
 
-static int i_ppixf_ddoub(i_img *im, int x, int y, i_fcolor *val) {
+static int i_ppixf_ddoub(i_img *im, int x, int y, const i_fcolor *val) {
   int off, ch;
 
   if (x < 0 || x >= im->xsize || y < 0 || y > im->ysize) 
     return -1;
 
   off = (x + y * im->xsize) * im->channels;
   int off, ch;
 
   if (x < 0 || x >= im->xsize || y < 0 || y > im->ysize) 
     return -1;
 
   off = (x + y * im->xsize) * im->channels;
-  for (ch = 0; ch < im->channels; ++ch)
-    ((double *)im->idata)[off+ch] = val->channel[ch];;
+  if (I_ALL_CHANNELS_WRITABLE(im)) {
+    for (ch = 0; ch < im->channels; ++ch)
+      ((double *)im->idata)[off+ch] = val->channel[ch];
+  }
+  else {
+    for (ch = 0; ch < im->channels; ++ch)
+      if (im->ch_mask & (1 << ch))
+       ((double *)im->idata)[off+ch] = val->channel[ch];
+  }
 
   return 0;
 }
 
   return 0;
 }
@@ -214,7 +230,7 @@ static int i_glin_ddoub(i_img *im, int l, int r, int y, i_color *vals) {
   }
 }
 
   }
 }
 
-static int i_plin_ddoub(i_img *im, int l, int r, int y, i_color *vals) {
+static int i_plin_ddoub(i_img *im, int l, int r, int y, const i_color *vals) {
   int ch, count, i;
   int off;
   if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
   int ch, count, i;
   int off;
   if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
@@ -222,10 +238,21 @@ static int i_plin_ddoub(i_img *im, int l, int r, int y, i_color *vals) {
       r = im->xsize;
     off = (l+y*im->xsize) * im->channels;
     count = r - l;
       r = im->xsize;
     off = (l+y*im->xsize) * im->channels;
     count = r - l;
-    for (i = 0; i < count; ++i) {
-      for (ch = 0; ch < im->channels; ++ch) {
-        ((double *)im->idata)[off] = Sample8ToF(vals[i].channel[ch]);
-        ++off;
+    if (I_ALL_CHANNELS_WRITABLE(im)) {
+      for (i = 0; i < count; ++i) {
+       for (ch = 0; ch < im->channels; ++ch) {
+         ((double *)im->idata)[off] = Sample8ToF(vals[i].channel[ch]);
+         ++off;
+       }
+      }
+    }
+    else {
+      for (i = 0; i < count; ++i) {
+       for (ch = 0; ch < im->channels; ++ch) {
+         if (im->ch_mask & (1 << ch))
+           ((double *)im->idata)[off] = Sample8ToF(vals[i].channel[ch]);
+         ++off;
+       }
       }
     }
     return count;
       }
     }
     return count;
@@ -256,7 +283,7 @@ 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_plinf_ddoub(i_img *im, int l, int r, int y, const i_fcolor *vals) {
   int ch, count, i;
   int off;
   if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
   int ch, count, i;
   int off;
   if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
@@ -264,10 +291,21 @@ static int i_plinf_ddoub(i_img *im, int l, int r, int y, i_fcolor *vals) {
       r = im->xsize;
     off = (l+y*im->xsize) * im->channels;
     count = r - l;
       r = im->xsize;
     off = (l+y*im->xsize) * im->channels;
     count = r - l;
-    for (i = 0; i < count; ++i) {
-      for (ch = 0; ch < im->channels; ++ch) {
-        ((double *)im->idata)[off] = vals[i].channel[ch];
-        ++off;
+    if (I_ALL_CHANNELS_WRITABLE(im)) {
+      for (i = 0; i < count; ++i) {
+       for (ch = 0; ch < im->channels; ++ch) {
+         ((double *)im->idata)[off] = vals[i].channel[ch];
+         ++off;
+       }
+      }
+    }
+    else {
+      for (i = 0; i < count; ++i) {
+       for (ch = 0; ch < im->channels; ++ch) {
+         if (im->ch_mask & (1 << ch))
+           ((double *)im->idata)[off] = vals[i].channel[ch];
+         ++off;
+       }
       }
     }
     return count;
       }
     }
     return count;