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

« back to all changes in this revision

Viewing changes to cuneiform_src/Kern/rneg/sources/src/searchneg/searchneg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-07-10 17:58:10 UTC
  • Revision ID: james.westby@ubuntu.com-20090710175810-rqc89d2i3tki9m89
Tags: upstream-0.7.0+dfsg
Import upstream version 0.7.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 1993-2008, Cognitive Technologies
 
3
All rights reserved.
 
4
 
 
5
����������� ��������� ��������������� � ������������� ��� � ���� ��������� ����,
 
6
��� � � �������� �����, � ����������� ��� ���, ��� ���������� ��������� �������:
 
7
 
 
8
      * ��� ��������� ��������������� ��������� ���� ������ ���������� ���������
 
9
        ���� ����������� �� ��������� �����, ���� ������ ������� � �����������
 
10
        ����� �� ��������.
 
11
      * ��� ��������� ��������������� ��������� ���� � ������������ �/��� �
 
12
        ������ ����������, ������������ ��� ���������������, ������ �����������
 
13
        ��������� ���� ���������� �� ��������� �����, ���� ������ ������� �
 
14
        ����������� ����� �� ��������.
 
15
      * �� �������� Cognitive Technologies, �� ����� �� ����������� �� �����
 
16
        ���� ������������ � �������� �������� ��������� �/��� �����������
 
17
        ���������, ���������� �� ���� ��, ��� ���������������� �����������
 
18
        ����������.
 
19
 
 
20
��� ��������� ������������� ����������� ��������� ���� �/��� ������� ������ "���
 
21
��� ����" ��� ������-���� ���� ��������, ���������� ���� ��� ���������������,
 
22
������� �������� ������������ �������� � ����������� ��� ���������� ����, �� ��
 
23
������������� ���. �� �������� ��������� ���� � �� ���� ������ ����, �������
 
24
����� �������� �/��� �������� �������������� ���������, �� � ���� ������ ��
 
25
��Ѩ� ���������������, ������� ����� �����, ���������, ����������� ���
 
26
������������� ������, ��������� � �������������� ��� ���������� ����������
 
27
������������� ������������� ��������� (������� ������ ������, ��� ������,
 
28
������� ���������, ��� ������ �/��� ������ �������, ���������� ��-�� ��������
 
29
������� ��� �/��� ������ ��������� �������� ��������� � ������� �����������,
 
30
�� �� ������������� ����� ��������), �� �� ������������� ���, ���� ���� �����
 
31
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
 
32
 
 
33
Redistribution and use in source and binary forms, with or without modification,
 
34
are permitted provided that the following conditions are met:
 
35
 
 
36
    * Redistributions of source code must retain the above copyright notice,
 
37
      this list of conditions and the following disclaimer.
 
38
    * Redistributions in binary form must reproduce the above copyright notice,
 
39
      this list of conditions and the following disclaimer in the documentation
 
40
      and/or other materials provided with the distribution.
 
41
    * Neither the name of the Cognitive Technologies nor the names of its
 
42
      contributors may be used to endorse or promote products derived from this
 
43
      software without specific prior written permission.
 
44
 
 
45
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
46
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
47
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
48
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
 
49
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
50
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
51
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
52
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
53
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
54
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
55
*/
 
56
 
 
57
#include <string.h>
 
58
#include "searchneg.h"
 
59
 
 
60
 
 
61
 
 
62
void DelIn(Handle hCPage,NegList** proot,int& nRc)
 
63
{
 
64
 NegList* root=*proot;
 
65
 NegList* nowin=root;
 
66
 NegList* nowout=root;
 
67
 NegList* temp;
 
68
 BOOL fl_cont;
 
69
 BOOL vert;
 
70
 Word8 Data[1000];
 
71
 memset (Data, 0, sizeof (Data));
 
72
 Word8* pmasp;
 
73
 Rect16 Rc;
 
74
 double blackout;
 
75
 double blackin;
 
76
 while(nowout)
 
77
 {
 
78
         if((nowout->neg).pRc[0].bottom-(nowout->neg).pRc[(nowout->neg).nRc-1].top>(nowout->neg).pRc[0].right-(nowout->neg).pRc[0].left)
 
79
                 vert=TRUE;
 
80
         else
 
81
                 vert=FALSE;
 
82
         while(nowin && nowout)
 
83
         {
 
84
                 fl_cont=FALSE;
 
85
                 if(nowin==nowout)
 
86
                 {
 
87
                         fl_cont=TRUE;
 
88
                         nowin=nowin->next;
 
89
                 }
 
90
                 if(fl_cont)
 
91
                         continue;
 
92
                 if(vert)
 
93
                         ;
 
94
                 else
 
95
                 {
 
96
                  if(!(nowin->neg.pRc[(nowin->neg).nRc-1].top>=nowout->neg.pRc[0].bottom||nowout->neg.pRc[(nowout->neg).nRc-1].top>=nowin->neg.pRc[0].bottom))
 
97
          {
 
98
            if( ((nowout->neg).pRc[0].left<(nowin->neg).pRc[0].left)&&((nowout->neg).pRc[0].right>(nowin->neg).pRc[0].left))
 
99
                        {
 
100
              Rc.bottom=(nowout->neg).pRc[0].bottom;
 
101
                          Rc.top=(nowout->neg).pRc[(nowout->neg).nRc-1].top;
 
102
                          Rc.left=(nowout->neg).pRc[0].left;
 
103
                          Rc.right=(nowin->neg).pRc[0].left;
 
104
                          pmasp=Data;
 
105
                          if(!GetMasP(&Rc,&pmasp))
 
106
                                  blackout=.0;
 
107
                          else
 
108
                              blackout=NegBlack(pmasp,Rc);
 
109
              Rc.bottom=(nowin->neg).pRc[0].bottom;
 
110
                          Rc.top=(nowin->neg).pRc[(nowin->neg).nRc-1].top;
 
111
                          Rc.left=(nowout->neg).pRc[0].right;
 
112
                          Rc.right=(nowin->neg).pRc[0].right;
 
113
                          if(Rc.right<=Rc.left)
 
114
                  blackin=.0;
 
115
                          else
 
116
                          {
 
117
               pmasp=Data;
 
118
                           if(!GetMasP(&Rc,&pmasp))
 
119
                                   blackin=.0;
 
120
               else
 
121
                               blackin=NegBlack(pmasp,Rc);
 
122
                          }
 
123
                          if(blackout>=blackin)
 
124
                          {
 
125
                                  nRc--;
 
126
                                  temp=nowin;
 
127
                                  if(root==temp)
 
128
                                          root=temp->next;
 
129
                                  nowin=nowin->next;
 
130
                                  delete temp;
 
131
                                  fl_cont=TRUE;
 
132
                          }
 
133
                          else
 
134
                          {
 
135
                                  nRc--;
 
136
                                  temp=nowout;
 
137
                                  if(root==temp)
 
138
                                          root=temp->next;
 
139
                                  nowout=nowout->next;
 
140
                                  delete temp;
 
141
                                  nowin=root;
 
142
                                  fl_cont=TRUE;
 
143
                          }
 
144
                        }
 
145
                  }
 
146
                 }
 
147
                 if(fl_cont)
 
148
                          ;
 
149
                 else
 
150
                     nowin=nowin->next;
 
151
         }
 
152
         if (nowout)
 
153
     {
 
154
        nowout=nowout->next;
 
155
            nowin=root;
 
156
     }
 
157
 }
 
158
 (*proot)=root;
 
159
}
 
