~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/sys/image/imput.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)Image handling (setting values in an image)
  2  */
  3 
  4 #include <math.h>
  5 #include <stdio.h>
  6 #include <tina/sys.h>
  7 #include <tina/math.h>
  8 #include <tina/mathfuncs.h>
  9 
 10 void    im_put_pix(int pixval, Imrect * image, int i, int j)
 11 {
 12     Imregion *region;
 13 
 14     if (image == NULL || image->vtype == ptr_v)
 15         return;
 16 
 17     region = image->region;
 18     if (i < region->ly || i >= region->uy || j < region->lx || j >= region->ux)
 19         return;
 20 
 21     IM_PIX_SET(image, i, j, pixval);
 22 }
 23 
 24 void    im_put_ptr(void *ptr, Imrect * image, int i, int j)
 25 {
 26     Imregion *region;
 27 
 28     if (image == NULL || image->vtype != ptr_v)
 29         return;
 30 
 31     region = image->region;
 32     if (i < region->ly || i >= region->uy || j < region->lx || j >= region->ux)
 33         return;
 34 
 35     IM_PTR(image, i, j) = ptr;
 36 }
 37 
 38 void    im_put_pixf(double pixval, Imrect * image, int i, int j)
 39 {
 40     Imregion *region;
 41 
 42     if (image == NULL || image->vtype == ptr_v)
 43         return;
 44 
 45     region = image->region;
 46     if (i < region->ly || i >= region->uy || j < region->lx || j >= region->ux)
 47         return;
 48 
 49     IM_PIX_SET(image, i, j, pixval);
 50 }
 51 
 52 /* Increment pixel (i, j) in image. Pixels outside image are ignored */
 53 void    im_pixf_inc(Imrect * image, int i, int j)
 54 {
 55     Imregion *region;
 56 
 57     if (image && (image->vtype != ptr_v) && (region = image->region))
 58     {
 59         if (region->ly <= i && i < region->uy && region->lx <= j && j < region->ux)
 60         {
 61             double  pixval;
 62 
 63             IM_PIX_GET(image, i, j, pixval);
 64             IM_PIX_SET(image, i, j, ++pixval);
 65         }
 66     }
 67 }
 68 
 69 /* Decrement pixel (i, j) in image. Pixels outside image are ignored */
 70 void    im_pixf_dec(Imrect * image, int i, int j)
 71 {
 72     Imregion *region;
 73 
 74     if (image && (image->vtype != ptr_v) && (region = image->region))
 75     {
 76         if (region->ly <= i && i < region->uy && region->lx <= j && j < region->ux)
 77         {
 78             double  pixval;
 79 
 80             IM_PIX_GET(image, i, j, pixval);
 81             IM_PIX_SET(image, i, j, --pixval);
 82         }
 83     }
 84 }
 85 
 86 void    im_put_pixz(Complex pixval, Imrect * image, int i, int j)
 87 {
 88     Imregion *region;
 89 
 90     if (image == NULL || image->vtype == ptr_v)
 91         return;
 92 
 93     region = image->region;
 94     if (i < region->ly || i >= region->uy || j < region->lx || j >= region->ux)
 95         return;
 96 
 97     if (image->vtype == complex_v)
 98         IM_COMPLEX(image, i, j) = pixval;
 99     else
100         IM_PIX_SET(image, i, j, pixval.x);
101 }
102 
103 void    im_put_row(int *line, Imrect * image, int i, int from, int to)
104 {
105     int     j;
106     Imregion *region;
107 
108     if (image == NULL || image->vtype == ptr_v)
109         return;
110 
111     region = image->region;
112     if (i < region->ly || i >= region->uy)
113         return;
114 
115     if (from >= region->ux || to < region->lx)
116         return;
117 
118     if (to > region->ux)
119         to = region->ux;
120 
121     if (from < region->lx)
122         from = region->lx;
123 
124     for (j = from; j < to; ++j)
125         IM_PIX_SET(image, i, j, line[j]);
126 }
127 
128 void    im_put_col(int *line, Imrect * image, int i, int from, int to)
129 {
130     int     j;
131     Imregion *region;
132 
133     if (image == NULL || image->vtype == ptr_v)
134         return;
135 
136     region = image->region;
137     if (i < region->lx || i >= region->ux)
138         return;
139 
140     if (from >= region->uy || to < region->ly)
141         return;
142 
143     if (to > region->uy)
144         to = region->uy;
145 
146     if (from < region->ly)
147         from = region->ly;
148 
149     for (j = from; j < to; ++j)
150         IM_PIX_SET(image, j, i, line[j]);
151 }
152 
153 void    im_put_rowf(float *line, Imrect * image, int i, int from, int to)
154 {
155     int     j;
156     Imregion *region;
157 
158     if (image == NULL || image->vtype == ptr_v)
159         return;
160 
161     region = image->region;
162     if (i < region->ly || i >= region->uy)
163         return;
164 
165     if (from >= region->ux || to < region->lx)
166         return;
167 
168     if (to > region->ux)
169         to = region->ux;
170 
171     if (from < region->lx)
172         from = region->lx;
173 
174     for (j = from; j < to; ++j)
175         IM_PIX_SET(image, i, j, line[j]);
176 }
177 
178 void    im_put_colf(float *line, Imrect * image, int i, int from, int to)
179 {
180     int     j;
181     Imregion *region;
182 
183     if (image == NULL || image->vtype == ptr_v)
184         return;
185 
186     region = image->region;
187     if (i < region->lx || i >= region->ux)
188         return;
189 
190     if (from >= region->uy || to < region->ly)
191         return;
192 
193     if (to > region->uy)
194         to = region->uy;
195 
196     if (from < region->ly)
197         from = region->ly;
198 
199     for (j = from; j < to; ++j)
200         IM_PIX_SET(image, j, i, line[j]);
201 }
202 
203 void    im_put_rowz(Complex * line, Imrect * image, int i, int from, int to)
204 {
205     int     j;
206     Imregion *region;
207 
208     if (image == NULL || image->vtype == ptr_v)
209         return;
210 
211     region = image->region;
212     if (i < region->ly || i >= region->uy)
213         return;
214 
215     if (from >= region->ux || to < region->lx)
216         return;
217 
218     if (to > region->ux)
219         to = region->ux;
220 
221     if (from < region->lx)
222         from = region->lx;
223 
224     if (image->vtype == complex_v)
225     {
226         for (j = from; j < to; ++j)
227             IM_COMPLEX(image, i, j) = line[j];
228     } else
229     {
230         for (j = from; j < to; ++j)
231             IM_PIX_SET(image, i, j, line[j].x);
232     }
233 }
234 
235 void    im_put_colz(Complex * line, Imrect * image, int i, int from, int to)
236 {
237     int     j;
238     Imregion *region;
239 
240     if (image == NULL || image->vtype == ptr_v)
241         return;
242 
243     region = image->region;
244     if (i < region->lx || i >= region->ux)
245         return;
246 
247     if (from >= region->uy || to < region->ly)
248         return;
249 
250     if (to > region->uy)
251         to = region->uy;
252 
253     if (from < region->ly)
254         from = region->ly;
255 
256     if (image->vtype == complex_v)
257     {
258         for (j = from; j < to; ++j)
259             IM_COMPLEX(image, j, i) = line[j];
260     } else
261     {
262         for (j = from; j < to; ++j)
263             IM_PIX_SET(image, j, i, line[j].x);
264     }
265 }
266 
267 void    im_put_pos_diag(int *line, Imrect * image, int x, int y, int len)
268 {
269     int     j;
270     int     minoff;
271     Imregion *region;
272 
273     if (image == NULL)
274         return;
275 
276     region = image->region;
277 
278     if (x >= region->ux || (x + len) < region->lx)
279         return;
280 
281     if (y >= region->uy || (y + len) < region->ly)
282         return;
283 
284     minoff = MIN(x - region->lx, y - region->ly);
285     if (minoff < 0)
286     {
287         x -= minoff;
288         y -= minoff;
289         len += minoff;
290     }
291     minoff = MIN(region->ux - x - len, region->uy - y - len);
292     if (minoff < 0)
293         len += minoff;
294 
295     switch (image->vtype)
296     {
297     case char_v:
298         {
299             char  **array = (char **) image->data;
300 
301             for (j = 0; j < len; j++)
302                 array[y + j][x + j] = line[j];
303         }
304         break;
305     case uchar_v:
306         {
307             unsigned char **array = (unsigned char **) image->data;
308 
309             for (j = 0; j < len; j++)
310                 array[y + j][x + j] = abs(line[j]);
311         }
312         break;
313     case short_v:
314         {
315             short **array = (short **) image->data;
316 
317             for (j = 0; j < len; j++)
318                 array[y + j][x + j] = line[j];
319         }
320         break;
321     case ushort_v:
322         {
323             unsigned short **array = (unsigned short **) image->data;
324 
325             for (j = 0; j < len; j++)
326                 array[y + j][x + j] = abs(line[j]);
327         }
328         break;
329     case int_v:
330         {
331             int   **array = (int **) image->data;
332 
333             for (j = 0; j < len; j++)
334                 array[y + j][x + j] = line[j];
335         }
336         break;
337     case uint_v:
338         {
339             unsigned int **array = (unsigned int **) image->data;
340 
341             for (j = 0; j < len; j++)
342                 array[y + j][x + j] = abs(line[j]);
343         }
344         break;
345     case float_v:
346         {
347             float **array = (float **) image->data;
348 
349             for (j = 0; j < len; j++)
350                 array[y + j][x + j] = (float)line[j];
351         }
352         break;
353     case double_v:
354         {
355             double **array = (double **) image->data;
356 
357             for (j = 0; j < len; j++)
358                 array[y + j][x + j] = line[j];
359         }
360         break;
361     }
362 }
363 
364 void    im_put_neg_diag(int *line, Imrect * image, int x, int y, int len)
365 {
366     int     j;
367     int     minoff;
368     Imregion *region;
369 
370     if (image == NULL)
371         return;
372 
373     region = image->region;
374 
375     if ((x - len) >= region->ux || x < region->lx)
376         return;
377 
378     if (y >= region->uy || (y + len) < region->ly)
379         return;
380 
381     minoff = MIN(region->ux - x, y - region->ly);
382     if (minoff < 0)
383     {
384         x += minoff;
385         y -= minoff;
386         len += minoff;
387     }
388     minoff = MIN(x - len - region->lx, region->uy - y - len);
389     if (minoff < 0)
390         len += minoff;
391 
392     switch (image->vtype)
393     {
394     case char_v:
395         {
396             char  **array = (char **) image->data;
397 
398             for (j = 0; j < len; j++)
399                 array[y + j][x + j] = line[j];
400         }
401         break;
402     case uchar_v:
403         {
404             unsigned char **array = (unsigned char **) image->data;
405 
406             for (j = 0; j < len; j++)
407                 array[y + j][x + j] = abs(line[j]);
408         }
409         break;
410     case short_v:
411         {
412             short **array = (short **) image->data;
413 
414             for (j = 0; j < len; j++)
415                 array[y + j][x + j] = line[j];
416         }
417         break;
418     case ushort_v:
419         {
420             unsigned short **array = (unsigned short **) image->data;
421 
422             for (j = 0; j < len; j++)
423                 array[y + j][x + j] = abs(line[j]);
424         }
425         break;
426     case int_v:
427         {
428             int   **array = (int **) image->data;
429 
430             for (j = 0; j < len; j++)
431                 array[y + j][x + j] = line[j];
432         }
433         break;
434     case uint_v:
435         {
436             unsigned int **array = (unsigned int **) image->data;
437 
438             for (j = 0; j < len; j++)
439                 array[y + j][x + j] = abs(line[j]);
440         }
441         break;
442     case float_v:
443         {
444             float **array = (float **) image->data;
445 
446             for (j = 0; j < len; j++)
447                 array[y + j][x + j] = (float)line[j];
448         }
449         break;
450     case double_v:
451         {
452             double **array = (double **) image->data;
453 
454             for (j = 0; j < len; j++)
455                 array[y + j][x + j] = line[j];
456         }
457         break;
458     }
459 }
460 
461 void    im_put_pos_diagf(float *line, Imrect * image, int x, int y, int len)
462 {
463     int     j;
464     int     minoff;
465     Imregion *region;
466 
467     if (image == NULL)
468         return;
469 
470     region = image->region;
471 
472     if (x >= region->ux || (x + len) < region->lx)
473         return;
474 
475     if (y >= region->uy || (y + len) < region->ly)
476         return;
477 
478     minoff = MIN(x - region->lx, y - region->ly);
479     if (minoff < 0)
480     {
481         x -= minoff;
482         y -= minoff;
483         len += minoff;
484     }
485     minoff = MIN(region->ux - x - len, region->uy - y - len);
486     if (minoff < 0)
487         len += minoff;
488 
489     switch (image->vtype)
490     {
491     case char_v:
492         {
493             char  **array = (char **) image->data;
494 
495             for (j = 0; j < len; j++)
496                 array[y + j][x + j] = (char)line[j];
497         }
498         break;
499     case uchar_v:
500         {
501             unsigned char **array = (unsigned char **) image->data;
502 
503             for (j = 0; j < len; j++)
504                 array[y + j][x + j] = (unsigned char)(fabs(line[j]));
505         }
506         break;
507     case short_v:
508         {
509             short **array = (short **) image->data;
510 
511             for (j = 0; j < len; j++)
512                 array[y + j][x + j] = (short)line[j];
513         }
514         break;
515     case ushort_v:
516         {
517             unsigned short **array = image->data;
518 
519             for (j = 0; j < len; j++)
520                 array[y + j][x + j] = (unsigned short)fabs(line[j]);
521         }
522         break;
523     case int_v:
524         {
525             int   **array = image->data;
526 
527             for (j = 0; j < len; j++)
528                 array[y + j][x + j] = (int)line[j];
529         }
530         break;
531     case uint_v:
532         {
533             unsigned int **array = image->data;
534 
535             for (j = 0; j < len; j++)
536                 array[y + j][x + j] = (unsigned int)fabs(line[j]);
537         }
538         break;
539     case float_v:
540         {
541             float **array = image->data;
542 
543             for (j = 0; j < len; j++)
544                 array[y + j][x + j] = line[j];
545         }
546         break;
547     case double_v:
548         {
549             double **array = image->data;
550 
551             for (j = 0; j < len; j++)
552                 array[y + j][x + j] = line[j];
553         }
554         break;
555     }
556 }
557 
558 void    im_put_neg_diagf(float *line, Imrect * image, int x, int y, int len)
559 {
560     int     j;
561     int     minoff;
562     Imregion *region;
563 
564     if (image == NULL)
565         return;
566 
567     region = image->region;
568 
569     if ((x - len) >= region->ux || x < region->lx)
570         return;
571 
572     if (y >= region->uy || (y + len) < region->ly)
573         return;
574 
575     minoff = MIN(region->ux - x, y - region->ly);
576     if (minoff < 0)
577     {
578         x += minoff;
579         y -= minoff;
580         len += minoff;
581     }
582     minoff = MIN(x - len - region->lx, region->uy - y - len);
583     if (minoff < 0)
584         len += minoff;
585 
586     switch (image->vtype)
587     {
588     case char_v:
589         {
590             char  **array = image->data;
591 
592             for (j = 0; j < len; j++)
593                 array[y + j][x + j] = (char)line[j];
594         }
595         break;
596     case uchar_v:
597         {
598             unsigned char **array = image->data;
599 
600             for (j = 0; j < len; j++)
601                 array[y + j][x + j] = (unsigned char)fabs(line[j]);
602         }
603         break;
604     case short_v:
605         {
606             short **array = image->data;
607 
608             for (j = 0; j < len; j++)
609                 array[y + j][x + j] = (short)line[j];
610         }
611         break;
612     case ushort_v:
613         {
614             unsigned short **array = image->data;
615 
616             for (j = 0; j < len; j++)
617                 array[y + j][x + j] = (unsigned short)fabs(line[j]);
618         }
619         break;
620     case int_v:
621         {
622             int   **array = image->data;
623 
624             for (j = 0; j < len; j++)
625                 array[y + j][x + j] = (int)line[j];
626         }
627         break;
628     case uint_v:
629         {
630             unsigned int **array = image->data;
631 
632             for (j = 0; j < len; j++)
633                 array[y + j][x + j] = (unsigned int)fabs(line[j]);
634         }
635         break;
636     case float_v:
637         {
638             float **array = image->data;
639 
640             for (j = 0; j < len; j++)
641                 array[y + j][x + j] = line[j];
642         }
643         break;
644     case double_v:
645         {
646             double **array = image->data;
647 
648             for (j = 0; j < len; j++)
649                 array[y + j][x + j] = line[j];
650         }
651         break;
652     }
653 }
654 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.