~ubuntu-branches/debian/experimental/cuneiform/experimental

« back to all changes in this revision

Viewing changes to cuneiform_src/Kern/rblock/sources/c/ltremove.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-07-10 17:58:10 UTC
  • Revision ID: james.westby@ubuntu.com-20090710175810-rqc89d2i3tki9m89
Tags: upstream-0.7.0+dfsg
ImportĀ upstreamĀ versionĀ 0.7.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 1993-2008, Cognitive Technologies
 
3
All rights reserved.
 
4
 
 
5
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½,
 
6
ļæ½ļæ½ļæ½ ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½:
 
7
 
 
8
      * ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
9
        ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
10
        ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½.
 
11
      * ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½/ļæ½ļæ½ļæ½ ļæ½
 
12
        ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
13
        ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½
 
14
        ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½.
 
15
      * ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ Cognitive Technologies, ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½
 
16
        ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½/ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
17
        ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½, ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
18
        ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½.
 
19
 
 
20
ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½/ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ "ļæ½ļæ½ļæ½
 
21
ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½" ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½-ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½,
 
22
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ ļæ½ļæ½
 
23
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½. ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
24
ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½/ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½
 
25
ļæ½ļæ½ŃØļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½
 
26
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
27
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ (ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½,
 
28
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½/ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½-ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
29
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½/ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½,
 
30
ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½), ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½
 
31
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½.
 
32
 
 
33
Redistribution and use in source and binary forms, with or without modification,
 
34
are permitted provided that the following conditions are met:
 
35
 
 
36
    * Redistributions of source code must retain the above copyright notice,
 
37
      this list of conditions and the following disclaimer.
 
38
    * Redistributions in binary form must reproduce the above copyright notice,
 
39
      this list of conditions and the following disclaimer in the documentation
 
40
      and/or other materials provided with the distribution.
 
41
    * Neither the name of the Cognitive Technologies nor the names of its
 
42
      contributors may be used to endorse or promote products derived from this
 
43
      software without specific prior written permission.
 
44
 
 
45
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
46
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
47
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
48
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
 
49
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
50
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
51
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
52
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
53
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
54
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
55
*/
 
56
 
 
57
 
 
58
 
 
59
/****************************************************************************
 
60
 *                                                                          *
 
61
 *                   P A G E   L A Y O U T                                  *
 
62
 *                                                                          *
 
63
 *              Written in 1991 by Yuri Panchul                             *
 
64
 *                                                                          *
 
65
 *              LTREMOVE.C - Blocks removing                                *
 
66
 *                                                                          *
 
67
 ***************************************************************************/
 
68
 
 
69
# include <stdlib.h>
 
70
 
 
71
# include "layout.h"
 
72
# include "my_mem.h"
 
73
# include "lang.h"
 
74
 
 
75
# include "dpuma.h"
 
76
#include "minmax.h"
 
77
 
 
78
 
 
79
extern Handle hRemoveEmptyBlocks;
 
80
 
 
81
// new page
 
82
/****************************************************************************
 
83
 *                                                                          *
 
84
 *                   P A R T   O N E                                        *
 
85
 *                                                                          *
 
86
 *              Blocks removing with Pictures data                          *
 
87
 *                                                                          *
 
88
 *       Heuristic: If block is small and is surrounded by picture          *
 
89
 *       at least from three directions, this block should be removed.      *
 
90
 *                                                                          *
 
91
 ***************************************************************************/
 
92
 
 
93
# define MIN_DISTANCE    0
 
94
# define MAX_DISTANCE    3
 
95
# define N_LAYERS        (MAX_DISTANCE - MIN_DISTANCE + 1)
 
96
 
 
97
# define N_DIRECTIONS    4
 
98
 
 
99
# define LEFT   0
 
100
# define TOP    1
 
101
# define RIGHT  2
 
102
# define BOTTOM 3
 
103
 
 
104
# ifdef LT_DEBUG
 
105
char *apDirName [N_DIRECTIONS] = { "Left  ", "Top   ", "Right ", "Bottom" };
 
106
# endif
 
107
 
 
108
typedef struct _Dir
 
109
        {
 
110
            int nDir;
 
111
            int nWidth;
 
112
            int nPictureSquare;
 
113
        } DIRECTION;
 
114
 
 
115
static DIRECTION Dirs [N_DIRECTIONS];
 
116
// new page
 
117
static int PassHorzInterval (int y, int x1, int x2)
 
