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

Linux Cross Reference
Tina4/src/vision/improc/im_add.c

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

  1 #include <math.h>
  2 #include <tina/sys.h>
  3 #include <tina/sysfuncs.h>
  4 #include <tina/math.h>
  5 #include <tina/mathfuncs.h>
  6 #include <tina/vision.h>
  7 
  8 Imrect *imc_add(int k,Imrect *im)
  9 {
 10     Imrect *im2;
 11     Imregion *roi;
 12     int *row1, *row2;
 13     int lx, ux, ly, uy;
 14     int width, height;
 15     int i, j;
 16 
 17     if (im == NULL)
 18         return (NULL);
 19 
 20     roi = im->region;
 21     if (roi == NULL)
 22         return (NULL);
 23     lx = roi->lx;
 24     ux = roi->ux;
 25     ly = roi->ly;
 26     uy = roi->uy;
 27 
 28     width = im->width;
 29     height = im->height;
 30 
 31     im2 = im_alloc(height, width, roi, char_v);
 32     row1 = ivector_alloc(lx, ux);
 33     row2 = ivector_alloc(lx, ux);
 34 
 35     for (i = ly; i < uy; ++i)
 36     {
 37         im_get_row(row1, im, i, lx, ux);
 38         for (j = lx; j < ux; ++j)
 39         {
 40 /* warning if you are trying to compute negative chars here there will be problems */
 41             if (row1[j]+k<0) row2[j] =0;
 42             else if (row1[j]+k>255) row2[j] = 255;
 43             else    row2[j] = row1[j]+k;
 44         }
 45         im_put_row(row2, im2, i, lx, ux);
 46     }
 47 
 48     ivector_free(row1, lx);
 49     ivector_free(row2, lx);
 50     return (im2);
 51 }
 52 
 53 Imrect *imi_add(int k,Imrect *im)
 54 {
 55     Imrect *im2;
 56     Imregion *roi;
 57     int *row1, *row2;
 58     int lx, ux, ly, uy;
 59     int width, height;
 60     int i, j;
 61 
 62     if (im == NULL)
 63         return (NULL);
 64 
 65     roi = im->region;
 66     if (roi == NULL)
 67         return (NULL);
 68     lx = roi->lx;
 69     ux = roi->ux;
 70     ly = roi->ly;
 71     uy = roi->uy;
 72 
 73     width = im->width;
 74     height = im->height;
 75 
 76     im2 = im_alloc(height, width, roi, int_v);
 77     row1 = ivector_alloc(lx, ux);
 78     row2 = ivector_alloc(lx, ux);
 79 
 80     for (i = ly; i < uy; ++i)
 81     {
 82         im_get_row(row1, im, i, lx, ux);
 83         for (j = lx; j < ux; ++j)
 84             row2[j] = row1[j]+k;
 85         im_put_row(row2, im2, i, lx, ux);
 86     }
 87 
 88     ivector_free(row1, lx);
 89     ivector_free(row2, lx);
 90     return (im2);
 91 }
 92 
 93 Imrect *imf_add(double k,Imrect *im)
 94 {
 95     Imrect *im2;
 96     Imregion *roi;
 97     float *row1, *row2;
 98     int lx, ux, ly, uy;
 99     int width, height;
100     int i, j;
101 
102     if (im == NULL)
103         return (NULL);
104 
105     roi = im->region;
106     if (roi == NULL)
107         return (NULL);
108     lx = roi->lx;
109     ux = roi->ux;
110     ly = roi->ly;
111     uy = roi->uy;
112 
113     width = im->width;
114     height = im->height;
115 
116     im2 = im_alloc(height, width, roi, float_v);
117     row1 = fvector_alloc(lx, ux);
118     row2 = fvector_alloc(lx, ux);
119 
120     for (i = ly; i < uy; ++i)
121     {
122         im_get_rowf(row1, im, i, lx, ux);
123         for (j = lx; j < ux; ++j)
124             row2[j] = (float)(row1[j]+k);
125         im_put_rowf(row2, im2, i, lx, ux);
126     }
127 
128     fvector_free(row1, lx);
129     fvector_free(row2, lx);
130     return (im2);
131 }
132 
133 Imrect *imz_add(Complex k,Imrect *im)
134 {
135     Imrect *im2;
136     Imregion *roi;
137     Complex *row1, *row2;
138     int lx, ux, ly, uy;
139     int width, height;
140     int i, j;
141 
142     if (im == NULL)
143         return (NULL);
144 
145     roi = im->region;
146     if (roi == NULL)
147         return (NULL);
148     lx = roi->lx;
149     ux = roi->ux;
150     ly = roi->ly;
151     uy = roi->uy;
152 
153     width = im->width;
154     height = im->height;
155 
156     im2 = im_alloc(height, width, roi, complex_v);
157     row1 = zvector_alloc(lx, ux);
158     row2 = zvector_alloc(lx, ux);
159 
160     for (i = ly; i < uy; ++i)
161     {
162         im_get_rowz(row1, im, i, lx, ux);
163         for (j = lx; j < ux; ++j)
164         {
165             row2[j].x = row1[j].x+k.x;
166             row2[j].y = row1[j].y+k.y;
167         }
168         im_put_rowz(row2, im2, i, lx, ux);
169     }
170 
171     zvector_free(row1, lx);
172     zvector_free(row2, lx);
173     return (im2);
174 }
175 
176 Imrect *im_add(k,im)
177 Imrect *im;
178 double k;
179 {
180     if(im == NULL )
181         return(NULL);
182     switch(im->vtype)
183     {
184         case uchar_v:
185         case char_v:
186             return(imc_add((int)k,im));
187         case short_v:
188         case ushort_v:
189         case int_v:
190             return(imi_add((int)k,im));
191         case float_v:
192             return(imf_add(k,im));
193         case complex_v: /* im sure this should be cmplx(k,k) NAT */
194             return(imz_add(cmplx(k,0.0),im));
195         default:
196             return(NULL);
197     }
198 }
199 

~ [ 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.