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

« back to all changes in this revision

Viewing changes to cuneiform_src/Kern/rstr/src/skew.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:
63
63
 
64
64
#include <stdlib.h>
65
65
#include <string.h>
66
 
#include "nt_types.h"
 
66
 
67
67
#include "struct.h"
68
68
#include "func.h"
69
69
 
70
 
struct pairs {INT x,y; CHAR f;};
 
70
struct pairs {int16_t x,y; char f;};
71
71
typedef struct pairs pairs;
72
72
 
73
 
extern INT nIncline;
74
 
extern INT page_nIncline;
75
 
extern INT line_number;
76
 
extern BYTE fax1x2;
77
 
 
78
 
static INT row,row_prev;
79
 
static INT incline_prev;
80
 
static INT relab;
81
 
 
82
 
static INT skew_pool_fill(CSTR_line,pairs *);
83
 
static INT skew_pool_refill(CSTR_line ln,pairs *pool);
84
 
static INT skew_pool_refill2(CSTR_line ln,pairs *pool);
85
 
 
86
 
static INT incl_init(INT,pairs *);
87
 
static WORD skew_stat(INT,CSTR_line,INT,pairs *);
 
73
extern int16_t nIncline;
 
74
extern int16_t page_nIncline;
 
75
extern int16_t line_number;
 
76
extern uchar fax1x2;
 
77
 
 
78
static int16_t row,row_prev;
 
79
static int16_t incline_prev;
 
80
static int16_t relab;
 
81
 
 
82
static int16_t skew_pool_fill(CSTR_line,pairs *);
 
83
static int16_t skew_pool_refill(CSTR_line ln,pairs *pool);
 
84
static int16_t skew_pool_refill2(CSTR_line ln,pairs *pool);
 
85
 
 
86
static int16_t incl_init(int16_t,pairs *);
 
87
static uint16_t skew_stat(int16_t,CSTR_line,int16_t,pairs *);
88
88
static void total_skew();
89
89
 
90
90
#define DINCL  10
93
93
#define NRELABMIN 7
94
94
#define NRELABMAX 30
95
95
 
96
 
Int16 skew_corr(CSTR_line ln, INT pool_src)
 
96
int16_t skew_corr(CSTR_line ln, int16_t pool_src)
97
97
 {
98
 
 INT skew_pool_n=0,inclini;
99
 
 WORD l,l1;
 
98
 int16_t skew_pool_n=0,inclini;
 
99
 uint16_t l,l1;
100
100
 pairs skew_pool[255];
101
101
 
102
102
 if (pool_src==0)
116
116
 l=skew_stat(nIncline,ln,skew_pool_n,skew_pool);
117
117
 if (l==0)
118
118
         return nIncline;
119
 
 while ((l1=skew_stat((INT)(nIncline-1),ln,skew_pool_n,skew_pool))>l)
 
119
 while ((l1=skew_stat((int16_t)(nIncline-1),ln,skew_pool_n,skew_pool))>l)
120
120
  { nIncline--; l=l1;}
121
121
 if (nIncline==inclini)
122
 
  while ((l1=skew_stat((INT)(nIncline+1),ln,skew_pool_n,skew_pool))>l)
 
122
  while ((l1=skew_stat((int16_t)(nIncline+1),ln,skew_pool_n,skew_pool))>l)
123
123
   { nIncline++; l=l1;}
124
124
 total_skew();
125
125
 
126
126
 return nIncline;
127
127
}
128
128
 
129
 
static INT skew_pool_fill(CSTR_line ln,pairs *pool)
 
