1 /**********
2 *
3 * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
4 * University of Manchester, UK. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 *
9 * . Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * . Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * . Neither the name of the University of Manchester nor the names of its
17 * contributors may be used to endorse or promote products derived from this
18 * software without specific prior written permission.
19 *
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 **********
34 *
35 * Program : TINA
36 * File : $Source: /home/tina/cvs/tina-libs/tina/image/imgGen_put.c,v $
37 * Date : $Date: 2003/09/22 16:09:02 $
38 * Version : $Revision: 1.4 $
39 * CVS Id : $Id: imgGen_put.c,v 1.4 2003/09/22 16:09:02 tony Exp $
40 */
41
42 /**
43 * @file
44 * @brief Pixel level write access to Imrect data.
45 *
46 * Pixels can be set individually, or along rows, columns or diagonals.
47 *
48 */
49
50
51 #include "imgGen_put.h"
52
53 #if HAVE_CONFIG_H
54 #include <config.h>
55 #endif
56
57 #include <stdio.h>
58 #include <math.h>
59 #include <stdlib.h>
60 #include <tina/sys/sysDef.h>
61 #include <tina/sys/sysPro.h>
62 #include <tina/math/mathDef.h>
63 #include <tina/math/mathPro.h>
64 #include <tina/image/img_GenDef.h>
65
66 void im_put_pix(int pixval, Imrect * image, int i, int j)
67 {
68 Imregion *region;
69
70 if (image == NULL || image->vtype == ptr_v)
71 return;
72
73 region = image->region;
74 if (i < region->ly || i >= region->uy || j < region->lx
75 || j >= region->ux)
76 return;
77
78 IM_PIX_SET(image, i, j, pixval);
79 }
80
81 void im_put_ptr(void *ptr, Imrect * image, int i, int j)
82 {
83 Imregion *region;
84
85 if (image == NULL || image->vtype != ptr_v)
86 return;
87
88 region = image->region;
89 if (i < region->ly || i >= region->uy || j < region->lx
90 || j >= region->ux)
91 return;
92
93 IM_PTR(image, i, j) = ptr;
94 }
95
96 void im_put_pixf(double pixval, Imrect * image, int i, int j)
97 {
98 Imregion *region;
99
100 if (image == NULL || image->vtype == ptr_v)
101 return;
102
103 region = image->region;
104 if (i < region->ly || i >= region->uy || j < region->lx
105 || j >= region->ux)
106 return;
107
108 IM_PIX_SET(image, i, j, pixval);
109 }
110
111 /* Increment pixel (i, j) in image. Pixels outside image are ignored */
112 void im_pixf_inc(Imrect * image, int i, int j)
113 {
114 Imregion *region;
115
116 if (image && (image->vtype != ptr_v) && (region = image->region))
117 {
118 if (region->ly <= i && i < region->uy && region->lx <= j
119 && j < region->ux)
120 {
121 double pixval;
122
123 IM_PIX_GET(image, i, j, pixval);
124 IM_PIX_SET(image, i, j, ++pixval);
125 }
126 }
127 }
128
129 /* Decrement pixel (i, j) in image. Pixels outside image are ignored */
130 void im_pixf_dec(Imrect * image, int i, int j)
131 {
132 Imregion *region;
133
134 if (image && (image->vtype != ptr_v) && (region = image->region))
135 {
136 if (region->ly <= i && i < region->uy && region->lx <= j
137 && j < region->ux)
138 {
139 double pixval;
140
141 IM_PIX_GET(image, i, j, pixval);
142 IM_PIX_SET(image, i, j, --pixval);
143 }
144 }
145 }
146
147 void im_put_pixz(Complex pixval, Imrect * image, int i, int j)
148 {
149 Imregion *region;
150
151 if (image == NULL || image->vtype == ptr_v)
152 return;
153
154 region = image->region;
155 if (i < region->ly || i >= region->uy || j < region->lx
156 || j >= region->ux)
157 return;
158
159 if (image->vtype == complex_v)
160 IM_COMPLEX(image, i, j) = pixval;
161 else
162 IM_PIX_SET(image, i, j, pixval.x);
163 }
164
165 void im_put_row(int *line, Imrect * image, int i, int from, int to)
166 {
167 int j;
168 Imregion *region;
169
170 if (image == NULL || image->vtype == ptr_v)
171 return;
172
173 region = image->region;
174 if (i < region->ly || i >= region->uy)
175 return;
176
177 if (from >= region->ux || to < region->lx)
178 return;
179
180 if (to > region->ux)
181 to = region->ux;
182
183 if (from < region->lx)
184 from = region->lx;
185
186 for (j = from; j < to; ++j)
187 IM_PIX_SET(image, i, j, line[j]);
188 }
189
190 void im_put_col(int *line, Imrect * image, int i, int from, int to)
191 {
192 int j;
193 Imregion *region;
194
195 if (image == NULL || image->vtype == ptr_v)
196 return;
197
198 region = image->region;
199 if (i < region->lx || i >= region->ux)
200 return;
201
202 if (from >= region->uy || to < region->ly)
203 return;
204
205 if (to > region->uy)
206 to = region->uy;
207
208 if (from < region->ly)
209 from = region->ly;
210
211 for (j = from; j < to; ++j)
212 IM_PIX_SET(image, j, i, line[j]);
213 }
214
215 void im_put_rowf(float *line, Imrect * image, int i, int from, int to)
216 {
217 int j;
218 Imregion *region;
219
220 if (image == NULL || image->vtype == ptr_v)
221 return;
222
223 region = image->region;
224 if (i < region->ly || i >= region->uy)
225 return;
226
227 if (from >= region->ux || to < region->lx)
228 return;
229
230 if (to > region->ux)
231 to = region->ux;
232
233 if (from < region->lx)
234 from = region->lx;
235
236 for (j = from; j < to; ++j)
237 IM_PIX_SET(image, i, j, line[j]);
238 }
239
240 void im_put_colf(float *line, Imrect * image, int i, int from, int to)
241 {
242 int j;
243 Imregion *region;
244
245 if (image == NULL || image->vtype == ptr_v)
246 return;
247
248 region = image->region;
249 if (i < region->lx || i >= region->ux)
250 return;
251
252 if (from >= region->uy || to < region->ly)
253 return;
254
255 if (to > region->uy)
256 to = region->uy;
257
258 if (from < region->ly)
259 from = region->ly;
260
261 for (j = from; j < to; ++j)
262 IM_PIX_SET(image, j, i, line[j]);
263 }
264
265 void im_put_rowz(Complex * line, Imrect * image, int i, int from, int to)
266 {
267 int j;
268 Imregion *region;
269
270 if (image == NULL || image->vtype == ptr_v)
271 return;
272
273 region = image->region;
274 if (i < region->ly || i >= region->uy)
275 return;
276
277 if (from >= region->ux || to < region->lx)
278 return;
279
280 if (to > region->ux)
281 to = region->ux;
282
283 if (from < region->lx)
284 from = region->lx;
285
286 if (image->vtype == complex_v)
287 {
288 for (j = from; j < to; ++j)
289 IM_COMPLEX(image, i, j) = line[j];
290 } else
291 {
292 for (j = from; j < to; ++j)
293 IM_PIX_SET(image, i, j, line[j].x);
294 }
295 }
296
297 void im_put_colz(Complex * line, Imrect * image, int i, int from, int to)
298 {
299 int j;
300 Imregion *region;
301
302 if (image == NULL || image->vtype == ptr_v)
303 return;
304
305 region = image->region;
306 if (i < region->lx || i >= region->ux)
307 return;
308
309 if (from >= region->uy || to < region->ly)
310 return;
311
312 if (to > region->uy)
313 to = region->uy;
314
315 if (from < region->ly)
316 from = region->ly;
317
318 if (image->vtype == complex_v)
319 {
320 for (j = from; j < to; ++j)
321 IM_COMPLEX(image, j, i) = line[j];
322 } else
323 {
324 for (j = from; j < to; ++j)
325 IM_PIX_SET(image, j, i, line[j].x);
326 }
327 }
328
329 void im_put_pos_diag(int *line, Imrect * image, int x, int y, int len)
330 {
331 int j;
332 int minoff;
333 Imregion *region;
334
335 if (image == NULL)
336 return;
337
338 region = image->region;
339
340 if (x >= region->ux || (x + len) < region->lx)
341 return;
342
343 if (y >= region->uy || (y + len) < region->ly)
344 return;
345
346 minoff = MIN(x - region->lx, y - region->ly);
347 if (minoff < 0)
348 {
349 x -= minoff;
350 y -= minoff;
351 len += minoff;
352 }
353 minoff = MIN(region->ux - x - len, region->uy - y - len);
354 if (minoff < 0)
355 len += minoff;
356
357 switch (image->vtype)
358 {
359 case char_v:
360 {
361 char **array = (char **) image->data;
362
363 for (j = 0; j < len; j++)
364 array[y + j][x + j] = line[j];
365 }
366 break;
367 case uchar_v:
368 {
369 unsigned char **array = (unsigned char **) image->data;
370
371 for (j = 0; j < len; j++)
372 array[y + j][x + j] = abs(line[j]);
373 }
374 break;
375 case short_v:
376 {
377 short **array = (short **) image->data;
378
379 for (j = 0; j < len; j++)
380 array[y + j][x + j] = line[j];
381 }
382 break;
383 case ushort_v:
384 {
385 unsigned short **array = (unsigned short **) image->data;
386
387 for (j = 0; j < len; j++)
388 array[y + j][x + j] = abs(line[j]);
389 }
390 break;
391 case int_v:
392 {
393 int **array = (int **) image->data;
394
395 for (j = 0; j < len; j++)
396 array[y + j][x + j] = line[j];
397 }
398 break;
399 case uint_v:
400 {
401 unsigned int **array = (unsigned int **) image->data;
402
403 for (j = 0; j < len; j++)
404 array[y + j][x + j] = abs(line[j]);
405 }
406 break;
407 case float_v:
408 {
409 float **array = (float **) image->data;
410
411 for (j = 0; j < len; j++)
412 array[y + j][x + j] = (float) line[j];
413 }
414 break;
415 case double_v:
416 {
417 double **array = (double **) image->data;
418
419 for (j = 0; j < len; j++)
420 array[y + j][x + j] = line[j];
421 }
422 break;
423 default:
424 error("im_put_pos_diag: unsupported type", non_fatal);
425 break;
426 }
427 }
428
429 void im_put_neg_diag(int *line, Imrect * image, int x, int y, int len)
430 {
431 int j;
432 int minoff;
433 Imregion *region;
434
435 if (image == NULL)
436 return;
437
438 region = image->region;
439
440 if ((x - len) >= region->ux || x < region->lx)
441 return;
442
443 if (y >= region->uy || (y + len) < region->ly)
444 return;
445
446 minoff = MIN(region->ux - x, y - region->ly);
447 if (minoff < 0)
448 {
449 x += minoff;
450 y -= minoff;
451 len += minoff;
452 }
453 minoff = MIN(x - len - region->lx, region->uy - y - len);
454 if (minoff < 0)
455 len += minoff;
456
457 switch (image->vtype)
458 {
459 case char_v:
460 {
461 char **array = (char **) image->data;
462
463 for (j = 0; j < len; j++)
464 array[y + j][x + j] = line[j];
465 }
466 break;
467 case uchar_v:
468 {
469 unsigned char **array = (unsigned char **) image->data;
470
471 for (j = 0; j < len; j++)
472 array[y + j][x + j] = abs(line[j]);
473 }
474 break;
475 case short_v:
476 {
477 short **array = (short **) image->data;
478
479 for (j = 0; j < len; j++)
480 array[y + j][x + j] = line[j];
481 }
482 break;
483 case ushort_v:
484 {
485 unsigned short **array = (unsigned short **) image->data;
486
487 for (j = 0; j < len; j++)
488 array[y + j][x + j] = abs(line[j]);
489 }
490 break;
491 case int_v:
492 {
493 int **array = (int **) image->data;
494
495 for (j = 0; j < len; j++)
496 array[y + j][x + j] = line[j];
497 }
498 break;
499 case uint_v:
500 {
501 unsigned int **array = (unsigned int **) image->data;
502
503 for (j = 0; j < len; j++)
504 array[y + j][x + j] = abs(line[j]);
505 }
506 break;
507 case float_v:
508 {
509 float **array = (float **) image->data;
510
511 for (j = 0; j < len; j++)
512 array[y + j][x + j] = (float) line[j];
513 }
514 break;
515 case double_v:
516 {
517 double **array = (double **) image->data;
518
519 for (j = 0; j < len; j++)
520 array[y + j][x + j] = line[j];
521 }
522 break;
523 default:
524 error("im_put_neg_diag: unsupported type", non_fatal);
525 break;
526 }
527 }
528
529 void im_put_pos_diagf(float *line, Imrect * image, int x, int y, int len)
530 {
531 int j;
532 int minoff;
533 Imregion *region;
534
535 if (image == NULL)
536 return;
537
538 region = image->region;
539
540 if (x >= region->ux || (x + len) < region->lx)
541 return;
542
543 if (y >= region->uy || (y + len) < region->ly)
544 return;
545
546 minoff = MIN(x - region->lx, y - region->ly);
547 if (minoff < 0)
548 {
549 x -= minoff;
550 y -= minoff;
551 len += minoff;
552 }
553 minoff = MIN(region->ux - x - len, region->uy - y - len);
554 if (minoff < 0)
555 len += minoff;
556
557 switch (image->vtype)
558 {
559 case char_v:
560 {
561 char **array = (char **) image->data;
562
563 for (j = 0; j < len; j++)
564 array[y + j][x + j] = (char) line[j];
565 }
566 break;
567 case uchar_v:
568 {
569 unsigned char **array = (unsigned char **) image->data;
570
571 for (j = 0; j < len; j++)
572 array[y + j][x + j] = (unsigned char) (fabs(line[j]));
573 }
574 break;
575 case short_v:
576 {
577 short **array = (short **) image->data;
578
579 for (j = 0; j < len; j++)
580 array[y + j][x + j] = (short) line[j];
581 }
582 break;
583 case ushort_v:
584 {
585 unsigned short **array = image->data;
586
587 for (j = 0; j < len; j++)
588 array[y + j][x + j] = (unsigned short) fabs(line[j]);
589 }
590 break;
591 case int_v:
592 {
593 int **array = image->data;
594
595 for (j = 0; j < len; j++)
596 array[y + j][x + j] = (int) line[j];
597 }
598 break;
599 case uint_v:
600 {
601 unsigned int **array = image->data;
602
603 for (j = 0; j < len; j++)
604 array[y + j][x + j] = (unsigned int) fabs(line[j]);
605 }
606 break;
607 case float_v:
608 {
609 float **array = image->data;
610
611 for (j = 0; j < len; j++)
612 array[y + j][x + j] = line[j];
613 }
614 break;
615 case double_v:
616 {
617 double **array = image->data;
618
619 for (j = 0; j < len; j++)
620 array[y + j][x + j] = line[j];
621 }
622 break;
623 default:
624 error("im_put_pos_diagf: unsupported type", non_fatal);
625 break;
626 }
627 }
628
629 void im_put_neg_diagf(float *line, Imrect * image, int x, int y, int len)
630 {
631 int j;
632 int minoff;
633 Imregion *region;
634
635 if (image == NULL)
636 return;
637
638 region = image->region;
639
640 if ((x - len) >= region->ux || x < region->lx)
641 return;
642
643 if (y >= region->uy || (y + len) < region->ly)
644 return;
645
646 minoff = MIN(region->ux - x, y - region->ly);
647 if (minoff < 0)
648 {
649 x += minoff;
650 y -= minoff;
651 len += minoff;
652 }
653 minoff = MIN(x - len - region->lx, region->uy - y - len);
654 if (minoff < 0)
655 len += minoff;
656
657 switch (image->vtype)
658 {
659 case char_v:
660 {
661 char **array = image->data;
662
663 for (j = 0; j < len; j++)
664 array[y + j][x + j] = (char) line[j];
665 }
666 break;
667 case uchar_v:
668 {
669 unsigned char **array = image->data;
670
671 for (j = 0; j < len; j++)
672 array[y + j][x + j] = (unsigned char) fabs(line[j]);
673 }
674 break;
675 case short_v:
676 {
677 short **array = image->data;
678
679 for (j = 0; j < len; j++)
680 array[y + j][x + j] = (short) line[j];
681 }
682 break;
683 case ushort_v:
684 {
685 unsigned short **array = image->data;
686
687 for (j = 0; j < len; j++)
688 array[y + j][x + j] = (unsigned short) fabs(line[j]);
689 }
690 break;
691 case int_v:
692 {
693 int **array = image->data;
694
695 for (j = 0; j < len; j++)
696 array[y + j][x + j] = (int) line[j];
697 }
698 break;
699 case uint_v:
700 {
701 unsigned int **array = image->data;
702
703 for (j = 0; j < len; j++)
704 array[y + j][x + j] = (unsigned int) fabs(line[j]);
705 }
706 break;
707 case float_v:
708 {
709 float **array = image->data;
710
711 for (j = 0; j < len; j++)
712 array[y + j][x + j] = line[j];
713 }
714 break;
715 case double_v:
716 {
717 double **array = image->data;
718
719 for (j = 0; j < len; j++)
720 array[y + j][x + j] = line[j];
721 }
722 break;
723 default:
724 error("im_put_neg_diagf: unsupported type", non_fatal);
725 break;
726 }
727 }
728
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.