2
Copyright (c) 1993-2008, Cognitive Technologies
5
����������� ��������� ��������������� � ������������� ��� � ���� ��������� ����,
6
��� � � �������� �����, � ����������� ��� ���, ��� ���������� ��������� �������:
8
* ��� ��������� ��������������� ��������� ���� ������ ���������� ���������
9
���� ����������� �� ��������� �����, ���� ������ ������� � �����������
11
* ��� ��������� ��������������� ��������� ���� � ������������ �/��� �
12
������ ����������, ������������ ��� ���������������, ������ �����������
13
��������� ���� ���������� �� ��������� �����, ���� ������ ������� �
14
����������� ����� �� ��������.
15
* �� �������� Cognitive Technologies, �� ����� �� ����������� �� �����
16
���� ������������ � �������� �������� ��������� �/��� �����������
17
���������, ���������� �� ���� ��, ��� ���������������� �����������
20
��� ��������� ������������� ����������� ��������� ���� �/��� ������� ������ "���
21
��� ����" ��� ������-���� ���� ��������, ���������� ���� ��� ���������������,
22
������� �������� ������������ �������� � ����������� ��� ���������� ����, �� ��
23
������������� ���. �� �������� ��������� ���� � �� ���� ������ ����, �������
24
����� �������� �/��� �������� �������������� ���������, �� � ���� ������ ��
25
��Ѩ� ���������������, ������� ����� �����, ���������, ����������� ���
26
������������� ������, ��������� � �������������� ��� ���������� ����������
27
������������� ������������� ��������� (������� ������ ������, ��� ������,
28
������� ���������, ��� ������ �/��� ������ �������, ���������� ��-�� ��������
29
������� ��� �/��� ������ ��������� �������� ��������� � ������� �����������,
30
�� �� ������������� ����� ��������), �� �� ������������� ���, ���� ���� �����
31
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
33
Redistribution and use in source and binary forms, with or without modification,
34
are permitted provided that the following conditions are met:
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.
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.
57
/********** ��������� *******************************************************/
61
/* ������ : ������� �������� */
62
/* �������� : 08.06.00 */
63
/* ���� : 'Normalise.cpp' */
64
/* ���������� : ������������ ����� */
66
/*----------------------------------------------------------------------------*/
74
#include "rsglobaldata.h"
76
#include "mpumatime.h"
80
#include "line_vp_util.h"
81
#include "line_vp_2_am.h"
82
#include "markdataoper.h"
100
const int MIN_BIG_H=30;
101
const int MIN_BIG_W=30;
102
# define TYPE_BIG_COMP CPAGE_GetInternalType("TYPE_BIG_COMP")
106
Word8 ImageName[CPAGE_MAXNAME];
109
#define RSL_VERLINE CPAGE_GetInternalType("RVL_VERIFY")
110
extern Bool32 gbRSLT;
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;
121
extern Handle hContBigComp;
122
extern Handle hSearchLine;
123
extern Handle hDotLine;
124
extern Handle hCalcIncline;
125
extern Handle hVerOrNewLine;
127
extern Handle hKillLine;
128
extern Handle hPrep2;
129
extern Handle hKillLineAfter;
131
extern Handle hDebugAutoTemplate;
132
extern Handle hWndTurn;
133
extern Handle hDebugPrintResolution;
135
Bool32 AutoTemplate ( PRSPreProcessImage );
136
void checkResolution(Handle hCCOM, Handle hCPAGE);
137
////////////////////////////////////////////////////////////////////////////////
139
// (07.07.2000) ���������� ����� �� puma.dll ��� ���������
140
Bool32 Normalise( PRSPreProcessImage Image)
146
rc = PreProcessImage( Image );
148
LDPUMA_Skip(hDebugAutoTemplate);
151
// rc = AutoTemplate( Image );
152
// rc = RNORM_AutoTemplate( Image );
154
LDPUMA_Skip(hSearchLine);
157
rc = SearchLines( Image );
159
LDPUMA_Skip(hCalcIncline);
162
rc = CalcIncline( Image );
167
rc = OrtoMove( Image );
169
LDPUMA_Skip(hContBigComp);
172
rc= CreateContainerBigComp( Image );
174
LDPUMA_Skip(hVerOrNewLine);
178
// � �������� ����� ��������� ����� ��� �������. 02.07.2002 E.P..
179
Image->gnLanguage != LANG_TURKISH &&
181
LDPUMA_Skip(hDotLine) &&
182
LDPUMA_Skip(Image->hDebugCancelSearchDotLines)
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);*/
189
rc = SearchNewLines( Image );
191
LDPUMA_Skip(hKillLine);
195
rc = KillLinesN( Image );
197
LDPUMA_Skip(hKillLineAfter);
199
// ������� ������� ����� ����� �����
200
if ( rc && LDPUMA_Skip(Image->hDebugCancelRemoveLines))
201
// rc = //almi 28.11.00
208
/////////////////////////////////////////////////////////////////////////////////////////////////////
213
Bool32 VerifyN( PRSPreProcessImage Image )
217
rc = VerifyLines( Image );
222
Bool32 SearchNewLines( PRSPreProcessImage Image )
225
bool searchlines = LDPUMA_Skip(Image->hDebugCancelSearchDotLines) && !LDPUMA_Skip(hDotLine);
226
Handle hSaveImage = CPAGE_CreateBlock(Image->hCPAGE, RSL_VERLINE, 0, 0, Image, sizeof (RSPreProcessImage));
228
if(LDPUMA_Skip(Image->hDebugCancelVerifyLines))
230
ret=RLINE_LinesPass1(Image->hCPAGE,*(Image->phCCOM),Image->phCLINE,Image->pgneed_clean_line, searchlines, (Word8)Image->gnLanguage);
233
ret = RLINE_LinesPass2(*(Image->phCCOM),Image->phCLINE, Image->hCPAGE);
236
CPAGE_DeleteBlock(Image->hCPAGE, hSaveImage);
241
Bool32 CreateContainerBigComp( PRSPreProcessImage Image )
243
CCOM_handle hCCOM_old=(CCOM_handle)(*(Image->phCCOM));
244
Handle hCPage=Image->hCPAGE;
245
CCOM_handle hCCOM_new=0;
248
GetPageInfo(hCPage,&info);
251
for(i=0;i<CPAGE_MAXNAME;i++)
252
big_Image.ImageName[i]=info.szImageName[i];
254
hCCOM_new = CCOM_CreateContainer();
257
big_Image.hCCOM=NULL;
261
CCOM_comp* comp=NULL;
263
comp=CCOM_GetFirst(hCCOM_old,FALSE);
267
if( (comp->h>=MIN_BIG_H)&&(comp->w>=MIN_BIG_W) )
269
new_comp=CCOM_New(hCCOM_new,comp->upper,comp->left,comp->w,comp->h);
272
if(comp->size_linerep<0)
276
if(!CCOM_Copy(new_comp,comp) )
277
CCOM_Delete(hCCOM_new,comp);
281
comp=CCOM_GetNext(comp,FALSE);
284
big_Image.hCCOM=hCCOM_new;
286
CPAGE_CreateBlock(hCPage,TYPE_BIG_COMP,0,0,&big_Image,sizeof(BIG_IMAGE));
290
/////////////////////////////////////////////////////////////////////////////////////////////////////
292
Bool32 KillLinesN( PRSPreProcessImage Image )
296
rc = KillLines( Image );
300
////////////////////////////////////////////////////////////////////////////////
301
// ��������������� ���������
302
// (07.07.2000) ���������� ����� �� puma.dll ��� ���������
303
// ������ ��������� � ����
304
// � ������ ��������� ��������� ���������
305
Bool32 PreProcessImage( PRSPreProcessImage Image )
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
/////////////////////////////////
315
//char * lpRecogName = NULL;
323
if(!ProgressStep(1,5))
327
// ����������������� ��������� CPAGE
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; ��� �����������
343
PInfo.Incline2048 = 0;
347
SetPageInfo(hCPAGE,PInfo);
350
////////////////////////////////////////////////////////
351
// ������� ����������
353
if(!ProgressStep(2,65))
358
if(LDPUMA_Skip(Image->hDebugCancelComponent)/*DPumaSkipComponent()*/)
361
PRGTIME prev = StorePRGTIME(65, 85);
362
rc = ExtractComponents( gbAutoRotate, NULL, (PWord8)glpRecogName, Image);
363
RestorePRGTIME(prev);
364
/* if(rc && gbAutoRotate)
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 )
370
SetReturnCode_rstuff(RNORM_GetReturnCode());
376
if(ori && !(db_spec_prj==SPEC_PRJ_GIP&&ori==4))
383
dwTurn = RIMAGE_TURN_270;
387
dwTurn = RIMAGE_TURN_90;
391
dwTurn = RIMAGE_TURN_180;
395
if( LDPUMA_Skip(Image->hDebugCancelTurn) /*umaSkipTurn()*/ /*)
397
if(!RIMAGE_Turn((PWord8)glpRecogName,(PWord8)PUMA_IMAGE_TURN,dwTurn,0))
399
SetReturnCode_rstuff_rstuff(RIMAGE_GetReturnCode());
405
if(!CIMAGE_ReadDIB((PWord8)PUMA_IMAGE_TURN,(Handle*)gpRecogDIB,TRUE))
407
SetReturnCode_rstuff_rstuff(CIMAGE_GetReturnCode());
413
// ������ ����� ���������
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);
420
GetPageInfo(hCPAGE,&info);
421
info.Images|=IMAGE_TURN;
422
// strcpy((char*)info.szImageName,PUMA_IMAGE_TURN);
423
SetPageInfo(hCPAGE,info);
424
RestorePRGTIME(prev);
432
//�������� ������� ���������� � ���������� ���������� �� �����������, ���� ��� ���
433
checkResolution(*(Image->phCCOM), hCPAGE);
434
if(!ProgressStep(2,100))
439
LDPUMA_Console("�������� ���� ��������� ���������.\n");
442
// ������������������ ��������� CPAGE
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; ��� �����������
458
PInfo.Incline2048 = 0;
462
SetPageInfo(hCPAGE,PInfo);
470
//////////////////////////////////////////////////
471
////////////////////////////////////////////////////////////////////////////////
472
// ��������� ���������
473
Bool32 ExtractComponents( Bool32 bIsRotate, Handle * prev_ccom, PWord8 name, PRSPreProcessImage Image)
476
ExcControl exc = {0};
477
// RSGETMODULEPATH pGetModulePath;
478
// RSSETUPDATE pSetUpdate;
480
// if ( ProgressPoints.pGetModulePath && ProgressPoints.pSetUpdate)
482
// pGetModulePath = (RSGETMODULEPATH)ProgressPoints.pGetModulePath;
483
// pSetUpdate = (RSSETUPDATE)ProgressPoints.pSetUpdate;
492
*prev_ccom = *Image->phCCOM ? *Image->phCCOM: NULL;
497
CCOM_DeleteContainer((CCOM_handle)*Image->phCCOM);
501
if(!REXC_SetImportData(REXC_ProgressStep, (void*)rexcProgressStep))
503
SetReturnCode_rstuff(REXC_GetReturnCode());
507
// ����� ������������� ��������
508
//Andrey: ����������� �������� � ��������� ������ RRecCom
509
exc.Control = Ex_ExtraComp|/*Ex_EvnRecog|*/Ex_Picture;
510
//exc.Control |= Ex_NetRecog;
512
//Andrey: orientation is obtained from new library RNORM
513
//exc.Control |= ( bIsRotate ? Ex_Orient : 0 );
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());
526
Word8 w8 = (Word8)Image->gbDotMatrix;
527
REXC_SetImportData(REXC_Word8_Matrix,&w8);
529
w8 = (Word8)Image->gbFax100;
530
REXC_SetImportData(REXC_Word8_Fax1x2,&w8);
533
//exc.Control ^= Ex_EvnRecog;
535
if(rc && !REXCExtraDIB( exc, lpdata,0,0,0,0) ) // ����� ��������� � DIB-e
537
CIMAGEIMAGECALLBACK clbk;
538
if(rc && !CIMAGE_GetCallbackImage(name, &clbk))
540
SetReturnCode_rstuff(CIMAGE_GetReturnCode());
543
if( rc && !REXCExtracomp3CB(exc, // ����� ��������� by 3CallBacks
544
(TImageOpen)clbk.CIMAGE_ImageOpen,
545
(TImageClose)clbk.CIMAGE_ImageClose,
546
(TImageRead)clbk.CIMAGE_ImageRead)
549
SetReturnCode_rstuff(REXC_GetReturnCode());
555
*Image->phCCOM = (Handle)REXCGetContainer();
556
if(*Image->phCCOM==0)
558
SetReturnCode_rstuff(REXC_GetReturnCode());
562
RRecComControl rec_control;
563
memset(&rec_control, 0, sizeof(RRecComControl));
564
rec_control.flags = RECOG_EVN;
566
if (!RRECCOM_Recog(*(Image->phCCOM), rec_control, GetModulePath(), (Word8)Image->gnLanguage))
568
SetReturnCode_rstuff(RRECCOM_GetReturnCode());
573
SetUpdate(FLG_UPDATE_NO,FLG_UPDATE_CCOM);
576
//////////////////////////////////////////////////////////////////////////////////
578
Bool32 SearchLines ( PRSPreProcessImage Image )
582
if(LDPUMA_Skip(Image->hDebugCancelSearchLines))
584
Bool32 b32 = !Image->gbDotMatrix;
585
RLINE_SetImportData(RLINE_Bool32_NOFILLGAP3,&b32);
587
RLINE_SetImportData(RLINE_Bool32_NOHBORDER,&b32);
588
RLINE_SetImportData(RLINE_Bool32_NOVBORDER,&b32);
590
if(!RLINE_SearchLines(Image->hCPAGE,Image->phCLINE))
592
//SetReturnCode_rstuff(RLINE_GetReturnCode());
594
*Image->pgrc_line = FALSE;
595
LDPUMA_Console("��������������: RLINE(0x%X) %s\n",RLINE_GetReturnCode(),RLINE_GetReturnString(RLINE_GetReturnCode()));
599
LDPUMA_Console("�������� ���� ������ �����.\n");
603
//////////////////////////////////////////////////////////////////////////////////
604
Bool32 VerifyLines ( PRSPreProcessImage Image )
608
#ifdef _USE_RVERLINE_
609
if( *Image->pgrc_line )
611
if(LDPUMA_Skip(Image->hDebugCancelVerifyLines))
613
Regime_VerifyLines val = Image->gnTables ? RVL_FutuTablCorr:RVL_Default;
615
if( !RVERLINE_SetImportData(RVERLINE_DTRVERLINE_RegimeOfVerifyLines,&val)||
616
!RVERLINE_MarkLines(*Image->phCCOM, Image->hCPAGE))
618
SetReturnCode_rstuff(RVERLINE_GetReturnCode());
623
Bool32 BadScan = FALSE;
625
// RVERLINE_AboutLines(Image->hCPAGE,*Image->phCCOM, Image->pgneed_clean_line, &BadScan, &ScanQual); }
626
AboutLines(Image, &BadScan, &ScanQual);
629
if(!*Image->pgneed_clean_line)
630
LDPUMA_Console("��������������: RSTUFF �������, ��� ������� ����� �� ����.\n");
633
LDPUMA_Console("�������� ���� ������ �����.\n");
634
//// if(LDPUMA_Skip(hDebugCancelVerifyLines))
636
//// Regime_VerifyLines val = gnTables ? RVL_FutuTablCorr:RVL_Default;
638
//// if( !RLTABLE_SetImportData(RLTABLE_DTRLTABLE_RegimeOfVerifyLines,&val)||
639
//// !RLTABLE_MarkLines(hCCOM, hCPAGE))
641
//// SetReturnCode_rstuff(RLTABLE_GetReturnCode());
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");
653
//// LDPUMA_Console("�������� ���� ������ �����.\n");
655
#endif //_USE_RVERLINE_
660
////////////////////////////////////////////////////////////////////////////////////////////////////////
662
/*Bool32 ShortVerticalLinesProcess ( PRSPreProcessImage Image, Word32 Step )
669
if ( Step == RS_SVL_FIRST_STEP )
672
//gLTInfo->Hor.Lns = (LineInfo *)RSTUFFAlloc(sizeof(LineInfo) * RStuffMaxNumLines * 2);
673
gLinesData.VLinefBufferA = gLTInfo->Ver.Lns = (LineInfo *)RSTUFFAlloc(sizeof(LineInfo) * RStuffMaxNumLines * 2);
675
if (gLTInfo->Ver.Lns != NULL )
679
bRet = ReadSVLFromPageContainer( Image, (void *)gLTInfo );
683
if ( Step == RS_SVL_SECOND_STEP )
685
LinesTotalInfo LTInfo = {0};
687
//LTInfo.Hor.Lns = (LineInfo *)RSTUFFAlloc(sizeof(LineInfo) * RStuffMaxNumLines * 2);
688
gLinesData.VLinefBufferB = LTInfo.Ver.Lns = (LineInfo *)RSTUFFAlloc(sizeof(LineInfo) * RStuffMaxNumLines * 2);
690
if (LTInfo.Ver.Lns != NULL )
694
bRet = ReadSVLFromPageContainer( Image, (void *)<Info );
696
//RSTUFFFree ( LTInfo.Hor.Lns );
697
RSTUFFFree ( gLinesData.VLinefBufferA );
698
//RSTUFFFree ( gLTInfo->Hor.Lns );
699
RSTUFFFree ( gLinesData.VLinefBufferB );
705
////////////////////////////////////////////////////////////////////////////////////////////////////////
707
/*Bool32 ReadSVLFromPageContainer ( PRSPreProcessImage Image, void * pInf )
711
LinesTotalInfo *LTInfo = (LinesTotalInfo *) pInf;
712
LineInfo *pLHor, *pLVer;
715
Handle hBlockLineHor;
716
Handle hBlockLineVer;
717
Handle hBlockLinePrev;
722
nTagSize = sizeof (LinesTotalInfo);
723
pLHor = LTInfo->Hor.Lns;
724
pLVer = LTInfo->Ver.Lns;
726
hBlockLine = CPAGE_GetBlockFirst (Image->hCPAGE, RLINE_BLOCK_TYPE);
729
//sprintf (pStr, "����� �� ����������.");
734
wErr32 = CPAGE_GetReturnCode ();
738
//Error_CPage ("[GetBlockFirst]");
741
//�����.... ��� �����?
744
nReal = CPAGE_GetBlockData (Image->hCPAGE, hBlockLine, RLINE_BLOCK_TYPE, (void *)LTInfo, nTagSize);
746
wErr32 = CPAGE_GetReturnCode ();
749
if ((nReal!=nTagSize)||(wErr32!=0))
751
//Error_CPage ("[GetBlockData]");
754
if (LTInfo->Hor.Cnt + LTInfo->Ver.Cnt >= RStuffMaxNumLines)
756
//sprintf (pStr, "�� ������� ������ ��� %d �����!", LTInfo.Hor.Cnt + LTInfo.Ver.Cnt);
760
if ((LTInfo->Hor.Cnt==0)&&(LTInfo->Ver.Cnt==0))
762
//sprintf (pStr, "����� ����������, �� �� ����� �� ��������.");
766
// �������������� �����
767
if ( bRet && pLHor != NULL )
769
for (Int32 i=0; i<LTInfo->Hor.Cnt; i++)
772
hBlockLineHor = CPAGE_GetBlockFirst (Image->hCPAGE, (Word32)(LTInfo->Hor.Lns));
774
hBlockLineHor = CPAGE_GetBlockNext (Image->hCPAGE, hBlockLinePrev, (Word32)(LTInfo->Hor.Lns));
775
wErr32 = CPAGE_GetReturnCode ();
779
//Error_CPage ("[GetBlockFirst]");
781
//Error_CPage ("[GetBlockNext]");
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))
790
//Error_CPage ("[GetBlockData]");
794
hBlockLinePrev = hBlockLineHor;
797
// ������������ �����
798
if ( bRet && pLVer != NULL )
800
for (Int32 i=0; i<LTInfo->Ver.Cnt; i++)
803
hBlockLineVer = CPAGE_GetBlockFirst (Image->hCPAGE, (Word32)(LTInfo->Ver.Lns));
805
hBlockLineVer = CPAGE_GetBlockNext (Image->hCPAGE, hBlockLinePrev, (Word32)(LTInfo->Ver.Lns));
806
wErr32 = CPAGE_GetReturnCode ();
810
//Error_CPage ("[GetBlockFirst]");
812
//Error_CPage ("[GetBlockNext]");
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))
821
//Error_CPage ("[GetBlockData]");
825
hBlockLinePrev = hBlockLineVer;
829
//*pHoriType = (Word32)LTInfo.Hor.Lns;
830
//*pVertType = (Word32)LTInfo.Ver.Lns;
831
//LTInfo->Hor.Lns = pLHor;
832
//LTInfo->Ver.Lns = pLVer;
837
/////////////////////////////////////////////////////////////////////////////////////////////////////
839
Bool32 KillLines(PRSPreProcessImage Image)
843
if(!ProgressStepLines(1/*,GetResourceString(IDS_REMOVELINE)*/,30))
846
if( rc && *Image->pgrc_line && *Image->pgneed_clean_line)
848
if(LDPUMA_Skip(Image->hDebugCancelRemoveLines) )
851
PRGTIME prev = StorePRGTIME(30, 40);
853
rc = RemoveLines(Image, &pDIB);
857
*Image->pgpRecogDIB = pDIB;
858
LDPUMA_CreateWindow(NAME_IMAGE_DELLINE,*Image->pgpRecogDIB);
860
RestorePRGTIME(prev);
863
LDPUMA_Console("�������� ���� ������ �����.\n");
868
/////////////////////////////////////////////////////////////////////////////////////////////////////
870
Bool32 RemoveLines(PRSPreProcessImage Image, PWord8 * lppDIB)
872
Handle hccom = *Image->phCCOM;
873
Handle hcpage = Image->hCPAGE;
874
Handle *hLinesCCOM = Image->phLinesCCOM;
879
CCOM_comp *victim[100];
881
Bool32 yes_victim = FALSE;
885
if(!LDPUMA_Skip(ObvKillLines)||(LDPUMA_Skip(hNewLine)&&LDPUMA_Skip(Image->hDebugCancelVerifyLines)))
886
rc=DeleteLines(hcpage,Image->phCLINE,PUMA_IMAGE_DELLINE);
889
if(rc && !RLINE_DeleteLines(hcpage,PUMA_IMAGE_DELLINE))
891
SetReturnCode_rstuff(RLINE_GetReturnCode());
894
if (rc && LDPUMA_Skip(NotKillPointed) && LDPUMA_Skip(Image->hDebugCancelSearchDotLines))
895
rc = DeleteDotLines(Image->phCLINE, PUMA_IMAGE_DELLINE);
900
// ������� ����������� � ���������� �������
902
if(rc && !CIMAGE_ReadDIB((PWord8)PUMA_IMAGE_DELLINE,(Handle*)&hDIB,TRUE))
904
SetReturnCode_rstuff(CIMAGE_GetReturnCode());
910
// ������ ���������� � ������� �� ������.
912
*lppDIB = (PWord8)hDIB;
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 )
923
CCOM_DeleteContainer((CCOM_handle)*Image->phCCOM);
927
if(!ExtractComponents(FALSE, hLinesCCOM, (PWord8)PUMA_IMAGE_DELLINE, Image))
934
GetPageInfo(Image->hCPAGE,&inf);
935
strcpy((char*)inf.szImageName,PUMA_IMAGE_DELLINE);
936
inf.Images|=IMAGE_DELLINE;
937
SetPageInfo(Image->hCPAGE,inf);
943
*Image->phCCOM = (Handle)REXCGetContainer();
944
if(*Image->phCCOM == 0)
946
SetReturnCode_rstuff(REXC_GetReturnCode());
949
hccom = *Image->phCCOM;
955
CCOM_comp *exa=CCOM_GetFirst((CCOM_handle)*hLinesCCOM,NULL);
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);
972
if(!LDPUMA_Skip(hShowCheckLetters))
974
LDPUMA_Console("Puma_������� ����� \n");
975
LDPUMA_WaitUserInput(NULL, NULL);
976
LDPUMA_DeleteRects(NULL, key);
982
if( remove_overlayed(exa,(CCOM_handle)*Image->phCCOM) )
984
CCOM_comp *dup=CCOM_New((CCOM_handle)*Image->phCCOM,exa->upper,exa->left,exa->w,exa->h);
989
exa->linerep, exa->nl,
990
exa->begs, exa->ends,
992
dup->scale= exa->scale;
993
dup->type = exa->type;
999
CCOM_DeleteContainer((CCOM_handle)*hLinesCCOM);
1003
LDPUMA_Console("�������� ���� ��������� ��������� ����� �������� �����.\n");
1008
/////////////////////////////////////////////////////////////////////////////////////////////////////
1010
Bool32 MyGetZher (void **vvZher, Int32 *nZher, Int32 MaxZher, Handle hCPage)
1012
Word32 err32, nTeor, nReal;
1016
nTeor = sizeof (void *);
1021
hBlockZher = CPAGE_GetBlockFirst (hCPage, RVERLINE_ZHERTVY_LINIY);
1023
hBlockZher = CPAGE_GetBlockNext (hCPage, hBlockPrev, RVERLINE_ZHERTVY_LINIY);
1024
err32 = CPAGE_GetReturnCode ();
1028
// Error_CPage ("[GetBlockFirst]");
1030
// Error_CPage ("[GetBlockNext]");
1037
nReal = CPAGE_GetBlockData (hCPage, hBlockZher, RVERLINE_ZHERTVY_LINIY, (void *)&(vvZher[i]), nTeor);
1038
err32 = CPAGE_GetReturnCode ();
1039
if (!nReal||(err32!=0))
1041
//Error_CPage ("[SetBlockData]");
1044
hBlockPrev = hBlockZher;
1050
/////////////////////////////////////////////////////////////////////////////////////////////////////
1052
Bool32 remove_overlayed(CCOM_comp *sour,CCOM_handle haCCOM)
1054
CCOM_comp *cur=CCOM_GetFirst(haCCOM,NULL), *curn;
1059
curn=CCOM_GetNext(cur,NULL);
1060
if( cur->upper<sour->upper && sour->upper-cur->upper>10*sour->h)
1065
if( comp_over(sour,cur) )
1067
CCOM_Delete(haCCOM,cur);
1070
if( cur->upper-sour->upper>10*sour->h)
1071
break; // downer zone
1073
}while( cur!=NULL );
1077
/////////////////////////////////////////////////////////////////////////////////////////////////////
1079
Bool32 comp_over(CCOM_comp *sour,CCOM_comp *cur)
1081
Int32 le,ri,up,dn,w,h;
1083
if( sour->left+sour->w<=cur->left || cur->left+cur->w<=sour->left )
1085
if( sour->upper+sour->h<=cur->upper || cur->upper+cur->h<=sour->upper )
1088
if( sour->left<cur->left )
1093
if( sour->left+sour->w<cur->left+cur->w )
1094
ri = sour->left+sour->w;
1096
ri = cur->left+cur->w;
1098
if( sour->upper<cur->upper )
1103
if( sour->upper+sour->h<cur->upper+cur->h )
1104
dn = cur->upper+cur->h;
1106
dn = sour->upper+sour->h;
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 )
1114
/////////////////////////////////////////////////////////////////////////////////////////////////////
1117
Bool32 SearchTables( PRSPreProcessImage Image)
1121
if(!ProgressStepTables(1,20))
1123
if( rc && Image->gnTables != PUMA_TABLE_NONE )
1125
if(LDPUMA_Skip(Image->hDebugCancelSearchTables))
1127
if (!RLTABLE_SetImportData(RLTABLE_DTRLTABLE_WhereMustSearchTable, NULL))
1129
SetReturnCode_rstuff(RLTABLE_GetReturnCode());
1135
//// ������������� ������ ������
1136
HowToSearch = SST_Default;
1137
if(!RLTABLE_SetImportData(RLTABLE_DTRLTABLE_StyleOfSearchTable, (void *)(&HowToSearch)))
1139
SetReturnCode_rstuff(RLTABLE_GetReturnCode());
1144
if(!RLTABLE_SearchTable(*Image->phCCOM,Image->hCPAGE, TRUE, Image->pgnNumberTables))
1146
SetReturnCode_rstuff(RLTABLE_GetReturnCode());
1153
LDPUMA_Console("�������� ���� ������ ������.\n");
1159
/////////////////////////////////////////////////////////////////////////////////////////////////////
1161
//Bool32 AboutLines(PRSPreProcessImage Image, Bool32 *BadScan, Int32 *ScanQual)
1165
/////////////////////////////////////////////////////////////////////////////////////////////////////
1167
Bool32 CalcIncline(PRSPreProcessImage Image)
1169
int SizeWork,SizeMain;
1171
Bool ret, WasLine, ManyComp;
1172
Bool CalcMuchSkew, TalkMuchSkew;
1174
Int32 SkewReg, Skew, SkewLocVerLin;
1176
PAGEINFO info = {0};
1177
UN_BUFF MainBuff = {0};
1180
Handle hCPage=Image->hCPAGE;
1181
CLINE_handle hCLINE=*((CLINE_handle*)Image->phCLINE);
1183
GetPageInfo(hCPage,&info);
1185
/* 2. �������������. */
1186
/*** ���������� ***/
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);
1196
// if(!LDPUMA_Skip(hUseCLine))
1197
ret=LoadLinesVP_rv(hCLINE,UN_LD_LinesVP2,&MainBuff,Str,&Code);
1199
// ret = LoadLinesVP_rv (hCPage, UN_LD_LinesVP, (void *)(&MainBuff), Str, &Code);
1200
if ((ret!=RV_TRUE)&&(ret!=RV_EMPTY))
1202
SetReturnCode_rstuff (Code);
1205
WasLine = (ret==RV_TRUE);
1206
/*** ���������� ***/
1207
ret = LoadComps_rv (*(Image->phCCOM), (void *)(&MainBuff), Str, 0); //t-e-d
1210
SetReturnCode_rstuff (Code);
1211
CleanLastDataPart ((void *)(&MainBuff));
1213
ManyComp = (ret==RV_TRUE)&&(MainBuff.nPartUnits[MainBuff.nPart-1]>10000);
1216
CleanLastDataPart ((void *)(&MainBuff));
1218
if (ret==RV_DOUBT||ManyComp)
1220
ret = LoadComps_rv (*(Image->phCCOM), (void *)(&MainBuff), Str, 3); //t-e-d
1223
SetReturnCode_rstuff (Code);
1224
CleanLastDataPart ((void *)(&MainBuff));
1233
RcReg.right=(Int16)info.Width;
1235
RcReg.bottom=(Int16)info.Height;
1239
CalcMuchSkew = (!LDPUMA_Skip(hCalcMuchSkew));
1240
TalkMuchSkew = (!LDPUMA_Skip(hTalkMuchSkew));
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);
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
1251
SetReturnCode_rstuff (Code);
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);
1262
info.Incline2048 = Skew*2;
1263
info.SkewLocVerLin2048 = SkewLocVerLin*2;
1264
if(!CPAGE_SetPageData(Image->hCPAGE,PT_PAGEINFO,&info,sizeof(PAGEINFO)))
1266
SetReturnCode_rstuff(CPAGE_GetReturnCode());
1272
////////////////////////////////////////////////////////////////////////////////////////////////////
1273
void checkResolution(Handle hCCOM, Handle hCPAGE)
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;
1281
if (!GetPageInfo(hCPAGE, &page_info)) return;
1283
if (page_info.DPIX > min_res && page_info.DPIY > min_res) return;
1285
for (i=0; i<100; i++) Masx[i] = Masy[i] = 0;
1287
pcomp = CCOM_GetFirst(hCCOM, NULL);
1291
if (pcomp->h > 9 && pcomp->h < 100) Masy[pcomp->h]++;
1293
if (pcomp->w > 9 && pcomp->w < 100) Masx[pcomp->w]++;
1295
pcomp = CCOM_GetNext(pcomp, NULL);
1298
for (i=11; i < 99; i++)
1300
M_t = Masy[i-1] + Masy[i] + Masy[i+1];
1308
M_t = Masx[i-1] + Masx[i] + Masx[i+1];
1317
if (Jy_m > 10 && My_m > 100 && !(page_info.DPIY*22 < 2*300*Jy_m && 2*page_info.DPIY*22 > 300*Jy_m))
1319
page_info.DPIY = (300*Jy_m+11)/22;
1323
if (Jx_m > 10 && Mx_m > 100 && !(page_info.DPIX*22 < 2*300*Jx_m && 2*page_info.DPIX*22 > 300*Jx_m))
1325
page_info.DPIX = (300*Jx_m+11)/22;
1331
SetPageInfo(hCPAGE, page_info);
1333
if (!LDPUMA_Skip(hDebugPrintResolution))
1334
LDPUMA_ConsoleN("����� ����������: DPIX=%d, DPIY=%d", page_info.DPIX, page_info.DPIY);
1337
////////////////////////////////////////////////////////////////////////////////////////////////////