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/imgGen_getvec.c,v $
37 * Date : $Date: 2003/09/22 16:09:02 $
38 * Version : $Revision: 1.5 $
39 * CVS Id : $Id: imgGen_getvec.c,v 1.5 2003/09/22 16:09:02 tony Exp $
40 *
41 * Author : Legacy TINA
42 */
43
44 /**
45 * @file
46 * @brief Extract data from image row or col in vector format
47 *
48 */
49
50 #include "imgGen_getvec.h"
51
52 #if HAVE_CONFIG_H
53 #include <config.h>
54 #endif
55
56 #include <stdio.h>
57 #include <math.h>
58 #include <tina/sys/sysDef.h>
59 #include <tina/math/mathDef.h>
60 #include <tina/math/mathPro.h>
61 #include <tina/sys/sysGen_error.h>
62 #include <tina/image/img_GenDef.h>
63
64 /* return vector of data in row y from lx to ux, cast to vtype */
65 Vector *im_row_vector(Imrect * im, int y, int lx, int ux, Vartype vtype)
66 {
67 int x, xmin, xmax;
68 Vector *v = vector_alloc(ux - lx, vtype);
69
70 if (v == NULL)
71 return (NULL);
72 if (im == NULL || y < im->region->ly || y >= im->region->uy)
73 return (v);
74
75 xmin = MAX(lx, im->region->lx);
76 xmax = MIN(ux, im->region->ux);
77 switch (vtype)
78 {
79 case char_v:
80 case uchar_v:
81 case short_v:
82 case ushort_v:
83 case int_v:
84 case uint_v:
85 {
86 for (x = xmin; x < xmax; x++)
87 {
88 double gl;
89
90 IM_PIX_GET(im, y, x, gl);
91 VECTOR_SET(v, x - lx, gl);
92 }
93 break;
94 }
95 case float_v:
96 case double_v:
97 {
98 for (x = xmin; x < xmax; x++)
99 {
100 double gl;
101
102 IM_PIX_GET(im, y, x, gl);
103 VECTOR_SET(v, x - lx, gl);
104 }
105 break;
106 }
107 case complex_v:
108 {
109 for (x = xmin; x < xmax; x++)
110 {
111 Complex gl = {Complex_id};
112
113 IM_PIX_GETZ(im, y, x, gl);
114 VECTOR_SETZ(v, x - lx, gl);
115 }
116 break;
117 }
118 default:
119 vector_free(v);
120 return (NULL);
121 }
122
123 return (v);
124 }
125
126 /* return vector of data in column x from ly to uy, cast to vtype */
127 Vector *im_col_vector(Imrect * im, int x, int ly, int uy, Vartype vtype)
128 {
129 int y, ymin, ymax;
130 Vector *v = vector_alloc(uy - ly, vtype);
131
132 if (v == NULL)
133 return (NULL);
134 if (im == NULL || x < im->region->lx || x >= im->region->ux)
135 return (v);
136
137 ymin = MAX(ly, im->region->ly);
138 ymax = MIN(uy, im->region->uy);
139 switch (vtype)
140 {
141 case char_v:
142 case uchar_v:
143 case short_v:
144 case ushort_v:
145 case int_v:
146 case uint_v:
147 {
148 for (y = ymin; y < ymax; y++)
149 {
150 double gl;
151
152 IM_PIX_GET(im, y, x, gl);
153 VECTOR_SET(v, y - ly, gl);
154 }
155 break;
156 }
157 case float_v:
158 case double_v:
159 {
160 for (y = ymin; y < ymax; y++)
161 {
162 double gl;
163
164 IM_PIX_GET(im, y, x, gl);
165 VECTOR_SET(v, y - ly, gl);
166 }
167 break;
168 }
169 case complex_v:
170 {
171 for (y = ymin; y < ymax; y++)
172 {
173 Complex gl = {Complex_id};
174
175 IM_PIX_GETZ(im, y, x, gl);
176 VECTOR_SETZ(v, y - ly, gl);
177 }
178 break;
179 }
180 default:
181 vector_free(v);
182 return (NULL);
183 }
184
185 return (v);
186 }
187
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.