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
86 Creates a new double per sample image.
90 i_img *i_img_double_new_low(i_img *im, int x, int y, int ch) {
93 mm_log((1,"i_img_double_new(x %d, y %d, ch %d)\n", x, y, ch));
96 i_push_error(0, "Image sizes must be positive");
99 if (ch < 1 || ch > MAXCHANNELS) {
100 i_push_errorf(0, "channels must be between 1 and %d", MAXCHANNELS);
103 bytes = x * y * ch * sizeof(double);
104 if (bytes / y / ch / sizeof(double) != x) {
105 i_push_errorf(0, "integer overflow calculating image allocation");
109 *im = IIM_base_double_direct;
110 i_tags_new(&im->tags);
116 im->idata = mymalloc(im->bytes);
118 memset(im->idata, 0, im->bytes);
121 i_tags_destroy(&im->tags);
128 i_img *i_img_double_new(int x, int y, int ch) {
133 im = mymalloc(sizeof(i_img));
135 if (!i_img_double_new_low(im, x, y, ch)) {
141 mm_log((1, "(%p) <- i_img_double_new\n", im));
146 static int i_ppix_ddoub(i_img *im, int x, int y, const i_color *val) {
149 if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
152 off = (x + y * im->xsize) * im->channels;
153 if (I_ALL_CHANNELS_WRITABLE(im)) {
154 for (ch = 0; ch < im->channels; ++ch)
155 ((double*)im->idata)[off+ch] = Sample8ToF(val->channel[ch]);
158 for (ch = 0; ch < im->channels; ++ch)
159 if (im->ch_mask & (1<<ch))
160 ((double*)im->idata)[off+ch] = Sample8ToF(val->channel[ch]);
166 static int i_gpix_ddoub(i_img *im, int x, int y, i_color *val) {
169 if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
172 off = (x + y * im->xsize) * im->channels;
173 for (ch = 0; ch < im->channels; ++ch)
174 val->channel[ch] = SampleFTo8(((double *)im->idata)[off+ch]);
179 static int i_ppixf_ddoub(i_img *im, int x, int y, const i_fcolor *val) {
182 if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
185 off = (x + y * im->xsize) * im->channels;
186 if (I_ALL_CHANNELS_WRITABLE(im)) {
187 for (ch = 0; ch < im->channels; ++ch)
188 ((double *)im->idata)[off+ch] = val->channel[ch];
191 for (ch = 0; ch < im->channels; ++ch)
192 if (im->ch_mask & (1 << ch))
193 ((double *)im->idata)[off+ch] = val->channel[ch];
199 static int i_gpixf_ddoub(i_img *im, int x, int y, i_fcolor *val) {
202 if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
205 off = (x + y * im->xsize) * im->channels;
206 for (ch = 0; ch < im->channels; ++ch)
207 val->channel[ch] = ((double *)im->idata)[off+ch];
212 static int i_glin_ddoub(i_img *im, int l, int r, int y, i_color *vals) {
215 if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
218 off = (l+y*im->xsize) * im->channels;
220 for (i = 0; i < count; ++i) {
221 for (ch = 0; ch < im->channels; ++ch) {
222 vals[i].channel[ch] = SampleFTo8(((double *)im->idata)[off]);
233 static int i_plin_ddoub(i_img *im, int l, int r, int y, const i_color *vals) {
236 if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
239 off = (l+y*im->xsize) * im->channels;
241 if (I_ALL_CHANNELS_WRITABLE(im)) {
242 for (i = 0; i < count; ++i) {
243 for (ch = 0; ch < im->channels; ++ch) {
244 ((double *)im->idata)[off] = Sample8ToF(vals[i].channel[ch]);
250 for (i = 0; i < count; ++i) {
251 for (ch = 0; ch < im->channels; ++ch) {
252 if (im->ch_mask & (1 << ch))
253 ((double *)im->idata)[off] = Sample8ToF(vals[i].channel[ch]);
265 static int i_glinf_ddoub(i_img *im, int l, int r, int y, i_fcolor *vals) {
268 if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
271 off = (l+y*im->xsize) * im->channels;
273 for (i = 0; i < count; ++i) {
274 for (ch = 0; ch < im->channels; ++ch) {
275 vals[i].channel[ch] = ((double *)im->idata)[off];
286 static int i_plinf_ddoub(i_img *im, int l, int r, int y, const i_fcolor *vals) {
289 if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
292 off = (l+y*im->xsize) * im->channels;
294 if (I_ALL_CHANNELS_WRITABLE(im)) {
295 for (i = 0; i < count; ++i) {
296 for (ch = 0; ch < im->channels; ++ch) {
297 ((double *)im->idata)[off] = vals[i].channel[ch];
303 for (i = 0; i < count; ++i) {
304 for (ch = 0; ch < im->channels; ++ch) {
305 if (im->ch_mask & (1 << ch))
306 ((double *)im->idata)[off] = vals[i].channel[ch];
318 static int i_gsamp_ddoub(i_img *im, int l, int r, int y, i_sample_t *samps,
319 int const *chans, int chan_count) {
323 if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
326 off = (l+y*im->xsize) * im->channels;
331 /* make sure we have good channel numbers */
332 for (ch = 0; ch < chan_count; ++ch) {
333 if (chans[ch] < 0 || chans[ch] >= im->channels) {
334 i_push_errorf(0, "No channel %d in this image", chans[ch]);
338 for (i = 0; i < w; ++i) {
339 for (ch = 0; ch < chan_count; ++ch) {
340 *samps++ = SampleFTo8(((double *)im->idata)[off+chans[ch]]);
347 for (i = 0; i < w; ++i) {
348 for (ch = 0; ch < chan_count; ++ch) {
349 *samps++ = SampleFTo8(((double *)im->idata)[off+ch]);
363 static int i_gsampf_ddoub(i_img *im, int l, int r, int y, i_fsample_t *samps,
364 int const *chans, int chan_count) {
368 if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
371 off = (l+y*im->xsize) * im->channels;
376 /* make sure we have good channel numbers */
377 for (ch = 0; ch < chan_count; ++ch) {
378 if (chans[ch] < 0 || chans[ch] >= im->channels) {
379 i_push_errorf(0, "No channel %d in this image", chans[ch]);
383 for (i = 0; i < w; ++i) {
384 for (ch = 0; ch < chan_count; ++ch) {
385 *samps++ = ((double *)im->idata)[off+chans[ch]];
392 for (i = 0; i < w; ++i) {
393 for (ch = 0; ch < chan_count; ++ch) {
394 *samps++ = ((double *)im->idata)[off+ch];
414 Tony Cook <tony@develop-help.com>