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

Linux Cross Reference
Tina5/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: /home/tina/cvs/tina-libs/tina/image/imgPrc_rot.c,v $
 37  * Date    :  $Date: 2006/04/11 14:15:30 $
 38  * Version :  $Revision: 1.5 $
 39  * CVS Id  :  $Id: imgPrc_rot.c,v 1.5 2006/04/11 14:15:30 neil Exp $
 40  *
 41  * Author  : Legacy TINA
 42  */
 43 
 44 /** 
 45  *  @file
 46  *  @brief Image rotation, with bi-linear interpolation.
 47  *
 48  *
 49  *
 50  * Rotates image around im_center. If im_center is passed as NULL
 51  * the center of the passed image is used. 
 52  *
 53  */
 54 
 55 #include "imgPrc_rot.h"
 56 
 57 #if HAVE_CONFIG_H
 58 #include <config.h>
 59 #endif
 60 
 61 #include <math.h>
 62 #include <tina/sys/sysDef.h>
 63 #include <tina/sys/sysPro.h>
 64 #include <tina/math/mathDef.h>
 65 #include <tina/math/mathPro.h>
 66 #include <tina/image/img_GenDef.h>
 67 #include <tina/image/img_GenPro.h>
 68 
 69 
 70 Imrect         *im_rotate(Imrect * im, double angle, Vec2 * im_center)
 71 {
 72 
 73         Mat2            M;
 74         Imrect         *dest_im;
 75         Imregion       *region;
 76         int             lx, ly, ux, uy;
 77         int             i, j;
 78         Vec2            OC;     /* O = origin, C = image center, P = pixel
 79                                  * center */
 80         Vec2            OP;
 81         Vec2            CP;
 82         Vec2            CP_source;
 83         Vec2            OP_source;
 84         double          v;
 85 
 86         if (im == NULL)
 87                 return NULL;
 88 
 89         M = rot2(angle);
 90 
 91         dest_im = im_copy(im);
 92         region = dest_im->region;
 93 
 94         lx = region->lx;
 95         ly = region->ly;
 96         ux = region->ux;
 97         uy = region->uy;
 98 
 99         if (im_center == NULL)
100         {
101                 vec2_x(OC) = (float) (ux - lx) / (float) 2.0;
102                 vec2_y(OC) = (float) (uy - ly) / (float) 2.0;
103         } else
104         {
105                 vec2_x(OC) = vec2_x(*im_center);
106                 vec2_y(OC) = vec2_y(*im_center);
107         }
108 
109 
110         for (j = ly; j < uy; j++)
111         {
112                 vec2_y(OP) = (float) (j + 0.5);
113 
114                 for (i = lx; i < ux; i++)
115                 {
116                         vec2_x(OP) = (float) (i + 0.5);
117 
118                         CP = vec2_sum(OP, vec2_minus(OC));
119 
120                         CP_source = mat2_vprod(M, CP);
121                         OP_source = vec2_sum(OC, CP_source);
122 
123                         v = im_sub_pixqf(im, vec2_y(OP_source), vec2_x(OP_source));
124                         IM_PIX_SET(dest_im, j, i, v);
125                 }
126         }
127 
128         return dest_im;
129 }
130 
131 Imrect *im_trans(Imrect *im, double angle, Vec2 *im_center, Vec2 *offset)
132 {
133 
134     Mat2 M;
135     Imrect *dest_im;
136     Imregion *region;
137     int lx, ly, ux, uy;
138     int i, j;
139     Vec2 OC;     /* O = origin, C = image center, P = pixel center, S = center shift */
140     Vec2 OP;
141     Vec2 OS;
142     Vec2 CP;
143     Vec2 CP_source;
144     Vec2 OP_source;
145     double v;
146 
147     if (im==NULL) return NULL;
148 
149     M = rot2(angle);
150 
151     dest_im = im_copy(im);
152     region = dest_im->region;
153 
154     lx = region->lx;
155     ly = region->ly;
156     ux = region->ux;
157     uy = region->uy;
158 
159     if (im_center==NULL)
160     {
161         vec2_x(OC) = (float)(ux-lx)/(float)2.0;
162         vec2_y(OC) = (float)(uy-ly)/(float)2.0;
163     }
164     else
165     {
166         vec2_x(OC) = vec2_x(*im_center);
167         vec2_y(OC) = vec2_y(*im_center);
168     }
169     if (offset == NULL)
170     {
171         vec2_x(OS) = 0.0;
172         vec2_x(OS) = 0.0;
173     }
174     else
175     {
176         vec2_x(OS) = vec2_x(*offset);
177         vec2_y(OS) = vec2_y(*offset);
178     }
179 
180 
181     for(j=ly;j<uy;j++)
182     {
183         vec2_y(OP) = (float)(j+0.5);
184 
185         for(i=lx;i<ux;i++)
186         {
187             vec2_x(OP) = (float)(i+0.5);
188 
189             CP = vec2_sum(vec2_sum(OP, vec2_minus(OC)),OS);
190 
191             CP_source = mat2_vprod(M, CP);
192             OP_source = vec2_sum(OC, CP_source);
193 
194             v = im_sub_pixqf(im, vec2_y(OP_source), vec2_x(OP_source));
195             IM_PIX_SET(dest_im, j, i, v);
196         }
197     }
198 
199     return dest_im;
200 }
201 
202 

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