author | viric <viriketo@gmail.com> |
Sun, 24 Apr 2011 18:47:28 +0200 | |
changeset 2 | 5cdb891abc1e |
parent 0 | 6b8091ca909a |
permissions | -rw-r--r-- |
2
5cdb891abc1e
Almenys faig que compili amb un g++ -I. -lnetpbm -o rektigi *.cc
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
1 |
#include <cstdio> |
0 | 2 |
#include <Text.h> |
3 |
||
4 |
void Text::getLines(Bitmap *map) |
|
5 |
{ |
|
6 |
int map_height = map->get_height(); |
|
7 |
int linenum=0; |
|
8 |
int last_linenum=0; |
|
9 |
int lineSize; |
|
10 |
||
11 |
// FIXME: Comprovacions |
|
12 |
||
13 |
int line_top; |
|
14 |
int line_bottom; |
|
15 |
int lastline_top; |
|
16 |
int lastline_bottom; |
|
17 |
||
18 |
Lines.clear(); |
|
19 |
||
20 |
for (int i = 0; i < map_height; i++) |
|
21 |
{ |
|
22 |
// Fins a trobar començament de línia |
|
23 |
while (i< map_height && |
|
24 |
map->points_per_row(i) < NoiseTolerance) |
|
25 |
i++; |
|
26 |
||
27 |
line_top = i++; |
|
28 |
// Fins a trobar final de línia |
|
29 |
while (i< map_height && |
|
30 |
map->points_per_row(i) > NoiseTolerance) |
|
31 |
i++; |
|
32 |
||
33 |
// If this line is less than MinVertSeparation away |
|
34 |
// from the last line. Join the two together. |
|
35 |
if (linenum > 0) |
|
36 |
{ |
|
37 |
if (line_top - lastline_bottom < MinVertSeparation) |
|
38 |
lastline_bottom = i; |
|
39 |
} |
|
40 |
||
41 |
lineSize = i - line_top + 1; |
|
42 |
if (lineSize >= MinLineSize) |
|
43 |
{ |
|
44 |
line_bottom = i; |
|
45 |
Lines.push_back(Rectangle(0,line_top, |
|
46 |
map->get_height(), line_bottom)); |
|
47 |
||
48 |
fprintf(stderr, "Line from %i to %i : %i.\n", line_top, |
|
49 |
line_bottom, line_bottom - line_top + 1); |
|
50 |
||
51 |
lastline_top = line_top; |
|
52 |
lastline_bottom = line_bottom; |
|
53 |
} |
|
54 |
} |
|
55 |
} |