~ubuntu-branches/ubuntu/trusty/cuneiform/trusty

« back to all changes in this revision

Viewing changes to cuneiform_src/Kern/exc/src/extrcomp.c

  • Committer: Bazaar Package Importer
  • Author(s): Jakub Wilk, c-assert.diff, slovenian-slv.diff
  • Date: 2011-01-26 21:53:07 UTC
  • mfrom: (5.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20110126215307-62x61mcesr607qb7
Tags: 1.0.0+dfsg-2
* Upload to unstable.
* Explicitly build-depend on pkg-config. Thanks to Stefano Rivera for the
  bug report.
* Add Vcs-* fields.
* Use the standard C assert() macro, rather than custom Cuneiform one.
  [c-assert.diff]
* Pass CFLAGS, CXXFLAGS and LDFLAGS (get from dpkg-buildflags) to cmake
  (closes: #608345). Thanks to Sami Liedes for the bug report.
  + Build depend on dpkg-dev (>= 1.15.7).
* Pass --parallel to dh.
  + Bump debhelper minimum version to 7.4.10.
* Update debian/copyright to the latest DEP-5 version.
* Bump year in debian/copyright.
* Explicitly link to GraphicsMagick (rather than via the ImageMagick
  compatibility layer).
* Don't ship /usr/lib/cuneiform/*.so symlinks. These libraries are
  considered private, at least until #598616 is fixed.
* Rename some private variables in debian/rules to make them lowercase.
* Update patch headers.
* Provide proper ‘build-arch’ and ‘build-indep’ targets in debian/rules.
* Document input format in the manual page (closes: #572061). Thanks to
  Janusz S. Bień for the bug report.
* Use ‘slv’ (rather than ‘slo’) as language code for Slovenian.
  [slovenian-slv.diff]
* Fix package description: Slovenian is supported, Slovak is not.
* Improve documentation of the language (-l) option (closes: #602512).
  Thanks to Jari Aalto for the bug report.
* Install reasons file for vrms.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Copyright (c) 1993-2008, Cognitive Technologies
3
3
All rights reserved.
4
4
 
5
 
����������� ��������� ��������������� � ������������� ��� � ���� ��������� ����,
6
 
��� � � �������� �����, � ����������� ��� ���, ��� ���������� ��������� �������:
7
 
 
8
 
      * ��� ��������� ��������������� ��������� ���� ������ ���������� ���������
9
 
        ���� ����������� �� ��������� �����, ���� ������ ������� � �����������
10
 
        ����� �� ��������.
11
 
      * ��� ��������� ��������������� ��������� ���� � ������������ �/��� �
12
 
        ������ ����������, ������������ ��� ���������������, ������ �����������
13
 
        ��������� ���� ���������� �� ��������� �����, ���� ������ ������� �
14
 
        ����������� ����� �� ��������.
15
 
      * �� �������� Cognitive Technologies, �� ����� �� ����������� �� �����
16
 
        ���� ������������ � �������� �������� ��������� �/��� �����������
17
 
        ���������, ���������� �� ���� ��, ��� ���������������� �����������
18
 
        ����������.
19
 
 
20
 
��� ��������� ������������� ����������� ��������� ���� �/��� ������� ������ "���
21
 
��� ����" ��� ������-���� ���� ��������, ���������� ���� ��� ���������������,
22
 
������� �������� ������������ �������� � ����������� ��� ���������� ����, �� ��
23
 
������������� ���. �� �������� ��������� ���� � �� ���� ������ ����, �������
24
 
����� �������� �/��� �������� �������������� ���������, �� � ���� ������ ��
25
 
��Ѩ� ���������������, ������� ����� �����, ���������, ����������� ���
26
 
������������� ������, ��������� � �������������� ��� ���������� ����������
27
 
������������� ������������� ��������� (������� ������ ������, ��� ������,
28
 
������� ���������, ��� ������ �/��� ������ �������, ���������� ��-�� ��������
29
 
������� ��� �/��� ������ ��������� �������� ��������� � ������� �����������,
30
 
�� �� ������������� ����� ��������), �� �� ������������� ���, ���� ���� �����
31
 
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
 
5
Разрешается повторное распространение и использование как в виде исходного кода,
 
6
так и в двоичной форме, с изменениями или без, при соблюдении следующих условий:
 
7
 
 
8
      * При повторном распространении исходного кода должны оставаться указанное
 
9
        выше уведомление об авторском праве, этот список условий и последующий
 
10
        отказ от гарантий.
 
11
      * При повторном распространении двоичного кода в документации и/или в
 
12
        других материалах, поставляемых при распространении, должны сохраняться
 
13
        указанная выше информация об авторском праве, этот список условий и
 
14
        последующий отказ от гарантий.
 
15
      * Ни название Cognitive Technologies, ни имена ее сотрудников не могут
 
16
        быть использованы в качестве средства поддержки и/или продвижения
 
17
        продуктов, основанных на этом ПО, без предварительного письменного
 
18
        разрешения.
 
19
 
 
20
ЭТА ПРОГРАММА ПРЕДОСТАВЛЕНА ВЛАДЕЛЬЦАМИ АВТОРСКИХ ПРАВ И/ИЛИ ДРУГИМИ ЛИЦАМИ "КАК
 
21
ОНА ЕСТЬ" БЕЗ КАКОГО-ЛИБО ВИДА ГАРАНТИЙ, ВЫРАЖЕННЫХ ЯВНО ИЛИ ПОДРАЗУМЕВАЕМЫХ,
 
22
ВКЛЮЧАЯ ГАРАНТИИ КОММЕРЧЕСКОЙ ЦЕННОСТИ И ПРИГОДНОСТИ ДЛЯ КОНКРЕТНОЙ ЦЕЛИ, НО НЕ
 
23
ОГРАНИЧИВАЯСЬ ИМИ. НИ ВЛАДЕЛЕЦ АВТОРСКИХ ПРАВ И НИ ОДНО ДРУГОЕ ЛИЦО, КОТОРОЕ
 
24
МОЖЕТ ИЗМЕНЯТЬ И/ИЛИ ПОВТОРНО РАСПРОСТРАНЯТЬ ПРОГРАММУ, НИ В КОЕМ СЛУЧАЕ НЕ
 
25
НЕСЁТ ОТВЕТСТВЕННОСТИ, ВКЛЮЧАЯ ЛЮБЫЕ ОБЩИЕ, СЛУЧАЙНЫЕ, СПЕЦИАЛЬНЫЕ ИЛИ
 
26
ПОСЛЕДОВАВШИЕ УБЫТКИ, СВЯЗАННЫЕ С ИСПОЛЬЗОВАНИЕМ ИЛИ ПОНЕСЕННЫЕ ВСЛЕДСТВИЕ
 
27
НЕВОЗМОЖНОСТИ ИСПОЛЬЗОВАНИЯ ПРОГРАММЫ (ВКЛЮЧАЯ ПОТЕРИ ДАННЫХ, ИЛИ ДАННЫЕ,
 
28
СТАВШИЕ НЕГОДНЫМИ, ИЛИ УБЫТКИ И/ИЛИ ПОТЕРИ ДОХОДОВ, ПОНЕСЕННЫЕ ИЗ-ЗА ДЕЙСТВИЙ
 
29
ТРЕТЬИХ ЛИЦ И/ИЛИ ОТКАЗА ПРОГРАММЫ РАБОТАТЬ СОВМЕСТНО С ДРУГИМИ ПРОГРАММАМИ,
 
30
НО НЕ ОГРАНИЧИВАЯСЬ ЭТИМИ СЛУЧАЯМИ), НО НЕ ОГРАНИЧИВАЯСЬ ИМИ, ДАЖЕ ЕСЛИ ТАКОЙ
 
31
ВЛАДЕЛЕЦ ИЛИ ДРУГОЕ ЛИЦО БЫЛИ ИЗВЕЩЕНЫ О ВОЗМОЖНОСТИ ТАКИХ УБЫТКОВ И ПОТЕРЬ.
32
32
 
33
33
Redistribution and use in source and binary forms, with or without modification,
34
34
are permitted provided that the following conditions are met:
86
86
#include "minmax.h"
87
87
 
88
88
#include "resource.h"
89
 
//static  Word8*  lnOcrPath;
 
89
//static  uchar*  lnOcrPath;
90
90
static  Rect16  merge_frame;
91
91
static  Bool32  is_merge_frame=FALSE;
92
92
static  CCOM_handle NumContainer =0;
93
 
static  Int32   curr_line=0, original_density;
94
 
static  Word8   original_begends;
95
 
static  Word8 * rasterDIB4=NULL;
96
 
static  Int32   DIB_Hei,    DIB_Wid,
 
93
static  int32_t   curr_line=0, original_density;
 
94
static  uchar   original_begends;
 
95
static  uchar * rasterDIB4=NULL;
 
96
static  int32_t   DIB_Hei,    DIB_Wid,
97
97
                DIB_HRes,   DIB_VRes,
98
98
                DIB_TCol,   DIB_TRow,
99
99
                DIB_BW,     DIB_FM=1,
100
100
                DIB_TWid,   DIB_THei ;
101
101
static  Bool32  EnableTemplate=FALSE;
102
 
static  Word8 mask_l[]     =
 
102
static  uchar mask_l[]     =
103
103
        {255,    127,   63,   31,   15,    7,    3,   1};
104
 
static  Word8 mask_r[]     =
 
104
static  uchar mask_r[]     =
105
105
        {  128,  192,  224,  240,  248,  252,  254, 255};
106
106
static FNREXC_ProgressStart  fnProgressStart_exc =NULL;
107
107
static FNREXC_ProgressStep   fnProgressStep_exc  =NULL;
108
108
static FNREXC_ProgressFinish fnProgressFinish_exc=NULL;
109
109
//=========== Progress Monitor
110
 
static  Word32 progress_vol=0, progress_rel=0;
111
 
void    progress_start (Word32 volume)
 
110
static  uint32_t progress_vol=0, progress_rel=0;
 
111
void    progress_start (uint32_t volume)
112
112
{
113
113
progress_vol=volume;
114
114
if( fnProgressStart_exc )
125
125
return ;
126
126
}
127
127
 
128
 
Word32  progress_set_percent (Word32 step)
 
128
uint32_t  progress_set_percent (uint32_t step)
129
129
{
130
 
Word32  rel = (step/progress_vol)*100;
 
130
uint32_t  rel = (step/progress_vol)*100;
131
131
if( !progress_vol || rel<progress_rel+10 )
132
132
    return step;
133
133
progress_rel = rel;
136
136
return step;
137
137
}
138
138
 //------------------ Image attributes ---------------------
139
 
Word16 image_disp_byte, image_disp_end;
140
 
Word8 image_disp_mask;
141
 
Int16  image_blth    ;  // pixels per line
142
 
Int16  image_height  ;  // lines in file number
143
 
Int16  image_lth     ;  // bytes per line
144
 
Word8 image_black   ;  // mask for black pixels adding
145
 
Word8 image_white   ;  // mask for wite pixels adding
 
139
uint16_t image_disp_byte, image_disp_end;
 
140
uchar image_disp_mask;
 
141
int16_t  image_blth    ;  // pixels per line
 
142
int16_t  image_height  ;  // lines in file number
 
143
int16_t  image_lth     ;  // bytes per line
 
144
uchar image_black   ;  // mask for black pixels adding
 
145
uchar image_white   ;  // mask for wite pixels adding
146
146
 
147
 
static Int8 image_file_status = -1;
148
 
static Word8 image_invert = 0;
 
147
static char image_file_status = -1;
 
148
static uchar image_invert = 0;
149
149
//========== Global func ==========
150
150
void extrcomp(void);
151
151
void save_component(ExtComponent *c, version *vs, version *ve,
152
 
                           Word8 *lp, Word16 lpl);
153
 
void invert_tiff (Word8 *p, Word16 lth);
 
152
                           uchar *lp, uint16_t lpl);
 
153
void invert_tiff (uchar *p, uint16_t lth);
154
154
void image_file_close(void);
155
155
Bool image_file_open (void);
156
 
Int16 source_read(Word8 *start, Word8 *ptr, Word8 *end);
 
156
int16_t source_read(uchar *start, uchar *ptr, uchar *end);
157
157
 
158
158
//========= Import func =========
159
159
// from GRA_REC.c
161
161
//--------------------------------------------------------------
162
162
extern void     exc_ori_init(void);
163
163
extern void     exc_ori_add(void);
164
 
extern Word8    exc_ori_result(void);
 
164
extern uchar    exc_ori_result(void);
165
165
-*/
166
166
// from COMPKIT.C
167
 
extern Int16   MN_to_line(MN * mn);
168
 
//-extern Word8 * make_raster();
 
167
extern int16_t   MN_to_line(MN * mn);
 
168
//-extern uchar * make_raster();
169
169
// from ALPHABET.C
170
170
/*-Andrey: moved to RRecCom (recognition) and RNorm (autorotate)
171
171
//--------------------------------------------------------------
172
 
extern Bool16   rexc_set_alpha(Word8 language, Word8 *alphabet);
173
 
extern Bool16   rexc_load_tables(Word8 language);
174
 
extern Bool16   rexc_is_language(Word8 language);
175
 
extern Int32    rexc_gra_type_ori(Word8 lang);
176
 
extern Int32    rexc_gra_type_rec(Word8 lang);
 
172
extern Bool16   rexc_set_alpha(uchar language, uchar *alphabet);
 
173
extern Bool16   rexc_load_tables(uchar language);
 
174
extern Bool16   rexc_is_language(uchar language);
 
175
extern int32_t    rexc_gra_type_ori(uchar lang);
 
176
extern int32_t    rexc_gra_type_rec(uchar lang);
177
177
extern void     exc_ori_recog(RecVersions *v);
178
178
-*/
179
179
// from MATRIX.C
180
 
extern Int16  matrix_read(Word8 *buff, Word16 lth);
 
180
extern int16_t  matrix_read(uchar *buff, uint16_t lth);
181
181
extern void matrix_open ();
182
182
extern void matrix_close();
183
183
extern void matrix_reset();
184
184
//========== Local func ==========
185
185
static void save_gcomp(ExtComponent *c);
186
 
static Bool process_comp(void * pool,Word32 size);
 
186
static Bool process_comp(void * pool,uint32_t size);
187
187
static Bool flush_cache(void);
188
188
static void reset_cache(void);
189
189
static Bool init_dump_file(void);
190
 
static Bool write_dump(void * pool,Int32 size);
 
190
static Bool write_dump(void * pool,int32_t size);
191
191
static Bool extrcomp_setup_memory(void);
192
192
 
193
193
//========== Import data
194
194
extern struct main_memory_str Q;
195
195
extern ExtComponent wcomp;
196
 
extern Word16 lpool_lth;
197
 
extern Word8 lpool[];
198
 
extern Word8 work_raster[];
199
 
extern Int32 sz_work_raster, sz_work_raster_1;
 
196
extern uint16_t lpool_lth;
 
197
extern uchar lpool[];
 
198
extern uchar work_raster[];
 
199
extern int32_t sz_work_raster, sz_work_raster_1;
200
200
extern BOX *dl_last_in_chain;
201
201
//========== Global data
202
 
Word8       language=-1;
203
 
Int32       gra_type_ori =-1;
204
 
Int32       gra_type_rec =-1;
 
202
uchar       language=-1;
 
203
int32_t       gra_type_ori =-1;
 
204
int32_t       gra_type_rec =-1;
205
205
TImageOpen  Tiger_ImageOpen;
206
206
TImageRead  Tiger_ImageRead;
207
207
TImageClose Tiger_ImageClose;
208
208
Tiger_ProcComp    Tiger_ProcessComp;
209
 
Int32   box_number=BOX_NUMBER;
210
 
Word8   fax1x2=0,matrix=0;
211
 
Word16  actual_resolution;
212
 
Word16  comp_max_h, comp_max_w, comp_min_h, comp_min_w;
213
 
Word8   alphabet[256];
214
 
Int16   nBlack,nAll,nWid;
215
 
Int32 ExControl;
 
209
int32_t   box_number=BOX_NUMBER;
 
210
uchar   fax1x2=0,matrix=0;
 
211
uint16_t  actual_resolution;
 
212
uint16_t  comp_max_h, comp_max_w, comp_min_h, comp_min_w;
 
213
uchar   alphabet[256];
 
214
int16_t   nBlack,nAll,nWid;
 
215
int32_t ExControl;
216
216
//========== Local data
217
217
 
218
218
#define CACHESIZE       (64*1024)
219
219
 
220
 
static Word8 cache[CACHESIZE],*cache_end,*cache_curr;
 
220
static uchar cache[CACHESIZE],*cache_end,*cache_curr;
221
221
static char dumpfile[]= EXC_DUMP_FILE;
222
 
static Int16  MaxScale;
 
222
static int16_t  MaxScale;
223
223
static jmp_buf jumper;
224
 
static Word16            wHeightRC =                         0;
225
 
static Word16            wLowRC =                            REXC_ERR_NO;;
 
224
static uint16_t            wHeightRC =                         0;
 
225
static uint16_t            wLowRC =                            REXC_ERR_NO;;
226
226
 
227
227
//============= Source CODE =============
228
228
 
229
229
EXC_FUNC(Bool32)  ExtrcompInit( void )
230
230
{
231
231
FNCCOM_MakeLP      MLP=(FNCCOM_MakeLP)REXCMakeLP;
232
 
Int32                ccom_vers, vers=REXC_VERSION_CODE;
 
232
int32_t                ccom_vers, vers=REXC_VERSION_CODE;
233
233
 
234
234
if( Q.boxstart )
235
235
    {
269
269
 
270
270
 
271
271
 
272
 
EXC_FUNC(Int32)  Extracomp(ExcControl ExCW,TImageOpen tio,
 
272
EXC_FUNC(int32_t)  Extracomp(ExcControl ExCW,TImageOpen tio,
273
273
                                TImageClose tic, TImageRead tir,
274
274
                                Tiger_ProcComp tipc)
275
275
{
349
349
                                TImageClose tic, TImageRead tir,
350
350
                                Tiger_ProcComp tipc)
351
351
{
352
 
Int32 ret;
 
352
int32_t ret;
353
353
ret = Extracomp(ExCW,tio,tic,tir,tipc);
354
354
 
355
355
switch (ret)
408
408
if( !rasterDIB4 )
409
409
    return FALSE;
410
410
memset(lpImageInfo,0,sizeof(Tiger_ImageInfo));
411
 
lpImageInfo -> wImageHeight       = (Word16)DIB_Hei;
412
 
lpImageInfo -> wImageWidth        = (Word16)DIB_Wid;
 
411
lpImageInfo -> wImageHeight       = (uint16_t)DIB_Hei;
 
412
lpImageInfo -> wImageWidth        = (uint16_t)DIB_Wid;
413
413
 
414
414
lpImageInfo -> wImageByteWidth    = (lpImageInfo -> wImageWidth + 7) / 8;
415
 
lpImageInfo -> wResolutionX       = (Word16)DIB_HRes;
416
 
lpImageInfo -> wResolutionY       = (Word16)DIB_VRes;
417
 
lpImageInfo -> bFotoMetrics       = (Word8)DIB_FM; // inverted tiff image
 
415
lpImageInfo -> wResolutionX       = (uint16_t)DIB_HRes;
 
416
lpImageInfo -> wResolutionY       = (uint16_t)DIB_VRes;
 
417
lpImageInfo -> bFotoMetrics       = (uchar)DIB_FM; // inverted tiff image
418
418
 
419
419
return TRUE;
420
420
}
421
421
 
422
 
Int16   EXC_DIBRead(Word8 *lpImage, Word16 wMaxSize)
 
422
int16_t   EXC_DIBRead(uchar *lpImage, uint16_t wMaxSize)
423
423
{
424
424
int     d = (DIB_Wid+7)/8, len;
425
425
 
464
464
return len;
465
465
}
466
466
// reverse order of string. DIB
467
 
Int16   EXC_DIBReadReverse(Word8 *lpImage, Word16 wMaxSize)
 
467
int16_t   EXC_DIBReadReverse(uchar *lpImage, uint16_t wMaxSize)
468
468
{
469
469
int     d = (DIB_Wid+7)/8, len;
470
470
if( !EnableTemplate )
510
510
/////////////////////
511
511
// OUTPUT CALLBACKs
512
512
/////////////////////
513
 
Word16          push_box_to_container(ExcBox *  g)
 
513
uint16_t          push_box_to_container(ExcBox *  g)
514
514
{
515
515
CCOM_New(NumContainer ,g->row, g->col, g->w, g->h);
516
516
return 1;
517
517
}
518
518
 
519
 
Bool    AcceptBoxes(void * pool, Word32 size)
 
519
Bool    AcceptBoxes(void * pool, uint32_t size)
520
520
{
521
521
ExcBox* g , *ge;
522
522
 
530
530
return TRUE;
531
531
}
532
532
 
533
 
Word16          push_comp_to_container(ExtComponent *  g)
 
533
uint16_t          push_comp_to_container(ExtComponent *  g)
534
534
{
535
 
Word8           res[16];
 
535
uchar           res[16];
536
536
int             nvers, i;
537
537
RecVersions     vers={0};
538
538
CCOM_comp    *  curr_comp;
539
539
CCOM_USER_BLOCK ublock[3];
540
 
Word16          lth;
541
 
Word8        *  lpool;
 
540
uint16_t          lth;
 
541
uchar        *  lpool;
542
542
 
543
 
lth = *((Word16*)((Word8*)g + sizeof(ExtComponent))); // size
544
 
lpool = (Word8*) ((Word8*)g + g->lines); // linerepesentation
 
543
lth = *((uint16_t*)((uchar*)g + sizeof(ExtComponent))); // size
 
544
lpool = (uchar*) ((uchar*)g + g->lines); // linerepesentation
545
545
if( g->nvers )
546
546
    {
547
547
    nvers = g->nvers;
548
 
    memcpy(res,(Word8*)g + g->records, g->nvers);
 
548
    memcpy(res,(uchar*)g + g->records, g->nvers);
549
549
    }
550
550
else
551
551
    nvers=res[0]=0;
578
578
        {
579
579
        ublock[0].code=CCOM_UB_DENSITY;
580
580
        ublock[0].size=4;
581
 
        ublock[0].data=(Word8*)&g->dens;
 
581
        ublock[0].data=(uchar*)&g->dens;
582
582
        ublock[0].next_block=&ublock[1];
583
583
        ublock[1].code=CCOM_UB_BEGENDS;
584
584
        ublock[1].size=1;
585
 
        ublock[1].data=(Word8*)&g->begends;
 
585
        ublock[1].data=(uchar*)&g->begends;
586
586
        ublock[1].next_block=0;
587
587
        }
588
588
    if( is_merge_frame )
590
590
        ublock[1].next_block=&ublock[2];
591
591
        ublock[2].code=CCOM_UB_MERGEFRAME;
592
592
        ublock[2].size=sizeof(merge_frame);
593
 
        ublock[2].data=(Word8*)&merge_frame;
 
593
        ublock[2].data=(uchar*)&merge_frame;
594
594
        ublock[2].next_block=0;
595
595
        }
596
596
    CCOM_Store(curr_comp,0,
607
607
return lth ;
608
608
}
609
609
 
610
 
Bool    AcceptComps(void * pool, Word32 size)
 
610
Bool    AcceptComps(void * pool, uint32_t size)
611
611
{
612
612
ExtComponent *  g , *ge;
613
 
Word16          lth;
 
613
uint16_t          lth;
614
614
 
615
615
for( g = (ExtComponent*)pool, ge = (ExtComponent*)((char*)pool+size);
616
616
g<ge    ;
617
 
g=(ExtComponent*)((char*)g+sizeof(Word16)+sizeof(ExtComponent)+lth+g->nvers))
 
617
g=(ExtComponent*)((char*)g+sizeof(uint16_t)+sizeof(ExtComponent)+lth+g->nvers))
618
618
    {
619
 
    lth = *((Word16*)((Word8*)g + sizeof(ExtComponent))); // size
 
619
    lth = *((uint16_t*)((uchar*)g + sizeof(ExtComponent))); // size
620
620
       //push_comp_to_container(g);
621
621
    }
622
622
return TRUE;
624
624
 
625
625
 
626
626
Bool32  REXCExtra(ExcControl ExCW,
627
 
    Word8 *lpRaster, Int32 BWid, Bool32 ReverseOrder,
628
 
    Int32 Wid, Int32 Hei, Int32 HRes, Int32 VRes,
629
 
    Int32 TemplCol, Int32 TemplRow, Int32 TemplWid, Int32 TemplHei, Bool32 FotoMetr )
 
627
    uchar *lpRaster, int32_t BWid, Bool32 ReverseOrder,
 
628
    int32_t Wid, int32_t Hei, int32_t HRes, int32_t VRes,
 
629
    int32_t TemplCol, int32_t TemplRow, int32_t TemplWid, int32_t TemplHei, Bool32 FotoMetr )
630
630
 
631
631
{
632
 
Int32 ret;
 
632
int32_t ret;
633
633
if( Wid<=0 || BWid<=0 || Hei<=0 ||
634
634
    HRes<WORLD_MIN_RESOLUTION || VRes<WORLD_MIN_RESOLUTION  )
635
635
    {
734
734
Bool32  REXCExtracomp3CB(ExcControl ExCW,TImageOpen tio,
735
735
                                TImageClose tic, TImageRead tir)
736
736
{
737
 
Int32 ret;
 
737
int32_t ret;
738
738
  if( !(ExControl & Ex_NoContainer) )
739
739
    {
740
740
    NumContainer = CCOM_CreateContainer();
793
793
}
794
794
 
795
795
Bool32  REXCExtraDIB(ExcControl ExCW,
796
 
     Word8 *lp_DIB,
797
 
     Int32 TemplCol, Int32 TemplRow, Int32 TemplWid, Int32 TemplHei)
 
796
     uchar *lp_DIB,
 
797
     int32_t TemplCol, int32_t TemplRow, int32_t TemplWid, int32_t TemplHei)
798
798
 
799
799
{
800
800
REXC_DIB        *lpDIB = (REXC_DIB *)lp_DIB;
801
 
REXC_RGBQUAD    *pal=(REXC_RGBQUAD    *)((Word8*)(lpDIB)+sizeof(REXC_DIB ));
 
801
REXC_RGBQUAD    *pal=(REXC_RGBQUAD    *)((uchar*)(lpDIB)+sizeof(REXC_DIB ));
802
802
Bool32           foto_metric = TRUE;
803
803
 
804
804
if( pal[0].rgbBlue!=0 && pal[0].rgbRed!=0 && pal[0].rgbGreen!=0 &&
806
806
    foto_metric = FALSE;
807
807
 
808
808
return REXCExtra(ExCW,
809
 
    (Word8*)(lpDIB)+sizeof(REXC_DIB )+2*sizeof(REXC_RGBQUAD),
 
809
    (uchar*)(lpDIB)+sizeof(REXC_DIB )+2*sizeof(REXC_RGBQUAD),
810
810
    ((((lpDIB->biWidth+7)/8)+3)/4)*4, 1,
811
811
    lpDIB->biWidth, lpDIB->biHeight,
812
812
    lpDIB->biXPelsPerMeter, lpDIB->biYPelsPerMeter,
842
842
 image_file_status = -1;
843
843
}
844
844
 
845
 
static Word8 rest_line_mask_tab[8]=
 
845
static uchar rest_line_mask_tab[8]=
846
846
 {0xff,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe};
847
 
static Word8 start_line_mask_tab[8]=
 
847
static uchar start_line_mask_tab[8]=
848
848
 {0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01};
849
849
 
850
850
Bool image_file_open (void)
871
871
 fax1x2 = 0; //(p.wResolutionX == 200 && p.wResolutionY == 100);
872
872
 if ((actual_resolution < WORLD_MIN_RESOLUTION) || (actual_resolution > WORLD_MAX_RESOLUTION))
873
873
 {
874
 
         //������� �. 11.12.2002
875
 
         //���� ���������� �� � �������� ����� �������� �������� 300
 
874
         //Никитин А. 11.12.2002
 
875
         //если разрешение не в пределах нормы локально выставим 300
876
876
         actual_resolution = 300;
877
877
//        error_exit (ERR_image,ExRc_IncorrectParam);
878
878
 }
891
891
}
892
892
 
893
893
 
894
 
Int16 source_read(Word8* start, Word8* ptr, Word8* end)
 
894
int16_t source_read(uchar* start, uchar* ptr, uchar* end)
895
895
{
896
 
 Int16 i, l;
 
896
 int16_t i, l;
897
897
 
898
898
 i=end-ptr; /* length of rest of last string */
899
899
 if (i)  { memcpy (start,ptr,i); start += i; }
909
909
}
910
910
 
911
911
 
912
 
void error_exit(Int16 group, Int16 element)
 
912
void error_exit(int16_t group, int16_t element)
913
913
{
914
914
group=element;
915
915
longjmp(jumper,element);
925
925
        save_gcomp(&wcomp);
926
926
}
927
927
 
928
 
void save_component(ExtComponent *c, version *vs, version *ve, Word8* lp, Word16 lpl)
 
928
void save_component(ExtComponent *c, version *vs, version *ve, uchar* lp, uint16_t lpl)
929
929
{
930
930
char pool[64*1024];
931
931
char *p=pool;
944
944
        }
945
945
#endif
946
946
 vs=ve; /* avoid warn */
947
 
 c->size = sizeof(ExtComponent)+sizeof(Word16)+lpl;
 
947
 c->size = sizeof(ExtComponent)+sizeof(uint16_t)+lpl;
948
948
 c->lines= sizeof(ExtComponent);
949
949
 if( lpl>sizeof(pool)-10 )
950
950
        {
964
964
        c->h >>=c->scale;
965
965
        c->rw  =(c->w+7)/8;
966
966
        }
967
 
    c->nvers=  (Int16)EVNRecog_lp(  (ExtComponent *)c, lp, lpl, evn_res   );
968
 
    c->records = (Int16)(sizeof(ExtComponent)+sizeof(Word16)+lpl);
 
967
    c->nvers=  (int16_t)EVNRecog_lp(  (ExtComponent *)c, lp, lpl, evn_res   );
 
968
    c->records = (int16_t)(sizeof(ExtComponent)+sizeof(uint16_t)+lpl);
969
969
    mkrs=FALSE;
970
970
 
971
971
    if( ((ExControl & Ex_NetRecog)||c->scale) &&
990
990
            gra_res[j]=0;
991
991
            if( gra_res[0] )
992
992
                {
993
 
                c->nvers=(Int16)j;
 
993
                c->nvers=(int16_t)j;
994
994
                memcpy(evn_res, gra_res,j);
995
995
                c->cs=255; // gra versions
996
996
                }
1015
1015
    c->begends=original_begends;
1016
1016
    }
1017
1017
memcpy(p,c   ,sizeof(ExtComponent));  p += sizeof(ExtComponent);
1018
 
memcpy(p,&lpl,sizeof(Word16));  p += sizeof(Word16);
 
1018
memcpy(p,&lpl,sizeof(uint16_t));  p += sizeof(uint16_t);
1019
1019
memcpy(p,lp,lpl);               p += lpl;
1020
1020
/*-
1021
1021
if( (ExControl & Ex_EvnRecog) && c->nvers>0 )
1054
1054
 process_comp(&g,sizeof(gcomp));
1055
1055
}
1056
1056
 
1057
 
Bool process_comp(void * pool,Word32 size)
 
1057
Bool process_comp(void * pool,uint32_t size)
1058
1058
{
1059
1059
 assert(size < CACHESIZE);
1060
1060
 assert(pool && cache);
1082
1082
Bool init_dump_file(void)
1083
1083
{ return remove(dumpfile) == 0; }
1084
1084
 
1085
 
Bool write_dump(void * pool,Int32 size)
 
1085
Bool write_dump(void * pool,int32_t size)
1086
1086
{
1087
1087
int h;
1088
1088
 
1093
1093
 return close(h)==0;
1094
1094
}
1095
1095
 
1096
 
EXC_FUNC(Bool32)  REXCMakeLP( RecRaster   *rRaster , Word8 *lp, Int16 *lp_size, Int16 *numcomp)
 
1096
EXC_FUNC(Bool32)  REXCMakeLP( RecRaster   *rRaster , uchar *lp, int16_t *lp_size, int16_t *numcomp)
1097
1097
{
1098
 
Word8  *l, *ls;
 
1098
uchar  *l, *ls;
1099
1099
int     len, numc;
1100
 
Int16  *llen;
 
1100
int16_t  *llen;
1101
1101
ls=l=EVNMakeLine( rRaster , 2);
1102
1102
if( !l )
1103
1103
    {
1106
1106
    }
1107
1107
for(numc=len=0;;)
1108
1108
    {
1109
 
    llen = (Int16*)l;
 
1109
    llen = (int16_t*)l;
1110
1110
    len += *llen;
1111
1111
    if( *llen==0 )
1112
1112
        break;
1113
1113
    numc++;
1114
1114
    l+=*llen;
1115
1115
    }
1116
 
*lp_size = (Int16)len;
1117
 
*numcomp = (Int16)numc;
 
1116
*lp_size = (int16_t)len;
 
1117
*numcomp = (int16_t)numc;
1118
1118
memcpy(lp,ls,len);
1119
1119
return TRUE;
1120
1120
}
1121
1121
 
1122
1122
/*-Andrey: moved to RNorm (autorotate)
1123
1123
//--------------------------------------------------------------
1124
 
EXC_FUNC(Bool32) REXC_GetOrient(Word8 *ori)
 
1124
EXC_FUNC(Bool32) REXC_GetOrient(uchar *ori)
1125
1125
{
1126
1126
if( !ori )
1127
1127
    {
1133
1133
if (*ori == 5)
1134
1134
{
1135
1135
        const double formatA4 = 1.4;
1136
 
        Word32 PageNumber = CPAGE_GetCurrentPage();
 
1136
        uint32_t PageNumber = CPAGE_GetCurrentPage();
1137
1137
        Handle h_Page = CPAGE_GetHandlePage(PageNumber);
1138
1138
        PAGEINFO page_info = {0};
1139
1139
    if(GetPageInfo(h_Page,&page_info))
1149
1149
}
1150
1150
-*/
1151
1151
 
1152
 
EXC_FUNC(Bool32) REXC_GetInvertion(Word8 *inv)
 
1152
EXC_FUNC(Bool32) REXC_GetInvertion(uchar *inv)
1153
1153
{
1154
1154
if( !(ExControl & Ex_Background) )
1155
1155
    {
1173
1173
return TRUE;
1174
1174
}
1175
1175
 
1176
 
EXC_FUNC(Bool32) REXC_GetExportData(Word32 dwType, void * pData)
 
1176
EXC_FUNC(Bool32) REXC_GetExportData(uint32_t dwType, void * pData)
1177
1177
{
1178
1178
#define CASE_DATA(a,b,c)        case a: *(b *)pData = c; break
1179
1179
        Bool32 rc = TRUE;
1181
1181
  wLowRC = REXC_ERR_NO;
1182
1182
        switch(dwType)
1183
1183
        {
1184
 
        CASE_DATA(REXC_Word8_Matrix                     ,Word8,matrix);
1185
 
        CASE_DATA(REXC_Word8_Fax1x2                     ,Word8,fax1x2);
1186
 
        CASE_DATA(REXC_Word16_ActualResolution  ,Word16,actual_resolution);
 
1184
        CASE_DATA(REXC_Word8_Matrix                     ,uchar,matrix);
 
1185
        CASE_DATA(REXC_Word8_Fax1x2                     ,uchar,fax1x2);
 
1186
        CASE_DATA(REXC_Word16_ActualResolution  ,uint16_t,actual_resolution);
1187
1187
/*-Andrey: moved to RRecCom (recognition) and RNorm (autorotate)
1188
1188
//--------------------------------------------------------------
1189
1189
        case REXC_FNEVNPROPERT:
1190
 
            *(Word32*)pData =          (Word32)REXC_SetEVNProperties;
 
1190
            *(uint32_t*)pData =          (uint32_t)REXC_SetEVNProperties;
1191
1191
            break;
1192
1192
-*/
1193
1193
        case REXC_FNEXTRACOMP :
1194
 
            *(Word32*)pData =          (Word32)REXCExtracomp;
 
1194
            *(uint32_t*)pData =          (uint32_t)REXCExtracomp;
1195
1195
            break;
1196
1196
        case REXC_FNEXTRA :
1197
 
            *(Word32*)pData =          (Word32)REXCExtra;
 
1197
            *(uint32_t*)pData =          (uint32_t)REXCExtra;
1198
1198
            break;
1199
1199
        case REXC_FNEXTRADIB:
1200
 
            *(Word32*)pData =          (Word32)REXCExtraDIB;
 
1200
            *(uint32_t*)pData =          (uint32_t)REXCExtraDIB;
1201
1201
            break;
1202
1202
 
1203
1203
        case    REXC_FNGETCONTAINER:
1204
 
            *(Word32*)pData =          (Word32)REXCGetContainer;
 
1204
            *(uint32_t*)pData =          (uint32_t)REXCGetContainer;
1205
1205
            break;
1206
1206
 
1207
1207
        case    REXC_FNGETLENEREP:
1208
 
            *(Word32*)pData =          (Word32)REXCMakeLP;
 
1208
            *(uint32_t*)pData =          (uint32_t)REXCMakeLP;
1209
1209
            break;
1210
1210
        case    REXC_FNVERSION:
1211
 
            *(Word32*)pData =          (Word32)REXC_VERSION_CODE;
 
1211
            *(uint32_t*)pData =          (uint32_t)REXC_VERSION_CODE;
1212
1212
            break;
1213
1213
/*-Andrey: moved to RRecCom (recognition) and RNorm (autorotate)
1214
1214
//--------------------------------------------------------------
1215
1215
        case    REXC_FNREX_ISLANGUAGE:
1216
 
            *(Word32*)pData =          (Word32)REXC_IsLanguage;
 
1216
            *(uint32_t*)pData =          (uint32_t)REXC_IsLanguage;
1217
1217
            break;
1218
1218
        case    REXC_FNGETORIENT:
1219
 
            *(Word32*)pData =          (Word32)REXC_GetOrient;
 
1219
            *(uint32_t*)pData =          (uint32_t)REXC_GetOrient;
1220
1220
            break;
1221
1221
-*/
1222
1222
        case    REXC_FNMN2CCOM:
1223
 
            *(Word32*)pData =          (Word32)REXC_MN2CCOM;
 
1223
            *(uint32_t*)pData =          (uint32_t)REXC_MN2CCOM;
1224
1224
            break;
1225
1225
        case    REXC_FNGETINVERTION:
1226
 
            *(Word32*)pData =          (Word32)REXC_GetInvertion;
 
1226
            *(uint32_t*)pData =          (uint32_t)REXC_GetInvertion;
1227
1227
            break;
1228
1228
/*-Andrey: moved to RRecCom (recognition) and RNorm (autorotate)
1229
1229
//--------------------------------------------------------------
1230
 
        case    REXC_FNEVNALPHABET:     // ��������� �������� ��� �����
1231
 
            *(Word32*)pData =          (Word32)REXC_SetEVNAlphabet;
 
1230
        case    REXC_FNEVNALPHABET:     // установка алфавита для евент
 
1231
            *(uint32_t*)pData =          (uint32_t)REXC_SetEVNAlphabet;
1232
1232
            break;
1233
1233
-*/
1234
 
        case    REXC_FNEXTRACOMP3CB:    // 3 ��������
1235
 
            *(Word32*)pData =          (Word32)REXCExtracomp3CB;
 
1234
        case    REXC_FNEXTRACOMP3CB:    // 3 коллбэка
 
1235
            *(uint32_t*)pData =          (uint32_t)REXCExtracomp3CB;
1236
1236
            break;
1237
1237
/*-Andrey: moved to RRecCom (recognition) and RNorm (autorotate)
1238
1238
//--------------------------------------------------------------
1239
 
        case    REXC_FNEXTGETRECRASTERORIENT: // ���������� �������� ������
1240
 
            *(Word32*)pData =          (Word32)exc_get_rec_raster_orient;
 
1239
        case    REXC_FNEXTGETRECRASTERORIENT: // ориентация рабочего растра
 
1240
            *(uint32_t*)pData =          (uint32_t)exc_get_rec_raster_orient;
1241
1241
            break;
1242
 
        case    REXC_FNSETALLALPHAGRA: // ������� ��������� ����
1243
 
            *(Word32*)pData =          (Word32)exc_set_all_alphabet_gra;
 
1242
        case    REXC_FNSETALLALPHAGRA: // алфавит нейронной сети
 
1243
            *(uint32_t*)pData =          (uint32_t)exc_set_all_alphabet_gra;
1244
1244
            break;
1245
1245
-*/
1246
1246
        default:
1251
1251
return rc;
1252
1252
}
1253
1253
 
1254
 
EXC_FUNC(Bool32) REXC_SetImportData(Word32 dwType, void * pData)
 
1254
EXC_FUNC(Bool32) REXC_SetImportData(uint32_t dwType, void * pData)
1255
1255
{
1256
1256
#define CASE_DATA(a,b,c)        case a: c = *(b *)pData; break
1257
1257
#define CASE_PDATA(a,b,c)       case a: c = (b)pData;    break
1258
1258
wLowRC = REXC_ERR_NO;
1259
1259
switch(dwType)
1260
1260
    {
1261
 
        CASE_DATA(REXC_Word8_Matrix             ,Word8,matrix);
1262
 
        CASE_DATA(REXC_Word8_Fax1x2             ,Word8,fax1x2);
1263
 
    CASE_DATA(REXC_Word16_ActualResolution,Word16,actual_resolution);
 
1261
        CASE_DATA(REXC_Word8_Matrix             ,uchar,matrix);
 
1262
        CASE_DATA(REXC_Word8_Fax1x2             ,uchar,fax1x2);
 
1263
    CASE_DATA(REXC_Word16_ActualResolution,uint16_t,actual_resolution);
1264
1264
    CASE_PDATA(REXC_ProgressStart,      FNREXC_ProgressStart, fnProgressStart_exc);
1265
1265
        CASE_PDATA(REXC_ProgressStep,   FNREXC_ProgressStep,  fnProgressStep_exc);
1266
1266
        CASE_PDATA(REXC_ProgressFinish, FNREXC_ProgressFinish,fnProgressFinish_exc);
1267
 
//    CASE_PDATA(REXC_OcrPath,    Word8*, lnOcrPath);
 
1267
//    CASE_PDATA(REXC_OcrPath,    uchar*, lnOcrPath);
1268
1268
    default:
1269
1269
            wLowRC = REXC_ERR_NOTIMPLEMENT;
1270
1270
            return FALSE;
1274
1274
return TRUE;
1275
1275
}
1276
1276
 
1277
 
EXC_FUNC(Word32)   REXC_GetReturnCode(void)
 
1277
EXC_FUNC(uint32_t)   REXC_GetReturnCode(void)
1278
1278
{
1279
1279
if( wLowRC == REXC_ERR_NO )
1280
1280
  return 0;
1281
1281
return (wHeightRC<<16)|(wLowRC-REXC_ERR_MIN);
1282
1282
}
1283
1283
 
1284
 
EXC_FUNC(char*)   REXC_GetReturnString(Word32 dwError)
 
1284
EXC_FUNC(char*)   REXC_GetReturnString(uint32_t dwError)
1285
1285
{
1286
 
        Word16 rc = (Word16)((dwError & 0xFFFF) );
 
1286
        uint16_t rc = (uint16_t)((dwError & 0xFFFF) );
1287
1287
        static char szBuffer[512];
1288
1288
 
1289
1289
        if( dwError >> 16 != wHeightRC)
1297
1297
        return szBuffer;
1298
1298
}
1299
1299
 
1300
 
EXC_FUNC(Bool32) REXC_Init(Word16 wHeightCode, Handle hStorage)
 
1300
EXC_FUNC(Bool32) REXC_Init(uint16_t wHeightCode, Handle hStorage)
1301
1301
{
1302
1302
if(Q.boxstart)
1303
1303
    {
1322
1322
 
1323
1323
struct cut_pnt
1324
1324
{
1325
 
 Int16 xl;
1326
 
 Int16 xr;
1327
 
 Int16 est;
1328
 
 Int16 ref;
 
1325
 int16_t xl;
 
1326
 int16_t xr;
 
1327
 int16_t est;
 
1328
 int16_t ref;
1329
1329
};
1330
1330
 
1331
1331
typedef struct cut_pnt CP;
1332
1332
#define MAX_NUM_CUTPN 2048
1333
1333
struct big_merge_struct
1334
1334
{
1335
 
 Int16 vh[2*RASTER_MAX_HEIGHT+2];
 
1335
 int16_t vh[2*RASTER_MAX_HEIGHT+2];
1336
1336
 char eh[MAX_NUM_CUTPN];
1337
1337
 char sh[MAX_NUM_CUTPN];
1338
 
 Word16 np;
1339
 
 Int16 min_est;
 
1338
 uint16_t np;
 
1339
 int16_t min_est;
1340
1340
 CP cp[MAX_NUM_CUTPN];
1341
1341
};
1342
1342
 
1345
1345
BM W;
1346
1346
 
1347
1347
static void frame_hist (MN *mn);
1348
 
Word8* frame_cut_MN(Int16, Int16);
 
1348
uchar* frame_cut_MN(int16_t, int16_t);
1349
1349
static Bool32 frame_cut_points();
1350
1350
static void frame_select();
1351
1351
static Bool16 frame_check();
1352
 
static Int32 frame_cut(MN *mn);
 
1352
static int32_t frame_cut(MN *mn);
1353
1353
static Bool16 save_picture_scale (MN *mn);
1354
1354
 
1355
 
static Int16 big_merge(MN *mn)
 
1355
static int16_t big_merge(MN *mn)
1356
1356
{
1357
1357
 
1358
1358
 if ((wcomp.h > comp_max_h) || (wcomp.w >= sizeof (W.eh)))
1359
1359
    return 0;
1360
 
//Andrey: ����������� ����� ���������� �������� � ������ RCutP - �����
 
1360
//Andrey: определение точек разрезания вынесено в модуль RCutP - откат
1361
1361
 
1362
1362
 frame_hist (mn);
1363
1363
 if (!frame_check())
1380
1380
 BOX *box;
1381
1381
 LNSTRT * ls;
1382
1382
 BOXINT * iv;
1383
 
 Int16 i,j, row, end, lth;
 
1383
 int16_t i,j, row, end, lth;
1384
1384
 memset (&W,0,sizeof(W));
1385
1385
 i = mn->mnboxcnt;      box = (BOX *)(mn->mnfirstbox);
1386
1386
 while (--i >= 0)
1416
1416
 
1417
1417
static Bool16 frame_check()
1418
1418
{
1419
 
 Word16 hist[2*RASTER_MAX_HEIGHT+2];
1420
 
 Word16 s,bound,i;
1421
 
 Word8* pe,*pb;
1422
 
 Word16 out_4max;
 
1419
 uint16_t hist[2*RASTER_MAX_HEIGHT+2];
 
1420
 uint16_t s,bound,i;
 
1421
 uchar* pe,*pb;
 
1422
 uint16_t out_4max;
1423
1423
 memset (hist,0,sizeof(hist));
1424
1424
 pb = W.sh; pe = W.sh+wcomp.w;
1425
1425
 while (pb != pe) hist[*(pb++)]++;
1442
1442
 
1443
1443
static Bool32 frame_cut_points()
1444
1444
{
1445
 
 Int16 ncp,ndown,nups,nupe,nw,nstart;
1446
 
 Int16 add_est;
1447
 
 Int16 thick_b;
 
1445
 int16_t ncp,ndown,nups,nupe,nw,nstart;
 
1446
 int16_t add_est;
 
1447
 int16_t thick_b;
1448
1448
 W.min_est = 0x7fff; W.np = 1; thick_b = (wcomp.h < 34) ? 2 : 3;
1449
1449
 
1450
1450
if( actual_resolution>400 )
1547
1547
}
1548
1548
 
1549
1549
 
1550
 
static Int16 dist_est (Int16 est)
 
1550
static int16_t dist_est (int16_t est)
1551
1551
{
1552
1552
      if (est < 64) return 0;
1553
1553
      else
1560
1560
 
1561
1561
static void frame_select()
1562
1562
{
1563
 
 Int16 i, j, est, mest, ref, we, wr;
 
1563
 int16_t i, j, est, mest, ref, we, wr;
1564
1564
 if (W.np == 1) return;
1565
1565
 W.min_est--;
1566
1566
 W.cp[0].est = W.min_est;
1569
1569
    ref = 0;
1570
1570
    we = W.cp[i].est - W.min_est;
1571
1571
    wr = W.cp[i].xr;
1572
 
    mest = we + dist_est((Int16)(wcomp.w - wr));
 
1572
    mest = we + dist_est((int16_t)(wcomp.w - wr));
1573
1573
    for (j = i+1; j<W.np; j++)
1574
1574
     {
1575
 
      est = W.cp[j].est + we + dist_est((Int16)(W.cp[j].xl - wr));
 
1575
      est = W.cp[j].est + we + dist_est((int16_t)(W.cp[j].xl - wr));
1576
1576
      if (est < mest) { ref = j; mest = est; }
1577
1577
     }
1578
1578
    W.cp[i].est = mest; W.cp[i].ref = ref;
1581
1581
//----------------------- Frame cut ---------------------------------------
1582
1582
 
1583
1583
MN * frame_comp;
1584
 
Int16 frame_upper, frame_comp_col, frame_height;
 
1584
int16_t frame_upper, frame_comp_col, frame_height;
1585
1585
BOX * frame_end;
1586
 
static void frame_put (Word8* p, Int16 x, Int16 l, Int16 from, Int16 to);
 
1586
static void frame_put (uchar* p, int16_t x, int16_t l, int16_t from, int16_t to);
1587
1587
 
1588
1588
void frame_cut_MN_set (MN *mn)                  //AK 14.03.97 void
1589
1589
{
1592
1592
 frame_height = wcomp.h;
1593
1593
}
1594
1594
 
1595
 
Word8* frame_cut_MN (Int16 from, Int16 to)
 
1595
uchar* frame_cut_MN (int16_t from, int16_t to)
1596
1596
{
1597
 
 Int16 bw, col, x, cnt;
 
1597
 int16_t bw, col, x, cnt;
1598
1598
 BOX *bp;
1599
 
 Word8* p;
 
1599
 uchar* p;
1600
1600
 LNSTRT *lp;
1601
1601
 BOXINT *ip;
1602
1602
 to -= from; bw = (to+7) >> 3;
1622
1622
  }
1623
1623
 return work_raster;
1624
1624
}
1625
 
static Word8 start_shift[] = {255, 127, 63, 31, 15, 7, 3 ,1};
1626
 
static Word8 end_shift[] = {0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe};
1627
 
static void frame_put (Word8* p, Int16 x, Int16 l, Int16 from, Int16 to)
 
1625
static uchar start_shift[] = {255, 127, 63, 31, 15, 7, 3 ,1};
 
1626
static uchar end_shift[] = {0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe};
 
1627
static void frame_put (uchar* p, int16_t x, int16_t l, int16_t from, int16_t to)
1628
1628
{
1629
 
 Word8 b;
 
1629
 uchar b;
1630
1630
 x -= l + from; if (x < 0) { if ((l+=x) < 0) return; x = 0; }
1631
1631
 if ( x >= to) return; if (to - x < l) l = to - x;
1632
1632
 p += x >> 3; b = start_shift [x & 7]; l+= x&7;
1634
1634
 b &= end_shift[l]; *p |= b;
1635
1635
}
1636
1636
 
1637
 
static Bool16 exclude_one_piece(Int16 xl, Int16 xr, Int16 x0, Int16 y0, Int16 xmax, Int16 h)
 
1637
static Bool16 exclude_one_piece(int16_t xl, int16_t xr, int16_t x0, int16_t y0, int16_t xmax, int16_t h)
1638
1638
{
1639
1639
#ifdef _USE_LOC_
1640
1640
MN * wm;
1641
 
Word8* raster;
 
1641
uchar* raster;
1642
1642
 
1643
1643
 
1644
1644
     raster = frame_cut_MN(xl,xr);
1645
 
     wm = LOC_CLocomp (raster, (xr - xl + 7)>>3, h, y0, (Int16)(x0 + xl));
 
1645
     wm = LOC_CLocomp (raster, (xr - xl + 7)>>3, h, y0, (int16_t)(x0 + xl));
1646
1646
 
1647
1647
     while (wm && wm->mnfirstbox)
1648
1648
       {
1658
1658
#endif
1659
1659
}
1660
1660
 
1661
 
static Int32 frame_cut(MN *mn)
 
1661
static int32_t frame_cut(MN *mn)
1662
1662
{
1663
 
 Int16 xl, xr, ncp,cutn;
1664
 
 Int16 x0 = wcomp.left, y0=wcomp.upper, xmax = wcomp.w, h=wcomp.h;
 
1663
 int16_t xl, xr, ncp,cutn;
 
1664
 int16_t x0 = wcomp.left, y0=wcomp.upper, xmax = wcomp.w, h=wcomp.h;
1665
1665
 
1666
1666
 
1667
1667
 if (W.cp[0].ref == 0)
1685
1685
    }
1686
1686
   else if( xr - xl>=comp_max_w && xr - xl < 2*comp_max_w)
1687
1687
    {
1688
 
    if( !exclude_one_piece(xl, (Int16)((xl+xr)/2), x0, y0, xmax, h) )
 
1688
    if( !exclude_one_piece(xl, (int16_t)((xl+xr)/2), x0, y0, xmax, h) )
1689
1689
        break;
1690
 
    if( !exclude_one_piece((Int16)((xl+xr)/2), xr, x0, y0, xmax, h) )
 
1690
    if( !exclude_one_piece((int16_t)((xl+xr)/2), xr, x0, y0, xmax, h) )
1691
1691
        break;
1692
1692
    cutn++;
1693
1693
    }
1730
1730
 
1731
1731
static void save_prot(void)
1732
1732
        { // protocol for exernal viewer
1733
 
         Word8* p;
1734
 
         Int16 l;
 
1733
         uchar* p;
 
1734
         int16_t l;
1735
1735
         FILE *ev;
1736
 
         Word8 wr_ltr;
 
1736
         uchar wr_ltr;
1737
1737
         wr_ltr = 'c';
1738
1738
         ev=fopen("sqprot.pro","a");
1739
1739
         if (ev==NULL) ev=fopen("sqprot.pro","w");
1752
1752
        }
1753
1753
 
1754
1754
 
1755
 
extern void WriteInterval ( Word8 *p, int x , int l);
 
1755
extern void WriteInterval ( uchar *p, int x , int l);
1756
1756
static void WriteOneInterval ( int h, int b, int e, int bw, int scale)
1757
1757
{
1758
1758
if( b<0 )
1777
1777
 
1778
1778
 
1779
1779
// compress MN to work_raster
1780
 
static Bool16 scaleMN2work_raster(  MN *mn,Int16 upper, Int16 left, Int16 w, Int16 h,
 
1780
static Bool16 scaleMN2work_raster(  MN *mn,int16_t upper, int16_t left, int16_t w, int16_t h,
1781
1781
                        int     scale_2)
1782
1782
{
1783
1783
BOX    *pBox;
1787
1787
BOXINT *pAfterInts;
1788
1788
BOXINT *pInt;
1789
1789
int             xEnd, xBeg, y, hmin, hmax;
1790
 
Int16     top=upper+h, right=left+w;
 
1790
int16_t     top=upper+h, right=left+w;
1791
1791
 
1792
1792
 
1793
1793
memset( work_raster,0, wcomp.rw*wcomp.h);
1799
1799
        {
1800
1800
    if (pBox -> boxflag & BOXBEG)
1801
1801
        { // new line
1802
 
        pLine = (LNSTRT *) ((Word8 *) pBox + sizeof (BOX));
 
1802
        pLine = (LNSTRT *) ((uchar *) pBox + sizeof (BOX));
1803
1803
 
1804
1804
        xEnd = pLine -> x-wcomp.left;
1805
1805
        y    = pLine -> y-wcomp.upper;
1807
1807
        if( y>hmax )    hmax=y;
1808
1808
        xBeg = MAX(xEnd - pLine -> l,0);
1809
1809
        WriteOneInterval ( y, xBeg, MIN(xEnd,right) ,wcomp.rw,scale_2);
1810
 
        pInts = (BOXINT *) ((Word8 *) pBox + sizeof (BOX) + sizeof (LNSTRT));
 
1810
        pInts = (BOXINT *) ((uchar *) pBox + sizeof (BOX) + sizeof (LNSTRT));
1811
1811
        }
1812
1812
    else
1813
1813
        { // continue BOX
1814
 
        pInts = (BOXINT *) ((Word8 *) pBox + sizeof (BOX));
 
1814
        pInts = (BOXINT *) ((uchar *) pBox + sizeof (BOX));
1815
1815
        }
1816
1816
 
1817
 
    pAfterInts = (BOXINT *) ((Word8 *) pBox + pBox -> boxptr);
 
1817
    pAfterInts = (BOXINT *) ((uchar *) pBox + pBox -> boxptr);
1818
1818
 
1819
1819
    for (pInt = pInts;   ;     pInt++)
1820
1820
        { // cont line
1821
 
        int s=(Word8 *) pAfterInts - (Word8 *) pInt;
 
1821
        int s=(uchar *) pAfterInts - (uchar *) pInt;
1822
1822
        if( s<sizeof (BOXINT) )
1823
1823
            break;
1824
1824
        xEnd += pInt -> d;
1844
1844
#endif
1845
1845
}
1846
1846
 
1847
 
static store_MN(MN *locmn,Int16 upper, Int16 left, Int16 w, Int16 h,
 
1847
static store_MN(MN *locmn,int16_t upper, int16_t left, int16_t w, int16_t h,
1848
1848
                        int     scale_2)
1849
1849
{
1850
1850
if( !locmn )
1915
1915
        {
1916
1916
    if (pBox -> boxflag & BOXBEG)
1917
1917
        { // new line
1918
 
        pLine = (LNSTRT *) ((Word8 *) pBox + sizeof (BOX));
 
1918
        pLine = (LNSTRT *) ((uchar *) pBox + sizeof (BOX));
1919
1919
 
1920
1920
        xEnd = pLine -> x-wcomp.left;
1921
1921
        if( (xEnd>>scale_2)>255 || (pLine->l>>scale_2)>255 )
1922
1922
            return TRUE;
1923
 
        pInts = (BOXINT *) ((Word8 *) pBox + sizeof (BOX) + sizeof (LNSTRT));
 
1923
        pInts = (BOXINT *) ((uchar *) pBox + sizeof (BOX) + sizeof (LNSTRT));
1924
1924
        }
1925
1925
    else
1926
1926
            { // continue BOX
1927
 
        pInts = (BOXINT *) ((Word8 *) pBox + sizeof (BOX));
 
1927
        pInts = (BOXINT *) ((uchar *) pBox + sizeof (BOX));
1928
1928
        }
1929
1929
 
1930
 
    pAfterInts = (BOXINT *) ((Word8 *) pBox + pBox -> boxptr);
 
1930
    pAfterInts = (BOXINT *) ((uchar *) pBox + pBox -> boxptr);
1931
1931
 
1932
1932
    for (pInt = pInts;     ;      pInt++)
1933
1933
        { // cont line
1934
 
        int s=(Word8 *) pAfterInts - (Word8 *) pInt;
 
1934
        int s=(uchar *) pAfterInts - (uchar *) pInt;
1935
1935
        if( s<sizeof (BOXINT) )
1936
1936
            break;
1937
1937
        xEnd += pInt -> d;
1943
1943
return FALSE;
1944
1944
}
1945
1945
 
1946
 
Int32 sizeMN(MN *mn)
 
1946
int32_t sizeMN(MN *mn)
1947
1947
{
1948
 
Int32    s;
 
1948
int32_t    s;
1949
1949
BOX    *pBox;
1950
1950
int    nBox;
1951
1951
LNSTRT *pLine;
1968
1968
            {
1969
1969
            start=0;
1970
1970
            }
1971
 
        pLine = (LNSTRT *) ((Word8 *) pBox + sizeof (BOX));
 
1971
        pLine = (LNSTRT *) ((uchar *) pBox + sizeof (BOX));
1972
1972
        hh=1;
1973
 
        pInts = (BOXINT *) ((Word8 *) pBox + sizeof (BOX) + sizeof (LNSTRT));
 
1973
        pInts = (BOXINT *) ((uchar *) pBox + sizeof (BOX) + sizeof (LNSTRT));
1974
1974
        }
1975
1975
    else
1976
1976
        { // continue BOX
1977
 
        pInts = (BOXINT *) ((Word8 *) pBox + sizeof (BOX));
 
1977
        pInts = (BOXINT *) ((uchar *) pBox + sizeof (BOX));
1978
1978
        }
1979
1979
 
1980
 
    pAfterInts = (BOXINT *) ((Word8 *) pBox + pBox -> boxptr);
 
1980
    pAfterInts = (BOXINT *) ((uchar *) pBox + pBox -> boxptr);
1981
1981
 
1982
1982
    for (pInt = pInts;      ;   pInt++)
1983
1983
        { // cont line
1984
 
        int s=(Word8 *) pAfterInts - (Word8 *) pInt;
 
1984
        int s=(uchar *) pAfterInts - (uchar *) pInt;
1985
1985
        if( s<sizeof (BOXINT) )
1986
1986
            break;
1987
1987
        hh++;
1994
1994
}
1995
1995
 
1996
1996
// store long MN intervals to container
1997
 
static Bool16 longMN2container(  MN *mn,Int16 upper, Int16 left, Int16 w, Int16 h,
 
1997
static Bool16 longMN2container(  MN *mn,int16_t upper, int16_t left, int16_t w, int16_t h,
1998
1998
                        int     scale_2)
1999
1999
{
2000
2000
BOX    *pBox;
2004
2004
BOXINT *pAfterInts;
2005
2005
BOXINT *pInt;
2006
2006
int             xEnd, xBeg, y;
2007
 
Int32   size;
 
2007
int32_t   size;
2008
2008
int             hh, y0, start=1;
2009
2009
CCOM_lnhead *lnh={0};
2010
2010
CCOM_comp   *cmp;
2021
2021
        { // new line
2022
2022
        if( !start )
2023
2023
            {
2024
 
            CCOM_LargeNewInterval(cmp,(Int16)0,(Int16)0); // fictive interval
 
2024
            CCOM_LargeNewInterval(cmp,(int16_t)0,(int16_t)0); // fictive interval
2025
2025
            lnh->lth=4*2+4*(hh+1); // header + intervals + fictive interval
2026
2026
            lnh->h      =hh; // store actual line header
2027
2027
            }
2029
2029
            {
2030
2030
            start=0;
2031
2031
            }
2032
 
        pLine = (LNSTRT *) ((Word8 *) pBox + sizeof (BOX));
 
2032
        pLine = (LNSTRT *) ((uchar *) pBox + sizeof (BOX));
2033
2033
        hh=1;
2034
2034
        xEnd = pLine -> x-wcomp.left;
2035
2035
        y0=y    = pLine -> y-wcomp.upper;
2040
2040
        lnh->h  =0; // store actual line header
2041
2041
        lnh->row        =y;
2042
2042
        lnh->flg        =pBox->boxflag;
2043
 
        CCOM_LargeNewInterval(cmp,(Int16)xEnd,(Int16)pLine -> l);
2044
 
        pInts = (BOXINT *) ((Word8 *) pBox + sizeof (BOX) + sizeof (LNSTRT));
 
2043
        CCOM_LargeNewInterval(cmp,(int16_t)xEnd,(int16_t)pLine -> l);
 
2044
        pInts = (BOXINT *) ((uchar *) pBox + sizeof (BOX) + sizeof (LNSTRT));
2045
2045
        }
2046
2046
    else
2047
2047
        { // continue BOX
2048
2048
        lnh->flg        |=pBox->boxflag;
2049
 
        pInts = (BOXINT *) ((Word8 *) pBox + sizeof (BOX));
 
2049
        pInts = (BOXINT *) ((uchar *) pBox + sizeof (BOX));
2050
2050
        }
2051
2051
 
2052
 
    pAfterInts = (BOXINT *) ((Word8 *) pBox + pBox -> boxptr);
 
2052
    pAfterInts = (BOXINT *) ((uchar *) pBox + pBox -> boxptr);
2053
2053
 
2054
2054
    for (pInt = pInts;  ;  pInt++)
2055
2055
        { // cont line
2056
 
        int s=(Word8 *) pAfterInts - (Word8 *) pInt;
 
2056
        int s=(uchar *) pAfterInts - (uchar *) pInt;
2057
2057
        if( s<sizeof (BOXINT) )
2058
2058
            break;
2059
2059
        xEnd += pInt -> d;
2060
2060
        y++;
2061
2061
        hh++;
2062
 
        CCOM_LargeNewInterval(cmp,(Int16)xEnd,(Int16)pInt -> l);
 
2062
        CCOM_LargeNewInterval(cmp,(int16_t)xEnd,(int16_t)pInt -> l);
2063
2063
        }
2064
2064
 
2065
2065
    }
2066
 
CCOM_LargeNewInterval(cmp,(Int16)0,(Int16)0); // fictive interval
 
2066
CCOM_LargeNewInterval(cmp,(int16_t)0,(int16_t)0); // fictive interval
2067
2067
lnh->lth=4*2+4*(hh+1); // header + intervals + fictive interval
2068
2068
lnh->h  =hh; // store actual line header
2069
2069
CCOM_LargeClose(cmp);
2071
2071
{
2072
2072
        CCOM_USER_BLOCK ublock;
2073
2073
        ublock.code = CCOM_UB_SIZELINEREP;
2074
 
        ublock.data = (Word8*)&size;
 
2074
        ublock.data = (uchar*)&size;
2075
2075
        ublock.size = 4;
2076
2076
        CCOM_SetUserBlock(cmp, &ublock);
2077
2077
}
2079
2079
}
2080
2080
 
2081
2081
 
2082
 
static Int32 mn_sum(  MN *mn )
 
2082
static int32_t mn_sum(  MN *mn )
2083
2083
{
2084
2084
BOX    *pBox;
2085
2085
int    nBox;
2087
2087
BOXINT *pInts;
2088
2088
BOXINT *pAfterInts;
2089
2089
BOXINT *pInt;
2090
 
Int32     sum;
 
2090
int32_t     sum;
2091
2091
 
2092
2092
sum=0;
2093
2093
for (pBox = (BOX *) mn -> mnfirstbox, nBox = 0;
2096
2096
        {
2097
2097
    if (pBox -> boxflag & BOXBEG)
2098
2098
        { // new line
2099
 
        pLine = (LNSTRT *) ((Word8 *) pBox + sizeof (BOX));
 
2099
        pLine = (LNSTRT *) ((uchar *) pBox + sizeof (BOX));
2100
2100
 
2101
2101
        sum += pLine -> l;
2102
 
        pInts = (BOXINT *) ((Word8 *) pBox + sizeof (BOX) + sizeof (LNSTRT));
 
2102
        pInts = (BOXINT *) ((uchar *) pBox + sizeof (BOX) + sizeof (LNSTRT));
2103
2103
        }
2104
2104
    else
2105
2105
            { // continue BOX
2106
 
        pInts = (BOXINT *) ((Word8 *) pBox + sizeof (BOX));
 
2106
        pInts = (BOXINT *) ((uchar *) pBox + sizeof (BOX));
2107
2107
        }
2108
2108
 
2109
 
    pAfterInts = (BOXINT *) ((Word8 *) pBox + pBox -> boxptr);
 
2109
    pAfterInts = (BOXINT *) ((uchar *) pBox + pBox -> boxptr);
2110
2110
 
2111
2111
    for (pInt = pInts;   ;    pInt++)
2112
2112
        { // cont line
2113
 
        int s=(Word8 *) pAfterInts - (Word8 *) pInt;
 
2113
        int s=(uchar *) pAfterInts - (uchar *) pInt;
2114
2114
        if( s<sizeof (BOXINT) )
2115
2115
                break;
2116
2116
        sum += pInt->l;
2121
2121
 
2122
2122
Bool16 save_picture_scale (MN *mn)
2123
2123
{
2124
 
Int32     scale_2, scale;
2125
 
Int16     sv_upper, sv_left, sv_w, sv_h;
 
2124
int32_t     scale_2, scale;
 
2125
int16_t     sv_upper, sv_left, sv_w, sv_h;
2126
2126
MN      *locmn;
2127
2127
 
2128
2128
if( !(ExControl&Ex_Picture) )
2173
2173
    }
2174
2174
scale_2 = MIN(scale_2,MaxScale-1);
2175
2175
scale = 1<<scale_2 ;
2176
 
original_begends=(Word8)(MIN(wcomp.begs+wcomp.ends,255));
 
2176
original_begends=(uchar)(MIN(wcomp.begs+wcomp.ends,255));
2177
2177
// COMPRESSION PICTURES TO comp_max_w:comp_max_h
2178
2178
sv_upper    =wcomp.upper;
2179
2179
sv_left     =wcomp.left ;