160
 
 
161
double NegBlack(Word8* pmasp,Rect16 Rc)
 
162
{
 
163
 int w=Rc.right-Rc.left+1;
 
164
 const int bytewide=(w+7)/8;
 
165
 int h=Rc.bottom-Rc.top+1;
 
166
 register int i=7-(bytewide*8-w);
 
167
 int k;
 
168
 int rect=w&7;
 
169
 if(!rect)
 
170
         rect=8;
 
171
 register Word8 bytep;
 
172
 register int count_black=w*h;
 
173
 register Word8* p=pmasp;
 
174
 register Word8* pend=p+h*bytewide;
 
175
 i=1;
 
176
 for(;p<pend;p++)
 
177
 {
 
178
   bytep=(*p);
 
179
          if(i==bytewide)
 
180
          {
 
181
       for(k=0;k<rect;k++)
 
182
          count_black-=((bytep&(128>>k))>>(7-k));
 
183
           i=0;
 
184
          }
 
185
          else
 
186
          {
 
187
          count_black-=((bytep>>7)+((bytep&64)>>6)+((bytep&32)>>5)+((bytep&16)>>4)+((bytep&8)>>3)+((bytep&4)>>2)+((bytep&2)>>1)+(bytep&1));
 
188
          }
 
189
   p++;
 
190
   i++;
 
191
 }
 
192
 return (double)(count_black)/(double)(w*h);
 
193
}
 
194
 
 
195
void CutNegStr(Handle hCPage,NegList** proot,int& nRc,int skew)
 
196
{
 
197
 if(nRc<=0)
 
198
         return;
 
199
 
 
200
 int h,w;
 
201
 Word8* pmasp;
 
202
 NegList* now=(*proot);
 
203
 NegList* temp;
 
204
 Word8 Data[1000];
 
205
 BOOL fl_cont=FALSE;
 
206
 Rect16 Rc;
 
207
 memset (Data, 0, sizeof (Data));
 
208
 while(now->next)
 
209
         now=now->next;
 
210
 while(now)
 
211
 {
 
212
  fl_cont=FALSE;
 
213
 
 
214
  w=(now->neg).pRc[0].right-(now->neg).pRc[0].left+1;
 
215
  h=(now->neg).pRc[0].bottom-(now->neg).pRc[0].top+1;
 
216
  if( (h<=inf_neg_h*2) || (w<=inf_neg_w ) || (h>w) )
 
217
  {
 
218
          now=now->prev;
 
219
          fl_cont=TRUE;
 
220
  }
 
221
  if(fl_cont)
 
222
          continue;
 
223
 
 
224
  if((now->neg).rot.pmasp)
 
225
    pmasp=(now->neg).rot.pmasp;
 
226
  else
 
227
  {
 
228
        pmasp = Data;
 
229
   if(!(GetMasP((now->neg).pRc,&pmasp)) )
 
230
   {
 
231
          now=now->prev;
 
232
          fl_cont=TRUE;
 
233
   }
 
234
  }
 
235
  if(fl_cont)
 
236
          continue;
 
237
 
 
238
  NegInvert(pmasp,(now->neg).pRc[0]);
 
239
  Rc.top=now->neg.pRc->top;
 
240
  Rc.bottom=now->neg.pRc->bottom;
 
241
  RSELSTR_CutStr(&((now->neg).pRc),(now->neg).nRc,(now->neg).len_mas,pmasp,DPIX,DPIY,30);
 
242
 
 
243
  if(!(now->neg).nRc)
 
244
  {
 
245
          if(!now->prev)
 
246
                  (*proot)=now->next;
 
247
          temp=now;
 
248
          now=now->prev;
 
249
          delete temp;
 
250
          nRc--;
 
251
  }
 
252
  else
 
253
  {
 
254
         now->neg.pRc[now->neg.nRc-1].top=Rc.top;
 
255
         now->neg.pRc->bottom=Rc.bottom;
 
256
     now=now->prev;
 
257
  }
 
258
 }
 
259
 
 
260
}
 
261
 
 
262
 
 
263
void CutNeg(Handle hCPage,NegList** proot,int& nRc,int skew)
 
