2
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
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
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
33
Redistribution and use in source and binary forms, with or without modification,
34
34
are permitted provided that the following conditions are met:
82
81
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
85
extern INT up_position,dw_position;
86
BYTE MemForCutPoints[65536];
87
BYTE MemForCutPointsTwo[65536];
89
extern BYTE db_status; // snap presence byte
84
extern int16_t up_position,dw_position;
85
uchar MemForCutPoints[65536];
86
uchar MemForCutPointsTwo[65536];
87
uchar ForRaster3[R_S];
88
extern uchar db_status; // snap presence byte
90
89
void snap_clear_screen(void);
93
static INT GDE_KAK[13][3] = {{1,0,0} ,{4,0,0} ,{8,0,0} ,
92
static int16_t GDE_KAK[13][3] = {{1,0,0} ,{4,0,0} ,{8,0,0} ,
94
93
{1,8,0} ,{8,1,0} ,{8,8,0},
95
94
{1,8,8},{8,8,1},{8,1,8},{8,8,8},
96
95
{4,8,8},{8,4,8},{8,8,4}};
98
INT Alik_define_cut_points(
97
int16_t Alik_define_cut_points(
100
99
struct own_cut *ans,
101
INT dx, /* ࠡ��� �ਭ� ���� */
102
INT dy, /* ࠡ��� ���� ���� */
100
int16_t dx, /* ࠡ��� �ਭ� ���� */
101
int16_t dy, /* ࠡ��� ���� ���� */
107
INT hor_byte,ver_byte,nshort,CP,i,j,bl_up,bl_dw,tret_h;
108
PINT penalty,cut_points,adr_cut_points,my_penalty;
109
PCHAR adrw,adrw_two,product,product_two,trace,adr_raster,stek,adr_ras_two,
106
int16_t hor_byte,ver_byte,nshort,CP,i,j,bl_up,bl_dw,tret_h;
107
pint16_t penalty,cut_points,adr_cut_points,my_penalty;
108
pchar adrw,adrw_two,product,product_two,trace,adr_raster,stek,adr_ras_two,
111
PBYTE IntBuf,CountCut,UpBlackPoint;
110
puchar IntBuf,CountCut,UpBlackPoint;
112
111
struct own_cut *ans_ptr;
114
CHAR snap[380],*buf=snap;
113
char snap[380],*buf=snap;
120
adr_cut_points=(PINT)ForRaster3;
119
adr_cut_points=(pint16_t)ForRaster3;
122
121
hor_byte=(dx+7)>>3;
123
122
ver_byte=(dy+7)>>3;
126
125
tret_h = (dy<<1)/3;
128
adr_raster=(PCHAR)MemForCutPoints; /* ��� ��室�� �࠭ᯮ������ ���� */
129
adrw=adr_raster+CP; /* ��� ��ࠡ�⠭�� �࠭ᯮ������ ���� */
130
trace=adrw+(CP>i?CP:i); /* ��� ��室 */
131
penalty=(PINT)trace+dx; /* ��� ����� */
132
product=(PCHAR)(penalty+dx); /* ��� �ந�������� ������⥫��� �⮫�殢 */
133
cut_points=(PINT)(product+dx); /* ��� �窨 ࠧ१���� */
127
adr_raster=(pchar)MemForCutPoints; /* ��� ��室�� �࠭ᯮ������ ���� */
128
adrw=adr_raster+CP; /* ��� ��ࠡ�⠭�� �࠭ᯮ������ ���� */
129
trace=adrw+(CP>i?CP:i); /* ��� ��室 */
130
penalty=(pint16_t)trace+dx; /* ��� ����� */
131
product=(pchar)(penalty+dx); /* ��� �ந�������� ������⥫��� �⮫�殢 */
132
cut_points=(pint16_t)(product+dx); /* ��� �窨 ࠧ१���� */
135
adrw_two=(PCHAR)MemForCutPointsTwo;
134
adrw_two=(pchar)MemForCutPointsTwo;
136
135
adr_ras_two = adrw_two+(CP>i?CP:i);
137
product_two = adr_ras_two+(CP>i?CP:i); /* ��� �ந�������� ������⥫��� �⮫�殢 �� � �ࠢ�*/
138
UpBlackPoint= (PBYTE)(product_two+dx);
139
CountCut = (PBYTE)(UpBlackPoint+dx);
140
SourceRaster= (PCHAR)(CountCut+dx);
141
my_penalty = (PINT)(SourceRaster+(CP>i?CP:i));
142
IntBuf = (PBYTE)(my_penalty+dx);
136
product_two = adr_ras_two+(CP>i?CP:i); /* ��� �ந�������� ������⥫��� �⮫�殢 �� � �ࠢ�*/
137
UpBlackPoint= (puchar)(product_two+dx);
138
CountCut = (puchar)(UpBlackPoint+dx);
139
SourceRaster= (pchar)(CountCut+dx);
140
my_penalty = (pint16_t)(SourceRaster+(CP>i?CP:i));
141
IntBuf = (puchar)(my_penalty+dx);
144
CP = (dx<3||dy<3)? 0 : 1; /* १��� �� �㤥�, � ���� ��� �� ������ �� ���ࠢ����� */
143
CP = (dx<3||dy<3)? 0 : 1; /* १��� �� �㤥�, � ���� ��� �� ������ �� ���ࠢ����� */
148
147
memcpy(SourceRaster,raster_frag,hor_byte*dy);
149
memset((PBYTE)adr_cut_points,0,R_S);
148
memset((puchar)adr_cut_points,0,R_S);
150
149
memset(CountCut,0,dx);
152
Alik_tr_bit_matr(ver_byte,dy,raster_frag,adr_raster,hor_byte,dx); /* �࠭ᯮ������ ��室���� ���� */
153
memset((PINT)trace,0,sizeof(INT)*dx); /* ���㫥��� ���� ���⮢�� ���ᨢ�� */
154
memset(penalty,0,sizeof(INT)*dx); /* ���㫥��� ���ᨢ� ���䮢 */
155
CP=Alik_del_detail(raster_frag,dx,(INT)(dy*hor_byte),penalty);
151
Alik_tr_bit_matr(ver_byte,dy,raster_frag,adr_raster,hor_byte,dx); /* �࠭ᯮ������ ��室���� ���� */
152
memset((pint16_t)trace,0,sizeof(int16_t)*dx); /* ���㫥��� ���� ���⮢�� ���ᨢ�� */
153
memset(penalty,0,sizeof(int16_t)*dx); /* ���㫥��� ���ᨢ� ���䮢 */
154
CP=Alik_del_detail(raster_frag,dx,(int16_t)(dy*hor_byte),penalty);
156
155
if(!CP && dx>20 && dx<=128) CP=1; //10-09-96 03:24pm Alik cten33.tif
157
if(!CP) /* ���� �ᯠ��� */
156
if(!CP) /* ���� �ᯠ��� */
159
memset(penalty,0,sizeof(INT)*dx); /* ���㫥��� ���ᨢ� ���䮢 */
158
memset(penalty,0,sizeof(int16_t)*dx); /* ���㫥��� ���ᨢ� ���䮢 */
160
159
memcpy(adr_raster,adrw,ver_byte*dx);
163
Alik_tr_bit_matr(ver_byte,dy,raster_frag,adrw,hor_byte,dx); /* �࠭ᯮ������ ��⮢�� ������ */
162
Alik_tr_bit_matr(ver_byte,dy,raster_frag,adrw,hor_byte,dx); /* �࠭ᯮ������ ��⮢�� ������ */
165
164
if(CP) CP=Alik_search_bound_point_in_raster(adrw,ver_byte,dx);
167
if(CP) /* ���� ������ */
166
if(CP) /* ���� ������ */
169
168
Alik_form_bound(adrw,dx,dy,ver_byte,trace,0);
170
169
memcpy(adr_ras_two,adrw,ver_byte*dx);
171
170
memcpy(adrw_two,adrw,ver_byte*dx);
172
memcpy(my_penalty,penalty,sizeof(INT)*dx);
171
memcpy(my_penalty,penalty,sizeof(int16_t)*dx);
174
173
Alik_CountCut(adrw,dy,dx,CountCut,IntBuf);
175
174
Alik_UpBlackPoint(adrw,dy,dx,UpBlackPoint);
176
175
Alik_cut_short(adrw,adrw_two,dx,ver_byte,product,penalty,cut_points,product_two);
177
176
nshort=*cut_points;
178
177
Alik_cut_hole(trace,dx,cut_points,nshort,dy,product,penalty,0x00);
179
Alik_del_equal_hole(cut_points,product,(PINT)penalty,dx,dy,nshort);
178
Alik_del_equal_hole(cut_points,product,(pint16_t)penalty,dx,dy,nshort);
182
181
if( db_status && snap_activity('j') && snap_activity('a'))
184
183
product,product_two,penalty);
186
185
if(language==LANG_RUSSIAN)
187
Alik_find_brus(raster_frag,SourceRaster,adr_ras_two,(INT)(bl_dw-bl_up),dy,dx,
186
Alik_find_brus(raster_frag,SourceRaster,adr_ras_two,(int16_t)(bl_dw-bl_up),dy,dx,
188
187
product,product_two,penalty,cut_points,CountCut,
192
191
buf+=sprintf(buf,"bl_up=%2d,bl_dw=%2d ",bl_up,bl_dw);
194
Alik_my_correct_base_lines(&bl_up,&bl_dw,dy,dx,row,(PBYTE)adr_ras_two,
193
Alik_my_correct_base_lines(&bl_up,&bl_dw,dy,dx,row,(puchar)adr_ras_two,
195
194
(PWORD)penalty,IntBuf);
197
196
buf+=sprintf(buf,"bl_up=%2d,bl_dw=%2d ",bl_up,bl_dw);
211
210
if(bl_up>=0 && bl_dw<=dy)
213
212
Alik_double_serif(cut_points,trace,product,dx,dy,bl_up,bl_dw,penalty,
214
(PBYTE)adr_ras_two,IntBuf);
215
Alik_cut_d(trace+dx,cut_points,product,dx,dy,bl_up,bl_dw,(PCHAR)penalty);
213
(puchar)adr_ras_two,IntBuf);
214
Alik_cut_d(trace+dx,cut_points,product,dx,dy,bl_up,bl_dw,(pchar)penalty);
216
215
Alik_defis(trace,cut_points,dx,dy,bl_up,bl_dw,penalty);
217
216
if(language==LANG_ENGLISH)
218
217
Alik_cut_l(cut_points,trace,dx,bl_dw,penalty);
228
227
Alik_del_equal(cut_points);
229
228
Alik_del_3_cut(adrw,cut_points,nshort,ver_byte,dx,CountCut);
230
229
if(abs((row+dy)-(minrow+bbs3))>3)
231
Alik_del_p_cut(adrw,cut_points,dx,dy,nshort,(CHAR)(bl_dw-bl_up-3));
230
Alik_del_p_cut(adrw,cut_points,dx,dy,nshort,(char)(bl_dw-bl_up-3));
232
231
if(language==LANG_RUSSIAN)
233
232
Alik_Check_Rus_D(raster_frag,SourceRaster,dy,dx,cut_points,IntBuf,row,
234
233
product,product_two,penalty,CountCut);
250
Alik_cor_pnt((PINT)adr_cut_points,penalty,cut_points,CP,dx,dy,ver_byte,(PCHAR)adrw,(PCHAR)trace);
249
Alik_cor_pnt((pint16_t)adr_cut_points,penalty,cut_points,CP,dx,dy,ver_byte,(pchar)adrw,(pchar)trace);
251
250
Alik_form_bound(adr_raster,dx,dy,ver_byte,trace,1);
252
stek=(PCHAR)(penalty+((CP+1)<<2)-(CP+1)); /* ��९��뢠�� �ࠣ����� ����� ��室� */
251
stek=(pchar)(penalty+((CP+1)<<2)-(CP+1)); /* ��९��뢠�� �ࠣ����� ����� ��室� */
253
252
cut_points=penalty+3*(CP-1)+1;
254
253
for (j=CP; j>0; j--, cut_points-=4,stek++)
256
*stek=(CHAR)*cut_points++;
255
*stek=(char)*cut_points++;
257
256
if (*stek) (*stek)--;
258
257
*++stek=dy-*cut_points;
259
258
if (*stek) (*stek)--;
261
trace=(PCHAR)(penalty+((CP+1)<<2)-(CP+1));
260
trace=(pchar)(penalty+((CP+1)<<2)-(CP+1));
263
262
for(j=CP-1,i=0; j>=0; j--,i+=2)
265
ans_ptr->x = (CHAR)*((PINT)adr_cut_points+j);
264
ans_ptr->x = (char)*((pint16_t)adr_cut_points+j);
266
265
ans_ptr->h = dy - *(trace+i);
267
266
ans_ptr->dh = dy+1 - *(trace+i+1)-*(trace+i);
268
ans_ptr->dh = (CHAR)MIN(ans_ptr->dh,dy);
267
ans_ptr->dh = (char)MIN(ans_ptr->dh,dy);
269
268
ans_ptr->dh = MIN(ans_ptr->dh,ans_ptr->h);
270
269
if (ans_ptr->dh < tret_h) ans_ptr->var=1;
271
270
else ans_ptr->var=8;
287
void Alik_new_points(INT *CP,struct own_cut *a,struct own_cut *ptr,INT dy,
288
INT dx,PINT pen,PCHAR prod)
286
void Alik_new_points(int16_t *CP,struct own_cut *a,struct own_cut *ptr,int16_t dy,
287
int16_t dx,pint16_t pen,pchar prod)
290
INT i,j,count,min_pen,min_prod,real_x,Ix,IIx;
289
int16_t i,j,count,min_pen,min_prod,real_x,Ix,IIx;
293
292
for(i=0; i<count; i++)
433
432
switch(CountGrupElem)
435
/******************** ���� �窠*******************************/
434
/******************** ���� �窠*******************************/
437
436
/* {1,0,0} ,{4,0,0} ,{8,0,0} */
438
437
/**************************************************************/
439
case 0: /* ���� �窠 */
438
case 0: /* ���� �窠 */
440
439
if(ans->dh < min_dh+3) return 0;
441
440
if(ans->dh <= two_min_dh) return 1;
443
/******************** ��� �窨 *******************************/
442
/******************** ��� �窨 *******************************/
445
444
/* {1,8,0} ,{8,1,0} ,{8,8,0} */
446
445
/**************************************************************/
449
448
if(ans->dh<min_dh+3 || (ans+1)->dh<min_dh+3 )
451
450
if(ans->dh<(min_dh+3) && ans->dh<(ans+1)->dh) return 3;
455
/* ������� ��� ���⪨� ���������� */
454
/* ������� ��� ���⪨� ���������� */
456
455
if((ans->dh<=min_dh || (ans+1)->dh<=min_dh) &&
457
456
end[0]<tret_h && end[1] <tret_h)
521
/*� �।��� �� ���⪨� ���������� � ���ꥬ��*/
520
/*� �।��� �� ���⪨� ���������� � ���ꥬ��*/
522
521
if(ans->dh<chetvert_h && (ans+1)->dh<chetvert_h && (ans+2)->dh<chetvert_h &&
523
522
begin[0]>=tret_h && begin[1]>=tret_h && begin[2]>=tret_h &&
524
523
end[0]<=dve_tret_h && end[1]<=dve_tret_h && end[2]<=dve_tret_h &&
525
524
ans->h<(ans+1)->h && (ans+1)->h < (ans+2)->h)
528
/*� �।��� �� �������*/
527
/*� �।��� �� �������*/
529
528
if(ans->dh>=tret_h && (ans+1)->dh>=tret_h && (ans+2)->dh>=tret_h &&
530
529
begin[0]>=chetvert_h && begin[1]>=chetvert_h && begin[2]>=chetvert_h &&
531
530
ans->h >=chetvert_h && (ans+1)->h>=chetvert_h && (ans+2)->h>=chetvert_h)
534
/*�� �ᥩ ���� �� �������*/
533
/*�� �ᥩ ���� �� �������*/
535
534
if(abs(ans->dh-height)<4 && abs((ans+1)->dh-height)<4 &&
536
535
abs((ans+2)->dh-height)<4)
539
/*����� �� ���⪨� ����������*/
538
/*����� �� ���⪨� ����������*/
540
539
if(ans->h<=chetvert_h && (ans+1)->h<=chetvert_h && (ans+2)->h<=chetvert_h)
542
541
max_h=MAX(MAX(ans->h,(ans+1)->h),MAX((ans+1)->h,(ans+2)->h));