GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 92.5% 49 / 0 / 53
Functions: 100.0% 1 / 0 / 1
Branches: 86.4% 19 / 0 / 22

libfprint/nbis/mindtct/line.c
Line Branch Exec Source
1 /*******************************************************************************
2
3 License:
4 This software and/or related materials was developed at the National Institute
5 of Standards and Technology (NIST) by employees of the Federal Government
6 in the course of their official duties. Pursuant to title 17 Section 105
7 of the United States Code, this software is not subject to copyright
8 protection and is in the public domain.
9
10 This software and/or related materials have been determined to be not subject
11 to the EAR (see Part 734.3 of the EAR for exact details) because it is
12 a publicly available technology and software, and is freely distributed
13 to any interested party with no licensing requirements. Therefore, it is
14 permissible to distribute this software as a free download from the internet.
15
16 Disclaimer:
17 This software and/or related materials was developed to promote biometric
18 standards and biometric technology testing for the Federal Government
19 in accordance with the USA PATRIOT Act and the Enhanced Border Security
20 and Visa Entry Reform Act. Specific hardware and software products identified
21 in this software were used in order to perform the software development.
22 In no case does such identification imply recommendation or endorsement
23 by the National Institute of Standards and Technology, nor does it imply that
24 the products and equipment identified are necessarily the best available
25 for the purpose.
26
27 This software and/or related materials are provided "AS-IS" without warranty
28 of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY,
29 NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY
30 or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the
31 licensed product, however used. In no event shall NIST be liable for any
32 damages and/or costs, including but not limited to incidental or consequential
33 damages of any kind, including economic damage or injury to property and lost
34 profits, regardless of whether NIST shall be advised, have reason to know,
35 or in fact shall know of the possibility.
36
37 By using this software, you agree to bear all risk relating to quality,
38 use and performance of the software and/or related materials. You agree
39 to hold the Government harmless from any claim arising from your use
40 of the software.
41
42 *******************************************************************************/
43
44
45 /***********************************************************************
46 LIBRARY: LFS - NIST Latent Fingerprint System
47
48 FILE: LINE.C
49 AUTHOR: Michael D. Garris
50 DATE: 03/16/1999
51
52 Contains routines that compute contiguous linear trajectories
53 between two coordinate points required by the NIST Latent
54 Fingerprint System (LFS).
55
56 ***********************************************************************
57 ROUTINES:
58 line_points()
59 ***********************************************************************/
60
61 #include <stdio.h>
62 #include <lfs.h>
63
64 /*************************************************************************
65 **************************************************************************
66 #cat: line_points - Returns the contiguous coordinates of a line connecting
67 #cat: 2 specified points.
68
69 Input:
70 x1 - x-coord of first point
71 y1 - y-coord of first point
72 x2 - x-coord of second point
73 y2 - y-coord of second point
74 Output:
75 ox_list - x-coords along line trajectory
76 oy_list - y-coords along line trajectory
77 onum - number of points along line trajectory
78 Return Code:
79 Zero - successful completion
80 Negative - system error
81 **************************************************************************/
82 24198 int line_points(int **ox_list, int **oy_list, int *onum,
83 const int x1, const int y1, const int x2, const int y2)
84 {
85 24198 int asize;
86 24198 int dx, dy, adx, ady;
87 24198 int x_incr, y_incr;
88 24198 int i, inx, iny, intx, inty;
89 24198 double x_factor, y_factor;
90 24198 double rx, ry;
91 24198 int ix, iy;
92 24198 int *x_list, *y_list;
93
94 /* Compute maximum number of points needed to hold line segment. */
95
2/2
✓ Branch 2 → 3 taken 10128 times.
✓ Branch 2 → 4 taken 14070 times.
24198 asize = max(abs(x2-x1)+2, abs(y2-y1)+2);
96
97 /* Allocate x and y-pixel coordinate lists to length 'asize'. */
98 24198 x_list = (int *)g_malloc(asize * sizeof(int));
99 24198 y_list = (int *)g_malloc(asize * sizeof(int));
100
101 /* Compute delta x and y. */
102 24198 dx = x2 - x1;
103 24198 dy = y2 - y1;
104
105 /* Set x and y increments. */
106
2/2
✓ Branch 7 → 8 taken 2915 times.
✓ Branch 7 → 9 taken 21283 times.
24198 if(dx >= 0)
107 x_incr = 1;
108 else
109 2915 x_incr = -1;
110
111
2/2
✓ Branch 9 → 10 taken 11344 times.
✓ Branch 9 → 11 taken 12854 times.
24198 if(dy >= 0)
112 y_incr = 1;
113 else
114 11344 y_incr = -1;
115
116 /* Compute |DX| and |DY|. */
117 24198 adx = abs(dx);
118 24198 ady = abs(dy);
119
120 /* Set x-orientation. */
121
2/2
✓ Branch 11 → 12 taken 14070 times.
✓ Branch 11 → 13 taken 10128 times.
24198 if(adx > ady)
122 inx = 1;
123 else
124 14070 inx = 0;
125
126 /* Set y-orientation. */
127
2/2
✓ Branch 13 → 14 taken 11191 times.
✓ Branch 13 → 15 taken 13007 times.
24198 if(ady > adx)
128 iny = 1;
129 else
130 11191 iny = 0;
131
132 /* CASE 1: |DX| > |DY| */
133 /* Increment in X by +-1 */
134 /* in Y by +-|DY|/|DX| */
135 /* inx = 1 */
136 /* iny = 0 */
137 /* intx = 1 (inx) */
138 /* inty = 0 (iny) */
139 /* CASE 2: |DX| < |DY| */
140 /* Increment in Y by +-1 */
141 /* in X by +-|DX|/|DY| */
142 /* inx = 0 */
143 /* iny = 1 */
144 /* intx = 0 (inx) */
145 /* inty = 1 (iny) */
146 /* CASE 3: |DX| == |DY| */
147 /* inx = 0 */
148 /* iny = 0 */
149 /* intx = 1 */
150 /* inty = 1 */
151 24198 intx = 1 - iny;
152 24198 inty = 1 - inx;
153
154 /* DX */
155 /* x_factor = (inx * +-1) + ( iny * ------------ ) */
156 /* max(1, |DY|) */
157 /* */
158
2/2
✓ Branch 15 → 16 taken 23506 times.
✓ Branch 15 → 17 taken 692 times.
24198 x_factor = (inx * x_incr) + (iny * ((double)dx/max(1, ady)));
159
160 /* DY */
161 /* y_factor = (iny * +-1) + ( inx * ------------ ) */
162 /* max(1, |DX|) */
163 /* */
164
2/2
✓ Branch 17 → 18 taken 23264 times.
✓ Branch 17 → 19 taken 934 times.
24198 y_factor = (iny * y_incr) + (inx * ((double)dy/max(1, adx)));
165
166 /* Initialize integer coordinates. */
167 24198 ix = x1;
168 24198 iy = y1;
169 /* Set floating point coordinates. */
170 24198 rx = (double)x1;
171 24198 ry = (double)y1;
172
173 /* Initialize to first point in line segment. */
174 24198 i = 0;
175
176 /* Assign first point into coordinate list. */
177 24198 x_list[i] = x1;
178 24198 y_list[i++] = y1;
179
180
2/2
✓ Branch 32 → 20 taken 647465 times.
✓ Branch 32 → 33 taken 24198 times.
671663 while((ix != x2) || (iy != y2)){
181
182
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 25 taken 647465 times.
647465 if(i >= asize){
183 fprintf(stderr, "ERROR : line_points : coord list overflow\n");
184 g_free(x_list);
185 g_free(y_list);
186 return(-412);
187 }
188
189 647465 rx += x_factor;
190 647465 ry += y_factor;
191
192 /* Need to truncate precision so that answers are consistent */
193 /* on different computer architectures when truncating doubles. */
194
1/2
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 27 taken 647465 times.
647465 rx = trunc_dbl_precision(rx, TRUNC_SCALE);
195
1/2
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 647465 times.
647465 ry = trunc_dbl_precision(ry, TRUNC_SCALE);
196
197 /* Compute new x and y-pixel coords in floating point and */
198 /* then round to the nearest integer. */
199 647465 ix = (intx * (ix + x_incr)) + (iny * (int)(rx + 0.5));
200 647465 iy = (inty * (iy + y_incr)) + (inx * (int)(ry + 0.5));
201
202 /* Assign first point into coordinate list. */
203 647465 x_list[i] = ix;
204 647465 y_list[i++] = iy;
205 }
206
207 /* Set output pointers. */
208 24198 *ox_list = x_list;
209 24198 *oy_list = y_list;
210 24198 *onum = i;
211
212 /* Return normally. */
213 24198 return(0);
214 }
215