118
{
 
119
    int nCounter;
 
120
    BYTE *p;
 
121
 
 
122
    if (y < 0 || y >= PAGE_MATRIX_HEIGHT)
 
123
        return (0);
 
124
 
 
125
    if (x1 > x2)
 
126
        EXCHANGE_INTS (x1, x2);
 
127
 
 
128
    if (x1 >= PAGE_MATRIX_WIDTH)
 
129
        return (0);
 
130
 
 
131
    if (x1 < 0)
 
132
        x1 = 0;
 
133
 
 
134
    if (x2 >= PAGE_MATRIX_WIDTH)
 
135
        x2 = PAGE_MATRIX_WIDTH - 1;
 
136
 
 
137
    nCounter = 0;
 
138
 
 
139
    for (p = PageMatrix + (y << PAGE_MATRIX_WIDTH_SHIFT) + x1;
 
140
             p <= PageMatrix + (y << PAGE_MATRIX_WIDTH_SHIFT) + x2;
 
141
                 p++)
 
142
    {
 
143
        if (*p & PMC_PICTURE)
 
144
            nCounter++;
 
145
    }
 
146
 
 
147
    return (nCounter);
 
148
}
 
149
// new page
 
150
static int PassVertInterval (int x, int y1, int y2)
 
151
{
 
152
    int nCounter;
 
153
    BYTE *p;
 
154
 
 
155
    if (x < 0 || x >= PAGE_MATRIX_WIDTH)
 
156
        return (0);
 
157
 
 
158
    if (y1 > y2)
 
159
        EXCHANGE_INTS (y1, y2);
 
160
 
 
161
    if (y1 >= PAGE_MATRIX_HEIGHT)
 
162
        return (0);
 
163
 
 
164
    if (y1 < 0)
 
165
        y1 = 0;
 
166
 
 
167
    if (y2 >= PAGE_MATRIX_HEIGHT)
 
168
        y2 = PAGE_MATRIX_HEIGHT - 1;
 
169
 
 
170
    nCounter = 0;
 
171
 
 
172
    for (p = PageMatrix + (y1 << PAGE_MATRIX_WIDTH_SHIFT) + x;
 
173
             p <= PageMatrix + (y2 << PAGE_MATRIX_WIDTH_SHIFT) + x;
 
174
                 p += PAGE_MATRIX_WIDTH)
 
175
    {
 
176
        if (*p & PMC_PICTURE)
 
177
            nCounter++;
 
178
    }
 
179
 
 
180
    return (nCounter);
 
181
}
 
182
// new page
 
183
static int CompDirsPictureDensity (const DIRECTION *p,
 
184
                                                                   const DIRECTION *q)
 
185
{
 
186
    if (p -> nWidth == 0 || q -> nWidth == 0)
 
187
        ErrorInternal ("p -> nWidth == 0 || q -> nWidth == 0 !");
 
188
 
 
189
    return (q -> nPictureSquare * p -> nWidth
 
190
            - p -> nPictureSquare * q -> nWidth);
 
191
}
 
192
// new page
 
193
static RECTANGLE rMatrix;
 
194
 
 
195
# ifdef LT_DEBUG
 
196
static RECTANGLE rBoundary;
 
197
static BYTE      *pFirstLine, *pLastLine, *pLine, *p;
 
198
 
 
199
void PrepareDebugPictureOutput (void)
 
200
{
 
201
    pFirstLine = PageMatrix + (rMatrix.yTop    << PAGE_MATRIX_WIDTH_SHIFT);
 
202
    pLastLine  = PageMatrix + (rMatrix.yBottom << PAGE_MATRIX_WIDTH_SHIFT);
 
203
 
 
204
    for (pLine = pFirstLine; pLine <= pLastLine; pLine += PAGE_MATRIX_WIDTH)
 
205
    {
 
206
        for (p = pLine + rMatrix.xLeft; p <= pLine + rMatrix.xRight; p++)
 
207
        {
 
208
            *p |= PMC_DEBUG1;
 
209
        }
 
210
    }
 
211
 
 
212
    rBoundary.xLeft   =
 
213
        MAX (0, rMatrix.xLeft - MAX_DISTANCE);
 
214
    rBoundary.xRight  =
 
215
        MIN (PAGE_MATRIX_WIDTH  - 1, rMatrix.xRight  + MAX_DISTANCE);
 
216
    rBoundary.yTop    =
 
217
        MAX (0, rMatrix.yTop  - MAX_DISTANCE);
 
218
    rBoundary.yBottom =
 
219
        MIN (PAGE_MATRIX_HEIGHT - 1, rMatrix.yBottom + MAX_DISTANCE);
 
220
 
 
221
    pFirstLine = PageMatrix + (rBoundary.yTop    << PAGE_MATRIX_WIDTH_SHIFT);
 
222
    pLastLine  = PageMatrix + (rBoundary.yBottom << PAGE_MATRIX_WIDTH_SHIFT);
 
223
 
 
224
    for (pLine = pFirstLine; pLine <= pLastLine; pLine += PAGE_MATRIX_WIDTH)
 
225
    {
 
226
        for (p = pLine + rBoundary.xLeft;
 
227
                    p <= pLine + rBoundary.xRight;
 
228
                        p++)
 
229
        {
 
230
            *p |= PMC_DEBUG2;
 
231
        }
 
232
    }
 
233
}
 
