4 imgdouble.c - implements double per sample images
8 i_img *im = i_img_double_new(int x, int y, int channels);
9 # use like a normal image
13 Implements double/sample images.
15 This basic implementation is required so that we have some larger
16 sample image type to work with.
26 static int i_ppix_ddoub(i_img *im, int x, int y, const i_color *val);
27 static int i_gpix_ddoub(i_img *im, int x, int y, i_color *val);
28 static int i_glin_ddoub(i_img *im, int l, int r, int y, i_color *vals);
29 static int i_plin_ddoub(i_img *im, int l, int r, int y, const i_color *vals);
30 static int i_ppixf_ddoub(i_img *im, int x, int y, const i_fcolor *val);
31 static int i_gpixf_ddoub(i_img *im, int x, int y, i_fcolor *val);
32 static int i_glinf_ddoub(i_img *im, int l, int r, int y, i_fcolor *vals);
33 static int i_plinf_ddoub(i_img *im, int l, int r, int y, const i_fcolor *vals);
34 static int i_gsamp_ddoub(i_img *im, int l, int r, int y, i_sample_t *samps,
35 int const *chans, int chan_count);
36 static int i_gsampf_ddoub(i_img *im, int l, int r, int y, i_fsample_t *samps,
37 int const *chans, int chan_count);
40 =item IIM_base_16bit_direct
42 Base structure used to initialize a 16-bit/sample image.
48 static i_img IIM_base_double_direct =
51 0, 0, 0, /* xsize, ysize, bytes */
53 i_double_bits, /* bits */
54 i_direct_type, /* type */
57 { 0, 0, NULL }, /* tags */
60 i_ppix_ddoub, /* i_f_ppix */
61 i_ppixf_ddoub, /* i_f_ppixf */
62 i_plin_ddoub, /* i_f_plin */
63 i_plinf_ddoub, /* i_f_plinf */
64 i_gpix_ddoub, /* i_f_gpix */
65 i_gpixf_ddoub, /* i_f_gpixf */
66 i_glin_ddoub, /* i_f_glin */
67 i_glinf_ddoub, /* i_f_glinf */
68 i_gsamp_ddoub, /* i_f_gsamp */
69 i_gsampf_ddoub, /* i_f_gsampf */
73 NULL, /* i_f_addcolor */
74 NULL, /* i_f_getcolor */
75 NULL, /* i_f_colorcount */
76 NULL, /* i_f_findcolor */
78 NULL, /* i_f_destroy */
82 =item i_img_double_new(int x, int y, int ch)
84 =category Image creation/destruction
85 =synopsis i_img *img = i_img_double_new(width, height, channels);
87 Creates a new double per sample image.
91 i_img *i_img_double_new_low(i_img *im, int x, int y, int ch) {
94 mm_log((1,"i_img_double_new(x %d, y %d, ch %d)\n", x, y, ch));
97 i_push_error(0, "Image sizes must be positive");
100 if (ch < 1 || ch > MAXCHANNELS) {
101 i_push_errorf(0, "channels must be between 1 and %d", MAXCHANNELS);
104 bytes = x * y * ch * sizeof(double);
105 if (bytes / y / ch / sizeof(double) != x) {
106 i_push_errorf(0, "integer overflow calculating image allocation");
110 *im = IIM_base_double_direct;
111 i_tags_new(&im->tags);
117 im->idata = mymalloc(im->bytes);
119 memset(im->idata, 0, im->bytes);
122 i_tags_destroy(&im->tags);
129 i_img *i_img_double_new(int x, int y, int ch) {
134 im = mymalloc(sizeof(i_img));
136 if (!i_img_double_new_low(im, x, y, ch)) {
142 mm_log((1, "(%p) <- i_img_double_new\n", im));
147 static int i_ppix_ddoub(i_img *im, int x, int y, const i_color *val) {
150 if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
153 off = (x + y * im->xsize) * im->channels;
154 if (I_ALL_CHANNELS_WRITABLE(im)) {
155 for (ch = 0; ch < im->channels; ++ch)
156 ((double*)im->idata)[off+ch] = Sample8ToF(val->channel[ch]);
159 for (ch = 0; ch < im->channels; ++ch)
160 if (im->ch_mask & (1<<ch))
161 ((double*)im->idata)[off+ch] = Sample8ToF(val->channel[ch]);
167 static int i_gpix_ddoub(i_img *im, int x, int y, i_color *val) {
170 if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
173 off = (x + y * im->xsize) * im->channels;
174 for (ch = 0; ch < im->channels; ++ch)
175 val->channel[ch] = SampleFTo8(((double *)im->idata)[off+ch]);
180 static int i_ppixf_ddoub(i_img *im, int x, int y, const i_fcolor *val) {
183 if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
186 off = (x + y * im->xsize) * im->channels;
187 if (I_ALL_CHANNELS_WRITABLE(im)) {
188 for (ch = 0; ch < im->channels; ++ch)
189 ((double *)im->idata)[off+ch] = val->channel[ch];
192 for (ch = 0; ch < im->channels; ++ch)
193 if (im->ch_mask & (1 << ch))
194 ((double *)im->idata)[off+ch] = val->channel[ch];
200 static int i_gpixf_ddoub(i_img *im, int x, int y, i_fcolor *val) {
203 if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
206 off = (x + y * im->xsize) * im->channels;
207 for (ch = 0; ch < im->channels; ++ch)
208 val->channel[ch] = ((double *)im->idata)[off+ch];
213 static int i_glin_ddoub(i_img *im, int l, int r, int y, i_color *vals) {
216 if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
219 off = (l+y*im->xsize) * im->channels;
221 for (i = 0; i < count; ++i) {
222 for (ch = 0; ch < im->channels; ++ch) {
223 vals[i].channel[ch] = SampleFTo8(((double *)im->idata)[off]);
234 static int i_plin_ddoub(i_img *im, int l, int r, int y, const i_color *vals) {
237 if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
240 off = (l+y*im->xsize) * im->channels;
242 if (I_ALL_CHANNELS_WRITABLE(im)) {
243 for (i = 0; i < count; ++i) {
244 for (ch = 0; ch < im->channels; ++ch) {
245 ((double *)im->idata)[off] = Sample8ToF(vals[i].channel[ch]);
251 for (i = 0; i < count; ++i) {
252 for (ch = 0; ch < im->channels; ++ch) {
253 if (im->ch_mask & (1 << ch))
254 ((double *)im->idata)[off] = Sample8ToF(vals[i].channel[ch]);
266 static int i_glinf_ddoub(i_img *im, int l, int r, int y, i_fcolor *vals) {
269 if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
272 off = (l+y*im->xsize) * im->channels;
274 for (i = 0; i < count; ++i) {
275 for (ch = 0; ch < im->channels; ++ch) {
276 vals[i].channel[ch] = ((double *)im->idata)[off];
287 static int i_plinf_ddoub(i_img *im, int l, int r, int y, const i_fcolor *vals) {
290 if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
293 off = (l+y*im->xsize) * im->channels;
295 if (I_ALL_CHANNELS_WRITABLE(im)) {
296 for (i = 0; i < count; ++i) {
297 for (ch = 0; ch < im->channels; ++ch) {
298 ((double *)im->idata)[off] = vals[i].channel[ch];
304 for (i = 0; i < count; ++i) {
305 for (ch = 0; ch < im->channels; ++ch) {
306 if (im->ch_mask & (1 << ch))
307 ((double *)im->idata)[off] = vals[i].channel[ch];
319 static int i_gsamp_ddoub(i_img *im, int l, int r, int y, i_sample_t *samps,
320 int const *chans, int chan_count) {
324 if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
327 off = (l+y*im->xsize) * im->channels;
332 /* make sure we have good channel numbers */
333 for (ch = 0; ch < chan_count; ++ch) {
334 if (chans[ch] < 0 || chans[ch] >= im->channels) {
335 i_push_errorf(0, "No channel %d in this image", chans[ch]);
339 for (i = 0; i < w; ++i) {
340 for (ch = 0; ch < chan_count; ++ch) {
341 *samps++ = SampleFTo8(((double *)im->idata)[off+chans[ch]]);
348 for (i = 0; i < w; ++i) {
349 for (ch = 0; ch < chan_count; ++ch) {
350 *samps++ = SampleFTo8(((double *)im->idata)[off+ch]);
364 static int i_gsampf_ddoub(i_img *im, int l, int r, int y, i_fsample_t *samps,
365 int const *chans, int chan_count) {
369 if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
372 off = (l+y*im->xsize) * im->channels;
377 /* make sure we have good channel numbers */
378 for (ch = 0; ch < chan_count; ++ch) {
379 if (chans[ch] < 0 || chans[ch] >= im->channels) {
380 i_push_errorf(0, "No channel %d in this image", chans[ch]);
384 for (i = 0; i < w; ++i) {
385 for (ch = 0; ch < chan_count; ++ch) {
386 *samps++ = ((double *)im->idata)[off+chans[ch]];
393 for (i = 0; i < w; ++i) {
394 for (ch = 0; ch < chan_count; ++ch) {
395 *samps++ = ((double *)im->idata)[off+ch];
415 Tony Cook <tony@develop-help.com>