264
{
 
265
 int k;
 
266
 int h,w;
 
267
 Word8* pmasp;
 
268
 NegList* root=(*proot);
 
269
 NegList* now=root;
 
270
 Word8 Data[1000];
 
271
 BOOL fl_cont=FALSE;
 
272
 int bytewide;
 
273
 int rect;
 
274
 int top;
 
275
 int oldtop;
 
276
 register Word8 bytep;
 
277
 register int count_black;
 
278
 double proc;
 
279
 BOOL neg;
 
280
 Rect16 Rc;
 
281
 NegList* temp;
 
282
 int stop;
 
283
 register Word8* p;
 
284
 register Word8* pend;
 
285
 int neg_top;
 
286
 int neg_bottom;
 
287
 int neg_left;
 
288
 int neg_right;
 
289
 const int size_Rect16=sizeof(Rect16);
 
290
 
 
291
 memset (Data, 0, sizeof (Data));
 
292
 while(now)
 
293
 {
 
294
  fl_cont=FALSE;
 
295
 
 
296
 
 
297
/*  if(IsNegBlack(hCPage,now))
 
298
  {
 
299
         if((now->neg).rot.pmasp)
 
300
           RSELSTR_UnRotateRect(-skew,&((now->neg).pRc[0]),1,(now->neg).rot.Rc,(now->neg).rot.begx,(now->neg).rot.movey,(now->neg).rot.flmovey,(now->neg).rot.hi);
 
301
         DeleteRotateMas(&((now->neg).rot.pmasp),&((now->neg).rot.begx),&((now->neg).rot.movey),&((now->neg).rot.flmovey),&((now->neg).rot.hi));
 
302
     fl_cont=TRUE;
 
303
         now=now->next;
 
304
  }
 
305
  if(fl_cont)
 
306
          continue;
 
307
*/
 
308
  w=(now->neg).pRc[0].right-(now->neg).pRc[0].left+1;
 
309
  h=(now->neg).pRc[0].bottom-(now->neg).pRc[0].top+1;
 
310
  if( (h<=inf_neg_h*3) || (w<=inf_neg_w ) )
 
311
  {
 
312
         if((now->neg).rot.pmasp)
 
313
           RSELSTR_UnRotateRect(-skew,&((now->neg).pRc[0]),1,(now->neg).rot.Rc,(now->neg).rot.begx,(now->neg).rot.movey,(now->neg).rot.flmovey,(now->neg).rot.hi);
 
314
         DeleteRotateMas(&((now->neg).rot.pmasp),&((now->neg).rot.begx),&((now->neg).rot.movey),&((now->neg).rot.flmovey),&((now->neg).rot.hi));
 
315
          now=now->next;
 
316
          fl_cont=TRUE;
 
317
  }
 
318
  if(fl_cont)
 
319
          continue;
 
320
 
 
321
  if((now->neg).rot.pmasp)
 
322
    pmasp=(now->neg).rot.pmasp;
 
323
 
 
324
  else
 
325
  {
 
326
        pmasp = Data;
 
327
   if(!(GetMasP(now->neg.pRc,&pmasp)) )
 
328
   {
 
329
           now=now->next;
 
330
          fl_cont=TRUE;
 
331
   }
 
332
  }
 
333
  if(fl_cont)
 
334
          continue;
 
335
 
 
336
    bytewide=(w+7)/8;
 
337
    rect=w&7;
 
338
        if(!rect)
 
339
                rect=8;
 
340
    top=(now->neg).pRc[0].top;
 
341
    oldtop=top;
 
342
    count_black=0;
 
343
    neg=TRUE;
 
344
        pend=pmasp+(bytewide-1);
 
345
        p=pmasp;
 
346
        neg_top=(now->neg).pRc[0].top;
 
347
        neg_bottom=(now->neg).pRc[0].bottom;
 
348
        neg_left=(now->neg).pRc[0].left;
 
349
        neg_right=(now->neg).pRc[0].right;
 
350
        stop=neg_bottom-top+1-inf_neg_h;
 
351
 
 
352
    while(stop>0)
 
353
        {
 
354
         while(root->prev)
 
355
                 root=root->prev;
 
356
 
 
357
     count_black=w;
 
358
     for(;p<pend;p++)
 
359
         {
 
360
      bytep=(*p);
 
361
 
 
362
          count_black-=((bytep>>7)+((bytep&64)>>6)+((bytep&32)>>5)+((bytep&16)>>4)+((bytep&8)>>3)+((bytep&4)>>2)+((bytep&2)>>1)+(bytep&1));
 
363
 
 
364
         }
 
365
     bytep=(*p);
 
366
       for(k=0;k<rect;k++)
 
367
          count_black-=((bytep&(128>>k))>>(7-k));
 
368
         p++;
 
369
     proc=((double)(count_black))/((double)(w));
 
370
 
 
371
     if(neg==TRUE)
 
372
         {
 
373
           if(proc<=neg_cut_white)
 
374
           {
 
375
                neg=FALSE;
 
376
                if(IsNegSize(top-neg_top+1,w)&&(!(IfNegIn(root,nRc,oldtop,top,neg_left,neg_right))) )
 
377
                {
 
378
            Rc.top=oldtop;
 
379
                        Rc.bottom=top;
 
380
                        Rc.left=(now->neg).pRc[0].left;
 
381
                        Rc.right=(now->neg).pRc[0].right;
 
382
                        if((now->neg).rot.pmasp)
 
383
            {
 
384
              RSELSTR_UnRotateRect(-skew,&Rc,1,(now->neg).rot.Rc,(now->neg).rot.begx,(now->neg).rot.movey,(now->neg).rot.flmovey,(now->neg).rot.hi);
 
385
            }
 
386
                        temp=NULL;
 
387
                        temp=new NegList(Rc);
 
388
            memcpy(&(temp->neg.rot.Rc),&(now->neg.rot.Rc),size_Rect16);
 
389
                        now->AddNeg(temp);
 
390
            PostRotate(temp,skew);
 
391
                        nRc++;
 
392
                }
 
393
           }
 
394
         }
 
395
     else
 
396
         {
 
397
          if(proc>=neg_cut_black)
 
398
          {
 
399
                neg=TRUE;
 
400
        oldtop=top;
 
401
          }
 
402
          else
 
403
                 oldtop=top+1;
 
404
         }
 
405
     top++;
 
406
         stop--;
 
407
         pend+=bytewide;
 
408
        }
 
409
 
 
410
    while(root->prev)
 
411
                root=root->prev;
 
412
    if(((now->neg).pRc[0].bottom-oldtop+1<inf_neg_h)||((IfNegIn(root,nRc,oldtop,top,(now->neg).pRc[0].left,(now->neg).pRc[0].right))) )
 
413
        {
 
414
                temp=now;
 
415
                now=now->next;
 
416
                if(!temp->prev)
 
417
                        root=now;
 
418
            delete temp;
 
419
                nRc--;
 
420
        }
 
421
        else
 
422
        {
 
423
          (now->neg).pRc[0].top=oldtop;
 
424
          if((now->neg).rot.pmasp)
 
425
      {
 
426
           RSELSTR_UnRotateRect(-skew,&((now->neg).pRc[0]),1,(now->neg).rot.Rc,(now->neg).rot.begx,(now->neg).rot.movey,(now->neg).rot.flmovey,(now->neg).rot.hi);
 
427
           PostRotate(now,skew);
 
428
      }
 
429
          DeleteRotateMas(&((now->neg).rot.pmasp),&((now->neg).rot.begx),&((now->neg).rot.movey),&((now->neg).rot.flmovey),&((now->neg).rot.hi));
 
430
      now=now->next;
 
431
        }
 
432
 }
 
433
 
 
434
 (*proot)=root;
 
435
 
 
436
 
 
437
}
 
438
 
 
439
BOOL IfNegIn(NegList* root,int nRc,int top,int bottom,int left,int right)
 
440
{
 
441
 int i;
 
442
 int d_top,d_bot;
 
443
 NegList* now=root;
 
444
 int s_top=3*(DPIY+1)/300;
 
445
 int s_bot=3*(DPIY+1)/300;
 
446
 int neg_top;
 
447
 int neg_bottom;
 
448
 int neg_left;
 
449
 int neg_right;
 
450
 
 
451
         for(i=0;i<nRc;i++)
 
452
         {
 
453
                 neg_top=(now->neg).pRc[0].top;
 
454
                 neg_bottom=(now->neg).pRc[0].bottom;
 
455
                 neg_left=(now->neg).pRc[0].left;
 
456
                 neg_right=(now->neg).pRc[0].right;
 
457
                 if((neg_top==top)&&(neg_bottom==bottom)&&(neg_left==left)&&(neg_right==right))
 
458
                         continue;
 
459
         d_top=top-neg_top;
 
460
                 d_bot=neg_bottom-bottom;
 
461
                 if((d_top<s_top)&&(d_bot<s_bot))
 
462
                 {
 
463
           if( ((neg_left<=left)&&(neg_right>left)) || ((neg_left>left)&&(right>neg_left)) )
 
464
                           return TRUE;
 
465
                 }
 
466
                now=now->next;
 
467
         }
 
468
         return FALSE;
 
469
}
 
470
 
 
471
 
 
472
 
 
473
BOOL SearchNegBySize(CCOM_handle hCCOM, Handle hCPage,NegList** ROOT,int& nRC)
 