234
// new page
 
235
void UnPrepareDebugPictureOutput (void)
 
236
{
 
237
    for (pLine = pFirstLine; pLine <= pLastLine; pLine += PAGE_MATRIX_WIDTH)
 
238
    {
 
239
        for (p = pLine + rBoundary.xLeft;
 
240
                    p <= pLine + rBoundary.xRight;
 
241
                        p++)
 
242
        {
 
243
            *p &= ~(PMC_DEBUG1 | PMC_DEBUG2);
 
244
        }
 
245
    }
 
246
}
 
247
# endif
 
248
// new page
 
249
static void CalculateDirectionsValues (BLOCK *pBlock)
 
250
{
 
251
    LPOINT    TopLeft, TopRight, BottomLeft, BottomRight;
 
252
    RECTANGLE rReal;
 
253
    int       i;
 
254
    int       nDistance;
 
255
 
 
256
    // Get rectangle of block in real coordinates
 
257
 
 
258
    TopLeft.x     = pBlock -> Rect.xLeft;
 
259
    TopLeft.y     = pBlock -> Rect.yTop;
 
260
    TopRight.x    = pBlock -> Rect.xRight;
 
261
    TopRight.y    = pBlock -> Rect.yTop;
 
262
    BottomLeft.x  = pBlock -> Rect.xLeft;
 
263
    BottomLeft.y  = pBlock -> Rect.yBottom;
 
264
    BottomRight.x = pBlock -> Rect.xRight;
 
265
    BottomRight.y = pBlock -> Rect.yBottom;
 
266
 
 
267
    REAL_XY (TopLeft.x    , TopLeft.y);
 
268
    REAL_XY (TopRight.x   , TopRight.y);
 
269
    REAL_XY (BottomLeft.x , BottomLeft.y);
 
270
    REAL_XY (BottomRight.x, BottomRight.y);
 
271
 
 
272
    rReal.xLeft   = MIN (TopLeft.x, BottomLeft.x);
 
273
    rReal.yTop    = MIN (TopLeft.y, TopRight.y);
 
274
    rReal.xRight  = MAX (TopRight.x, BottomRight.x);
 
275
    rReal.yBottom = MAX (BottomLeft.y, BottomRight.y);
 
276
 
 
277
    // Normalize rectangle coordinates
 
278
 
 
279
    rReal.xLeft   = MIN (MAX (rReal.xLeft,   0), PAGE_MATRIX_REAL_WIDTH  - 1);
 
280
    rReal.yTop    = MIN (MAX (rReal.yTop,    0), PAGE_MATRIX_REAL_HEIGHT - 1);
 
281
    rReal.xRight  = MIN (MAX (rReal.xRight,  0), PAGE_MATRIX_REAL_WIDTH  - 1);
 
282
    rReal.yBottom = MIN (MAX (rReal.yBottom, 0), PAGE_MATRIX_REAL_HEIGHT - 1);
 
283
 
 
284
    // Calculate matrix coordinates
 
285
 
 
286
    rMatrix.xLeft   = XY_COMPRESS (rReal.xLeft);
 
287
    rMatrix.xRight  = XY_COMPRESS (rReal.xRight);
 
288
    rMatrix.yTop    = XY_COMPRESS (rReal.yTop);
 
289
    rMatrix.yBottom = XY_COMPRESS (rReal.yBottom);
 
290
 
 
291
    // Calculate directions values
 
292
 
 
293
    for (i = 0; i < N_DIRECTIONS; i++)
 
294
        Dirs [i].nDir = i;
 
295
 
 
296
    Dirs [LEFT]  .nWidth = rMatrix.yBottom - rMatrix.yTop  + 1;
 
297
    Dirs [TOP]   .nWidth = rMatrix.xRight  - rMatrix.xLeft + 1;
 
298
    Dirs [RIGHT] .nWidth = rMatrix.yBottom - rMatrix.yTop  + 1;
 
299
    Dirs [BOTTOM].nWidth = rMatrix.xRight  - rMatrix.xLeft + 1;
 
300
 
 
301
    for (i = 0; i < N_DIRECTIONS; i++)
 
302
        Dirs [i].nPictureSquare = 0;
 
303
 
 
304
    for (nDistance = MIN_DISTANCE; nDistance <= MAX_DISTANCE; nDistance++)
 
305
    {
 
306
        Dirs [LEFT].nPictureSquare   +=
 
307
            PassVertInterval (rMatrix.xLeft   - nDistance,
 
308
                              rMatrix.yTop,  rMatrix.yBottom);
 
309
 
 
310
        Dirs [TOP].nPictureSquare    +=
 
311
            PassHorzInterval (rMatrix.yTop    - nDistance,
 
312
                              rMatrix.xLeft, rMatrix.xRight);
 
313
 
 
314
        Dirs [RIGHT].nPictureSquare  +=
 
315
            PassVertInterval (rMatrix.xRight  + nDistance,
 
316
                              rMatrix.yTop,  rMatrix.yBottom);
 
317
 
 
318
        Dirs [BOTTOM].nPictureSquare +=
 
319
            PassHorzInterval (rMatrix.yBottom + nDistance,
 
320
                              rMatrix.xLeft, rMatrix.xRight);
 
321
    }
 
322
 
 
323
    q_sort ((char *) Dirs, N_DIRECTIONS, sizeof (DIRECTION), CompDirsPictureDensity); //AK 04.03.97
 
324
}
 