129
static int16_t skew_pool_fill(CSTR_line ln,pairs *pool)
130
130
 {
131
 
 INT /*nl,*/i;
 
131
 int16_t /*nl,*/i;
132
132
 pairs *p;
133
133
 CSTR_rast       rst=CSTR_GetFirstRaster(ln);
134
134
 CCOM_comp *com;
142
142
 com=CSTR_GetComp(rst);
143
143
 row=com->upper;
144
144
 
145
 
 //nl=(c_comp **)((PCHAR)ln+ln->dust)-&(ln->c_comp[0]);
 
145
 //nl=(c_comp **)((pchar)ln+ln->dust)-&(ln->c_comp[0]);
146
146
 //if (nl>255) nl=255;
147
147
 for (   p=pool,i=0; i<255 && rst; rst=CSTR_GetNext(rst))
148
148
  {
151
151
  if( !(attr.flg&CSTR_f_dust) )
152
152
      {
153
153
      p->x=com->left;
154
 
      p->y=(INT)(com->upper+com->h-row);//attrlin.row-1);
 
154
      p->y=(int16_t)(com->upper+com->h-row);//attrlin.row-1);
155
155
      i++;
156
156
      p++;
157
157
      }
159
159
 return i;
160
160
 }
161
161
 
162
 
static INT skew_pool_refill(CSTR_line ln,pairs *pool)
 
162
static int16_t skew_pool_refill(CSTR_line ln,pairs *pool)
163
163
 {
164
 
 INT nl;
 
164
 int16_t nl;
165
165
 pairs *p;
166
166
 cell *cl;
167
167
 CSTR_attr              attrlin;
174
174
  {
175
175
  if (cl->difflg&64 && !(cl->difflg&4)) continue;   // skip totally forbidden
176
176
  p->x=cl->r_col;
177
 
  p->y=(INT)(cl->r_row+cl->h - attrlin.row);//-1);
 
177
  p->y=(int16_t)(cl->r_row+cl->h - attrlin.row);//-1);
178
178
  p++;
179
179
  nl++;
180
180
  if (nl > 254) break;
182
182
 return nl;
183
183
 }
184
184
 
185
 
static INT skew_pool_refill2(CSTR_line ln,pairs *pool)
 
185
static int16_t skew_pool_refill2(CSTR_line ln,pairs *pool)
186
186
 {
187
 
 INT nl;
 
187
 int16_t nl;
188
188
 pairs *p;
189
189
 CSTR_attr              attrlin;
190
190
 CSTR_rast       rst=CSTR_GetFirstRaster(ln);
205
205
  if ( (attr.difflg&64) && !(attr.difflg&4))
206
206
          continue;   // skip totally forbidden
207
207
  p->x=attr.r_col;
208
 
  p->y=(INT)(attr.r_row+attr.h - attrlin.row);//-1);
 
208
  p->y=(int16_t)(attr.r_row+attr.h - attrlin.row);//-1);
209
209
  p++;
210
210
  nl++;
211
211
 }
212
212
 return nl;
213
213
}
214
214
 
215
 
static INT incl_init(INT n,pairs *pool)
 
215
static int16_t incl_init(int16_t n,pairs *pool)
216
216
 {
217
 
 INT i,incl,shift,m,d;
218
 
 LONG sx,sy,sxy,sx2,w,sigma,dd;
 
217
 int16_t i,incl,shift,m,d;
 
218
 int32_t sx,sy,sxy,sx2,w,sigma,dd;
219
219
 pairs *p;
220
220
 
221
221
 for (p=pool,sx=sy=sxy=sx2=i=0; i<n; i++,p++)
222
222
  {
223
223
  sx+=p->x;
224
224
  sy+=p->y;
225
 
  sxy+=((LONG)p->x)*(p->y);
226
 
  sx2+=((LONG)p->x)*(p->x);
 
225
  sxy+=((int32_t)p->x)*(p->y);
 
226
  sx2+=((int32_t)p->x)*(p->x);
227
227
  }
228
228
 w=(n*((sx2+128)/256)-((sx+8)/16)*((sx+8)/16));
229
229
 if (w<=0)
230
230
  {relab=0; return nIncline;}
231
231
 dd=8*(n*sxy-sx*sy);
232
 
 incl=(INT)((dd+((dd>0)?w/2:-w/2))/w);
233
 
 shift=(INT)((((sx2+128)/256)*sy-((sxy+8)/16)*((sx+8)/16)+w/2)/w);
 
232
 incl=(int16_t)((dd+((dd>0)?w/2:-w/2))/w);
 
233
 shift=(int16_t)((((sx2+128)/256)*sy-((sxy+8)/16)*((sx+8)/16)+w/2)/w);
234
234
 for (p=pool,w=i=0; i<n; i++,p++)
235
235
  {
236
 
  dd=(LONG)incl*p->x;
237
 
  d=p->y-(INT)((dd+((dd>0)?1024:-1024))/2048)-shift;
 
236
  dd=(int32_t)incl*p->x;
 
237
  d=p->y-(int16_t)((dd+((dd>0)?1024:-1024))/2048)-shift;
238
238
  if (abs(d)>100)
239
239
   d=100;
240
240
  w+=d*d;
250
250
  }
251
251
 for (p=pool,sx=sy=sxy=sx2=m=i=0; i<n; i++,p++)
252
252
  {
253
 
  dd=(LONG)incl*p->x;
254
 
  d=p->y-(INT)((dd+((dd>0)?1024:-1024))/2048)-shift;
 
253
  dd=(int32_t)incl*p->x;
 
254
  d=p->y-(int16_t)((dd+((dd>0)?1024:-1024))/2048)-shift;
255
255
  if (abs(d)<100 && d*d<=sigma)
256
256
   {
257
257
   sx+=p->x;
258
258
   sy+=p->y;
259
 
   sxy+=((LONG)p->x)*(p->y);
260
 
   sx2+=((LONG)p->x)*(p->x);
 
259
   sxy+=((int32_t)p->x)*(p->y);
 
260
   sx2+=((int32_t)p->x)*(p->x);
261
261
   p->f=1;
262
262
   m++;
263
263
   }
267
267
 if (w>0 && 3*m>2*n)
268
268
  {
269
269
  dd=8*(m*sxy-sx*sy);
270
 
  incl=(INT)((dd+((dd>0)?w/2:-w/2))/w);
271
 
  shift=(INT)((((sx2+128)/256)*sy-((sxy+8)/16)*((sx+8)/16)+w/2)/w);
 
270
  incl=(int16_t)((dd+((dd>0)?w/2:-w/2))/w);
 
271
  shift=(int16_t)((((sx2+128)/256)*sy-((sxy+8)/16)*((sx+8)/16)+w/2)/w);
272
272
  for (p=pool,w=i=0; i<n; i++,p++)
273
273
   if (p->f)
274
274
    {
275
 
    dd=(LONG)incl*p->x;
276
 
    d=p->y-(INT)((dd+((dd>0)?1024:-1024))/2048)-shift;
 
275
    dd=(int32_t)incl*p->x;
 
276
    d=p->y-(int16_t)((dd+((dd>0)?1024:-1024))/2048)-shift;
277
277
    if (abs(d)>100)
278
278
     d=100;
279
279
    w+=d*d;
292
292
 
293
293
#define HIMAX  1000
294
294
 
295
 
static WORD skew_stat(INT incl,CSTR_line ln,INT pool_n,pairs *pool)
 
295
static uint16_t skew_stat(int16_t incl,CSTR_line ln,int16_t pool_n,pairs *pool)
296
296
 {
297
 
 INT i,im,d;
298
 
 WORD l;
299
 
 BYTE hist[HIMAX];
 
297
 int16_t i,im,d;
 
298
 uint16_t l;
 
299
 uchar hist[HIMAX];
300
300
 CSTR_attr              attrlin;
301
301
 
302
302
 CSTR_GetLineAttr(ln, &attrlin);
303
 
 im=(INT)(2*attrlin.hei);
 
303
 im=(int16_t)(2*attrlin.hei);
304
304
 if (im<0 || im>=HIMAX) return 0;
305
305
 memset(hist,0,HIMAX);// Piter change im) for HIMAX;
306
306
 for (i=0; i<pool_n; i++)
307
307
  {
308
 
  d=im/2+pool[i].y-(INT)((LONG)incl*pool[i].x/2048);
 
308
  d=im/2+pool[i].y-(int16_t)((int32_t)incl*pool[i].x/2048);
309
309
  if (d>0 && d<HIMAX) hist[d]++;
310
310
  }
311
311
 for (l=i=0; i<im; i++)
312
 
  l+=(WORD)hist[i]*hist[i];
 
312
  l+=(uint16_t)hist[i]*hist[i];
313
313
 return l;
314
314
 }
315
315
 
316
316
static void total_skew()
317
317
 {
318
 
 INT totincl;
 
318
 int16_t totincl;
319
319
 
320
320
 if (relab) return;
321
321
 if (line_number>1 && abs(row-row_prev)<=DPREVL)
334
334
 
335
335
void ideal_rc(cell *c)
336
336
 {
337
 
 c->row=c->r_row-(INT)((LONG)nIncline*c->r_col/2048);
338
 
 c->col=c->r_col+(INT)((LONG)nIncline*c->r_row/2048);
 
337
 c->row=c->r_row-(int16_t)((int32_t)nIncline*c->r_col/2048);
 
338
 c->col=c->r_col+(int16_t)((int32_t)nIncline*c->r_row/2048);
339
339
 }