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

Linux Cross Reference
Tina6/tina-libs/tina/image/imgPrc_rot.c

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

  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: imgPrc_rot.c $
 37  * Date    :  $Date: 2012/06/20 10:50 $
 38  * Version :  $Revision: 1.6 $
 39  *
 40  * Author  : Legacy TINA modified NAT/HR
 41  */
 42 
 43 /** 
 44  *  @file
 45  *  @brief Image rotation, with bi-linear interpolation.
 46  *
 47  *
 48  *
 49  * Rotates image around im_center. If im_center is passed as NULL
 50  * the center of the passed image is used. 
 51  *
 52  */
 53 
 54 #if HAVE_CONFIG_H
 55 #include <config.h>
 56 #endif
 57 
 58 #include <math.h>
 59 #include <tina/sys/sysDef.h>
 60 #include <tina/sys/sysPro.h>
 61 #include <tina/math/mathDef.h>
 62 #include <tina/math/mathPro.h>
 63 #include <tina/image/img_GenDef.h>
 64 #include <tina/image/img_GenPro.h>
 65 #include <tina/image/imgPrc_rot.h> /* HR */
 66 
 67 
 68 Imrect         *im_rotate(Imrect * im, double angle, Vec2 * im_center)
 69 {
 70 
 71         Mat2            M;
 72         Imrect         *dest_im;
 73         Imregion       *region;
 74         int             lx, ly, ux, uy;
 75         int             i, j;
 76         Vec2            OC;     /* O = origin, C = image center, P = pixel
 77                                  * center */
 78         Vec2            OP;
 79         Vec2            CP;
 80         Vec2            CP_source;
 81         Vec2            OP_source;
 82         double          v;
 83 
 84         if (im == NULL)
 85                 return NULL;
 86 
 87         M = rot2(angle);
 88 
 89         dest_im = im_copy(im);
 90         region = dest_im->region;
 91 
 92         lx = region->lx;
 93         ly = region->ly;
 94         ux = region->ux;
 95         uy = region->uy;
 96 
 97         if (im_center == NULL)
 98         {
 99                 vec2_x(OC) = (float) (ux - lx) / (float) 2.0;
100                 vec2_y(OC) = (float) (uy - ly) / (float) 2.0;
101         } else
102         {
103                 vec2_x(OC) = vec2_x(*im_center);
104                 vec2_y(OC) = vec2_y(*im_center);
105         }
106 
107 
108         for (j = ly; j < uy; j++)
109         {
110                 vec2_y(OP) = (float) (j + 0.5);
111 
112                 for (i = lx; i < ux; i++)
113                 {
114                         vec2_x(OP) = (float) (i + 0.5);
115 
116                         CP = vec2_sum(OP, vec2_minus(OC));
117 
118                         CP_source = mat2_vprod(M, CP);
119                         OP_source = vec2_sum(OC, CP_source);
120 
121                         v = im_sub_pixqf(im, vec2_y(OP_source), vec2_x(OP_source));
122                         IM_PIX_SET(dest_im, j, i, v);
123                 }
124         }
125 
126         return dest_im;
127 }
128 
129 Imrect *im_trans(Imrect *im, double angle, Vec2 *im_center, Vec2 *offset)
130 {
131     Mat2 M;
132     Imrect *dest_im;
133     Imregion *region;
134     int lx, ly, ux, uy;
135     int i, j;
136     Vec2 OC;     /* O = origin, C = image center, P = pixel center, S = center shift */
137     Vec2 OP;
138     Vec2 OS;
139     Vec2 CP;
140     Vec2 CP_source;
141     Vec2 OP_source;
142     double v;
143 
144     if (im==NULL) return NULL;
145 
146     M = rot2(angle);
147 
148     dest_im = im_copy(im);
149     region = dest_im->region;
150 
151     lx = region->lx;
152     ly = region->ly;
153     ux = region->ux;
154     uy = region->uy;
155 
156     if (im_center==NULL)
157     {
158         vec2_x(OC) = (float)(ux-lx)/(float)2.0;
159         vec2_y(OC) = (float)(uy-ly)/(float)2.0;
160     }
161     else
162     {
163         vec2_x(OC) = vec2_x(*im_center);
164         vec2_y(OC) = vec2_y(*im_center);
165     }
166     if (offset == NULL)
167     {
168         vec2_x(OS) = 0.0;
169         vec2_x(OS) = 0.0;
170     }
171     else
172     {
173         vec2_x(OS) = vec2_x(*offset);
174         vec2_y(OS) = vec2_y(*offset);
175     }
176 
177 
178     for(j=ly;j<uy;j++)
179     {
180         vec2_y(OP) = (float)(j+0.5);
181 
182         for(i=lx;i<ux;i++)
183         {
184             vec2_x(OP) = (float)(i+0.5);
185 
186             CP = vec2_sum(vec2_sum(OP, vec2_minus(OC)),OS);
187 
188             CP_source = mat2_vprod(M, CP);
189             OP_source = vec2_sum(OC, CP_source);
190 
191             v = im_sub_pixqf(im, vec2_y(OP_source), vec2_x(OP_source));
192             IM_PIX_SET(dest_im, j, i, v);
193         }
194     }
195 
196     return dest_im;
197 }
198 
199 Imrect *im_trans_scale(Imrect *im, double im_angle, double im_scale, Vec2 *im_center, Vec2 *offset) /* duplicated im_trans to include scale */
200 {
201     Mat2 M;
202     Imrect *dest_im;
203     Imregion *region;
204     int lx, ly, ux, uy;
205     int i, j;
206     Vec2 OC;     /* O = origin, C = image center, P = pixel center, S = center shift */
207     Vec2 OP;
208     Vec2 OS;
209     Vec2 CP;
210     Vec2 CP_source;
211     Vec2 OP_source;
212     double v;
213 
214     if (im==NULL) return NULL;
215 
216     M = rot2_with_scale(im_angle, im_scale);  /* HR: added scale */
217 
218     dest_im = im_copy(im);
219     region = dest_im->region;
220 
221     lx = region->lx;
222     ly = region->ly;
223     ux = region->ux;
224     uy = region->uy;
225 
226     if (im_center==NULL)
227     {
228         vec2_x(OC) = (float)(ux-lx)/(float)2.0;
229         vec2_y(OC) = (float)(uy-ly)/(float)2.0;
230     }
231     else
232     {
233         vec2_x(OC) = vec2_x(*im_center);
234         vec2_y(OC) = vec2_y(*im_center);
235     }
236     if (offset == NULL)
237     {
238         vec2_x(OS) = 0.0;
239         vec2_x(OS) = 0.0;
240     }
241     else
242     {
243         vec2_x(OS) = vec2_x(*offset);
244         vec2_y(OS) = vec2_y(*offset);
245     }
246 
247 
248     for(j=ly;j<uy;j++)
249     {
250         vec2_y(OP) = (float)(j+0.5);
251 
252         for(i=lx;i<ux;i++)
253         {
254             vec2_x(OP) = (float)(i+0.5);
255 
256             CP = vec2_sum(vec2_sum(OP, vec2_minus(OC)),OS);
257 
258             CP_source = mat2_vprod(M, CP);
259             OP_source = vec2_sum(OC, CP_source);
260 
261             v = im_sub_pixqf(im, vec2_y(OP_source), vec2_x(OP_source));
262             IM_PIX_SET(dest_im, j, i, v);
263         }
264     }
265 
266     return dest_im;
267 }
268 
269 Vec2 point_trans_scale(Vec2 *pos, double p_angle, double p_scale, Vec2 *p_center, Vec2 *p_offset) /* HR: modified im_trans_scale to transform a single point rather than an image */
270 {
271     Mat2 M;
272     Imregion *region;
273     int i, j, lx, ly, ux, uy;
274     Vec2 OC, OP, OS, CP, CP_source, OP_source;
275     double v;
276 
277     M = rot2_with_scale(p_angle, p_scale);
278 
279     if (p_center==NULL)
280     {
281         vec2_x(OC) = 0.0;
282         vec2_y(OC) = 0.0;
283     }
284     else
285     {
286         vec2_x(OC) = vec2_x(*p_center);
287         vec2_y(OC) = vec2_y(*p_center);
288     }
289     if (p_offset == NULL)
290     {
291         vec2_x(OS) = 0.0;
292         vec2_x(OS) = 0.0;
293     }
294     else
295     {
296         vec2_x(OS) = vec2_x(*p_offset);
297         vec2_y(OS) = vec2_y(*p_offset);
298     }
299 
300     vec2_x(OP) = vec2_x(*pos);
301     vec2_y(OP) = vec2_y(*pos);
302 
303     CP = vec2_sum(vec2_sum(OP, vec2_minus(OC)),OS);
304 
305     CP_source = mat2_vprod(M, CP);
306     OP_source = vec2_sum(OC, CP_source);
307 
308     return(OP_source);
309 }
310 

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