325
// new page
 
326
/****************************************************************************
 
327
 *                                                                          *
 
328
 *                   P A R T   T W O                                        *
 
329
 *                                                                          *
 
330
 *              Blocks removing with dust distribution                      *
 
331
 *                                                                          *
 
332
 *       Heuristic: If block contains many dust and this dust is            *
 
333
 *       proportional distributed on block rectangle, this block            *
 
334
 *       should be removed.                                                 *
 
335
 *                                                                          *
 
336
 ***************************************************************************/
 
337
 
 
338
# define DD_MATRIX_WIDTH   2
 
339
# define DD_MATRIX_HEIGHT  2
 
340
# define DD_MATRIX_SIZE    (DD_MATRIX_WIDTH * DD_MATRIX_HEIGHT)
 
341
 
 
342
int DQD_Matrix [DD_MATRIX_SIZE]; /* Dust Quantity Distribution */
 
343
int DSD_Matrix [DD_MATRIX_SIZE]; /* Dust Square   Distribution */
 
344
 
 
345
static int DD_CompProc (const int *p, const int *q)
 
346
{
 
347
    return (*q - *p);
 
348
}
 
349
// new page
 
350
int CalculateSquareOfLetters (BLOCK *p)
 
351
{
 
352
    ROOT * pRoot;
 
353
    int    nSquare = 0;
 
354
 
 
355
    for (pRoot = p -> pRoots; pRoot != NULL; pRoot = pRoot -> u1.pNext)
 
356
    {
 
357
        if (! IS_LAYOUT_DUST (*pRoot) &&
 
358
            (pRoot -> bType & ROOT_LETTER) != 0)
 
359
        {
 
360
            nSquare += pRoot -> nWidth * pRoot -> nHeight;
 
361
        }
 
362
    }
 
363
 
 
364
    return (nSquare);
 
365
}
 
366
// new page
 
367
void CalculateDustDistribution (BLOCK *p)
 
368
{
 
369
    ROOT *pRoot;
 
370
    int  nBlockWidth  = p -> Rect.xRight  - p -> Rect.xLeft + 1;
 
371
    int  nBlockHeight = p -> Rect.yBottom - p -> Rect.yTop  + 1;
 
372
    int  x, y;
 
373
    int  i;
 
374
    int  nDQD_Sum;
 
375
    int  nDSD_Sum;
 
376
 
 
377
    memset (DQD_Matrix, 0, DD_MATRIX_SIZE * sizeof (int));
 
378
    memset (DSD_Matrix, 0, DD_MATRIX_SIZE * sizeof (int));
 
379
 
 
380
    for (pRoot = p -> pRoots; pRoot != NULL; pRoot = pRoot -> u1.pNext)
 
381
    {
 
382
 
 
383
        if (! IS_LAYOUT_DUST (*pRoot))
 
384
        {
 
385
            continue;
 
386
        }
 
387
        x = (pRoot -> xColumn - p -> Rect.xLeft)
 
388
            * DD_MATRIX_WIDTH  / nBlockWidth;
 
389
 
 
390
        y = (pRoot -> yRow    - p -> Rect.yTop)
 
391
            * DD_MATRIX_HEIGHT / nBlockHeight;
 
392
 
 
393
        DQD_Matrix [x + y * DD_MATRIX_WIDTH]++;
 
394
 
 
395
        DSD_Matrix [x + y * DD_MATRIX_WIDTH] +=
 
396
            pRoot -> nWidth * pRoot -> nHeight;
 
397
    }
 
398
 
 
399
    nDQD_Sum = 0;
 
400
    nDSD_Sum = 0;
 
401
 
 
402
    for (i = 0; i < DD_MATRIX_SIZE; i++)
 
403
    {
 
404
        nDQD_Sum += DQD_Matrix [i];
 
405
        nDSD_Sum += DSD_Matrix [i];
 
406
    }
 
407
 
 
408
    if (nDQD_Sum == 0 || nDSD_Sum == 0)
 
409
        return;
 
410
 
 
411
    for (i = 0; i < DD_MATRIX_SIZE; i++)
 
412
    {
 
413
        DQD_Matrix [i] = DQD_Matrix [i] * 100 / nDQD_Sum;
 
414
        DSD_Matrix [i] = DSD_Matrix [i] * 100 / nDSD_Sum;
 
415
    }
 
416
 
 
417
    q_sort ((char*)DQD_Matrix, DD_MATRIX_SIZE, sizeof (int), DD_CompProc); //AK 04.03.97
 
418
    q_sort ((char*)DSD_Matrix, DD_MATRIX_SIZE, sizeof (int), DD_CompProc); //AK 04.03.97
 
419
}
 
