~ubuntu-branches/debian/wheezy/cuneiform/wheezy

« back to all changes in this revision

Viewing changes to cuneiform_src/Kern/rstuff/sources/main/normalise.cpp

  • 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
/*  ������     :  ������� ��������                                            */
 
62
/*  ��������   :  08.06.00                                                    */
 
63
/*  ����       :  'Normalise.cpp'                                             */
 
64
/*  ���������� :  ������������ �����                                          */
 
65
/*  ���������� :                                                              */
 
66
/*----------------------------------------------------------------------------*/
 
67
 
 
68
#include <fstream>
 
69
#include <stdio.h>
 
70
#include <string.h>
 
71
#include "puma.h"
 
72
#include "rstuff.h"
 
73
#include "rsfunc.h"
 
74
#include "rsglobaldata.h"
 
75
#include "rsmemory.h"
 
76
#include "mpumatime.h"
 
77
#include "pumadef.h"
 
78
#include "lnsdefs.h"
 
79
#include "un_buff.h"
 
80
#include "line_vp_util.h"
 
81
#include "line_vp_2_am.h"
 
82
#include "markdataoper.h"
 
83
#include "un_err.h"
 
84
#include "specprj.h"
 
85
 
 
86
// ������
 
87
#include "ccom.h"
 
88
#include "cpage.h"
 
89
#include "criimage.h"
 
90
#include "ctiimage.h"
 
91
#include "dpuma.h"
 
92
#include "exc.h"
 
93
#include "puma.h"
 
94
#include "rpic.h"
 
95
#include "rline.h"
 
96
#include "rverline.h"
 
97
#include "smetric.h"
 
98
#include "rreccom.h"
 
99
 
 
100
const int MIN_BIG_H=30;
 
101
const int MIN_BIG_W=30;
 
102
# define  TYPE_BIG_COMP         CPAGE_GetInternalType("TYPE_BIG_COMP")
 
103
struct BIG_IMAGE
 
104
{
 
105
        CCOM_handle hCCOM;
 
106
        Word8 ImageName[CPAGE_MAXNAME];
 
107
};
 
108
 
 
109
#define RSL_VERLINE CPAGE_GetInternalType("RVL_VERIFY")
 
110
extern Bool32 gbRSLT;
 
111
 
 
112
extern Handle ObvKillLines;
 
113
extern Handle hNewLine;
 
114
extern Handle NotKillPointed;
 
115
//extern Handle hUseCLine;
 
116
extern Handle hAngles;
 
117
extern Handle hCalcMuchSkew;
 
118
extern Handle hTalkMuchSkew;
 
119
 
 
120
extern Handle hPrep;
 
121
extern Handle hContBigComp;
 
122
extern Handle hSearchLine;
 
123
extern Handle hDotLine;
 
124
extern Handle hCalcIncline;
 
125
extern Handle hVerOrNewLine;
 
126
extern Handle hOrto;
 
127
extern Handle hKillLine;
 
128
extern Handle hPrep2;
 
129
extern Handle hKillLineAfter;
 
130
extern Handle hEnd;
 
131
extern Handle hDebugAutoTemplate;
 
132
extern Handle hWndTurn;
 
133
extern Handle hDebugPrintResolution;
 
134
 
 
135
Bool32    AutoTemplate          ( PRSPreProcessImage );
 
136
void checkResolution(Handle hCCOM, Handle hCPAGE);
 
137
////////////////////////////////////////////////////////////////////////////////
 
138
// ������������ ����
 
139
// (07.07.2000) ���������� ����� �� puma.dll ��� ���������
 
140
Bool32 Normalise( PRSPreProcessImage Image)
 
141
{
 
142
        Bool32 rc;
 
143
 
 
144
        LDPUMA_Skip(hPrep);
 
145
 
 
146
        rc =  PreProcessImage( Image );
 
147
 
 
148
  LDPUMA_Skip(hDebugAutoTemplate);
 
149
 
 
150
//      if( rc )
 
151
//              rc = AutoTemplate( Image );
 
152
//              rc = RNORM_AutoTemplate( Image );
 
153
 
 
154
  LDPUMA_Skip(hSearchLine);
 
155
 
 
156
        if ( rc )
 
157
                rc = SearchLines( Image );
 
158
 
 
159
    LDPUMA_Skip(hCalcIncline);
 
160
 
 
161
        if( rc )
 
162
                rc = CalcIncline( Image );
 
163
 
 
164
        LDPUMA_Skip(hOrto);
 
165
 
 
166
        if (rc)
 
167
                rc = OrtoMove( Image );
 
168
 
 
169
        LDPUMA_Skip(hContBigComp);
 
170
 
 
171
        if(rc)
 
172
            rc= CreateContainerBigComp( Image );
 
173
 
 
174
        LDPUMA_Skip(hVerOrNewLine);
 
175
 
 
176
/*    if (rc &&
 
177
 
 
178
                //  � �������� ����� ��������� ����� ��� �������. 02.07.2002 E.P..
 
179
                Image->gnLanguage != LANG_TURKISH &&
 
180
 
 
181
                LDPUMA_Skip(hDotLine) &&
 
182
                LDPUMA_Skip(Image->hDebugCancelSearchDotLines)
 
183
           )
 
184
//    if (rc && LDPUMA_Skip(hDotLine) && LDPUMA_Skip(Image->hDebugCancelSearchDotLines))
 
185
        rc = SLINEDOT_SearchDotLines(*(Image->phCCOM), Image->hCPAGE, Image->phCLINE);//Almi 0822
 
186
//        SLINEDOT_SearchDotLines(*(Image->phCCOM), Image->hCPAGE, Image->phCLINE);*/
 
187
 
 
188
        if ( rc )
 
189
        rc = SearchNewLines( Image );
 
190
 
 
191
    LDPUMA_Skip(hKillLine);
 
192
 
 
193
        // ������ �����
 
194
        if ( rc )
 
195
                rc = KillLinesN( Image );
 
196
 
 
197
        LDPUMA_Skip(hKillLineAfter);
 
198
 
 
199
        // ������� ������� ����� ����� �����
 
200
        if ( rc && LDPUMA_Skip(Image->hDebugCancelRemoveLines))
 
201
//              rc = //almi 28.11.00
 
202
             LineKiller(Image);
 
203
 
 
204
        LDPUMA_Skip(hEnd);
 
205
 
 
206
    return rc;
 
207
}
 
208
/////////////////////////////////////////////////////////////////////////////////////////////////////
 
209
//
 
210
 
 
211
 
 
212
 
 
213
Bool32    VerifyN( PRSPreProcessImage Image )
 
214
{
 
215
        Bool32 rc;
 
216
 
 
217
        rc = VerifyLines( Image );
 
218
 
 
219
        return rc;
 
220
}
 
221
 
 
222
Bool32 SearchNewLines( PRSPreProcessImage Image )
 
223
{
 
224
    Bool32 ret = TRUE;
 
225
    bool searchlines = LDPUMA_Skip(Image->hDebugCancelSearchDotLines) && !LDPUMA_Skip(hDotLine);
 
226
    Handle hSaveImage = CPAGE_CreateBlock(Image->hCPAGE, RSL_VERLINE, 0, 0, Image, sizeof (RSPreProcessImage));
 
227
 
 
228
    if(LDPUMA_Skip(Image->hDebugCancelVerifyLines))
 
229
    {
 
230
        ret=RLINE_LinesPass1(Image->hCPAGE,*(Image->phCCOM),Image->phCLINE,Image->pgneed_clean_line, searchlines, (Word8)Image->gnLanguage);
 
231
 
 
232
        if (ret && !gbRSLT)
 
233
            ret = RLINE_LinesPass2(*(Image->phCCOM),Image->phCLINE, Image->hCPAGE);
 
234
    }
 
235
 
 
236
    CPAGE_DeleteBlock(Image->hCPAGE, hSaveImage);
 
237
 
 
238
    return ret;
 
239
}
 
