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

Linux Cross Reference
Tina5/tina-libs/tina/image/img_GenDef.h

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/img_GenDef.h,v $
 37  * Date    :  $Date: 2008/12/07 02:27:36 $
 38  * Version :  $Revision: 1.7 $
 39  * CVS Id  :  $Id: img_GenDef.h,v 1.7 2008/12/07 02:27:36 paul Exp $
 40  *
 41  * Notes :  Image handling headers
 42  *
 43  *********
 44  * Author  : Legacy TINA
 45  */
 46  /**
 47  * @file
 48  * @brief Definitions of imrect, imregion, and macros to get or set image data.
 49  *
 50  * Definitions of imrect, imregion, and macros to get or set image data.
 51  */
 52 
 53 #ifndef TINA_IMG_GEN_DEF_HDR
 54 #define TINA_IMG_GEN_DEF_HDR
 55 
 56 #include <tina/sys/sysDef.h>
 57 
 58 /**
 59  * @brief Definition of imregion, the TINA rectangular region of interest data structure.
 60  *
 61  * Definition of  imregion, the TINA rectangular region of interest data structure. The fields are:
 62  * ts_id   TINA structure identifier.
 63  * lx, ux  Lower and upper extent of the region in x (spanning across image columns).
 64  * ly, uy  Lower and upper extent of the region in y (spanning across image rows).
 65  */
 66 typedef struct imregion
 67 {
 68     Ts_id ts_id;                
 69     int     lx, ly;             
 70     int     ux, uy;             
 71 }       Imregion;
 72 #define IMREGION_SWAP_STRING "iiii"
 73 
 74 /**
 75  * @brief Definition of imrect, the TINA image data structure.
 76  *
 77  * Definition of imrect, the TINA image data structure. The fields are:
 78  * ts_id TINA structure identifier.
 79  * vtype Variable type of the image data.
 80  * width, height Width (no of columns) and height (no of rows) in the image.
 81  * region The region of interest associsted with the image.
 82  * data The image data, as an array of pointers to the image rows.
 83  * props Freeform list of image properties, particularly the extras for an edge rect.
 84  */
 85 typedef struct imrect           
 86 {
 87     Ts_id ts_id;                
 88     Vartype vtype;
 89     int     width, height;      
 90     Imregion *region;           
 91     void   *data;               
 92     List *props;                
 93                                 
 94 }       Imrect;
 95 #define IMRECT_SWAP_STRING "iiippp"
 96 
 97 /**
 98  * @brief Variable-type specific macros to access image pixel data.
 99  * @param _im The image to access.
100  * @param _i The row number of the pixel.
101  * @params _j The column number of the pixel.
102  * 
103  * These macros access the pixel i,j in the input image. They are intended to be called through 
104  * IM_PIX_GET, IM_PIX_GETP, or IM_PIX_SET, which call the correct macro on the basis of the variable 
105  * type of the input image.
106  */
107 #define IM_CHAR(_im,_i,_j)      (((char **)(_im)->data)[(_i)][(_j)])
108 #define IM_UCHAR(_im,_i,_j)     (((unsigned char **)(_im)->data)[(_i)][(_j)])
109 #define IM_SHORT(_im,_i,_j)     (((short **)(_im)->data)[(_i)][(_j)])
110 #define IM_USHORT(_im,_i,_j)    (((unsigned short **)(_im)->data)[(_i)][(_j)])
111 #define IM_INT(_im,_i,_j)       (((int **)(_im)->data)[(_i)][(_j)])
112 #define IM_UINT(_im,_i,_j)      (((unsigned int **)(_im)->data)[(_i)][(_j)])
113 #define IM_FLOAT(_im,_i,_j)     (((float **)(_im)->data)[(_i)][(_j)])
114 #define IM_DOUBLE(_im,_i,_j)    (((double **)(_im)->data)[(_i)][(_j)])
115 #define IM_COMPLEX(_im,_i,_j)   (((Complex **)(_im)->data)[(_i)][(_j)])
116 #define IM_PTR(_im,_i,_j)       (((void ***)(_im)->data)[(_i)][(_j)])
117 
118 #define IM_VRAM0(_im,_i,_j)  \
119 (((Vram **)(_im)->data)[(_i)][(_j)].vram0)
120 
121 #define IM_VRAM1(_im,_i,_j) \
122 (((Vram **)(_im)->data)[(_i)][(_j)].vram1)
123 
124 #define IM_VRAM2(_im,_i,_j) \
125 (((Vram **)(_im)->data)[(_i)][(_j)].vram2)
126 
127 #define IM_VRAM3(_im,_i,_j) \
128 (((Vram **)(_im)->data)[(_i)][(_j)].vram3)
129 
130 /**
131  * @brief Macro to read image pixel data
132  * @param _im The image to read data from.
133  * @param _i The row number of the pixel.
134  * @params _j The column number of the pixel.
135  * @param _gl Pixel value at the desired coordinates.
136  * 
137  * This macro wraps the variable-type specific macros to access image pixel values, calling the correct one on
138  * the basis of the variable type of the input image.  It returns the value held in the image at the 
139  * specified pixel coordinates. For types (signed and unsigned) char short and int, float, and double,
140  * the pixel value itself is returned.  For complex images, the real part of the complex number is 
141  * returned: use IM_PIX_GETZ if you want the complex number itself. 
142  * 
143  * PAB 05/12/2008: The operation is undefined for pointer images and results in a fatal error: use
144  * IM_PIX_GETP instead.
145  */
146 #define IM_PIX_GET(_im, _i, _j, _gl) \
147         switch ((_im)->vtype) \
148         {\
149              case char_v: (_gl)       = (char) IM_CHAR((_im),(_i),(_j)); \
150                           break;\
151              case uchar_v: (_gl)      = (unsigned char) IM_UCHAR((_im),(_i),(_j)); \
152                           break;\
153              case short_v: (_gl)      = (short) IM_SHORT((_im),(_i),(_j)); \
154                           break;\
155              case ushort_v: (_gl)     = (unsigned short) IM_USHORT((_im),(_i),(_j)); \
156                           break;\
157              case int_v: (_gl)        = (int) IM_INT((_im),(_i),(_j)); \
158                           break;\
159              case uint_v: (_gl)       = (unsigned int) IM_UINT((_im),(_i),(_j)); \
160                           break;\
161              case float_v: (_gl)      = (float) IM_FLOAT((_im),(_i),(_j)); \
162                           break;\
163              case double_v: (_gl)     = (double) IM_DOUBLE((_im),(_i),(_j)); \
164                           break;\
165              case complex_v: (_gl)    = (double) IM_COMPLEX((_im),(_i),(_j)).x; \
166                           break;\
167              case ptr_v:  (_gl) = 0;\
168                           error ("IM_PIX_GET not implemented for pointer images: use IM_PIX_GETP instead\n", fatal);\
169                           break;\
170              case vram0_v: (_gl)      = (unsigned char) IM_VRAM0((_im),(_i),(_j)); \
171                           break;\
172              case vram1_v: (_gl)      = (unsigned char) IM_VRAM1((_im),(_i),(_j)); \
173                           break;\
174              case vram2_v: (_gl)      = (unsigned char) IM_VRAM2((_im),(_i),(_j)); \
175                           break;\
176              case vram3_v: (_gl)      = (unsigned char) IM_VRAM3((_im),(_i),(_j)); \
177                           break;\
178              default:\
179                           (_gl) = 0;\
180                           error ("IM_PIX_GET: unknown pixel type", fatal);\
181                           break;\
182         }
183 
184 /**
185  * @brief Macro to read image pixel pointers.
186  * @param _im The image to read data from.
187  * @param _i The row number of the pixel.
188  * @params _j The column number of the pixel.
189  * @param _gl Pointer to the desired pixel.
190  * 
191  * This macro wraps the variable-type specific macros to get image pixel values, calling the 
192  * correct one on the basis of the variable type of the input image.  It returns a pointer to 
193  * the pixel of the input image at the specified pixel coordinates.
194  */
195 #define IM_PIX_GETP(_im,_i,_j,_ptr) \
196         switch ((_im)->vtype) \
197         {\
198              case char_v: (_ptr)    = &IM_CHAR((_im),(_i),(_j)); \
199                           break;\
200              case uchar_v: (_ptr)   = &IM_UCHAR((_im),(_i),(_j)); \
201                           break;\
202              case short_v: (_ptr)   = &IM_SHORT((_im),(_i),(_j)); \
203                           break;\
204              case ushort_v: (_ptr)  = &IM_USHORT((_im),(_i),(_j)); \
205                           break;\
206              case int_v: (_ptr)     = &IM_INT((_im),(_i),(_j)); \
207                           break;\
208              case uint_v: (_ptr)    = &IM_UINT((_im),(_i),(_j)); \
209                           break;\
210              case float_v: (_ptr)   = &IM_FLOAT((_im),(_i),(_j)); \
211                           break;\
212              case double_v: (_ptr)  = &IM_DOUBLE((_im),(_i),(_j)); \
213                           break;\
214              case ptr_v: (_ptr)     = IM_PTR((_im),(_i),(_j)); \
215                           break;\
216              case complex_v: (_ptr) = &IM_COMPLEX((_im),(_i),(_j)); \
217                           break;\
218              default:    (_ptr) = 0;\
219                           error ("IM_PIX_GETP: unknown pixel type", fatal);\
220                           break;\
221         }
222 
223 /**
224  * @brief Macro to read image pixels as complex numbers.
225  * @param _im The image to read data from.
226  * @param _i The row number of the pixel.
227  * @params _j The column number of the pixel.
228  * @param _gl Complex pixel value at the desired coordinates.
229  * 
230  * This macro extracts the pixel at coordinates i,j from the input image as a complex number.
231  * For complex images, the complex number is returned: for other image types, the pixel value 
232  * is treated as the real part of the complex number, and the imaginary part is set to zero.
233  */
234 #define IM_PIX_GETZ(_im, _i, _j, _gl) \
235     {\
236         if ((_im)->vtype == complex_v)\
237             (_gl) = IM_COMPLEX((_im), (_i), (_j));\
238         else\
239         {\
240             IM_PIX_GET((_im), (_i), (_j), (_gl).x);\
241             (_gl).y = 0.0;\
242         }\
243     }
244 
245 
246 /**
247  * @brief Macro to set image pixel data.
248  * @param _im The image to write data to.
249  * @param _i The row number of the pixel.
250  * @params _j The column number of the pixel.
251  * @param _gl The pixel value to set.
252  * 
253  * This macro wraps the variable-type specific macros to access image pixel values, calling the 
254  * correct one on the basis of the variable type of the input image.  It sets the value of the 
255  * pixel at the specified coordinates i,j to the value held in _gl. For complex images, only the 
256  * real part of the complex number is set: use IM_PIX_SETZ to set the whole complex number.   
257  * 
258  * PAB 05/12/2008: The operation is undefined for pointer images and results in a fatal error: use
259  * IM_PTR instead.
260  */
261 #define IM_PIX_SET(_im,_i,_j,_gl) \
262         switch ((_im)->vtype) \
263         {\
264              case char_v: IM_CHAR((_im),(_i),(_j)) = (char) (_gl); \
265                           break;\
266              case uchar_v: IM_UCHAR((_im),(_i),(_j)) = (unsigned char) (_gl); \
267                           break;\
268              case short_v: IM_SHORT((_im),(_i),(_j)) = (short) (_gl); \
269                           break;\
270              case ushort_v: IM_USHORT((_im),(_i),(_j)) = (unsigned short) (_gl); \
271                           break;\
272              case int_v: IM_INT((_im),(_i),(_j)) = (int) (_gl); \
273                           break;\
274              case uint_v: IM_UINT((_im),(_i),(_j)) = (unsigned int) (_gl); \
275                           break;\
276              case float_v: IM_FLOAT((_im),(_i),(_j)) = (float) (_gl); \
277                           break;\
278              case double_v: IM_DOUBLE((_im),(_i),(_j)) = (double) (_gl); \
279                           break;\
280              case complex_v: IM_COMPLEX((_im),(_i),(_j)).x = (double) (_gl); \
281                           break;\
282              case ptr_v:  error ("IM_PIX_SET not implemented for pointer images: use IM_PTR instead\n", fatal);\
283                           break;\
284              case vram0_v: IM_VRAM0((_im),(_i),(_j)) = (unsigned char)(_gl); \
285                           break;\
286              case vram1_v: IM_VRAM1((_im),(_i),(_j)) = (unsigned char)(_gl); \
287                           break;\
288              case vram2_v: IM_VRAM2((_im),(_i),(_j)) = (unsigned char)(_gl); \
289                           break;\
290              case vram3_v: IM_VRAM3((_im),(_i),(_j)) = (unsigned char)(_gl); \
291                           break;\
292              default:     error ("IM_PIX_SET: unknown pixel type", fatal);\
293                           break;\
294         }
295 
296 /**
297  * @brief Macro to set complex image pixel data.
298  * @param _im The image to write data to.
299  * @param _i The row number of the pixel.
300  * @params _j The column number of the pixel.
301  * @param _gl The complex pixel value to set.
302  * 
303  * This macro sets the value of the pixel at the specified coordinates i,j to the complex number 
304  * held in _gl. For complex images, both real and imaginary part are set. For other image types, 
305  * the pixel value is set to the real part of the complex number.
306  */
307 #define IM_PIX_SETZ(_im, _i, _j, _gl) \
308     {\
309         if ((_im)->vtype == complex_v)\
310             IM_COMPLEX((_im), (_i), (_j)) = (_gl);\
311         else\
312             IM_PIX_SET((_im), (_i), (_j), (_gl).x);\
313     }
314 
315 /**
316  * @brief Macro to access a row of an image.
317  * @param _im The image to access.
318  * @param _i The coordinate of the row to access.
319  *
320  * This macro accesses row _i of image _im.
321  */
322 #define IM_ROW(_im, _i) (((void **)(_im)->data)[(_i)])
323 
324 
325 /**
326  * @brief Macro to get a pointer to a row in an image.
327  * @param _im Image to enter the row into.
328  * @param _i The coordinate of the desired row.
329  * @param _row Pointer to the desired row.
330  *
331  * This macro sets _row to point to row _i of image _im.
332  */
333 #define IM_ROW_GET(_im, _i, _row) _row = IM_ROW(_im, _i);
334 
335 /* Put a pointer to a row in an image (row is (void*)) */
336 /**
337  * @brief Macro to set a pointer to a row in an image.
338  * @param _im  The image in which to set the row.
339  * @param _i The coordinate of the row to replace.
340  * @param _row Pointer to the row to be entered into the image.
341  *
342  * This macro sets the pointer of row _i in image _im to _row. Image rows are void pointers.
343  */
344 #define IM_ROW_SET(_im, _i ,_row) IM_ROW(_im, _i) = _row;
345 
346 /**
347  * @brief Macro to loop over a region. 
348  * @param _roi The region over which to loop.
349  * @param _row The loop variable for the region row coordinates.
350  * @param _col The loop variable for the region column coordinates.
351  *
352  * This macro performs a loop over the coordinates within a region, using the loop variable 
353  * _row to loop from ly to uy and the loop variable _col to loop from lx to ux, where  these 
354  * extents are obtained from the imregion structure _roi.
355  */
356 #define FOR_IM(_roi,_row,_col) for ((_row)=(_roi)->ly; (_row)<(_roi)->uy; (_row)++) \
357                                  for ((_col)=(_roi)->lx; (_col)<(_roi)->ux; (_col)++)
358 
359 #endif  /* TINA_IMG_GEN_DEF_HDR */
360 

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