474
{
 
475
 NegList* root=NULL;
 
476
 NegList* temp=NULL;
 
477
 Rect16 Rc;
 
478
 CCOM_comp * pcomp;
 
479
 pcomp = CCOM_GetFirst (hCCOM, NULL);
 
480
 if(pcomp==NULL)
 
481
         return FALSE;
 
482
 PAGEINFO info = {0};
 
483
 GetPageInfo(hCPage,&info);
 
484
 DPIX=info.DPIX;
 
485
 DPIY=info.DPIY;
 
486
 
 
487
 InitRc(&Rc,pcomp);
 
488
 if( IsNegSize(Rc.bottom-Rc.top+1,Rc.right-Rc.left+1) )
 
489
 {
 
490
   if(!(root=new NegList(Rc) ))
 
491
          return FALSE;
 
492
   nRC++;
 
493
 }
 
494
 
 
495
 for(;;)
 
496
 {
 
497
  pcomp = CCOM_GetNext (pcomp, NULL);
 
498
 
 
499
  if (pcomp==NULL)
 
500
        break;
 
501
 
 
502
  InitRc(&Rc,pcomp);
 
503
  if( IsNegSize(Rc.bottom-Rc.top+1,Rc.right-Rc.left+1) )
 
504
  {
 
505
   if(!root)
 
506
   {
 
507
    if(!(root=new NegList(Rc) ))
 
508
          return FALSE;
 
509
        nRC++;
 
510
   }
 
511
   else
 
512
   {
 
513
    temp=NULL;
 
514
    temp=new NegList(Rc);
 
515
    root->AddNeg(temp);
 
516
    if(temp)
 
517
        {
 
518
                root=temp;
 
519
        nRC++;
 
520
        }
 
521
   }
 
522
  }
 
523
 }
 
524
 
 
525
 (*ROOT)=root;
 
526
 return TRUE;
 
527
}
 
528
 
 
529
 
 
530
void SearchNegByBlack(Handle hCPage,NegList** proot,int& nRC)
 
531
{
 
532
 NegList* now=(*proot);
 
533
 NegList* temp;
 
534
 while(now)
 
535
 {
 
536
  if(!(IsNegBlack(hCPage,now)) )
 
537
  {
 
538
   temp=now;
 
539
   now=now->next;
 
540
   if(!temp->prev)
 
541
           (*proot)=now;
 
542
   delete temp;
 
543
   nRC--;
 
544
  }
 
545
  else
 
546
          now=now->next;
 
547
 }
 
548
}
 
549
 
 
550
/*
 
551
BOOL IfDrob(Handle hCPage,Rect16* pRc,int num,CCOM_comp * pdr)
 
552
{
 
553
 int inteps=2;
 
554
 int delta=5;
 
555
 int oldbot=pRc[num].bottom;
 
556
 int oldtop=pRc[num].top;
 
557
 int left=pdr->left;
 
558
 int oldright=pRc[num].right;
 
559
 int oldleft=pRc[num].left;
 
560
 int delta_top=pRc[num].top-pdr->upper;
 
561
 if(delta_top<0) delta_top=-delta_top;
 
562
 int delta_bottom=pRc[num].bottom-pdr->upper-pdr->h+1;
 
563
 if(delta_bottom<0) delta_bottom=-delta_bottom;
 
564
 
 
565
 if( (left-oldright)>inteps || (left-oldright)<0 )
 
566
         return FALSE;
 
567
 if( (delta_top>delta) || (delta_bottom>delta) )
 
568
         return FALSE;
 
569
 
 
570
 if(oldtop>pdr->upper) pRc[num].top=pdr->upper;
 
571
 if(oldbot<pdr->upper+pdr->h-1) pRc[num].bottom=pdr->upper+pdr->h-1;
 
572
 pRc[num].left=oldright;
 
573
 pRc[num].right=left;
 
574
 if( !(IsNegBlack(hCPage,now,num)) )
 
575
 {
 
576
  pRc[num].top=oldtop;
 
577
  pRc[num].bottom=oldbot;
 
578
  pRc[num].right=oldright;
 
579
  pRc[num].left=oldleft;
 
580
  return FALSE;
 
581
 }
 
582
 else
 
583
 {
 
584
  pRc[num].left=oldleft;
 
585
  pRc[num].right=pdr->left+pdr->w-1;
 
586
 }
 
587
 
 
588
 return TRUE;
 
589
}
 
590
*/
 
591
 
 
592
 
 
593
 
 
594
void NormNeg(Handle hCPage,NegList* now,NegList** proot,int& nRc)
 