240
 
 
241
Bool32 CreateContainerBigComp( PRSPreProcessImage Image )
 
242
{
 
243
 CCOM_handle hCCOM_old=(CCOM_handle)(*(Image->phCCOM));
 
244
 Handle hCPage=Image->hCPAGE;
 
245
 CCOM_handle hCCOM_new=0;
 
246
 BIG_IMAGE big_Image;
 
247
 PAGEINFO info = {0};
 
248
 GetPageInfo(hCPage,&info);
 
249
 int i=0;
 
250
 
 
251
 for(i=0;i<CPAGE_MAXNAME;i++)
 
252
          big_Image.ImageName[i]=info.szImageName[i];
 
253
 
 
254
 hCCOM_new = CCOM_CreateContainer();
 
255
 if(!hCCOM_new)
 
256
 {
 
257
        big_Image.hCCOM=NULL;
 
258
    return TRUE;
 
259
 }
 
260
 
 
261
 CCOM_comp* comp=NULL;
 
262
 CCOM_comp* new_comp;
 
263
 comp=CCOM_GetFirst(hCCOM_old,FALSE);
 
264
 
 
265
  while(comp)
 
266
  {
 
267
          if( (comp->h>=MIN_BIG_H)&&(comp->w>=MIN_BIG_W) )
 
268
          {
 
269
           new_comp=CCOM_New(hCCOM_new,comp->upper,comp->left,comp->w,comp->h);
 
270
           if(new_comp)
 
271
           {
 
272
                if(comp->size_linerep<0)
 
273
                        ;
 
274
                else
 
275
                {
 
276
         if(!CCOM_Copy(new_comp,comp) )
 
277
                       CCOM_Delete(hCCOM_new,comp);
 
278
                }
 
279
           }
 
280
          }
 
281
          comp=CCOM_GetNext(comp,FALSE);
 
282
  }
 
283
 
 
284
  big_Image.hCCOM=hCCOM_new;
 
285
 
 
286
   CPAGE_CreateBlock(hCPage,TYPE_BIG_COMP,0,0,&big_Image,sizeof(BIG_IMAGE));
 
287
  return TRUE;
 
288
}
 
289
 
 
290
/////////////////////////////////////////////////////////////////////////////////////////////////////
 
291
//
 
292
Bool32    KillLinesN( PRSPreProcessImage Image )
 
293
{
 
294
        Bool32 rc;
 
295
 
 
296
        rc = KillLines( Image );
 
297
 
 
298
        return rc;
 
299
}
 
300
////////////////////////////////////////////////////////////////////////////////
 
301
// ��������������� ���������
 
302
// (07.07.2000) ���������� ����� �� puma.dll ��� ���������
 
303
// ������ ��������� � ����
 
304
// � ������ ��������� ��������� ���������
 
305
Bool32 PreProcessImage( PRSPreProcessImage Image )
 
306
{
 
307
 
 
308
        Bool32 gbAutoRotate          = Image->gbAutoRotate;
 
309
        PWord8 *gpRecogDIB           = Image->pgpRecogDIB;
 
310
        Handle hCPAGE                = Image->hCPAGE;
 
311
        const char * glpRecogName    = *Image->pglpRecogName;
 
312
        PCIMAGEBITMAPINFOHEADER info = (PCIMAGEBITMAPINFOHEADER)Image->pinfo;
 
313
        /////////////////////////////////
 
314
        Bool32 rc = TRUE;
 
315
        //char * lpRecogName = NULL;
 
316
        Word32 Angle = 0;
 
317
 
 
318
        hWndTurn = 0;
 
319
 
 
320
        if(InitPRGTIME())
 
321
                ProgressStart();
 
322
 
 
323
        if(!ProgressStep(1,5))
 
324
                rc = FALSE;
 
325
 
 
326
        // Andrey 12.11.01
 
327
        // ����������������� ��������� CPAGE
 
328
        //
 
329
        if(rc)
 
330
        {
 
331
                PAGEINFO           PInfo = {0};
 
332
                GetPageInfo(hCPAGE,&PInfo);
 
333
                strcpy((char*)PInfo.szImageName, glpRecogName);
 
334
                PInfo.BitPerPixel = info->biBitCount;
 
335
                PInfo.DPIX = info->biXPelsPerMeter*254L/10000;
 
336
//              PInfo.DPIX = PInfo.DPIX < 200 ? 200 : PInfo.DPIX;
 
337
                PInfo.DPIY = info->biYPelsPerMeter*254L/10000;
 
338
//              PInfo.DPIY = PInfo.DPIY < 200 ? 200 : PInfo.DPIY;
 
339
                PInfo.Height = info->biHeight;
 
340
                PInfo.Width = info->biWidth;
 
341
//              PInfo.X = 0; ��� �����������
 
342
//              PInfo.Y = 0;
 
343
                PInfo.Incline2048 = 0;
 
344
                PInfo.Page = 1;
 
345
                PInfo.Angle = Angle;
 
346
 
 
347
                SetPageInfo(hCPAGE,PInfo);
 
348
        }
 
349
 
 
350
        ////////////////////////////////////////////////////////
 
351
        // ������� ����������
 
352
        //
 
353
        if(!ProgressStep(2,65))
 
354
                rc = FALSE;
 
355
 
 
356
        if(rc)
 
357
        {
 
358
                if(LDPUMA_Skip(Image->hDebugCancelComponent)/*DPumaSkipComponent()*/)
 
359
                {
 
360
//                      Word8 ori;
 
361
                        PRGTIME prev = StorePRGTIME(65, 85);
 
362
                        rc = ExtractComponents( gbAutoRotate, NULL, (PWord8)glpRecogName, Image);
 
363
                        RestorePRGTIME(prev);
 
364
/*                      if(rc && gbAutoRotate)
 
365
                        {
 
366
                                //if(!REXC_GetOrient(&ori))
 
367
                                //if(!REXC_GetOrient(&ori) && db_spec_prj!=SPEC_PRJ_GIP )
 
368
                                if(!RNORM_GetOrient(&ori, *(Image->phCCOM)) && db_spec_prj!=SPEC_PRJ_GIP )
 
369
                                {
 
370
                                        SetReturnCode_rstuff(RNORM_GetReturnCode());
 
371
                                        rc = FALSE;
 
372
                                }
 
373
                                else
 
374
                                {
 
375
                                        //if(ori)
 
376
                                        if(ori && !(db_spec_prj==SPEC_PRJ_GIP&&ori==4))
 
377
                                        {
 
378
                                                Word32 dwTurn = 0;
 
379
                                                switch(ori)
 
380
                                                {
 
381
                                                case 1:
 
382
                                                        Angle = 270;
 
383
                                                        dwTurn = RIMAGE_TURN_270;
 
384
                                                        break;
 
385
                                                case 2:
 
386
                                                        Angle = 90;
 
387
                                                        dwTurn = RIMAGE_TURN_90;
 
388
                                                        break;
 
389
                                                case 3:
 
390
                                                        Angle = 180;
 
391
                                                        dwTurn = RIMAGE_TURN_180;
 
392
                                                        break;
 
393
                                                }
 
394
 
 
395
                                                if( LDPUMA_Skip(Image->hDebugCancelTurn) /*umaSkipTurn()*/ /*)
 
396
                                                {
 
397
                                                        if(!RIMAGE_Turn((PWord8)glpRecogName,(PWord8)PUMA_IMAGE_TURN,dwTurn,0))
 
398
                                                        {
 
399
                                                                SetReturnCode_rstuff_rstuff(RIMAGE_GetReturnCode());
 
400
                                                                rc = FALSE;
 
401
                                                        }
 
402
                                                        else
 
403
                                                        {
 
404
 
 
405
                                                                if(!CIMAGE_ReadDIB((PWord8)PUMA_IMAGE_TURN,(Handle*)gpRecogDIB,TRUE))
 
406
                                                                {
 
407
                                                                        SetReturnCode_rstuff_rstuff(CIMAGE_GetReturnCode());
 
408
                                                                        rc = FALSE;
 
409
                                                                }
 
410
                                                                else
 
411
                                                                {
 
412
                                                                        //
 
413
                                                                        //  ������ ����� ���������
 
414
                                                                        //
 
415
                                                                        glpRecogName = PUMA_IMAGE_TURN;
 
416
                                                                        hWndTurn = LDPUMA_CreateWindow(PUMA_IMAGE_TURN,(*gpRecogDIB));
 
417
                                                                        PRGTIME prev = StorePRGTIME(85, 100);
 
418
                                                                        rc = ExtractComponents( FALSE, NULL, (PWord8)glpRecogName, Image);
 
419
                                                                        PAGEINFO info = {0};
 
420
                                            GetPageInfo(hCPAGE,&info);
 
421
                                                                        info.Images|=IMAGE_TURN;
 
422
//                                                                      strcpy((char*)info.szImageName,PUMA_IMAGE_TURN);
 
423
                                            SetPageInfo(hCPAGE,info);
 
424
                                    RestorePRGTIME(prev);
 
425
                                                                }
 
426
                                                        }
 
427
                                                }
 
428
                                        }
 
429
                                }
 
430
                        }*/
 
431
 
 
432
                        //�������� ������� ���������� � ���������� ���������� �� �����������, ���� ��� ���
 
433
                        checkResolution(*(Image->phCCOM), hCPAGE);
 
434
                        if(!ProgressStep(2,100))
 
435
                                rc = FALSE;
 
436
 
 
437
                }
 
438
                else
 
439
                        LDPUMA_Console("�������� ���� ��������� ���������.\n");
 
440
        }
 
441
        //
 
442
        // ������������������ ��������� CPAGE
 
443
        //
 
444
        if(rc)
 
445
        {
 
446
                PAGEINFO           PInfo = {0};
 
447
                GetPageInfo(hCPAGE,&PInfo);
 
448
                strcpy((char*)PInfo.szImageName, glpRecogName);
 
449
                PInfo.BitPerPixel = info->biBitCount;
 
450
//              PInfo.DPIX = info->biXPelsPerMeter*254L/10000;
 
451
                PInfo.DPIX = PInfo.DPIX < 200 ? 200 : PInfo.DPIX;
 
452
//              PInfo.DPIY = info->biYPelsPerMeter*254L/10000;
 
453
                PInfo.DPIY = PInfo.DPIY < 200 ? 200 : PInfo.DPIY;
 
454
                PInfo.Height = info->biHeight;
 
455
                PInfo.Width = info->biWidth;
 
456
//              PInfo.X = 0; ��� �����������
 
457
//              PInfo.Y = 0;
 
458
                PInfo.Incline2048 = 0;
 
459
                PInfo.Page = 1;
 
460
                PInfo.Angle = Angle;
 
461
 
 
462
                SetPageInfo(hCPAGE,PInfo);
 
463
        }
 
464
 
 
465
        if(DonePRGTIME())
 
466
                ProgressFinish();
 
467
 
 
468
        return rc;
 
469
}
 
