Commit | Line | Data |
---|---|---|
61d96e53 DF |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | */ | |
6 | ||
7 | #ifndef lint | |
8 | static char sccsid[] = "@(#)aminmax.c 5.1 (Berkeley) %G%"; | |
9 | #endif not lint | |
10 | ||
ba67e389 RC |
11 | /* |
12 | * aminmax: find the 4 edges of the glyph within a window. | |
13 | * This version is approximate, in that it may include some | |
14 | * blank areas. But it's much faster because it doesn't have | |
15 | * to call mat over and over. | |
16 | */ | |
17 | ||
18 | #include "bit.h" | |
19 | ||
20 | aminmax(g, nrow, ncol, rmin, cmin, rmax, cmax) | |
21 | bitmat g; | |
22 | int nrow, ncol; | |
23 | int *rmin, *cmin, *rmax, *cmax; | |
24 | { | |
25 | register int i, j; | |
26 | register int nc = (ncol+7)>>3; | |
27 | register int r1, r2, c1, c2; | |
28 | ||
29 | r1 = nrow; c1 = nc; r2 = c2 = 0; | |
30 | for (i=0; i<nrow; i++) | |
31 | for (j=0; j<nc; j++) | |
32 | if (g[i*nc+j]) { | |
33 | r1 = min(r1, i); | |
34 | r2 = max(r2, i); | |
35 | c1 = min(c1, j); | |
36 | c2 = max(c2, j); | |
37 | } | |
38 | if (r2 < r1) { | |
39 | /* empty glyph! */ | |
40 | r1 = c1 = r2 = c2 = 1; | |
41 | } | |
42 | *rmin = r1; *rmax = r2; | |
43 | *cmin = 8*c1; *cmax = 8*c2+7; | |
44 | } |