595
{
 
596
 double black_del;
 
597
 int i,j,k;
 
598
 Word8* pmasp;
 
599
 Rect16* Rc=(now->neg).pRc;
 
600
 int w;
 
601
 int h;
 
602
 int rect;
 
603
 register Word8 bytep;
 
604
 register int count_black;
 
605
 int topp,lp;
 
606
 double proc;
 
607
 int stop;
 
608
 register Word8* p;
 
609
 register Word8* pend;
 
610
 Word8* pbeg;
 
611
 
 
612
 
 
613
 if((now->neg).rot.pmasp)
 
614
 {
 
615
         pmasp=(now->neg).rot.pmasp;
 
616
 }
 
617
 else
 
618
 {
 
619
  Word8 Data[1000];
 
620
  memset (Data, 0, sizeof (Data));
 
621
        pmasp = Data;
 
622
 
 
623
  if(!(GetMasP(Rc,&pmasp)) )
 
624
  {
 
625
 
 
626
         //������� - �� �����
 
627
 
 
628
   BOOL top=FALSE,left=FALSE,right=FALSE,bottom=FALSE;
 
629
 
 
630
          while((*Rc).top<=0)
 
631
                  ((*Rc).top)++;
 
632
          while( ((*Rc).bottom+1)>Height )
 
633
          ((*Rc).bottom)--;
 
634
 
 
635
 
 
636
          while((*Rc).left<0)
 
637
                  ((*Rc).left)++;
 
638
          while( ((*Rc).right+1)>Width )
 
639
          ((*Rc).right)--;
 
640
 
 
641
   int prewide=(((*Rc).right-(*Rc).left+8)/8)*8;
 
642
   if( ((*Rc).left+prewide)>Width )
 
643
            (*Rc).right-=8;
 
644
 
 
645
   pmasp = Data;
 
646
   if(!(GetMasP(Rc,&pmasp)) )
 
647
   {
 
648
//��������!!! ����� �� ������ ���������������
 
649
    if((*Rc).top<5) top=TRUE;
 
650
    if((*Rc).left<5) left=TRUE;
 
651
    if((*Rc).right>(Int16)(Width)-5) right=TRUE;
 
652
    if((*Rc).bottom>(Int16)(Height)-5) bottom=TRUE;
 
653
    k=10;
 
654
    for(i=0;i<k;i++)
 
655
    {
 
656
          if(top) ((*Rc).top)++;
 
657
          if(bottom) ((*Rc).bottom)--;
 
658
          if(left) ((*Rc).left)++;
 
659
          if(right) ((*Rc).right)--;
 
660
      pmasp = Data;
 
661
      if( GetMasP(Rc,&pmasp) )
 
662
                break;
 
663
    }
 
664
 
 
665
    if(i==k)
 
666
    {
 
667
     if(now==(*proot))
 
668
          (*proot)=now->next;
 
669
     delete now;
 
670
     nRc--;
 
671
    return;
 
672
    }
 
673
   }
 
674
  }
 
675
 }
 
676
 w=(*Rc).right-(*Rc).left+1;
 
677
 h=(*Rc).bottom-(*Rc).top+1;
 
678
 const int bytewide=(w+7)/8;
 
679
 
 
680
 i=7-(bytewide*8-w);
 
681
 j=128;
 
682
 rect=w&7;
 
683
 if(!rect)
 
684
         rect=8;
 
685
 topp=0;
 
686
 lp=0;
 
687
 stop=h-topp-inf_neg_h;
 
688
 
 
689
 black_del=sup_neg_black_del;
 
690
 p=pmasp;
 
691
 pend=p+(bytewide-1);
 
692
 i=w-lp;
 
693
 while(stop>0)
 
694
 {
 
695
//  if( (h-topp)>(w-lp) ) black_del=sup_neg_black_del;
 
696
//  else black_del=weak_neg_black_del;
 
697
  count_black=i;
 
698
  for(;p<pend;p++)
 
699
  {
 
700
          bytep=(*p);
 
701
          count_black-=((bytep>>7)+((bytep&64)>>6)+((bytep&32)>>5)+((bytep&16)>>4)+((bytep&8)>>3)+((bytep&4)>>2)+((bytep&2)>>1)+(bytep&1));
 
702
  }
 
703
  bytep=(*p);
 
704
       for(k=0;k<rect;k++)
 
705
          count_black-=((bytep&(128>>k))>>(7-k));
 
706
  p++;
 
707
  proc=((double)(count_black))/((double)(i));
 
708
  if(proc>black_del)
 
709
          break;
 
710
  topp++;
 
711
  stop--;
 
712
  pend+=bytewide;
 
713
 }
 
714
 
 
715
 if( !(IsNegSize(h-topp,w-lp)) )
 
716
 {
 
717
  if(now==(*proot))
 
718
         (*proot)=now->next;
 
719
  delete now;
 
720
  nRc--;
 
721
  return;
 
722
 }
 
723
 
 
724
 stop=(h-topp)-inf_neg_h;
 
725
 black_del=sup_neg_black_del;
 
726
 pend=pmasp+(h-1)*bytewide;
 
727
 p=pend+(bytewide-1);
 
728
 i=w-lp;
 
729
 while(stop>0)
 
730
 {
 
731
//  if( (h-topp)>(w-lp) ) black_del=sup_neg_black_del;
 
732
//  else black_del=weak_neg_black_del;
 
733
  count_black=i;
 
734
  bytep=(*p);
 
735
       for(k=0;k<rect;k++)
 
736
          count_black-=((bytep&(128>>k))>>(7-k));
 
737
  p--;
 
738
  for(;p>=pend;p--)
 
739
  {
 
740
          bytep=(*p);
 
741
          count_black-=((bytep>>7)+((bytep&64)>>6)+((bytep&32)>>5)+((bytep&16)>>4)+((bytep&8)>>3)+((bytep&4)>>2)+((bytep&2)>>1)+(bytep&1));
 
742
  }
 
743
  proc=((double)(count_black))/((double)(i));
 
744
  if(proc>black_del)
 
745
          break;
 
746
  h--;
 
747
  stop--;
 
748
  pend-=bytewide;
 
749
 }
 
750
 
 
751
 if( !(IsNegSize(h-topp,w-lp))  )
 
752
 {
 
753
  if(now==(*proot))
 
754
         (*proot)=now->next;
 
755
  delete now;
 
756
  nRc--;
 
757
  return;
 
758
 }
 
759
 
 
760
 if( (h-topp)<(w-lp) )
 
761
         black_del=sup_neg_black_del-.2;
 
762
 else
 
763
         black_del=weak_neg_black_del;
 
764
 
 
765
 stop=(w-lp-inf_neg_h);
 
766
 pbeg=pmasp+topp*bytewide+(lp>>3);
 
767
 i=h-topp-1;
 
768
 pend=pbeg+i*bytewide;
 
769
 i=h-topp;
 
770
 while(stop>0)
 
771
 {
 
772
  pbeg=pmasp+topp*bytewide+(lp>>3);
 
773
  pend=pbeg+i*bytewide;
 
774
  count_black=i;
 
775
  switch(lp&7)
 
776
  {
 
777
  case 0:
 
778
  for(p=pbeg;p<=pend;p+=bytewide)
 
779
  {
 
780
   count_black-=((*p)>>7);
 
781
  }
 
782
  break;
 
783
  case 1:
 
784
  for(p=pbeg;p<=pend;p+=bytewide)
 
785
  {
 
786
   count_black-=(((*p)&64)>>6);
 
787
  }
 
788
  break;
 
789
  case 2:
 
790
  for(p=pbeg;p<=pend;p+=bytewide)
 
791
  {
 
792
   count_black-=(((*p)&32)>>5);
 
793
  }
 
794
  break;
 
795
  case 3:
 
796
  for(p=pbeg;p<=pend;p+=bytewide)
 
797
  {
 
798
   count_black-=(((*p)&16)>>4);
 
799
  }
 
800
  break;
 
801
  case 4:
 
802
  for(p=pbeg;p<=pend;p+=bytewide)
 
803
  {
 
804
   count_black-=(((*p)&8)>>3);
 
805
  }
 
806
  break;
 
807
  case 5:
 
808
  for(p=pbeg;p<=pend;p+=bytewide)
 
809
  {
 
810
   count_black-=(((*p)&4)>>2);
 
811
  }
 
812
  break;
 
813
  case 6:
 
814
  for(p=pbeg;p<=pend;p+=bytewide)
 
815
  {
 
816
   count_black-=(((*p)&2)>>1);
 
817
  }
 
818
  break;
 
819
  case 7:
 
820
  for(p=pbeg;p<=pend;p+=bytewide)
 
821
  {
 
822
   count_black-=((*p)&1);
 
823
  }
 
824
  pbeg++;
 
825
  pend++;
 
826
  break;
 
827
  default:break;
 
828
  }
 
829
  proc=((double)(count_black))/((double)(h-topp));
 
830
  if(proc>black_del)
 
831
          break;
 
832
  lp++;
 
833
  stop--;
 
834
 }
 
835
 if( !(IsNegSize(h-topp,w-lp)) )
 
836
 {
 
837
  if(now==(*proot))
 
838
         (*proot)=now->next;
 
839
  delete now;
 
840
  nRc--;
 
841
   return;
 
842
 }
 
843
 
 
844
 if( (h-topp)<(w-lp) )
 
845
         black_del=sup_neg_black_del-.2;
 
846
 else
 
847
         black_del=weak_neg_black_del;
 
848
 
 
849
 stop=(w-lp-inf_neg_h);
 
850
 pbeg=pmasp+topp*bytewide+((w-1)>>3);
 
851
 i=h-topp-1;
 
852
 pend=pbeg+i*bytewide;
 
853
 i=h-topp;
 
854
 while(stop>0)
 
855
 {
 
856
  pbeg=pmasp+topp*bytewide+((w-1)>>3);
 
857
  pend=pbeg+i*bytewide;
 
858
  count_black=i;
 
859
  switch(w&7)// real need w-1!!!
 
860
  {
 
861
  case 1:
 
862
  for(p=pbeg;p<=pend;p+=bytewide)
 
863
  {
 
864
   count_black-=((*p)>>7);
 
865
  }
 
866
  pbeg--;
 
867
  pend--;
 
868
  break;
 
869
  case 2:
 
870
  for(p=pbeg;p<=pend;p+=bytewide)
 
871
  {
 
872
   count_black-=(((*p)&64)>>6);
 
873
  }
 
874
  break;
 
875
  case 3:
 
876
  for(p=pbeg;p<=pend;p+=bytewide)
 
877
  {
 
878
   count_black-=(((*p)&32)>>5);
 
879
  }
 
880
  break;
 
881
  case 4:
 
882
  for(p=pbeg;p<=pend;p+=bytewide)
 
883
  {
 
884
   count_black-=(((*p)&16)>>4);
 
885
  }
 
886
  break;
 
887
  case 5:
 
888
  for(p=pbeg;p<=pend;p+=bytewide)
 
889
  {
 
890
   count_black-=(((*p)&8)>>3);
 
891
  }
 
892
  break;
 
893
  case 6:
 
894
  for(p=pbeg;p<=pend;p+=bytewide)
 
895
  {
 
896
   count_black-=(((*p)&4)>>2);
 
897
  }
 
898
  break;
 
899
  case 7:
 
900
  for(p=pbeg;p<=pend;p+=bytewide)
 
901
  {
 
902
   count_black-=(((*p)&2)>>1);
 
903
  }
 
904
  break;
 
905
  case 0:
 
906
  for(p=pbeg;p<=pend;p+=bytewide)
 
907
  {
 
908
   count_black-=((*p)&1);
 
909
  }
 
910
  break;
 
911
  default:break;
 
912
  }
 
913
  proc=((double)(count_black))/((double)(h-topp));
 
914
  if(proc>black_del)
 
915
          break;
 
916
  w--;
 
917
  stop--;
 
918
 }
 
919
 if( !(IsNegSize(h-topp-2,w-lp-2)) )
 
920
 {
 
921
  if(now==(*proot))
 
922
         (*proot)=now->next;
 
923
  delete now;
 
924
  nRc--;
 
925
  return;
 
926
 }
 
927
 
 
928
 (*Rc).right=(*Rc).left+w-1-1;
 
929
 (*Rc).left+=lp+1;
 
930
 (*Rc).bottom=(*Rc).top+h-1-1;
 
931
 (*Rc).top+=topp+1;
 
932
}
 