470
//////////////////////////////////////////////////
 
471
////////////////////////////////////////////////////////////////////////////////
 
472
// ��������� ���������
 
473
Bool32  ExtractComponents( Bool32 bIsRotate, Handle * prev_ccom, PWord8 name, PRSPreProcessImage Image)
 
474
{
 
475
        Bool32 rc = TRUE;
 
476
        ExcControl      exc = {0};
 
477
//      RSGETMODULEPATH  pGetModulePath;
 
478
//      RSSETUPDATE      pSetUpdate;
 
479
//
 
480
//      if ( ProgressPoints.pGetModulePath && ProgressPoints.pSetUpdate)
 
481
//      {
 
482
//              pGetModulePath = (RSGETMODULEPATH)ProgressPoints.pGetModulePath;
 
483
//              pSetUpdate     = (RSSETUPDATE)ProgressPoints.pSetUpdate;
 
484
//      }
 
485
//      else
 
486
//      {
 
487
//              return false;
 
488
//      }
 
489
 
 
490
    if(prev_ccom)
 
491
    {
 
492
        *prev_ccom = *Image->phCCOM ? *Image->phCCOM: NULL;
 
493
        *Image->phCCOM=NULL;
 
494
    }
 
495
    else
 
496
    {
 
497
        CCOM_DeleteContainer((CCOM_handle)*Image->phCCOM);
 
498
        *Image->phCCOM=NULL;
 
499
    }
 
500
 
 
501
        if(!REXC_SetImportData(REXC_ProgressStep, (void*)rexcProgressStep))
 
502
        {
 
503
                SetReturnCode_rstuff(REXC_GetReturnCode());
 
504
                return FALSE;
 
505
        }
 
506
 
 
507
        // ����� ������������� ��������
 
508
        //Andrey: ����������� �������� � ��������� ������ RRecCom
 
509
        exc.Control  = Ex_ExtraComp|/*Ex_EvnRecog|*/Ex_Picture;
 
510
    //exc.Control |= Ex_NetRecog;
 
511
 
 
512
        //Andrey: orientation is obtained from new library RNORM
 
513
    //exc.Control |= ( bIsRotate ? Ex_Orient : 0 );
 
514
 
 
515
//Andrey: without flag Ex_PictureLarge big comps aren't extracted which may cause loss of big negatives
 
516
//    if( Image->gnPictures )
 
517
        exc.Control |= Ex_PictureLarge;
 
518
/*//Andrey: ����������� �������� � ��������� ������ RRecCom
 
519
        if(rc && !REXC_SetEVNProperties(exc, GetModulePath(),(Word8)Image->gnLanguage) )
 
520
        { // ���������������� ������������� �� ������� � ������ �������
 
521
                SetReturnCode_rstuff(REXC_GetReturnCode());
 
522
                rc = FALSE;
 
523
        }
 
524
        else
 
525
*/      {
 
526
                Word8 w8 = (Word8)Image->gbDotMatrix;
 
527
                        REXC_SetImportData(REXC_Word8_Matrix,&w8);
 
528
 
 
529
                w8 = (Word8)Image->gbFax100;
 
530
                        REXC_SetImportData(REXC_Word8_Fax1x2,&w8);
 
531
        }
 
532
 
 
533
//exc.Control ^= Ex_EvnRecog;
 
534
/*
 
535
        if(rc && !REXCExtraDIB( exc, lpdata,0,0,0,0) ) // ����� ��������� � DIB-e
 
536
*/
 
537
    CIMAGEIMAGECALLBACK clbk;
 
538
    if(rc && !CIMAGE_GetCallbackImage(name, &clbk))
 
539
    {
 
540
                SetReturnCode_rstuff(CIMAGE_GetReturnCode());
 
541
        rc = FALSE;
 
542
    }
 
543
    if( rc && !REXCExtracomp3CB(exc, // ����� ��������� by 3CallBacks
 
544
        (TImageOpen)clbk.CIMAGE_ImageOpen,
 
545
        (TImageClose)clbk.CIMAGE_ImageClose,
 
546
        (TImageRead)clbk.CIMAGE_ImageRead)
 
547
        )
 
548
                {
 
549
                SetReturnCode_rstuff(REXC_GetReturnCode());
 
550
                rc = FALSE;
 
551
                }
 
552
 
 
553
        if(rc)
 
554
        {
 
555
                *Image->phCCOM = (Handle)REXCGetContainer();
 
556
                if(*Image->phCCOM==0)
 
557
                {
 
558
                        SetReturnCode_rstuff(REXC_GetReturnCode());
 
559
                        rc = FALSE;
 
560
                }
 
561
 
 
562
                RRecComControl rec_control;
 
563
                memset(&rec_control, 0, sizeof(RRecComControl));
 
564
                rec_control.flags = RECOG_EVN;
 
565
 
 
566
                if (!RRECCOM_Recog(*(Image->phCCOM), rec_control, GetModulePath(), (Word8)Image->gnLanguage))
 
567
                {
 
568
                        SetReturnCode_rstuff(RRECCOM_GetReturnCode());
 
569
                        rc = FALSE;
 
570
                }
 
571
        }
 
572
        if(rc)
 
573
                SetUpdate(FLG_UPDATE_NO,FLG_UPDATE_CCOM);
 
574
        return rc ;
 
575
}
 