420
// new page
 
421
# ifdef LT_DEBUG
 
422
static BOOL bAtLeastOneOutput;
 
423
# endif
 
424
 
 
425
void BlockRemove (BLOCK *p)
 
426
{
 
427
    ROOT *pRoot;
 
428
 
 
429
# ifdef LT_DEBUG
 
430
    //if (LT_DebugGraphicsLevel == 2)
 
431
        if(!LDPUMA_Skip(hRemoveEmptyBlocks))
 
432
    {
 
433
        pDebugBlock = p;
 
434
        LT_GraphicsBlockOutput2 ("Removed or converted blocks");
 
435
        bAtLeastOneOutput = TRUE;
 
436
    }
 
437
 
 
438
# endif
 
439
// for pictures
 
440
        //DDD
 
441
    //DDD if(p -> Type == BLOCK_PICTURE){
 
442
    //DDD int ret = del_picture( p -> hPicture);
 
443
        //DDD ret=ret;
 
444
    //DDD goto OUT;
 
445
    //DDD }
 
446
// for any
 
447
    for (pRoot = p -> pRoots; pRoot != NULL; pRoot = pRoot -> u1.pNext)
 
448
    {
 
449
        pRoot -> nBlock =
 
450
            IS_LAYOUT_DUST (*pRoot) ? DUST_BLOCK_NUMBER : REMOVED_BLOCK_NUMBER;
 
451
    }
 
452
//OUT:
 
453
    BlocksRemoveDescriptor (p);
 
454
}
 
455
// new page
 
456
// Pit 02-11-94
 
457
void BlockEnglish(BLOCK *p)
 
458
{
 
459
  p -> language = LANG_ENGLISH;
 
460
}
 
461
// new page
 
462
void BlockConvertToDust (BLOCK *p)
 
463
{
 
464
    ROOT *pRoot;
 
465
 
 
466
# ifdef LT_DEBUG
 
467
    //if (LT_DebugGraphicsLevel == 2)
 
468
        if(!LDPUMA_Skip(hRemoveEmptyBlocks))
 
469
    {
 
470
        pDebugBlock = p;
 
471
        LT_GraphicsBlockOutput2 ("Removed or converted blocks");
 
472
        bAtLeastOneOutput = TRUE;
 
473
    }
 
474
# endif
 
475
 
 
476
    for (pRoot = p -> pRoots; pRoot != NULL; pRoot = pRoot -> u1.pNext)
 
477
    {
 
478
        pRoot -> nBlock = DUST_BLOCK_NUMBER;
 
479
    }
 
480
 
 
481
    BlocksRemoveDescriptor (p);
 
482
}
 
483
// new page
 
484
void BlocksRemoveEmptyBlocks (void)
 