933
 
 
934
 
 
935
void NegMoveMas(Rect16* pRc,int& nRc,int num)
 
936
{
 
937
 int i;
 
938
  for(i=num;i<(nRc-1);i++)
 
939
  {
 
940
          pRc[i].left=pRc[i+1].left;
 
941
      pRc[i].top=pRc[i+1].top;
 
942
          pRc[i].right=pRc[i+1].right;
 
943
          pRc[i].bottom=pRc[i+1].bottom;
 
944
  }
 
945
  nRc--;
 
946
}
 
947
/*
 
948
void NegMoveMas(Rotating* rot,int nRc,int num)
 
949
{
 
950
  Rotating r;
 
951
  r.begx=rot[num].begx;
 
952
  r.flmovey=rot[num].flmovey;
 
953
  r.hi=rot[num].hi;
 
954
  r.movey=rot[num].movey;
 
955
  r.pmasp=rot[num].pmasp;
 
956
        for(int i=num;i<nRc-1;i++)
 
957
        {
 
958
                rot[i].begx=rot[i+1].begx;
 
959
                rot[i].flmovey=rot[i+1].flmovey;
 
960
                rot[i].hi=rot[i+1].hi;
 
961
                rot[i].movey=rot[i+1].movey;
 
962
                rot[i].pmasp=rot[i+1].pmasp;
 
963
        }
 
964
   rot[i].begx=r.begx;
 
965
   rot[i].flmovey=r.flmovey;
 
966
   rot[i].hi=r.hi;
 
967
   rot[i].movey=r.movey;
 
968
   rot[i].pmasp=r.pmasp;
 
969
   DeleteRotateMas(rot[i].pmasp,rot[i].begx,rot[i].movey,rot[i].flmovey,rot[i].hi);
 
970
}
 
971
*/
 
972
void PMoveMas(double* p,int nRc,int num)
 
973
{
 
974
 int i;
 
975
  for(i=num;i<(nRc-1);i++)
 
976
          p[i]=p[i+1];
 
977
 
 
978
}
 
979
 
 
980
void NegMoveMasR(Rect16* pRc,int& nRc,int num)
 
981
{
 
982
 int i;
 
983
  for(i=nRc;i>num;i--)
 
984
  {
 
985
          pRc[i].left=pRc[i-1].left;
 
986
      pRc[i].top=pRc[i-1].top;
 
987
          pRc[i].right=pRc[i-1].right;
 
988
          pRc[i].bottom=pRc[i-1].bottom;
 
989
  }
 
990
  nRc++;
 
991
}
 
992
 
 
993
 
 
994
BOOL IsNegSize(Int16 h,Int16 w)
 
995
{
 
996
 if( (h<inf_neg_h) || (w<inf_neg_h) ) return FALSE;
 
997
 if( (h<inf_neg_w) && (w<inf_neg_w) ) return FALSE;
 
998
 return TRUE;
 
999
}
 
1000
 
 
1001
BOOL IsNegBlack(Handle hCPage,NegList* now)
 
1002
{
 
1003
 int i,j,k;
 
1004
 Word8 *pmasp;
 
1005
 if((now->neg).rot.pmasp)
 
1006
   pmasp=(now->neg).rot.pmasp;
 
1007
 else
 
1008
 {
 
1009
  Word8 Data[1000];
 
1010
  memset (Data, 0, sizeof (Data));
 
1011
        pmasp = Data;
 
1012
  if(!(GetMasP(now->neg.pRc,&pmasp)) )
 
1013
  {
 
1014
   while(IsNegSize((now->neg).pRc[0].bottom-(now->neg).pRc[0].top+1,(now->neg).pRc[0].right-(now->neg).pRc[0].left+1) )
 
1015
   {
 
1016
          ((now->neg).pRc[0].top)++;
 
1017
          ((now->neg).pRc[0].bottom)--;
 
1018
          ((now->neg).pRc[0].left)++;
 
1019
          ((now->neg).pRc[0].right)--;
 
1020
       pmasp = Data;
 
1021
      if( GetMasP((now->neg).pRc,&pmasp) )
 
1022
                break;
 
1023
   }
 
1024
   pmasp = Data;
 
1025
   if(!(GetMasP((now->neg).pRc,&pmasp)) )
 
1026
    return FALSE;
 
1027
  }
 
1028
 }
 
1029
 int w=(now->neg).pRc[0].right-(now->neg).pRc[0].left+1;
 
1030
 int h=(now->neg).pRc[0].bottom-(now->neg).pRc[0].top+1;
 
1031
 const int bytewide=(w+7)/8;
 
1032
 register int count_black=w*h;
 
1033
 register Word8 bytep;
 
1034
 i=7-(bytewide*8-w);
 
1035
 j=128;
 
1036
 int rect=w&7;
 
1037
 if(!rect)
 
1038
         rect=8;
 
1039
 
 
1040
 register Word8* p=pmasp;
 
1041
 const Word8* pend=p+h*bytewide;
 
1042
 i=1;
 
1043
 for(;p<pend;p++)
 
1044
 {
 
1045
   bytep=(*p);
 
1046
          if(i==bytewide)
 
1047
          {
 
1048
       for(k=0;k<rect;k++)
 
1049
          count_black-=((bytep&(128>>k))>>(7-k));
 
1050
           i=0;
 
1051
          }
 
1052
          else
 
1053
          {
 
1054
          count_black-=((bytep>>7)+((bytep&64)>>6)+((bytep&32)>>5)+((bytep&16)>>4)+((bytep&8)>>3)+((bytep&4)>>2)+((bytep&2)>>1)+(bytep&1));
 
1055
          }
 
1056
   p++;
 
1057
   i++;
 
1058
 }
 
1059
 double proc;
 
1060
 proc=((double)(count_black))/((double)(w*h));
 
1061
 
 
1062
 if(proc>inf_neg_black)
 
1063
     return TRUE;
 
1064
 else
 
1065
         return FALSE;
 
1066
}
 