576
//////////////////////////////////////////////////////////////////////////////////
 
577
 
 
578
Bool32 SearchLines ( PRSPreProcessImage Image )
 
579
{
 
580
        Bool32 rc = TRUE;
 
581
 
 
582
        if(LDPUMA_Skip(Image->hDebugCancelSearchLines))
 
583
        {
 
584
                Bool32 b32 = !Image->gbDotMatrix;
 
585
                RLINE_SetImportData(RLINE_Bool32_NOFILLGAP3,&b32);
 
586
                b32 = TRUE;
 
587
                RLINE_SetImportData(RLINE_Bool32_NOHBORDER,&b32);
 
588
                RLINE_SetImportData(RLINE_Bool32_NOVBORDER,&b32);
 
589
 
 
590
                if(!RLINE_SearchLines(Image->hCPAGE,Image->phCLINE))
 
591
                {
 
592
                        //SetReturnCode_rstuff(RLINE_GetReturnCode());
 
593
                        //rc = FALSE;
 
594
                        *Image->pgrc_line = FALSE;
 
595
                        LDPUMA_Console("��������������: RLINE(0x%X) %s\n",RLINE_GetReturnCode(),RLINE_GetReturnString(RLINE_GetReturnCode()));
 
596
                }
 
597
        }
 
598
        else
 
599
                LDPUMA_Console("�������� ���� ������ �����.\n");
 
600
        return rc;
 
601
 
 
602
}
 
603
//////////////////////////////////////////////////////////////////////////////////
 
604
Bool32 VerifyLines ( PRSPreProcessImage Image )
 
605
{
 
606
        Bool32 rc = TRUE;
 
607
 
 
608
#ifdef _USE_RVERLINE_
 
609
        if( *Image->pgrc_line )
 
610
        {
 
611
                if(LDPUMA_Skip(Image->hDebugCancelVerifyLines))
 
612
                {
 
613
                        Regime_VerifyLines val = Image->gnTables ? RVL_FutuTablCorr:RVL_Default;
 
614
 
 
615
                        if( !RVERLINE_SetImportData(RVERLINE_DTRVERLINE_RegimeOfVerifyLines,&val)||
 
616
                                !RVERLINE_MarkLines(*Image->phCCOM, Image->hCPAGE))
 
617
                        {
 
618
                                SetReturnCode_rstuff(RVERLINE_GetReturnCode());
 
619
                                rc = FALSE;
 
620
                        }
 
621
                        else
 
622
                        {
 
623
                                Bool32 BadScan = FALSE;
 
624
                                Int32  ScanQual= 0;
 
625
//                              RVERLINE_AboutLines(Image->hCPAGE,*Image->phCCOM, Image->pgneed_clean_line, &BadScan, &ScanQual);                       }
 
626
                                AboutLines(Image, &BadScan, &ScanQual);
 
627
                        }
 
628
 
 
629
                        if(!*Image->pgneed_clean_line)
 
630
                                LDPUMA_Console("��������������: RSTUFF �������, ��� ������� ����� �� ����.\n");
 
631
                        }
 
632
                else
 
633
                        LDPUMA_Console("�������� ���� ������ �����.\n");
 
634
////            if(LDPUMA_Skip(hDebugCancelVerifyLines))
 
635
////            {
 
636
////                    Regime_VerifyLines val = gnTables ? RVL_FutuTablCorr:RVL_Default;
 
637
////
 
638
////                    if( !RLTABLE_SetImportData(RLTABLE_DTRLTABLE_RegimeOfVerifyLines,&val)||
 
639
////                            !RLTABLE_MarkLines(hCCOM, hCPAGE))
 
640
////                    {
 
641
////                            SetReturnCode_rstuff(RLTABLE_GetReturnCode());
 
642
////                            rc = FALSE;
 
643
////                    }
 
644
////                    else
 
645
////                    {
 
646
////                            Bool32 BadScan = FALSE;
 
647
////                            Int32  ScanQual= 0;
 
648
////                            RLTABLE_AboutLines(hCPAGE,hCCOM, &gneed_clean_line, &BadScan, &ScanQual);                       }
 
649
////                            if(!gneed_clean_line)
 
650
////                                    LDPUMA_Console("��������������: RLTABLE_AboutLines �������, ��� ������� ����� �� ����.\n");
 
651
////                    }
 
652
////            else
 
653
////                    LDPUMA_Console("�������� ���� ������ �����.\n");
 
654
        }
 
655
#endif //_USE_RVERLINE_
 
656
 
 
657
        return rc;
 
658
}
 
659
 
 
660
////////////////////////////////////////////////////////////////////////////////////////////////////////
 
661
//
 
662
/*Bool32 ShortVerticalLinesProcess ( PRSPreProcessImage Image, Word32 Step )
 
663
{
 
664
        Bool32 bRet = FALSE;
 
665
 
 
666
        if ( !gLTInfo )
 
667
                return bRet;
 
668
 
 
669
        if ( Step == RS_SVL_FIRST_STEP )
 
670
        {
 
671
 
 
672
                //gLTInfo->Hor.Lns = (LineInfo *)RSTUFFAlloc(sizeof(LineInfo) * RStuffMaxNumLines * 2);
 
673
                gLinesData.VLinefBufferA = gLTInfo->Ver.Lns = (LineInfo *)RSTUFFAlloc(sizeof(LineInfo) * RStuffMaxNumLines * 2);
 
674
 
 
675
                if (gLTInfo->Ver.Lns != NULL )
 
676
                        bRet = TRUE;
 
677
 
 
678
                if ( bRet )
 
679
                        bRet = ReadSVLFromPageContainer( Image, (void *)gLTInfo );
 
680
 
 
681
        }
 
682
 
 
683
        if ( Step == RS_SVL_SECOND_STEP )
 
684
        {
 
685
                LinesTotalInfo       LTInfo = {0};
 
686
 
 
687
                //LTInfo.Hor.Lns = (LineInfo *)RSTUFFAlloc(sizeof(LineInfo) * RStuffMaxNumLines * 2);
 
688
                gLinesData.VLinefBufferB = LTInfo.Ver.Lns = (LineInfo *)RSTUFFAlloc(sizeof(LineInfo) * RStuffMaxNumLines * 2);
 
689
 
 
690
                if (LTInfo.Ver.Lns != NULL )
 
691
                        bRet = TRUE;
 
692
 
 
693
                if ( bRet )
 
694
                        bRet = ReadSVLFromPageContainer( Image, (void *)&LTInfo );
 
695
 
 
696
                //RSTUFFFree ( LTInfo.Hor.Lns );
 
697
                RSTUFFFree ( gLinesData.VLinefBufferA );
 
698
                //RSTUFFFree ( gLTInfo->Hor.Lns );
 
699
                RSTUFFFree ( gLinesData.VLinefBufferB );
 
700
        }
 
701
 
 
702
        return bRet;
 
703
}
 
704
*/
 
705
////////////////////////////////////////////////////////////////////////////////////////////////////////
 