485
{
 
486
    BLOCK *p, *pNext;
 
487
    int nBlockWidth, nBlockHeight;
 
488
 
 
489
# ifdef LT_DEBUG_CALIBRATE
 
490
    if (bDebugOptionCalibratePictureRemovingCriteria ||
 
491
        bDebugOptionCalibrateDD_RemovingCriteria     ||
 
492
        bDebugOptionCalibrateLinearRemovingCriteria)
 
493
    {
 
494
        LT_GraphicsOpen ();
 
495
    }
 
496
# endif
 
497
 
 
498
# ifdef LT_DEBUG
 
499
    //if (LT_DebugGraphicsLevel == 2)
 
500
        if(!LDPUMA_Skip(hRemoveEmptyBlocks))
 
501
    {
 
502
        LT_GraphicsClearScreen ();
 
503
        bAtLeastOneOutput = FALSE;
 
504
    }
 
505
# endif
 
506
 
 
507
    pNext = pBlocksList;
 
508
 
 
509
    while (pNext != NULL)
 
510
    {
 
511
        p = pNext;
 
512
        pNext = pNext -> pNext;
 
513
 
 
514
        if (p -> Type != BLOCK_TEXT)
 
515
            continue;
 
516
 
 
517
# ifdef LT_DEBUG
 
518
            //if (LT_DebugGraphicsLevel >= 3)
 
519
                if(!LDPUMA_Skip(hRemoveEmptyBlocks))
 
520
            {
 
521
                pDebugBlock = p;
 
522
                LT_ShowBlock("This block...");
 
523
                LT_Getch ();
 
524
            }
 
525
# endif
 
526
 
 
527
        nBlockWidth  = p -> Rect.xRight  - p -> Rect.xLeft + 1;
 
528
        nBlockHeight = p -> Rect.yBottom - p -> Rect.yTop  + 1;
 
529
 
 
530
        if (p -> nRoots == p -> nDust)
 
531
        {
 
532
            BlockRemove (p);
 
533
            continue;
 
534
        }
 
535
 
 
536
        if (! bOptionBlocksRemovingByPageMatrix)
 
537
            goto AFTER_REMOVING_BY_PAGE_MATRIX;
 
538
 
 
539
        if (p -> nLetters > 5 ||
 
540
            p -> nRoots - p -> nDust > 50)
 
541
        {
 
542
            goto AFTER_REMOVING_BY_PAGE_MATRIX;
 
543
        }
 
544
 
 
545
        CalculateDirectionsValues (p);
 
546
 
 
547
        if (Dirs [0].nPictureSquare >= Dirs [0].nWidth     &&
 
548
            Dirs [1].nPictureSquare >= Dirs [1].nWidth     &&
 
549
            Dirs [2].nPictureSquare >= Dirs [2].nWidth / 2
 
550
                ||
 
551
            Dirs [0].nPictureSquare >= Dirs [0].nWidth * 2 &&
 
552
            Dirs [1].nPictureSquare >= Dirs [1].nWidth * 2 &&
 
553
            Dirs [2].nPictureSquare >= Dirs [2].nWidth / 3)
 
554
        {
 
555
# ifdef LT_DEBUG
 
556
            //if (LT_DebugGraphicsLevel >= 3)
 
557
                        if(!LDPUMA_Skip(hRemoveEmptyBlocks))
 
558
            {
 
559
                CalculateDirectionsValues (p);
 
560
 
 
561
                PrepareDebugPictureOutput ();
 
562
                pDebugBlock = p;
 
563
                rDebugRect  = rBoundary;
 
564
 
 
565
                LT_GraphicsPictureRemovingConditionsOutput2
 
566
                    ("Remove by PageMatrix");
 
567
 
 
568
                UnPrepareDebugPictureOutput ();
 
569
                LT_Getch ();
 
570
            }
 
571
# endif
 
572
            BlockRemove (p);
 
573
            continue;
 
574
        }
 
575
 
 
576
      AFTER_REMOVING_BY_PAGE_MATRIX:
 
577
        ;
 
578
 
 
579
# ifdef LT_DEBUG_CALIBRATE
 
580
        if (bDebugOptionCalibratePictureRemovingCriteria &&
 
581
            p -> nLetters < 10)
 
582
        {
 
583
            int i;
 
584
            char cAnswer;
 
585
 
 
586
            CalculateDirectionsValues (p);
 
587
 
 
588
            PrepareDebugPictureOutput ();
 
589
            pDebugBlock = p;
 
590
            rDebugRect  = rBoundary;
 
591
 
 
592
            LT_GraphicsPictureRemovingConditionsOutput2
 
593
                ("Picture removing conditions");
 
594
 
 
595
            UnPrepareDebugPictureOutput ();
 
596
 
 
597
            cAnswer = LT_Getch ();
 
598
 
 
599
            if (cAnswer == '\r')
 
600
            {
 
601
                printf ("Roots: %4d Letters: %4d NoDust: %4d Dust: %4d ",
 
602
                        p -> nRoots,
 
603
                        p -> nLetters,
 
604
                        p -> nRoots - p -> nDust,
 
605
                        p -> nDust);
 
606
 
 
607
                printf ("Width %4d Height: %4d [ ", nBlockWidth, nBlockHeight);
 
608
 
 
609
                for (i = 0; i < N_DIRECTIONS; i++)
 
610
                {
 
611
                    printf ("%5.2f ",
 
612
                            (double) Dirs [i].nPictureSquare / Dirs [i].nWidth);
 
613
                }
 
614
 
 
615
                printf ("]\n");
 
616
            }
 
617
 
 
618
            continue;
 
619
        }
 
620
# endif
 
621
 
 
622
        if (! bOptionBlocksRemovingByDustDistribution)
 
623
            goto AFTER_REMOVING_BY_DUST_DISTRIBUTION;
 
624
 
 
625
        if (p -> nDust < 3 * (p -> nRoots - p -> nDust) ||
 
626
            CalculateSquareOfLetters (p)
 
627
                > (p -> Rect.xRight  - p -> Rect.xLeft + 1) *
 
628
                  (p -> Rect.yBottom - p -> Rect.yTop  + 1) / 3)
 
629
        {
 
630
            goto AFTER_REMOVING_BY_DUST_DISTRIBUTION;
 
631
        }
 
632
 
 
633
        CalculateDustDistribution (p);
 
634
 
 
635
        if (DSD_Matrix [0] <= 75 && DQD_Matrix [0] <= 60 &&
 
636
           // DSD_Matrix [2] >=  7 && DQD_Matrix [2] >= 11
 
637
            DSD_Matrix [3] >=  7 && DQD_Matrix [3] >= 11 // Pit 7-7-94
 
638
            &&  CalculateSquareOfLetters (p) == 0       // Pit
 
639
            )
 
640
        {
 
641
# ifdef LT_DEBUG
 
642
            //if (LT_DebugGraphicsLevel >= 3)
 
643
                        if(!LDPUMA_Skip(hRemoveEmptyBlocks))
 
644
            {
 
645
                CalculateDustDistribution (p);
 
646
 
 
647
                pDebugBlock = p;
 
648
                rDebugRect.xLeft   = 0;
 
649
                rDebugRect.xRight  = DD_MATRIX_WIDTH - 1;
 
650
                rDebugRect.yTop    = 0;
 
651
                rDebugRect.yBottom = DD_MATRIX_HEIGHT - 1;
 
652
 
 
653
                LT_GraphicsDD_RemovingConditionsOutput2
 
654
                    ("Remove by dust distribution");
 
655
 
 
656
                LT_Getch ();
 
657
            }
 
658
# endif
 
659
            BlockRemove (p);
 
660
            continue;
 
661
        }
 
662
 
 
663
      AFTER_REMOVING_BY_DUST_DISTRIBUTION:
 
664
        ;
 
665
 
 
666
# ifdef LT_DEBUG_CALIBRATE
 
667
        if (bDebugOptionCalibrateDD_RemovingCriteria)
 
668
        {
 
669
            int i;
 
670
            char cAnswer;
 
671
 
 
672
            CalculateDustDistribution (p);
 
673
 
 
674
            pDebugBlock = p;
 
675
            rDebugRect.xLeft   = 0;
 
676
            rDebugRect.xRight  = DD_MATRIX_WIDTH - 1;
 
677
            rDebugRect.yTop    = 0;
 
678
            rDebugRect.yBottom = DD_MATRIX_HEIGHT - 1;
 
679
 
 
680
            LT_GraphicsDD_RemovingConditionsOutput2 ("Dust distribution");
 
681
 
 
682
            cAnswer = LT_Getch ();
 
683
 
 
684
            if (cAnswer == '\r')
 
685
            {
 
686
                printf ("Roots: %4d Letters: %4d NoDust: %4d Dust: %4d ",
 
687
                        p -> nRoots,
 
688
                        p -> nLetters,
 
689
                        p -> nRoots - p -> nDust,
 
690
                        p -> nDust);
 
691
 
 
692
                printf ("Width %4d Height: %4d [ ", nBlockWidth, nBlockHeight);
 
693
 
 
694
                for (i = 0; i < DD_MATRIX_SIZE; i++)
 
695
                {
 
696
                    printf ("%5.2f ", (double) DSD_Matrix [i] / DQD_Matrix [i]);
 
697
                }
 
698
 
 
699
                printf ("]\n");
 
700
            }
 
701
 
 
702
            continue;
 
703
        }
 
704
# endif
 
705
 
 
706
        if ((
 
707
             p -> nLetters == 0                     &&
 
708
             p -> nRoots - p -> nDust <= 10      &&  /* CRSH5 */
 
709
             nBlockWidth >  0                       &&
 
710
             nBlockWidth <= MAX_DUST_WIDTH / 2      &&
 
711
             nBlockHeight / nBlockWidth >= 7
 
712
                 ||
 
713
             p -> nLetters == 0                     &&
 
714
             p -> nRoots - p -> nDust <= 2          &&
 
715
             nBlockHeight > 0                       &&
 
716
             nBlockHeight <= MAX_DUST_HEIGHT        &&
 
717
             nBlockWidth / nBlockHeight >= 10
 
718
                 ||
 
719
             p -> nLetters == 0                     &&
 
720
             p -> nRoots - p -> nDust == 1          &&
 
721
             nBlockHeight < MAX_DUST_HEIGHT * 3 / 2
 
722
                 ||                                       /* OK */
 
723
             p -> nLetters == 0                     &&
 
724
             p -> nRoots - p -> nDust < 5           &&
 
725
             nBlockHeight < MAX_DUST_HEIGHT * 4     &&
 
726
             nBlockWidth  < MAX_DUST_WIDTH  * 4)
 
727
 
 
728
             &&
 
729
 
 
730
            ! (                                 /* Page number */
 
731
             p -> nRoots < 5 &&
 
732
             p -> Rect.xLeft  > rRootSpace.xLeft + nRootSpaceWidth  * 3 / 10 &&
 
733
             p -> Rect.xRight < rRootSpace.xLeft + nRootSpaceWidth  * 7 / 10 &&
 
734
             p -> Rect.yTop   > rRootSpace.yTop  + nRootSpaceHeight * 7 / 10 &&
 
735
             nBlockHeight > MAX_DUST_HEIGHT                                  &&
 
736
             nBlockWidth  > MAX_DUST_WIDTH
 
737
            ))
 
738
        {
 
739
# ifdef LT_DEBUG
 
740
            //if (LT_DebugGraphicsLevel >= 3)
 
741
                        if(!LDPUMA_Skip(hRemoveEmptyBlocks))
 
742
            {
 
743
                pDebugBlock = p;
 
744
 
 
745
                LT_GraphicsLinearRemovingConditionsOutput2
 
746
                    ("Converted to dust by block parameter heuristic");
 
747
 
 
748
                LT_Getch ();
 
749
            }
 
750
# endif
 
751
            BlockConvertToDust (p);
 
752
            continue;
 
753
        }
 
754
 
 
755
# ifdef LT_DEBUG_CALIBRATE
 
756
        if (bDebugOptionCalibrateLinearRemovingCriteria &&
 
757
            p -> nRoots < 5)
 
758
        {
 
759
            char cAnswer;
 
760
 
 
761
            pDebugBlock = p;
 
762
            LT_GraphicsLinearRemovingConditionsOutput2 ("Remove");
 
763
            cAnswer = LT_Getch ();
 
764
 
 
765
            if (cAnswer == '\r')
 
766
            {
 
767
                printf ("Roots: %4d Letters: %4d NoDust: %4d Dust: %4d ",
 
768
                        p -> nRoots,
 
769
                        p -> nLetters,
 
770
                        p -> nRoots - p -> nDust,
 
771
                        p -> nDust);
 
772
 
 
773
                printf ("Width %4d Height: %4d H/W: %5.2f\n",
 
774
                        nBlockWidth,
 
775
                        nBlockHeight,
 
776
                        p -> Rect.xRight  - p -> Rect.xLeft + 1,
 
777
                        p -> Rect.yBottom - p -> Rect.yTop  + 1,
 
778
                        (double) (p -> Rect.yBottom - p -> Rect.yTop  + 1) /
 
779
                                 (p -> Rect.xRight  - p -> Rect.xLeft + 1)
 
780
                        );
 
781
            }
 
782
 
 
783
            continue;
 
784
        }
 
785
# endif
 
786
 
 
787
/*
 
788
        if (p -> nLetters <= (p -> nRoots - p -> nDust) / 10)
 
789
        {
 
790
            BlockRemove (p);
 
791
            continue;
 
792
        }
 
793
*/
 
794
    }
 
795
 
 
796
# ifdef LT_DEBUG
 
797
    //if (LT_DebugGraphicsLevel == 2 && bAtLeastOneOutput)
 
798
        if (!LDPUMA_Skip(hRemoveEmptyBlocks) && bAtLeastOneOutput)
 
799
        LT_Getch ();
 
800
# endif
 
801
 
 
802
# ifdef LT_DEBUG_CALIBRATE
 
803
    if (bDebugOptionCalibratePictureRemovingCriteria ||
 
804
        bDebugOptionCalibrateDD_RemovingCriteria     ||
 
805
        bDebugOptionCalibrateLinearRemovingCriteria)
 
806
    {
 
807
        LT_GraphicsClose ();
 
808
        ErrorInternal ("Calibrating complete");
 
809
    }
 
810
# endif
 
811
}