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

« back to all changes in this revision

Viewing changes to cuneiform_src/Kern/usage/amu_geom.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jakub Wilk, libm.diff, swapbytes.diff
  • Date: 2010-09-14 15:53:54 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100914155354-hhxaa13xmhb82e3e
Tags: 1.0.0+dfsg-1
* New upstream release (closes: #575419).
* New maintainer (closes: #543893).
* Document in README.source how to repackage upstream tarball.
* Update debian/copyright.
  + Document that the package is auto-buildable.
  + Document which files were stripped from the upstream tarball.
  + Convert to the DEP-5 format.
* Drop README.Debian, no longer needed.
* Rewrite debian/rules from scratch using dh.
  + Bump debhelper minimum version to 7.4.4 (for cmake support).
  + Turn on MAKE_VERBOSE_MAKEFILE.
  + Disable call to dh_makeshlibs to avoid creation of spurious
    calls to ldconfig in postrm/postinst.
  + Add get-orig-source target.
* Remove unused overrides.
* Link to GraphicsMagick rather than ImageMagick:
  + Build-depend on graphicsmagick-libmagick-dev-compat.
  + Add patch to properly initialize the library. [graphicsmagick.diff]    
* Bump standards version to 3.9.1 (no changes needed).
* Force upgrade of ocrodjvu to at least 0.4.2; earlier versions of ocrodjvu
  don't support this version of Cuneiform.
* List all the supported languages in the package description.
* Update the manual page.
  + Document --dotmatrix, --fax and --singlecolumn options.
  + Document all output formats.
  + Don't use hyphen as minus sign.
  + Fix a few formatting issues.
* Drop Vcs-* fields.
* Add watch file.
* Add patch from Dmitrijs Ledkovs to link the lao library with libm.
  [libm.diff]
* Add patch for a for a more portable function to swap byte order.
  [swapbytes.diff]
* Set Architecture to any; there's no good reason to limit it.
* Run rudimentary tests at build time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Copyright (c) 1993-2008, Cognitive Technologies
3
3
All rights reserved.
4
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
 
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
 
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
32
 
33
33
Redistribution and use in source and binary forms, with or without modification,
34
34
are permitted provided that the following conditions are met:
57
57
/*------------------------------------------------------------------------------------------------*/
58
58
/**
59
59
    \file   AMU_Geom.CPP
60
 
    \brief  ���������� ������� �������������� �������
61
 
    \author ��������� ��������
 
60
    \brief  Реализация типовых геометрических функций
 
61
    \author Александр Михайлов
62
62
    \date   21.04.2005
63
63
*/
64
64
/*------------------------------------------------------------------------------------------------*/
65
 
/*  N-� �������� 21.04.2005:
66
 
    - ���������� � ��������� ����������, ������������� � ������ "AMU_Geom.CPP" � 02.03.2001  */
 
65
/*  N-я Редакция 21.04.2005:
 
66
    - приведение к стандарту алгоритмов, реализованных в модуле "AMU_Geom.CPP" к 02.03.2001  */
67
67
/*------------------------------------------------------------------------------------------------*/
68
68
#include <stdio.h>
69
 
/*  ������������ �����  */
 
69
/*  межпроектные чужие  */
70
70
#include "skew1024.h"
71
 
/*  ������������ ��� (����������)  */
 
71
/*  общесорсовые мои (отдаваемые)  */
72
72
#include "amt_geom.h"
73
 
/*----------    ���������� ���������    ----------------------------------------------------------*/
 
73
/*----------    Управление локальное    ----------------------------------------------------------*/
74
74
/*+ (AverageRoundToBig) +*/
75
 
static const double HALF = .5; ///< �������� :-)
 
75
static const double HALF = .5; ///< половина :-)
76
76
/*+ (MakeInternalRectId) +*/
77
 
static const int SIZE_SKEW_SCALE = 1024; ///< ������� ����� �����
78
 
/** ������������ �� ������ ���� ��� ����������� ������������� */
 
77
static const int SIZE_SKEW_SCALE = 1024; ///< масштаб шкалы углов
 
78
/** Максимальный по модулю угол для нормального распознавания */
79
79
static const int MAX_ABS_SKEW = SIZE_SKEW_SCALE / 2;
80
 
/*----------    ��������� �������    -------------------------------------------------------------*/
 
80
/*----------    Локальные функции    -------------------------------------------------------------*/
81
81
/**
82
 
    \brief ������� ��������� ����� �� ������
83
 
    \param pA [in/out]   - ��������� �� ����� - ������ ����� � �������� �����������
84
 
    \param pB [in/out]   - ��������� �� ����� - ����� ����� � �������� �����������
85
 
    \param Lev [in]      - ������� ��������� � ��������� �����������
86
 
    \param Lev_A [in]    - ������� ������ ����� � ��������� �����������
87
 
    \param Lev_B [in]    - ������� ����� ����� � ��������� �����������
88
 
    \param LimIsMax [in] - ������� �� ����� ������� ���������
89
 
    \param Near [in]     - ���������� ������ (?)
90
 
    \retval bool         - ��� �������� ��� ���
 
82
    \brief Функция обрезания линии по уровню
 
83
    \param pA [in/out]   - указатель на точку - начало линии в реальных координатах
 
84
    \param pB [in/out]   - указатель на точку - конец линии в реальных координатах
 
85
    \param Lev [in]      - уровень обрезания в идеальных координатах
 
86
    \param Lev_A [in]    - уровень начала линии в идеальных координатах
 
87
    \param Lev_B [in]    - уровень конца линии в идеальных координатах
 
88
    \param LimIsMax [in] - верхнюю ли часть обрезка оставлять
 
89
    \param Near [in]     - расширение уровня (?)
 
90
    \retval bool         - так обрезали или нет
91
91
*/
92
92
static bool CanUse (Point16 *pA, Point16 *pB, const int Lev, const int Lev_A, const int Lev_B
93
93
    , const bool LimIsMax, const int Near)
94
94
{
95
95
    Point16 C = {0};
96
 
    if (LimIsMax)//������� ������������ ������
 
96
    if (LimIsMax)//уровень ограничивает сверху
97
97
    {
98
98
        if ((Lev_A <= Lev + Near) && (Lev_B <= Lev + Near))
99
99
            return true;
100
100
        if ((Lev_A >= Lev + Near) && (Lev_B >= Lev + Near))
101
101
            return false;
102
 
        /*  ������� ����� �������  */
 
102
        /*  Находим точку деления  */
103
103
        C.x = ((Lev - Lev_B) * pA->x + (Lev_A - Lev) * pB->x) / (Lev_A - Lev_B);
104
104
        C.y = ((Lev - Lev_B) * pA->y + (Lev_A - Lev) * pB->y) / (Lev_A - Lev_B);
105
 
        if (Lev_A > Lev)//�������� ��������
 
105
        if (Lev_A > Lev)//обрезаем верхушку
106
106
        {
107
107
            pA->x = C.x;
108
108
            pA->y = C.y;
113
113
            pB->y = C.y;
114
114
        }
115
115
    }
116
 
    else//������� ������������ �����
 
116
    else//уровень ограничивает снизу
117
117
    {
118
118
        if ((Lev_A >= Lev - Near) && (Lev_B >= Lev - Near))
119
119
            return true;
120
120
        if ((Lev_A <= Lev - Near) && (Lev_B <= Lev - Near))
121
121
            return false;
122
 
        /*  ������� ����� �������  */
 
122
        /*  Находим точку деления  */
123
123
        C.x = ((Lev - Lev_B) * pA->x + (Lev_A - Lev) * pB->x) / (Lev_A - Lev_B);
124
124
        C.y = ((Lev - Lev_B) * pA->y + (Lev_A - Lev) * pB->y) / (Lev_A - Lev_B);
125
 
        if (Lev_A < Lev)//�������� �������
 
125
        if (Lev_A < Lev)//обрезаем подошву
126
126
        {
127
127
            pA->x = C.x;
128
128
            pA->y = C.y;
137
137
}
138
138
/*------------------------------------------------------------------------------------------------*/
139
139
/**
140
 
    \brief ������� ���������� � ����������� � ������� �������
141
 
    \param a [in] - ������ �����������
142
 
    \param a [in] - ������ �����������
143
 
    \retval int   - ���������
 
140
    \brief Функция усреднения с округлением в большую сторону
 
141
    \param a [in] - первое усредняемое
 
142
    \param a [in] - второе усредняемое
 
143
    \retval int   - результат
144
144
*/
145
 
inline static int AverageRoundToBig (Int16 a, Int16 b)
 
145
inline static int AverageRoundToBig (int16_t a, int16_t b)
146
146
{
147
147
    return static_cast<int>(HALF * (a + b + 1));
148
148
}
149
 
/*----------    ���������� �������    ------------------------------------------------------------*/
150
 
void RotateRect (const Rect16 *pRcRe, Rect16 *pRcId, Int32 Skew)
 
149
/*----------    Переходные функции    ------------------------------------------------------------*/
 
150
void RotateRect (const Rect16 *pRcRe, Rect16 *pRcId, int32_t Skew)
151
151
{
152
152
    Point32 DirIdeal = {0};
153
 
    /*  ���������� ������ �������� ����  */
 
153
    /*  Координаты левого верхнего угла  */
154
154
    DirIdeal.x = AverageRoundToBig (pRcRe->left, pRcRe->right);
155
155
    DirIdeal.y = pRcRe->top;
156
156
    ::Deskew (DirIdeal, -Skew);
157
 
    pRcId->top = static_cast<Int16>(DirIdeal.y);
158
 
    /*  ���������� ������� �������� ����  */
 
157
    pRcId->top = static_cast<int16_t>(DirIdeal.y);
 
158
    /*  Координаты правого верхнего угла  */
159
159
    DirIdeal.x = AverageRoundToBig (pRcRe->left, pRcRe->right);
160
160
    DirIdeal.y = pRcRe->bottom;
161
161
    ::Deskew (DirIdeal, -Skew);
162
 
    pRcId->bottom = static_cast<Int16>(DirIdeal.y);
163
 
    /*  ���������� ������ ������� ����  */
 
162
    pRcId->bottom = static_cast<int16_t>(DirIdeal.y);
 
163
    /*  Координаты левого нижнего угла  */
164
164
    DirIdeal.x = pRcRe->left;
165
165
    DirIdeal.y = AverageRoundToBig (pRcRe->top, pRcRe->bottom);
166
166
    ::Deskew (DirIdeal, -Skew);
167
 
    pRcId->left = static_cast<Int16>(DirIdeal.x);
168
 
    /*  ���������� ������� ������� ����  */
 
167
    pRcId->left = static_cast<int16_t>(DirIdeal.x);
 
168
    /*  Координаты правого нижнего угла  */
169
169
    DirIdeal.x = pRcRe->right;
170
170
    DirIdeal.y = AverageRoundToBig (pRcRe->top, pRcRe->bottom);
171
171
    ::Deskew (DirIdeal, -Skew);
172
 
    pRcId->right = static_cast<Int16>(DirIdeal.x);
 
172
    pRcId->right = static_cast<int16_t>(DirIdeal.x);
173
173
}
174
174
/*------------------------------------------------------------------------------------------------*/
175
175
void FindMinimIdealRegion (const int nRc, const int *pDo, const Rect16 *pRcIdeal, Rect16 *pMIR)
176
176
{
177
 
    /*  ������� ������ ������� ����������  */
178
 
    int iFirst = -1;
 
177
    /*  находим первую стоящую компоненту  */
 
178
    int iFirst = -1;
179
179
    int i(0);
180
180
    for (i = 0; i < nRc; i++)
181
181
    {
185
185
        break;
186
186
    }
187
187
    if (iFirst == -1)
188
 
    {/*  �� ����� ���������� ��� � ������ ��� �������  */
 
188
    {/*  ни одной компоненты нет в списке для анализа  */
189
189
        pMIR->left   = 0;
190
190
        pMIR->right  = 0;
191
191
        pMIR->top    = 0;
192
192
        pMIR->bottom = 0;
193
193
        return;
194
194
    }
195
 
    /*  ������� �� ������ ����������  */
 
195
    /*  Пределы по первой компоненте  */
196
196
    int MinTop = pRcIdeal[iFirst].top;
197
197
    int MaxBot = pRcIdeal[iFirst].bottom;
198
198
    int MinLef = pRcIdeal[iFirst].left;
199
199
    int MaxRig = pRcIdeal[iFirst].right;
200
 
    /*  ������� �� ���� �����������  */
 
200
    /*  Пределы по всем компонентам  */
201
201
    for (i = iFirst; i < nRc; i++)
202
202
    {
203
203
        if (pDo[i] != 1)
221
221
    pMIR->bottom = MaxBot;
222
222
}
223
223
/*------------------------------------------------------------------------------------------------*/
224
 
bool HaveLinePartAtReg (Point16 *pA, Point16 *pB, const Rect16 *pRc, const Int32 Skew
 
224
bool HaveLinePartAtReg (Point16 *pA, Point16 *pB, const Rect16 *pRc, const int32_t Skew
225
225
    , const int NearHor, const int NearVer)
226
226
{
227
227
    Point16 Cur_A = {0}, Cur_B = {0};
228
 
    /*  �������� ���  */
 
228
    /*  Обрезаем низ  */
229
229
    Cur_A.x = pA->x;
230
230
    Cur_A.y = pA->y;
231
231
    ::Deskew (Cur_A, -Skew);
238
238
    bool ret = CanUse (pA, pB, Lev, Lev_A, Lev_B, false, NearHor);
239
239
    if (!ret)
240
240
        return ret;
241
 
    /*  �������� ����  */
 
241
    /*  Обрезаем верх  */
242
242
    Cur_A.x = pA->x;
243
243
    Cur_A.y = pA->y;
244
244
    ::Deskew (Cur_A, -Skew);
247
247
    ret = CanUse (pA, pB, Lev, Lev_A, Lev_B, true, NearHor);
248
248
    if (!ret)
249
249
        return ret;
250
 
    /*  �������� �����  */
 
250
    /*  Обрезаем слева  */
251
251
    Cur_B.x = pB->x;
252
252
    Cur_B.y = pB->y;
253
253
    ::Deskew (Cur_B, -Skew);
257
257
    ret = CanUse (pA, pB, Lev, Lev_A, Lev_B, false, NearVer);
258
258
    if (!ret)
259
259
        return ret;
260
 
    /*  �������� ������  */
 
260
    /*  Обрезаем справа  */
261
261
    Cur_A.x = pA->x;
262
262
    Cur_A.y = pA->y;
263
263
    ::Deskew (Cur_A, -Skew);
282
282
    return true;
283
283
}
284
284
/*------------------------------------------------------------------------------------------------*/
285
 
bool MakeInternalRectId (const Rect16 *pRcRe, Rect16 *pRcId, Int32 Skew)
 
285
bool MakeInternalRectId (const Rect16 *pRcRe, Rect16 *pRcId, int32_t Skew)
286
286
{
287
287
    Point32 LefTop = {0}, RigTop = {0}, LefBot = {0}, RigBot = {0};
288
288
    if ((Skew > MAX_ABS_SKEW) || (Skew < -MAX_ABS_SKEW))
301
301
    ::Deskew (RigTop, -Skew);
302
302
    ::Deskew (LefBot, -Skew);
303
303
    ::Deskew (RigBot, -Skew);
304
 
    if (Skew >= 0)//�� ������� ������� �� ������ �������� ����
 
304
    if (Skew >= 0)//по часовой стрелке из левого верхнего угла
305
305
    {
306
 
        pRcId->top    = static_cast<Int16>(LefTop.y);
307
 
        pRcId->bottom = static_cast<Int16>(RigBot.y);
308
 
        pRcId->left   = static_cast<Int16>(LefBot.x);
309
 
        pRcId->right  = static_cast<Int16>(RigTop.x);
 
306
        pRcId->top    = static_cast<int16_t>(LefTop.y);
 
307
        pRcId->bottom = static_cast<int16_t>(RigBot.y);
 
308
        pRcId->left   = static_cast<int16_t>(LefBot.x);
 
309
        pRcId->right  = static_cast<int16_t>(RigTop.x);
310
310
    }
311
311
    else
312
312
    {
313
 
        pRcId->top    = static_cast<Int16>(RigTop.y);
314
 
        pRcId->bottom = static_cast<Int16>(LefBot.y);
315
 
        pRcId->left   = static_cast<Int16>(LefTop.x);
316
 
        pRcId->right  = static_cast<Int16>(RigBot.x);
 
313
        pRcId->top    = static_cast<int16_t>(RigTop.y);
 
314
        pRcId->bottom = static_cast<int16_t>(LefBot.y);
 
315
        pRcId->left   = static_cast<int16_t>(LefTop.x);
 
316
        pRcId->right  = static_cast<int16_t>(RigBot.x);
317
317
    }
318
318
    if (pRcId->top > pRcId->bottom)
319
319
        return false;
322
322
    return true;
323
323
}
324
324
/*------------------------------------------------------------------------------------------------*/
325
 
/*----------    ��������� �������    -------------------------------------------------------------*/
 
325
/*----------    Локальные функции    -------------------------------------------------------------*/
326
326
static bool CanUse (Point16 *pA, Point16 *pB, const int Lev, const int Lev_A, const int Lev_B
327
327
    , const bool LimIsMax, int Near);
328
 
inline static int AverageRoundToBig (Int16 a, Int16 b);
 
328
inline static int AverageRoundToBig (int16_t a, int16_t b);
329
329
/*------------------------------------------------------------------------------------------------*/