706
//
 
707
/*Bool32 ReadSVLFromPageContainer ( PRSPreProcessImage Image, void * pInf )
 
708
{
 
709
        Bool32         bRet = TRUE;
 
710
 
 
711
        LinesTotalInfo *LTInfo = (LinesTotalInfo *) pInf;
 
712
        LineInfo       *pLHor, *pLVer;
 
713
 
 
714
        Handle         hBlockLine;
 
715
        Handle         hBlockLineHor;
 
716
        Handle         hBlockLineVer;
 
717
        Handle         hBlockLinePrev;
 
718
        Word32         nTagSize;
 
719
        Word32         nReal;
 
720
        Word32         wErr32;
 
721
 
 
722
        nTagSize = sizeof (LinesTotalInfo);
 
723
        pLHor = LTInfo->Hor.Lns;
 
724
        pLVer = LTInfo->Ver.Lns;
 
725
 
 
726
        hBlockLine = CPAGE_GetBlockFirst (Image->hCPAGE, RLINE_BLOCK_TYPE);
 
727
        if (!hBlockLine)
 
728
        {
 
729
                //sprintf (pStr, "����� �� ����������.");
 
730
                //return RV_EMPTY;
 
731
                bRet =  FALSE;
 
732
        }
 
733
 
 
734
        wErr32 = CPAGE_GetReturnCode ();
 
735
 
 
736
        if (wErr32!=0)
 
737
        {
 
738
                //Error_CPage ("[GetBlockFirst]");
 
739
                bRet =  FALSE;
 
740
        }
 
741
        //�����.... ��� �����?
 
742
        if ( bRet )
 
743
        {
 
744
                nReal = CPAGE_GetBlockData (Image->hCPAGE, hBlockLine, RLINE_BLOCK_TYPE, (void *)LTInfo, nTagSize);
 
745
 
 
746
                wErr32 = CPAGE_GetReturnCode ();
 
747
        }
 
748
 
 
749
        if ((nReal!=nTagSize)||(wErr32!=0))
 
750
        {
 
751
                //Error_CPage ("[GetBlockData]");
 
752
                bRet = FALSE;
 
753
        }
 
754
        if (LTInfo->Hor.Cnt + LTInfo->Ver.Cnt >= RStuffMaxNumLines)
 
755
        {
 
756
                //sprintf (pStr, "�� ������� ������ ��� %d �����!", LTInfo.Hor.Cnt + LTInfo.Ver.Cnt);
 
757
                //return RV_DOUBT;
 
758
                bRet = FALSE;
 
759
        }
 
760
        if ((LTInfo->Hor.Cnt==0)&&(LTInfo->Ver.Cnt==0))
 
761
        {
 
762
                //sprintf (pStr, "����� ����������, �� �� ����� �� ��������.");
 
763
                //return RV_EMPTY;
 
764
                bRet = FALSE;
 
765
        }
 
766
        //  �������������� �����
 
767
        if ( bRet && pLHor != NULL )
 
768
        {
 
769
                for (Int32 i=0; i<LTInfo->Hor.Cnt; i++)
 
770
                {
 
771
                        if (i==0)
 
772
                                hBlockLineHor = CPAGE_GetBlockFirst (Image->hCPAGE, (Word32)(LTInfo->Hor.Lns));
 
773
                        else
 
774
                                hBlockLineHor = CPAGE_GetBlockNext (Image->hCPAGE, hBlockLinePrev, (Word32)(LTInfo->Hor.Lns));
 
775
                        wErr32 = CPAGE_GetReturnCode ();
 
776
                        if (wErr32!=0)
 
777
                        {
 
778
                                //if (i==0)
 
779
                                        //Error_CPage ("[GetBlockFirst]");
 
780
                                //else
 
781
                                        //Error_CPage ("[GetBlockNext]");
 
782
                                bRet = FALSE;
 
783
                                break;
 
784
                        }
 
785
                        nTagSize = sizeof (LineInfo);
 
786
                        nReal = CPAGE_GetBlockData (Image->hCPAGE, hBlockLineHor, (Word32)(LTInfo->Hor.Lns), (void *)&(pLHor[i]), nTagSize);
 
787
                        wErr32 = CPAGE_GetReturnCode ();
 
788
                        if ((nReal!=nTagSize)||(wErr32!=0))
 
789
                        {
 
790
                                //Error_CPage ("[GetBlockData]");
 
791
                                bRet = FALSE;
 
792
                                break;
 
793
                        }
 
794
                        hBlockLinePrev = hBlockLineHor;
 
795
                }
 
796
        }
 
797
        //  ������������ �����
 
798
        if ( bRet && pLVer != NULL )
 
799
        {
 
800
                for (Int32 i=0; i<LTInfo->Ver.Cnt; i++)
 
801
                {
 
802
                        if (i==0)
 
803
                                hBlockLineVer = CPAGE_GetBlockFirst (Image->hCPAGE, (Word32)(LTInfo->Ver.Lns));
 
804
                        else
 
805
                                hBlockLineVer = CPAGE_GetBlockNext (Image->hCPAGE, hBlockLinePrev, (Word32)(LTInfo->Ver.Lns));
 
806
                        wErr32 = CPAGE_GetReturnCode ();
 
807
                        if (wErr32!=0)
 
808
                        {
 
809
                                //if (i==0)
 
810
                                        //Error_CPage ("[GetBlockFirst]");
 
811
                                //else
 
812
                                        //Error_CPage ("[GetBlockNext]");
 
813
                                bRet = FALSE;
 
814
                                break;
 
815
                        }
 
816
                        nTagSize = sizeof (LineInfo);
 
817
                        nReal = CPAGE_GetBlockData (Image->hCPAGE, hBlockLineVer, (Word32)(LTInfo->Ver.Lns), (void *)&(pLVer[i]), nTagSize);
 
818
                        wErr32 = CPAGE_GetReturnCode ();
 
819
                        if ((nReal!=nTagSize)||(wErr32!=0))
 
820
                        {
 
821
                                //Error_CPage ("[GetBlockData]");
 
822
                                bRet = FALSE;
 
823
                                break;
 
824
                        }
 
825
                        hBlockLinePrev = hBlockLineVer;
 
826
                }
 
827
        }
 
828
 
 
829
        //*pHoriType = (Word32)LTInfo.Hor.Lns;
 
830
        //*pVertType = (Word32)LTInfo.Ver.Lns;
 
831
        //LTInfo->Hor.Lns = pLHor;
 
832
        //LTInfo->Ver.Lns = pLVer;
 
833
 
 
834
        return bRet;
 
835
}
 
836
*/
 
837
/////////////////////////////////////////////////////////////////////////////////////////////////////
 
838
// ������� �����
 
839
Bool32    KillLines(PRSPreProcessImage Image)
 
840
{
 
841
        Bool32 rc = TRUE;
 
842
 
 
843
        if(!ProgressStepLines(1/*,GetResourceString(IDS_REMOVELINE)*/,30))
 
844
                rc = FALSE;
 
845
 
 
846
        if( rc && *Image->pgrc_line && *Image->pgneed_clean_line)
 
847
        {
 
848
                if(LDPUMA_Skip(Image->hDebugCancelRemoveLines)  )
 
849
                {
 
850
                        PWord8 pDIB = NULL;
 
851
                        PRGTIME prev = StorePRGTIME(30, 40);
 
852
 
 
853
                        rc = RemoveLines(Image, &pDIB);
 
854
 
 
855
                        if(rc)
 
856
                        {
 
857
                                *Image->pgpRecogDIB = pDIB;
 
858
                                LDPUMA_CreateWindow(NAME_IMAGE_DELLINE,*Image->pgpRecogDIB);
 
859
                        }
 
860
                        RestorePRGTIME(prev);
 
861
                }
 
862
                else
 
863
                        LDPUMA_Console("�������� ���� ������ �����.\n");
 
864
        }
 
865
 
 
866
        return rc;
 
867
}
 