1067
 
 
1068
 
 
1069
BOOL GetMasP(Handle hCPage,Rect16 Rc,Word8** ppmasp)
 
1070
{
 
1071
    int prewide;
 
1072
        int left=Rc.left;
 
1073
        int h=Rc.bottom-Rc.top+1;
 
1074
        int w=Rc.right-Rc.left+1;
 
1075
        int upper=Rc.top-1;
 
1076
        if( (w%8)==0)
 
1077
                prewide=w;
 
1078
        else
 
1079
        {prewide=w/8+1;
 
1080
         prewide*=8;
 
1081
        }
 
1082
 
 
1083
        PAGEINFO info = {0};
 
1084
        CIMAGEInfoDataInGet DataInto = {0};
 
1085
        CIMAGEInfoDataOutGet DataOut = {0};
 
1086
        Word8 Name[CPAGE_MAXNAME];
 
1087
        Bool ret;
 
1088
        int i;
 
1089
 
 
1090
        /*  1. ���������� � ������� ����� �����������.  */
 
1091
        DataInto.dwHeight   = (Word32)(h);
 
1092
        DataInto.dwWidth    = (Word32)(prewide);
 
1093
        DataInto.wByteWidth = (Word16)(prewide/8);
 
1094
        DataInto.dwX        = left;
 
1095
        DataInto.dwY        = upper;
 
1096
        DataInto.MaskFlag   = 0x00;
 
1097
    GetPageInfo(hCPage,&info);
 
1098
        for (i=0; i<CPAGE_MAXNAME; i++)
 
1099
                Name[i] = ImageName[i];
 
1100
        DataOut.dwWidth    = DataInto.dwWidth;
 
1101
        DataOut.dwHeight   = DataInto.dwHeight;
 
1102
        DataOut.wByteWidth = DataInto.wByteWidth;
 
1103
        DataOut.byBit      = (Word16)info.BitPerPixel;
 
1104
        DataOut.lpData     = *ppmasp;
 
1105
 
 
1106
        /*  5. ������ ����� �����������.  */
 
1107
        ret = CIMAGE_GetData (Name, &DataInto, &DataOut);
 
1108
        if (!ret)
 
1109
                return FALSE;
 
1110
        if (DataOut.lpData==NULL)
 
1111
                return FALSE;
 
1112
        *ppmasp = DataOut.lpData;
 
1113
        return TRUE;
 
1114
}
 
1115
 
 
1116
BOOL GetMasP(Rect16* pRc,Word8** ppmasp)
 
1117
{
 
1118
        *ppmasp=pNegImage->GetPmasp(pRc);
 
1119
        if(*ppmasp==NULL)
 
1120
                return FALSE;
 
1121
        return TRUE;
 
1122
}
 
1123
 
 
1124
void PrintFrameComp(Handle hCPage,Rect16* pRc,int num)
 
1125
{
 
1126
 int i,j,k,bytewide;
 
1127
 Word8 bytep;
 
1128
 Word8 Data[1000];
 
1129
 
 
1130
 int h=pRc[num].bottom-pRc[num].top+1;
 
1131
 int w=pRc[num].right-pRc[num].left+1;
 
1132
 bytewide=(w)/8;
 
1133
 if( ((w)%8) != 0)
 
1134
         bytewide++;
 
1135
 Word8* pmasp;
 
1136
 memset (Data, 0, sizeof (Data));
 
1137
 pmasp = Data;
 
1138
 if( !(GetMasP(&(pRc[num]),&pmasp)) )
 
1139
         return;
 
1140
 printf("up:");
 
1141
 i=7-(bytewide*8-w);
 
1142
 j=128;
 
1143
 int rect=j>>i;
 
1144
 for(j=0;j<(bytewide-1);j++)
 
1145
         {
 
1146
          bytep=pmasp[j];
 
1147
          for(k=128;k>=1;k=k>>1)
 
1148
           if( (bytep&k)==0 ) printf("b");
 
1149
           else printf("w");
 
1150
         }
 
1151
         bytep=pmasp[j];
 
1152
     for(k=128;k>=rect;k=k>>1)
 
1153
       if( (bytep&k)==0 ) printf("b");
 
1154
           else printf("w");
 
1155
 
 
1156
 printf("\ndown:");
 
1157
 for(j=0;j<(bytewide-1);j++)
 
1158
         {
 
1159
          bytep=pmasp[(h-1)*bytewide+j];
 
1160
          for(k=128;k>=1;k=k>>1)
 
1161
           if( (bytep&k)==0 ) printf("b");
 
1162
           else printf("w");
 
1163
         }
 
1164
         bytep=pmasp[(h-1)*bytewide+j];
 
1165
     for(k=128;k>=rect;k=k>>1)
 
1166
       if( (bytep&k)==0 ) printf("b");
 
1167
           else printf("w");
 
1168
 
 
1169
 printf("\nleft:");
 
1170
 for(i=0;i<h;i++)
 
1171
  {bytep=pmasp[i*bytewide];
 
1172
       if( (bytep&128)==0 ) printf("b");
 
1173
           else printf("w");
 
1174
  }
 
1175
 
 
1176
 printf("\nright:");
 
1177
 for(i=1;i<=h;i++)
 
1178
  {bytep=pmasp[i*bytewide-1];
 
1179
       if( (bytep&rect)==0 ) printf("b");
 
1180
           else printf("w");
 
1181
  }
 
1182
 printf("\n");
 
1183
}
 
1184
 
 
1185
BOOL InitNegMas(Rect16** ppRc,int len)
 
1186
{
 
1187
        (*ppRc)=NULL;
 
1188
        if(!((*ppRc)=new Rect16[len]))
 
1189
                return FALSE;
 
1190
        return TRUE;
 
1191
}
 
1192
 
 
1193
 
 
1194
BOOL InitNegMas(RecVersions** ppRc,int len)
 
1195
{
 
1196
        (*ppRc)=NULL;
 
1197
        if(!((*ppRc)= new RecVersions[len]))
 
1198
                return FALSE;
 
1199
        return TRUE;
 
1200
}
 
1201
 
 
1202
BOOL InitNegMas(UniVersions** ppRc,int len)
 
1203
{
 
1204
        (*ppRc)=NULL;
 
1205
        if(!((*ppRc)= new UniVersions[len]))
 
1206
                return FALSE;
 
1207
        return TRUE;
 
1208
}
 
1209
 
 
1210
 
 
1211
BOOL InitNegMas(CCOM_comp*** ppRc,int len)
 