868
/////////////////////////////////////////////////////////////////////////////////////////////////////
 
869
//
 
870
Bool32 RemoveLines(PRSPreProcessImage Image, PWord8 * lppDIB)
 
871
{
 
872
        Handle hccom = *Image->phCCOM;
 
873
        Handle hcpage = Image->hCPAGE;
 
874
        Handle *hLinesCCOM = Image->phLinesCCOM;
 
875
 
 
876
        PWord8 hDIB = NULL;
 
877
        Bool32 rc = TRUE;
 
878
    *hLinesCCOM = NULL;
 
879
    CCOM_comp   *victim[100];
 
880
    Int32       nvict,i;
 
881
    Bool32      yes_victim = FALSE;
 
882
        //
 
883
        // ������ �����
 
884
        //
 
885
        if(!LDPUMA_Skip(ObvKillLines)||(LDPUMA_Skip(hNewLine)&&LDPUMA_Skip(Image->hDebugCancelVerifyLines)))
 
886
                rc=DeleteLines(hcpage,Image->phCLINE,PUMA_IMAGE_DELLINE);
 
887
        else
 
888
        {
 
889
         if(rc && !RLINE_DeleteLines(hcpage,PUMA_IMAGE_DELLINE))
 
890
         {
 
891
                SetReturnCode_rstuff(RLINE_GetReturnCode());
 
892
                rc = FALSE;
 
893
         }
 
894
     if (rc && LDPUMA_Skip(NotKillPointed) && LDPUMA_Skip(Image->hDebugCancelSearchDotLines))
 
895
         rc = DeleteDotLines(Image->phCLINE, PUMA_IMAGE_DELLINE);
 
896
        }
 
897
 
 
898
        LDPUMA_Skip(hPrep2);
 
899
        //
 
900
        // ������� ����������� � ���������� �������
 
901
        //
 
902
        if(rc && !CIMAGE_ReadDIB((PWord8)PUMA_IMAGE_DELLINE,(Handle*)&hDIB,TRUE))
 
903
        {
 
904
                SetReturnCode_rstuff(CIMAGE_GetReturnCode());
 
905
                rc = FALSE;
 
906
        }
 
907
        if(hDIB)
 
908
        {
 
909
                //
 
910
                // ������ ���������� � ������� �� ������.
 
911
                //
 
912
                *lppDIB = (PWord8)hDIB;
 
913
                if(rc)
 
914
                {
 
915
                //if( CCOM_GetContainerVolume((CCOM_handle)*Image->phCCOM)>30000 )
 
916
                //      CCOM_CompressContatiner((CCOM_handle)*Image->phCCOM);
 
917
        if( CCOM_GetContainerVolume((CCOM_handle)*Image->phCCOM)<60000 &&
 
918
            MyGetZher ((void**)victim, &nvict, 100, hcpage) && nvict )
 
919
            yes_victim = TRUE;
 
920
 
 
921
        if( !yes_victim )
 
922
            {
 
923
            CCOM_DeleteContainer((CCOM_handle)*Image->phCCOM);
 
924
            *Image->phCCOM = 0;
 
925
            }
 
926
 
 
927
                if(!ExtractComponents(FALSE, hLinesCCOM, (PWord8)PUMA_IMAGE_DELLINE, Image))
 
928
                {
 
929
                                rc = FALSE;
 
930
                }
 
931
        else
 
932
        {
 
933
            PAGEINFO inf = {0};
 
934
            GetPageInfo(Image->hCPAGE,&inf);
 
935
            strcpy((char*)inf.szImageName,PUMA_IMAGE_DELLINE);
 
936
                        inf.Images|=IMAGE_DELLINE;
 
937
            SetPageInfo(Image->hCPAGE,inf);
 
938
        }
 
939
 
 
940
                if(rc)
 
941
                {
 
942
 
 
943
                        *Image->phCCOM = (Handle)REXCGetContainer();
 
944
                        if(*Image->phCCOM == 0)
 
945
                        {
 
946
                                SetReturnCode_rstuff(REXC_GetReturnCode());
 
947
                                rc = FALSE;
 
948
                        }
 
949
                        hccom = *Image->phCCOM;
 
950
            if( *hLinesCCOM )
 
951
                {
 
952
                //
 
953
                // Refersh CCOM
 
954
                //
 
955
                CCOM_comp   *exa=CCOM_GetFirst((CCOM_handle)*hLinesCCOM,NULL);
 
956
 
 
957
                if( yes_victim )
 
958
                {
 
959
                /*
 
960
                Rect16 rect1;
 
961
                    Word32 key = 111;
 
962
                for(i=0;i<nvict;i++)
 
963
                    {
 
964
                    exa = victim[i];
 
965
                    rect1.top = exa->upper;
 
966
                            rect1.left = exa->left;
 
967
                            rect1.bottom = exa->upper+exa->h;
 
968
                            rect1.right = exa->left+exa->w;
 
969
                            LDPUMA_DrawRect(NULL, &rect1, 0, 23635, 1, key);
 
970
                    }
 
971
 
 
972
                if(!LDPUMA_Skip(hShowCheckLetters))
 
973
                        {
 
974
                                LDPUMA_Console("Puma_������� �����  \n");
 
975
                                LDPUMA_WaitUserInput(NULL, NULL);
 
976
                                LDPUMA_DeleteRects(NULL, key);
 
977
                        }
 
978
                    */
 
979
                for(i=0;i<nvict;i++)
 
980
                    {
 
981
                    exa = victim[i];
 
982
                    if( remove_overlayed(exa,(CCOM_handle)*Image->phCCOM) )
 
983
                        {
 
984
                        CCOM_comp   *dup=CCOM_New((CCOM_handle)*Image->phCCOM,exa->upper,exa->left,exa->w,exa->h);
 
985
                        if( dup )
 
986
                            {
 
987
                            CCOM_Store(dup,0,
 
988
                                exa->size_linerep,
 
989
                                exa->linerep,  exa->nl,
 
990
                                exa->begs, exa->ends,
 
991
                                exa->vers,   NULL);
 
992
                            dup->scale= exa->scale;
 
993
                            dup->type = exa->type;
 
994
                            dup->cs   = exa->cs;
 
995
                            }
 
996
                        }
 
997
                    }
 
998
                }
 
999
                CCOM_DeleteContainer((CCOM_handle)*hLinesCCOM);
 
1000
                }
 
1001
                        }
 
1002
                        else
 
1003
                                LDPUMA_Console("�������� ���� ��������� ��������� ����� �������� �����.\n");
 
1004
                }
 
1005
        }
 
1006
return rc;
 
1007
}
 
1008
/////////////////////////////////////////////////////////////////////////////////////////////////////
 
1009
//
 
1010
Bool32 MyGetZher (void **vvZher, Int32 *nZher, Int32 MaxZher, Handle hCPage)
 
1011
{
 
1012
        Word32 err32, nTeor, nReal;
 
1013
        Handle hBlockZher;
 
1014
        Handle hBlockPrev;
 
1015
        int i;
 
1016
        nTeor = sizeof (void *);
 
1017
        i=0;
 
1018
        while (1)
 
1019
        {
 
1020
                if (i==0)
 
1021
                        hBlockZher = CPAGE_GetBlockFirst (hCPage, RVERLINE_ZHERTVY_LINIY);
 
1022
                else
 
1023
                        hBlockZher = CPAGE_GetBlockNext (hCPage, hBlockPrev, RVERLINE_ZHERTVY_LINIY);
 
1024
                err32 = CPAGE_GetReturnCode ();
 
1025
                if (err32!=0)
 
1026
                {
 
1027
                        //if (i==0)
 
1028
                        //      Error_CPage ("[GetBlockFirst]");
 
1029
                        //else
 
1030
                        //      Error_CPage ("[GetBlockNext]");
 
1031
                        return FALSE;
 
1032
                }
 
1033
                if (!hBlockZher)
 
1034
                        break;
 
1035
                if (i>=MaxZher)
 
1036
                        return FALSE;
 
1037
                nReal = CPAGE_GetBlockData (hCPage, hBlockZher, RVERLINE_ZHERTVY_LINIY, (void *)&(vvZher[i]), nTeor);
 
1038
                err32 = CPAGE_GetReturnCode ();
 
1039
                if (!nReal||(err32!=0))
 
1040
                {
 
1041
                        //Error_CPage ("[SetBlockData]");
 
1042
                        return FALSE;
 
1043
                }
 
1044
                hBlockPrev = hBlockZher;
 
1045
                i++;
 
1046
        }
 
1047
        *nZher = i;
 
1048
        return TRUE;
 
1049
}
 
1050
/////////////////////////////////////////////////////////////////////////////////////////////////////
 
1051
//
 
1052
Bool32  remove_overlayed(CCOM_comp *sour,CCOM_handle haCCOM)
 
1053
{
 
1054
        CCOM_comp   *cur=CCOM_GetFirst(haCCOM,NULL), *curn;
 
1055
        Int32       over=0;
 
1056
 
 
1057
        do
 
1058
        {
 
1059
                curn=CCOM_GetNext(cur,NULL);
 
1060
                if( cur->upper<sour->upper && sour->upper-cur->upper>10*sour->h)
 
1061
                        { // upper zone
 
1062
                        cur=curn;
 
1063
                        continue;
 
1064
                        }
 
1065
                if( comp_over(sour,cur) )
 
1066
                        {
 
1067
                        CCOM_Delete(haCCOM,cur);
 
1068
                        over++;
 
1069
                        }
 
1070
                if( cur->upper-sour->upper>10*sour->h)
 
1071
                        break; // downer zone
 
1072
                cur = curn;
 
1073
        }while( cur!=NULL );
 
1074
 
 
1075
        return (over>0);
 
1076
}
 
1077
/////////////////////////////////////////////////////////////////////////////////////////////////////
 
1078
//
 
1079
Bool32  comp_over(CCOM_comp *sour,CCOM_comp *cur)
 
1080
{
 
1081
        Int32   le,ri,up,dn,w,h;
 
1082
 
 
1083
        if( sour->left+sour->w<=cur->left || cur->left+cur->w<=sour->left )
 
1084
                return FALSE;
 
1085
        if( sour->upper+sour->h<=cur->upper || cur->upper+cur->h<=sour->upper )
 
1086
                return FALSE;
 
1087
 
 
1088
        if( sour->left<cur->left )
 
1089
                le = cur->left;
 
1090
        else
 
1091
                le = sour->left;
 
1092
 
 
1093
        if( sour->left+sour->w<cur->left+cur->w )
 
1094
                ri = sour->left+sour->w;
 
1095
        else
 
1096
                ri = cur->left+cur->w;
 
1097
        w=ri-le;
 
1098
        if( sour->upper<cur->upper )
 
1099
                up = cur->upper;
 
1100
        else
 
1101
                up = sour->upper;
 
1102
 
 
1103
        if( sour->upper+sour->h<cur->upper+cur->h )
 
1104
                dn = cur->upper+cur->h;
 
1105
        else
 
1106
                dn = sour->upper+sour->h;
 
1107
        h=dn-up;
 
1108
 
 
1109
        if( w>0 && h>0 && cur->w<2*sour->w && cur->h<2*sour->h &&
 
1110
                w*2>cur->w && h*2>cur->h )
 
1111
                return TRUE;
 
1112
        return FALSE;
 
1113
}
 
1114
/////////////////////////////////////////////////////////////////////////////////////////////////////
 
1115
//
 
1116
/*
 
1117
Bool32    SearchTables( PRSPreProcessImage Image)
 
1118
{
 
1119
        Bool32 rc = TRUE;
 
1120
 
 
1121
        if(!ProgressStepTables(1,20))
 
1122
                rc = FALSE;
 
1123
        if( rc && Image->gnTables != PUMA_TABLE_NONE )
 
1124
        {
 
1125
                if(LDPUMA_Skip(Image->hDebugCancelSearchTables))
 
1126
                {
 
1127
                        if (!RLTABLE_SetImportData(RLTABLE_DTRLTABLE_WhereMustSearchTable, NULL))
 
1128
                        {
 
1129
                                SetReturnCode_rstuff(RLTABLE_GetReturnCode());
 
1130
                                rc = FALSE;
 
1131
                        }
 
1132
                        else
 
1133
                        {
 
1134
                                int HowToSearch;
 
1135
////                             ������������� ������ ������
 
1136
                                HowToSearch = SST_Default;
 
1137
                                if(!RLTABLE_SetImportData(RLTABLE_DTRLTABLE_StyleOfSearchTable, (void *)(&HowToSearch)))
 
1138
                                {
 
1139
                                        SetReturnCode_rstuff(RLTABLE_GetReturnCode());
 
1140
                                        rc = FALSE;
 
1141
                                }
 
1142
                                else
 
1143
                                {
 
1144
                                   if(!RLTABLE_SearchTable(*Image->phCCOM,Image->hCPAGE, TRUE, Image->pgnNumberTables))
 
1145
                                        {
 
1146
                                                SetReturnCode_rstuff(RLTABLE_GetReturnCode());
 
1147
                                                rc = FALSE;
 
1148
                                        }
 
1149
                                }
 
1150
                        }
 
1151
                }
 
1152
                else
 
1153
                        LDPUMA_Console("�������� ���� ������ ������.\n");
 
1154
        }
 
1155
 
 
1156
        return rc;
 
1157
}
 
1158
*/
 
1159
/////////////////////////////////////////////////////////////////////////////////////////////////////
 
1160
//
 
1161
//Bool32 AboutLines(PRSPreProcessImage Image, Bool32 *BadScan, Int32 *ScanQual)
 
1162
//{
 
1163
//      return TRUE;
 
1164
//}
 
1165
/////////////////////////////////////////////////////////////////////////////////////////////////////
 
1166
//
 
1167
Bool32 CalcIncline(PRSPreProcessImage Image)
 