1212
{
 
1213
        (*ppRc)=NULL;
 
1214
        if(!((*ppRc)=new CCOM_comp*[len]))
 
1215
                return FALSE;
 
1216
        return TRUE;
 
1217
}
 
1218
 
 
1219
void DelNegMas(Rect16 **masp)
 
1220
{
 
1221
        delete[] (*masp);
 
1222
        (*masp)=NULL;
 
1223
}
 
1224
 
 
1225
void DelNegMas(RecVersions *masp)
 
1226
{
 
1227
        delete[] masp;
 
1228
}
 
1229
 
 
1230
void DelNegMas(UniVersions *masp)
 
1231
{
 
1232
        delete[] masp;
 
1233
}
 
1234
 
 
1235
void DelNegMas(CCOM_comp **masp)
 
1236
{
 
1237
        delete[] masp;
 
1238
}
 
1239
 
 
1240
 
 
1241
BOOL AddLenNegMas(Rect16** ppRc,int& len,int add)
 
1242
{Rect16 *dop;
 
1243
 int i;
 
1244
 if(!(InitNegMas(&dop,len)) )
 
1245
         return FALSE;
 
1246
 for(i=0;i<len;i++)
 
1247
         dop[i]=(*ppRc)[i];
 
1248
 DelNegMas(ppRc);
 
1249
 if(!(InitNegMas(ppRc,len+add)) )
 
1250
 {
 
1251
         (*ppRc)=dop;
 
1252
         return FALSE;
 
1253
 }
 
1254
 for(i=0;i<len;i++)
 
1255
         (*ppRc)[i]=dop[i];
 
1256
 len+=add;
 
1257
 DelNegMas(&dop);
 
1258
 return TRUE;
 
1259
}
 
1260
 
 
1261
BOOL AddLenNegMas(CCOM_comp*** ppRc,int& len,int add)
 
1262
{CCOM_comp **dop;
 
1263
 int i;
 
1264
 if(!(InitNegMas(&dop,len)) )
 
1265
         return FALSE;
 
1266
 for(i=0;i<len;i++)
 
1267
         dop[i]=(*ppRc)[i];
 
1268
 DelNegMas(*ppRc);
 
1269
 if(!(InitNegMas(ppRc,len+add)) )
 
1270
 {
 
1271
         (*ppRc)=dop;
 
1272
         return FALSE;
 
1273
 }
 
1274
 for(i=0;i<len;i++)
 
1275
         (*ppRc)[i]=dop[i];
 
1276
 len+=add;
 
1277
 DelNegMas(dop);
 
1278
 return TRUE;
 
1279
}
 
1280
 
 
1281
void InitRc(Rect16* pRc,CCOM_comp * pcomp)
 
1282
{
 
1283
 pRc->left   = pcomp->left;
 
1284
 pRc->right  = pcomp->left + pcomp->w - 1;
 
1285
 pRc->top    = pcomp->upper;
 
1286
 pRc->bottom = pcomp->upper + pcomp->h - 1;
 
1287
}
 
1288
 
 
1289
 
 
1290
void InitRc(Rect16* pRc,int nRc,CCOM_comp * pcomp)
 
1291
{
 
1292
 pRc[nRc].left   = pcomp->left;
 
1293
 pRc[nRc].right  = pcomp->left + pcomp->w - 1;
 
1294
 pRc[nRc].top    = pcomp->upper;
 
1295
 pRc[nRc].bottom = pcomp->upper + pcomp->h - 1;
 
1296
}
 
1297
 
 
1298
void NegInvert(Word8* pmasp,Rect16 N)
 
1299
{
 
1300
        Word8* p=pmasp;
 
1301
        Word8* pend=pmasp+(N.bottom-N.top+1)*( (N.right-N.left+8)/8 );
 
1302
        for(;p<pend;p++)
 
1303
                (*p)=~(*p);
 
1304
}
 
1305
 
 
1306
int absolut(int x)
 
1307
{
 
1308
        if(x<0)
 
1309
                return -x;
 
1310
        else
 
1311
                return x;
 
1312
}
 
1313
 
 
1314
void PostRotate(NegList* now,int skew)
 
1315
{
 
1316
    Rect16 Rc;
 
1317
    Rect16 Rect;
 
1318
    const int size_Rect16=sizeof(Rect16);
 
1319
    memcpy(&Rc,&(now->neg.rot.Rc),size_Rect16);
 
1320
    memcpy(&Rect,(now->neg.pRc),size_Rect16);
 
1321
    const int h=Rc.bottom-Rc.top+1;
 
1322
 
 
1323
    if(h<3*(Rect.bottom-Rect.top))
 
1324
        return;
 
1325
 
 
1326
    if(skew>0)
 
1327
    {
 
1328
        Rect.left+=((Rc.bottom-Rect.bottom)*skew)/2048;
 
1329
        Rect.right-=((Rect.top-Rc.top)*skew)/2048;
 
1330
    }
 
1331
    else
 
1332
    {
 
1333
        Rect.left+=((Rc.top-Rect.top)*skew)/2048;
 
1334
        Rect.right-=((Rect.bottom-Rc.bottom)*skew)/2048;
 
1335
    }
 
1336
 
 
1337
    if(Rect.left>=Rect.right)
 
1338
        Rect.right=Rect.left+1;
 
1339
 
 
1340
    memcpy(now->neg.pRc,&Rect,size_Rect16);
 
1341
}
 
1342
 
 
1343
 
 
1344
 
 
1345
/*union of two strogo more massivs
 
1346
 
 
1347
#include<stdio.h>
 
1348
#include<stdlib.h>
 
1349
void un(float [],float [],float [],int);
 
1350
 
 
1351
main()
 
1352
{float *a,*b,*c,s;int n,i=0;FILE *f,*g;
 
1353
printf("Enter N\n");scanf("%d",&n);
 
1354
a=(float*)malloc(n*sizeof(float));
 
1355
b=(float*)malloc(n*sizeof(float));
 
1356
c=(float*)malloc((2*n+1)*sizeof(float));
 
1357
do{f=fopen("a.dat","r");g=fopen("b.dat","r");}while((f==NULL)||(g==NULL));
 
1358
while(fscanf(f,"%f",&s)>0){a[i]=s;i++;printf("%f ",s);}fclose(f);
 
1359
i=0;printf("\n");
 
1360
while(fscanf(g,"%f",&s)>0){b[i]=s;i++;printf("%f ",s);}fclose(g);printf("\n");
 
1361
un(a,b,c,n);i=0;
 
1362
while(c[i]!='\0'){printf("%f ",c[i]);i++;}
 
1363
return;}
 
1364
 
 
1365
void un(float a[],float b[],float c[],int n)
 
1366
{int i,j,l=0,m=0,d,e=0,k;float x;
 
1367
for(i=0; i<n; i++){x=b[i];d=n;
 
1368
while(e!=d){k=(d+e)/2;if(x>a[k]) e=k+1;else d=k;}
 
1369
if(x==a[d]){c[l]=a[m];l++;m++;continue;}
 
1370
for(j=m ; j<d ; j++){c[l]=a[m];l++;m++;}
 
1371
c[l]=x;l++;} c[l]='\0';
 
1372
return;}
 
1373
 
 
1374
*/