1168
{
 
1169
        int SizeWork,SizeMain;
 
1170
        char Str[256];
 
1171
        Bool ret, WasLine, ManyComp;
 
1172
        Bool CalcMuchSkew, TalkMuchSkew;
 
1173
        Word16 Code;
 
1174
        Int32 SkewReg, Skew, SkewLocVerLin;
 
1175
        Rect16 RcReg;
 
1176
    PAGEINFO info = {0};
 
1177
        UN_BUFF MainBuff = {0};
 
1178
        void *vMain;
 
1179
        char *cWork;
 
1180
        Handle hCPage=Image->hCPAGE;
 
1181
        CLINE_handle hCLINE=*((CLINE_handle*)Image->phCLINE);
 
1182
 
 
1183
        GetPageInfo(hCPage,&info);
 
1184
 
 
1185
        /*  2. �������������.  */
 
1186
                /***  ����������  ***/
 
1187
    WasLine = 0;
 
1188
                /***  ����������� ������  ***/
 
1189
        GiveMainBuff (&vMain, &SizeMain);
 
1190
        MainBuff.vBuff    = vMain;
 
1191
        MainBuff.SizeBuff = SizeMain;
 
1192
        MainBuff.vCurr    = MainBuff.vBuff;
 
1193
        MainBuff.SizeCurr = MainBuff.SizeBuff;
 
1194
        GiveWorkBuff (&cWork, &SizeWork);
 
1195
                /***  �����  ***/
 
1196
//      if(!LDPUMA_Skip(hUseCLine))
 
1197
                ret=LoadLinesVP_rv(hCLINE,UN_LD_LinesVP2,&MainBuff,Str,&Code);
 
1198
//      else
 
1199
//          ret = LoadLinesVP_rv (hCPage, UN_LD_LinesVP, (void *)(&MainBuff), Str, &Code);
 
1200
        if ((ret!=RV_TRUE)&&(ret!=RV_EMPTY))
 
1201
        {
 
1202
                SetReturnCode_rstuff (Code);
 
1203
                return ret;
 
1204
        }
 
1205
        WasLine = (ret==RV_TRUE);
 
1206
                /***  ����������  ***/
 
1207
        ret = LoadComps_rv (*(Image->phCCOM), (void *)(&MainBuff), Str, 0); //t-e-d
 
1208
        if (ret==RV_DOUBT)
 
1209
        {
 
1210
                SetReturnCode_rstuff (Code);
 
1211
                CleanLastDataPart ((void *)(&MainBuff));
 
1212
        }
 
1213
        ManyComp = (ret==RV_TRUE)&&(MainBuff.nPartUnits[MainBuff.nPart-1]>10000);
 
1214
        if (ManyComp)
 
1215
        {
 
1216
                CleanLastDataPart ((void *)(&MainBuff));
 
1217
        }
 
1218
        if (ret==RV_DOUBT||ManyComp)
 
1219
        {
 
1220
                        ret = LoadComps_rv (*(Image->phCCOM), (void *)(&MainBuff), Str, 3); //t-e-d
 
1221
                        if (ret==RV_DOUBT)
 
1222
                        {
 
1223
                                SetReturnCode_rstuff (Code);
 
1224
                                CleanLastDataPart ((void *)(&MainBuff));
 
1225
                        }
 
1226
        }
 
1227
        if (ret!=RV_TRUE)
 
1228
        {
 
1229
                return ret;
 
1230
        }
 
1231
 
 
1232
        RcReg.left=0;
 
1233
        RcReg.right=(Int16)info.Width;
 
1234
        RcReg.top=0;
 
1235
    RcReg.bottom=(Int16)info.Height;
 
1236
        SkewReg=0;
 
1237
        Bool ContWarn = 0;
 
1238
        SkewLocVerLin = 0;
 
1239
        CalcMuchSkew = (!LDPUMA_Skip(hCalcMuchSkew));
 
1240
        TalkMuchSkew = (!LDPUMA_Skip(hTalkMuchSkew));
 
1241
 
 
1242
//  5.1 ���������� ���� ������� �������� (�� ���������� � �����).
 
1243
//      if(!LDPUMA_Skip(hUseCLine))
 
1244
                ret=ConvertLinesToAM_rv (UN_LD_LinesVP2, UN_LD_LinesAM, (void *)(&MainBuff)
 
1245
                        ,(int *)cWork, SizeWork / sizeof (int), &RcReg, SkewReg, Str, ContWarn);
 
1246
//      else
 
1247
//              ret = ConvertLinesToAM_rv (UN_LD_LinesVP, UN_LD_LinesAM, (void *)(&MainBuff)
 
1248
//                      ,(int *)cWork, SizeWork / sizeof (int), &RcReg, SkewReg, Str, ContWarn); // f-t-e-d
 
1249
        if (ret==RV_DOUBT)
 
1250
        {
 
1251
                        SetReturnCode_rstuff (Code);
 
1252
        }
 
1253
        if (ret!=RV_TRUE)
 
1254
                return ret;
 
1255
 
 
1256
        SMetric_SetImportData(SMetric_ResolX, (void *)info.DPIX);
 
1257
        SMetric_SetImportData(SMetric_ResolY, (void *)info.DPIY);
 
1258
        ret = SMetric_FindMainSkew ((void *)(&MainBuff), cWork, SizeWork, &Skew
 
1259
                        , &SkewLocVerLin, &RcReg, SkewReg, Str, CalcMuchSkew, TalkMuchSkew);
 
1260
        if (ret!=RV_TRUE)
 
1261
                return ret;
 
1262
        info.Incline2048 = Skew*2;
 
1263
        info.SkewLocVerLin2048 = SkewLocVerLin*2;
 
1264
        if(!CPAGE_SetPageData(Image->hCPAGE,PT_PAGEINFO,&info,sizeof(PAGEINFO)))
 
1265
        {
 
1266
                SetReturnCode_rstuff(CPAGE_GetReturnCode());
 
1267
                return FALSE;
 
1268
        }
 
1269
 
 
1270
        return TRUE;
 
1271
}
 
1272
////////////////////////////////////////////////////////////////////////////////////////////////////
 
1273
void checkResolution(Handle hCCOM, Handle hCPAGE)
 
1274
{
 
1275
        PAGEINFO page_info = {0};
 
1276
        const int min_res = 99;
 
1277
        CCOM_comp* pcomp=NULL;
 
1278
        unsigned int Masy[100], Masx[100], i, Jy_m = 0, My_m = 0, Jx_m = 0, Mx_m = 0, M_t;
 
1279
        bool flag_set = false;
 
1280
 
 
1281
        if (!GetPageInfo(hCPAGE, &page_info)) return;
 
1282
 
 
1283
        if (page_info.DPIX > min_res && page_info.DPIY > min_res) return;
 
1284
 
 
1285
        for (i=0; i<100; i++) Masx[i] = Masy[i] = 0;
 
1286
 
 
1287
        pcomp = CCOM_GetFirst(hCCOM, NULL);
 
1288
 
 
1289
        while (pcomp)
 
1290
        {
 
1291
                if (pcomp->h > 9 && pcomp->h < 100) Masy[pcomp->h]++;
 
1292
 
 
1293
                if (pcomp->w > 9 && pcomp->w < 100) Masx[pcomp->w]++;
 
1294
 
 
1295
                pcomp = CCOM_GetNext(pcomp, NULL);
 
1296
        }
 
1297
 
 
1298
        for (i=11; i < 99; i++)
 
1299
        {
 
1300
                M_t = Masy[i-1] + Masy[i] + Masy[i+1];
 
1301
 
 
1302
                if (M_t > My_m)
 
1303
                {
 
1304
                        Jy_m = i;
 
1305
                        My_m = M_t;
 
1306
                }
 
1307
 
 
1308
                M_t = Masx[i-1] + Masx[i] + Masx[i+1];
 
1309
 
 
1310
                if (M_t > Mx_m)
 
1311
                {
 
1312
                        Jx_m = i;
 
1313
                        Mx_m = M_t;
 
1314
                }
 
1315
        }
 
1316
 
 
1317
        if (Jy_m > 10 && My_m > 100 && !(page_info.DPIY*22 < 2*300*Jy_m && 2*page_info.DPIY*22 > 300*Jy_m))
 
1318
        {
 
1319
                page_info.DPIY = (300*Jy_m+11)/22;
 
1320
                flag_set = true;
 
1321
        }
 
1322
 
 
1323
        if (Jx_m > 10 && Mx_m > 100 && !(page_info.DPIX*22 < 2*300*Jx_m && 2*page_info.DPIX*22 > 300*Jx_m))
 
1324
        {
 
1325
                page_info.DPIX = (300*Jx_m+11)/22;
 
1326
                flag_set = true;
 
1327
        }
 
1328
 
 
1329
        if (flag_set)
 
1330
        {
 
1331
                SetPageInfo(hCPAGE, page_info);
 
1332
 
 
1333
                if (!LDPUMA_Skip(hDebugPrintResolution))
 
1334
                        LDPUMA_ConsoleN("����� ����������: DPIX=%d, DPIY=%d", page_info.DPIX, page_info.DPIY);
 
1335
        }
 
1336
}
 
1337
////////////////////////////////////////////////////////////////////////////////////////////////////
 
1338
// end of file