~ubuntu-branches/debian/experimental/cuneiform/experimental

« back to all changes in this revision

Viewing changes to cuneiform_src/Kern/rimage/sources/main/crrotator.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
// CRRotator.cpp: implementation of the CRRotator class.
 
58
//
 
59
//////////////////////////////////////////////////////////////////////
 
60
#include <memory.h>
 
61
#include <math.h>
 
62
#include <stdlib.h>
 
63
 
 
64
#include "ctdib.h"
 
65
#include "crrotator.h"
 
66
#include "crimemory.h"
 
67
#include "resource.h"
 
68
#include "minmax.h"
 
69
 
 
70
//////////////////////////////////////////////////////////////////////
 
71
 
 
72
static Word32 BitsInHalfByte[16] =
 
73
{//0x0  0x1  0x2  0x3  0x4  0x5  0x6  0x7  0x8  0x9  0xa  0xb  0xc  x0d  0xe  0xf
 
74
        0,   1,   1,   2,   1,   2,   2,   3,   1,   2,   2,   3,   2,   3,   3,   4   };
 
75
 
 
76
        static Word32 HalfBytetoFourBytes[16] =
 
77
{// 0x0         0x01        0x02        0x03
 
78
        0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
 
79
 // 0x04        0x05        0x06        0x07
 
80
        0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
 
81
 //     0x08        0x09        0x0a        0x0b
 
82
        0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
 
83
 //     0x0c        0x0d        0x0e        0x0f
 
84
        0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff,
 
85
};
 
86
static Word8 FourBytestoLeftHalfByte[16] =
 
87
{ 0x00, 0x10, 0x20, 0x30,
 
88
  0x40, 0x50, 0x60, 0x70,
 
89
  0x80, 0x90, 0xa0, 0xb0,
 
90
  0xc0, 0xd0, 0xe0, 0xf0
 
91
};
 
92
static Word8 FourBytestoRightHalfByte[16] =
 
93
{ 0x00, 0x01, 0x02, 0x03,
 
94
  0x04, 0x05, 0x06, 0x07,
 
95
  0x08, 0x09, 0x0a, 0x0b,
 
96
  0x0c, 0x0d, 0x0e, 0x0f
 
97
};
 
98
static Word8 MaskForRightShift[9] =
 
99
{
 
100
//  00000000   00000001   00000011   00000111   00001111
 
101
        0x00,      0x01,      0x03,      0x07,      0xf,
 
102
//  00011111   00111111   01111111   11111111
 
103
        0x1f,      0x3f,      0x7f,      0xff
 
104
};
 
105
static Word8 MaskForLeftShift[9] =
 
106
{
 
107
//  00000000   10000000   11000000   11100000   11110000
 
108
        0x00,      0x80,      0xc0,      0xe0,      0xf0,
 
109
//  11111000   11111100   11111110   11111111
 
110
        0xf8,      0xfc,      0xfe,      0xff
 
111
};
 
112
static Word8 OneBitMask[8] =
 
113
{
 
114
//  1-� �������
 
115
//  00000001   00000010   00000100   00001000
 
116
//      0x01,      0x02,      0x04,      0x08,
 
117
//  00010000   00100000   01000000   10000000
 
118
//      0x10,      0x20,      0x40,      0x80
 
119
//  2-� �������
 
120
//  10000000   01000000   00100000   00010000
 
121
        0x80,      0x40,      0x20,      0x10,
 
122
//  00001000   00000100   00000010   00000001
 
123
        0x08,      0x04,      0x02,      0x01
 
124
};
 
125
//////////////////////////////////////////////////////////////////////
 
126
// Construction/Destruction
 
127
//////////////////////////////////////////////////////////////////////
 
128
//
 
129
 
 
130
void CRRotator::ResetItself()
 
131
{
 
132
        AtX              = 0;
 
133
        AtY              = 0;
 
134
        ToX              = 0;
 
135
        ToY              = 0;
 
136
        mfCos            = 0.0;
 
137
        mfSin            = 0.0;
 
138
        mfTang           = 0.0;
 
139
        mwDescewedHeight = 0;
 
140
        mwDescewedWidth  = 0;
 
141
        mwOriginalHeight = 0;
 
142
        mwOriginalWidth  = 0;
 
143
        mwTablesRange    = 0;
 
144
        mbEnableHS       = TRUE;
 
145
        mbEnableVS       = TRUE;
 
146
        mbEnableVSS      = TRUE;
 
147
        mpProgressor     = NULL;
 
148
        BufferForGray    = NULL;
 
149
        hBufferForGray   = NULL;
 
150
        HShiftTable      = NULL;
 
151
        hHShiftTable     = NULL;
 
152
        VShiftTable      = NULL;
 
153
        hVShiftTable     = NULL;
 
154
        VShiftLenght     = NULL;
 
155
        hVShiftLenght    = NULL;
 
156
 
 
157
}
 
158
 
 
159
CRRotator::CRRotator()
 
160
{
 
161
        ResetItself();
 
162
}
 
163
//////////////////////////////////////////////////////////////////////
 
164
//
 
165
CRRotator::CRRotator(PCRProgressor pProgressIndicator)
 
166
{
 
167
        ResetItself();
 
168
        mpProgressor = pProgressIndicator;
 
169
}
 
170
///////////////////////////////////////////////////////////////////////////////////////
 
171
//
 
172
CRRotator::~CRRotator()
 
173
{
 
174
        FreeWorkBuffers();
 
175
}
 
176
///////////////////////////////////////////////////////////////////////////////////////
 
177
//
 
178
 
 
179
Bool32 CRRotator::Rotate(PCTDIB cDIBIn, PCTDIB cDIBOut, Int32 Num, Int32 Denum)
 
180
{
 
181
        Bool32  Ret = FALSE;
 
182
        Float80   fNum    = (Float80)Num;
 
183
        Float80   fDenum  = (Float80)Denum;
 
184
        Float80   fG      = sqrt( fNum * fNum + fDenum * fDenum );
 
185
 
 
186
        if ( Num == 0 || Denum == 0)
 
187
        {
 
188
                SetReturnCode_rimage(IDS_RIMAGE_ZERO_NUMERATOR_OR_DENUMERATOR);
 
189
                return FALSE;
 
190
        }
 
191
 
 
192
        /*
 
193
        if ( cDIBIn->GetPixelSize() == 4 )
 
194
        {
 
195
                SetReturnCode_rimage(IDS_RIMAGE_UNDER_CONSTRUCTION);
 
196
                return FALSE;
 
197
        }
 
198
        */
 
199
 
 
200
        mfTang=  fNum / fDenum;
 
201
        mfCos =  fDenum / fG;
 
202
        mfSin =  fNum / fG;
 
203
 
 
204
        if (  fabs(mfTang) > CTROTATOR_MAX_TANG )
 
205
        {
 
206
                SetReturnCode_rimage(IDS_RIMAGE_ANGLE_GREAT_MAXIMUM);
 
207
                return FALSE;
 
208
        }
 
209
 
 
210
        if ( fabs(mfTang) < CTROTATOR_MIN_TANG )
 
211
        {
 
212
                SetReturnCode_rimage(IDS_RIMAGE_ANGLE_LEAST_MINIMUM);
 
213
                return FALSE;
 
214
        }
 
215
 
 
216
        if ( !ConstructOutDIB(cDIBIn, cDIBOut, FALSE) )
 
217
                return FALSE;
 
218
        try
 
219
        {
 
220
                FreeWorkBuffers();
 
221
                Ret = Descew(cDIBIn, cDIBOut);
 
222
        }
 
223
 
 
224
        catch ( Word32 wExit )
 
225
        {
 
226
                if ( wExit = IDS_RIMAGE_EXIT_BY_USER)
 
227
                {
 
228
                        SetReturnCode_rimage(IDS_RIMAGE_EXIT_BY_USER);
 
229
                }
 
230
                else
 
231
                {
 
232
                        SetReturnCode_rimage(IDS_RIMAGE_UNKNOWN_ERROR);
 
233
                }
 
234
 
 
235
                FreeWorkBuffers();
 
236
                Ret =  FALSE;
 
237
        }
 
238
 
 
239
        return Ret;
 
240
}
 
241
/////////////////////////////////////////////////////////////////////////////////////////////////////
 
242
Bool32 CRRotator::Descew(PCTDIB cDIBIn, PCTDIB cDIBOut )
 
243
{
 
244
        # ifndef max
 
245
        #    define     MAX(a,b)             ( (a) > (b) ? (a) : (b) )
 
246
        # endif
 
247
        Bool32 Ret = TRUE;
 
248
        Word32 Line;
 
249
        Word32 wBitLenght = cDIBIn->GetPixelSize();
 
250
//      Word32 wLines = cDIBIn->GetLinesNumber();
 
251
//      Word32 wLineW = cDIBIn->GetLineWidth();
 
252
        Word32 wLineBytesW   = cDIBIn->GetLineWidthInBytes();
 
253
        Word32 wLineBytesWTo = cDIBOut->GetLineWidthInBytes();
 
254
        Word32 HorisontalShiftInBytes = (((wBitLenght * HorisontalShift) + 7) / 8);
 
255
        Int32  Direction = (mfTang > 0 ? 1 : -1);
 
256
        Int32  ToShift;
 
257
        PWord8 pToCopy;
 
258
 
 
259
        mwOriginalHeight = cDIBIn->GetLinesNumber();
 
260
        mwOriginalWidth  = cDIBIn->GetLineWidth();
 
261
        mwDescewedHeight = cDIBOut->GetLinesNumber();
 
262
        mwDescewedWidth  = cDIBOut->GetLineWidth();
 
263
        mwTablesRange    = MAX (mwDescewedHeight, mwDescewedWidth);
 
264
 
 
265
 
 
266
        AllocWorkBuffers(TRUE);
 
267
        PrepareTables(mwTablesRange, mwDescewedWidth - 1);
 
268
 
 
269
        /////////////
 
270
        //�������� ��������.
 
271
        mpProgressor->Start();
 
272
 
 
273
        for ( Line = 0; Line < mwDescewedHeight; Line++)
 
274
        {
 
275
 
 
276
                if ( mpProgressor->SetStep( (Line / mwDescewedHeight) * 100 ) )
 
277
                {
 
278
                        mpProgressor->Finish();
 
279
                        throw IDS_RIMAGE_EXIT_BY_USER;
 
280
                }
 
281
 
 
282
                memset(BufferForGray, BitFillforGray, HorisontalShiftInBytes);
 
283
                memset(BufferForGray + wLineBytesWTo - HorisontalShiftInBytes, BitFillforGray, HorisontalShiftInBytes);
 
284
 
 
285
                switch ( wBitLenght )
 
286
                {
 
287
                case 8:
 
288
                case 24:
 
289
                case 32:
 
290
                        ComposeLineG(cDIBIn, Direction, Line, mwDescewedWidth);
 
291
                        break;
 
292
                case 1:
 
293
                        //// ���������� ������ � ������ �������
 
294
                        // ��������! ������ ������������ �������!!!!!
 
295
                        ComposeLineLA(cDIBIn, Direction, Line, mwDescewedWidth);
 
296
                        //�������� ����� ������
 
297
                        SetEndLineLA(Line, mwOriginalWidth, wLineBytesWTo);
 
298
                        //// �������� �� �����������
 
299
                        ToShift = HShiftTable[Line]%8;             //(Int32)( (i * dTan) + 0.5) % 8
 
300
 
 
301
                        if ( ToShift != 0 )
 
302
                        {
 
303
                                ShiftLineLA(ToShift, wLineBytesWTo + HorisontalShiftInBytes - 1);
 
304
                        }
 
305
                        break;
 
306
                case 4:
 
307
                        ComposeLine4(cDIBIn, Direction, Line, mwDescewedWidth);
 
308
                default:
 
309
                        break;
 
310
                }
 
311
                        // �������� ������ � �������� ���
 
312
                pToCopy = (PWord8)(Direction > 0 ? cDIBOut->GetPtrToLine(Line) :
 
313
                                                   cDIBOut->GetPtrToLine(mwDescewedHeight - Line - 1));
 
314
                if (pToCopy )
 
315
                {
 
316
                        memcpy(pToCopy, BufferForGray, wLineBytesWTo);
 
317
                }
 
318
        }
 
319
 
 
320
        mpProgressor->Finish();
 
321
 
 
322
        return Ret;
 
323
}
 
324
 
 
325
void CRRotator::ComposeLineLA(PCTDIB cDIBIn, Int32 iDirect, Word32 wLine, Word32 wBuffLen)
 
326
{
 
327
        Word32 j;
 
328
        Word32 StartByte;
 
329
        Word32 EndByte;
 
330
        Word32 FulBytes;
 
331
        Word32 Bits;
 
332
        Int32  PosInBuff;
 
333
        Word32 Copy = 0;
 
334
        PWord8 PixFrom;
 
335
        Word8  LastByte;
 
336
        Word32 wLines = cDIBIn->GetLinesNumber();
 
337
 
 
338
        for ( j = 0; j < wBuffLen; )
 
339
        {
 
340
                StartByte = j / 8; //������ ������
 
341
//              EndByte   = (j + VShiftLenght[j])/8; //��������� ����������
 
342
                EndByte   = (j - 1 + VShiftLenght[j])/8; //��������� ����������
 
343
 
 
344
                FulBytes = EndByte - StartByte + 1;
 
345
//              Bits     = (j + VShiftLenght[j]) - EndByte * 8;
 
346
                Bits     = j - StartByte * 8;
 
347
 
 
348
                if ( VShiftLenght[j] == 0 )
 
349
                {
 
350
                        j++;
 
351
                        continue;
 
352
                }
 
353
 
 
354
                // ���� ���� ������ �������� ��������
 
355
                PixFrom = NULL;
 
356
                PosInBuff = ( HShiftTable[wLine]) / 8 + StartByte;
 
357
                if ( wLine + VShiftTable[j] >= AtY && wLine + VShiftTable[j] < ToY )
 
358
                {
 
359
                        if ( iDirect > 0 )
 
360
                        {
 
361
                                PixFrom = (PWord8)cDIBIn->GetPtrToPixel(j,wLine + VShiftTable[j] - AtY);
 
362
                        }
 
363
                        else
 
364
                        {
 
365
                                PixFrom = (PWord8)cDIBIn->GetPtrToPixel(j,wLines - (wLine + VShiftTable[j] - AtY));
 
366
                        }
 
367
                }
 
368
                //����� ������������ ������ ���������� ������ ����
 
369
                if ( j != 0  && Bits > 0 && mbEnableVSS)
 
370
                {
 
371
                        LastByte = 0x00;
 
372
                        LastByte |= *(BufferForGray + PosInBuff)&MaskForLeftShift[Bits];
 
373
                }
 
374
 
 
375
                if ( PixFrom )
 
376
                {
 
377
                        // �������� ��������� �����
 
378
                        if (EndByte > cDIBIn->GetUsedLineWidthInBytes() - 1)
 
379
                        {
 
380
                                EndByte = cDIBIn->GetUsedLineWidthInBytes() - 1;
 
381
                                FulBytes = EndByte - StartByte + 1;
 
382
                        }
 
383
 
 
384
                        memcpy(BufferForGray + PosInBuff,PixFrom, FulBytes );
 
385
                }
 
386
                else  //  if ( pixfrom )
 
387
                {
 
388
                        memset(BufferForGray + PosInBuff,BitFillforGray, FulBytes );
 
389
                }
 
390
                //�� ����� ��������� �������
 
391
                if ( Bits > 0 && j != 0 && mbEnableVSS)
 
392
                {
 
393
                        LastByte |= *(BufferForGray + PosInBuff)&MaskForRightShift[8 - Bits];
 
394
                        *(BufferForGray + PosInBuff) = LastByte;
 
395
                }
 
396
 
 
397
                Copy += FulBytes * 8;
 
398
                j+= VShiftLenght[j];
 
399
        }
 
400
}
 
401
 
 
402
void CRRotator::ComposeLine4(PCTDIB cDIBIn, Int32 iDirect, Word32 wLine, Word32 wBuffLen)
 
403
{
 
404
        Word32 j;
 
405
        Word32 StartByte;
 
406
        Word32 EndByte;
 
407
        Word32 FulBytes;
 
408
        Word32 Pixels;
 
409
        Int32  PosInBuff;
 
410
        Word32 Copy = 0;
 
411
        PWord8 PixFrom;
 
412
        Word8  LastByte;
 
413
        Word32 wLines = cDIBIn->GetLinesNumber();
 
414
 
 
415
        for ( j = 0; j < wBuffLen; )
 
416
        {
 
417
                StartByte = j / 2; //������ ������
 
418
                EndByte   = (j + VShiftLenght[j])/2; //��������� ����������
 
419
 
 
420
                FulBytes = EndByte - StartByte + 1;
 
421
                Pixels   = (j + VShiftLenght[j]) - EndByte * 2;
 
422
 
 
423
 
 
424
                if ( VShiftLenght[j] == 0 )
 
425
                {
 
426
                        j++;
 
427
                        continue;
 
428
                }
 
429
 
 
430
                // ���� ���� ������ �������� ��������
 
431
                PixFrom = NULL;
 
432
                PosInBuff = ( HShiftTable[wLine]) / 2 + StartByte;
 
433
 
 
434
                if ( wLine + VShiftTable[j] >= AtY && wLine + VShiftTable[j] < ToY )
 
435
                {
 
436
                        if ( iDirect > 0 )
 
437
                        {
 
438
                                PixFrom = (PWord8)cDIBIn->GetPtrToPixel(j,wLine + VShiftTable[j] - AtY);
 
439
                        }
 
440
                        else
 
441
                        {
 
442
                                PixFrom = (PWord8)cDIBIn->GetPtrToPixel(j,wLines - (wLine + VShiftTable[j] - AtY));
 
443
                        }
 
444
                }
 
445
                //����� ������������ ������ ���������� ������ ����
 
446
                if ( j != 0  && Pixels > 0 && mbEnableVSS)
 
447
                {
 
448
                        LastByte = 0x00;
 
449
                        LastByte |= *(BufferForGray + PosInBuff)&MaskForLeftShift[Pixels];
 
450
                }
 
451
 
 
452
                if ( PixFrom )
 
453
                {
 
454
                        // �������� ��������� �����
 
455
                        memcpy(BufferForGray + PosInBuff,PixFrom, FulBytes );
 
456
                }
 
457
                else  //  if ( pixfrom )
 
458
                {
 
459
                        memset(BufferForGray + PosInBuff,BitFillforGray, FulBytes );
 
460
                }
 
461
                //�� ����� ��������� �������
 
462
                if ( Pixels > 0 && j != 0 && mbEnableVSS)
 
463
                {
 
464
                        LastByte |= *(BufferForGray + PosInBuff)&MaskForRightShift[8 - Pixels];
 
465
                        *(BufferForGray + PosInBuff) = LastByte;
 
466
                }
 
467
 
 
468
                Copy += FulBytes * 2;
 
469
                j+= VShiftLenght[j];
 
470
        }
 
471
}
 
472
 
 
473
void CRRotator::SetEndLineLA(Word32 Line, Word32 wLineW, Word32 wLineBytes)
 
474
{
 
475
        Word32 StartByte = wLineW/8 + HShiftTable[Line]/8;
 
476
        Word32 EndByte   = wLineBytes;
 
477
        Word32 Bits      = wLineW + (HShiftTable[Line]/8)*8 - StartByte*8;
 
478
        Word8  LastByte;
 
479
 
 
480
        if ( Bits > 0 )
 
481
        {
 
482
                LastByte = 0x00;
 
483
                LastByte  |= *(BufferForGray + StartByte)&MaskForLeftShift[Bits];
 
484
                LastByte  |= BitFillforGray&MaskForRightShift[8 - Bits];
 
485
        }
 
486
 
 
487
        if ( (Int32)(EndByte - StartByte) > 0)
 
488
                memset(BufferForGray + StartByte, BitFillforGray, (EndByte - StartByte));
 
489
 
 
490
        if ( Bits > 0 )
 
491
                *(BufferForGray + StartByte) = LastByte;
 
492
}
 
493
 
 
494
void CRRotator::PrepareTables( Word32 wMax, Word32 wCheck)
 
495
{
 
496
        Word32 i;
 
497
        Int32  Shift;
 
498
        Int32  PrevS;
 
499
        Int32  PrevI;
 
500
        Float80 dmTan = (mfTang > 0 ? mfTang : -mfTang);
 
501
 
 
502
        for (PrevS = PrevI = i = 0; i < wMax; i++ )
 
503
        {
 
504
                Shift = (Int32)( (i * dmTan) + 0.5) ;
 
505
 
 
506
                if ( i < AtY )
 
507
                        HShiftTable[i] = Shift;
 
508
                else
 
509
                        Shift = (Shift < 0 ? 0 : Shift);
 
510
 
 
511
                HShiftTable[i] = Shift /*( Shift < HorisontalShift ? Shift : HorisontalShift )*/;
 
512
 
 
513
                VShiftTable[i] = ( Shift < VerticalShift ? Shift : VerticalShift );
 
514
 
 
515
                VShiftLenght[i] = 0;
 
516
                if ( PrevS != Shift || i == wCheck)
 
517
                {
 
518
                        VShiftLenght[PrevI] = i - PrevI;
 
519
                        PrevI = i;
 
520
                }
 
521
 
 
522
                PrevS = Shift;
 
523
        }
 
524
}
 
525
 
 
526
void CRRotator::ShiftLineLA(Word32 LocalShift, Word32 wBytesTo )
 
527
{
 
528
        Word32 LocalUnshift = 8 - LocalShift;
 
529
        Word32 ShiftedByte;
 
530
 
 
531
        for ( ShiftedByte = wBytesTo;
 
532
                  ShiftedByte > 0;
 
533
                  ShiftedByte-- )
 
534
        {
 
535
                BufferForGray[ShiftedByte] = BufferForGray[ShiftedByte]>>LocalShift;
 
536
                BufferForGray[ShiftedByte] &= MaskForRightShift[LocalUnshift];
 
537
                BufferForGray[ShiftedByte] |= ( BufferForGray[ShiftedByte - 1]<<LocalUnshift )&MaskForLeftShift[LocalShift];
 
538
        }
 
539
 
 
540
        BufferForGray[0] |= BitFillforGray&MaskForLeftShift[LocalShift];
 
541
 
 
542
 
 
543
}
 
544
///////////////////////////////////////////////////////////////////////////////////////
 
545
//
 
546
///////////////////////////////////////////////////////////////////////////////////////////////////
 
547
Bool32 CRRotator::Roll(PCTDIB cDIBIn, PCTDIB cDIBOut, Int32 Num, Int32 Denum)
 
548
{
 
549
        Float80   fNum    = (Float80)Num;
 
550
        Float80   fDenum  = (Float80)Denum;
 
551
        Float80   fG      = sqrt( fNum * fNum + fDenum * fDenum );
 
552
 
 
553
        mfTang =  fNum / fDenum;
 
554
        mfCos  =  fDenum / fG;
 
555
        mfSin  =  fNum / fG;
 
556
        mdDIBOut = cDIBOut;
 
557
 
 
558
        /*
 
559
        if ( mfTang > CTROTATOR_MAX_TANG || mfTang < CTROTATOR_MIN_TANG )
 
560
                return FALSE;
 
561
        */
 
562
 
 
563
        if ( !ConstructOutDIB(cDIBIn, cDIBOut, TRUE) )
 
564
                return FALSE;
 
565
 
 
566
        if ( !DescewGray( cDIBIn, cDIBOut) )
 
567
        {
 
568
                return FALSE;
 
569
        }
 
570
 
 
571
        return TRUE;
 
572
}
 
573
/////////////////////////////////////////////////////////////////////////////////////////////////////
 
574
Bool32 CRRotator::ConstructOutDIB(PCTDIB cDIBIn, PCTDIB cDIBOut, Bool32 Gray)
 
575
{
 
576
        Word32  NewWidth;
 
577
        Word32  NewHeigth;
 
578
        Word32  dpmX;
 
579
        Word32  dpmY;
 
580
        CTDIBRGBQUAD  Quad;
 
581
 
 
582
        if ( Gray )
 
583
        {
 
584
                HorisontalShift =  (Int32)((cDIBIn->GetLinesNumber() * mfSin) + 0.5);
 
585
                HorisontalShift -= (Int32)((cDIBIn->GetLineWidth() * (1.0 - mfCos))   + 0.5);
 
586
                VerticalShift   =  (Int32)((cDIBIn->GetLineWidth() * mfSin)   + 0.5);
 
587
                VerticalShift   -= (Int32)((cDIBIn->GetLinesNumber() * (1.0 - mfCos)) + 0.5);
 
588
 
 
589
                NewHeigth = (Word32)((cDIBIn->GetLineWidth() * mfSin)   + 0.5 ) +
 
590
                                (Word32)((cDIBIn->GetLinesNumber() * mfCos) + 0.5 );
 
591
                NewWidth  = (Word32)((cDIBIn->GetLineWidth() * mfCos)   + 0.5 ) +
 
592
                                (Word32)((cDIBIn->GetLinesNumber() * mfSin) + 0.5 );
 
593
 
 
594
                if ( mfTang > 0 )
 
595
                {
 
596
                        AtX             = 0;
 
597
                        AtY             = (Int32)(cDIBIn->GetLineWidth() * mfSin); //VerticalShift;
 
598
                }
 
599
                else
 
600
                {
 
601
                        AtX             = (Int32)(cDIBIn->GetLinesNumber() * mfSin); //HorisontalShift;
 
602
                        AtY             = 0;
 
603
                }
 
604
                ToX             = NewWidth;
 
605
                ToY             = NewHeigth;
 
606
        }
 
607
        else
 
608
        {
 
609
                HorisontalShift = (Word32)((cDIBIn->GetLinesNumber() * fabs(mfTang)) + 0.5);
 
610
                VerticalShift   = (Word32)((cDIBIn->GetLineWidth() * fabs(mfTang)) + 0.5);
 
611
 
 
612
                AtX             = 0;
 
613
                AtY             = VerticalShift;
 
614
                ToX             = AtX + cDIBIn->GetLineWidth();
 
615
                ToY             = AtY + cDIBIn->GetLinesNumber();
 
616
 
 
617
                NewWidth  = cDIBIn->GetLineWidth() + HorisontalShift;
 
618
                NewHeigth = cDIBIn->GetLinesNumber() + VerticalShift;
 
619
        }
 
620
 
 
621
        RIMAGEComment("ConstructOutDIB - out DIB");
 
622
        if ( !cDIBOut->SetExternals(RIMAGEAlloc, RIMAGEFree, RIMAGELock, RIMAGEUnlock) ||
 
623
                 !cDIBOut->CreateDIBBegin(NewWidth,
 
624
                                          NewHeigth,
 
625
                                                                  Gray ? 8 : cDIBIn->GetPixelSize(),
 
626
                                                                  0,
 
627
                                                                  cDIBIn->GetVersion()) )
 
628
                return FALSE;
 
629
 
 
630
        cDIBIn->GetResolutionDPM( &dpmX, &dpmY );
 
631
        cDIBOut->SetResolutionDPM( dpmX, dpmY );
 
632
 
 
633
        cDIBOut->CreateDIBEnd();
 
634
 
 
635
        cDIBOut->CopyPalleteFromDIB(cDIBIn);
 
636
 
 
637
        BitFillforGray   = (Word8)cDIBIn->GetWhitePixel();
 
638
 
 
639
        //��� ����������� ����������� ����������� ��� �� ���� ����
 
640
        if ( cDIBOut->GetPixelSize() == 1 )
 
641
                BitFillforGray += ( BitFillforGray << 1 ) +
 
642
                                  ( BitFillforGray << 2 ) +
 
643
                                                  ( BitFillforGray << 3 ) +
 
644
                                                  ( BitFillforGray << 4 ) +
 
645
                                  ( BitFillforGray << 5 ) +
 
646
                                                  ( BitFillforGray << 6 ) +
 
647
                                                  ( BitFillforGray << 7 );
 
648
 
 
649
        if ( Gray )
 
650
        {
 
651
                Int32 wQuadN;
 
652
 
 
653
                for ( wQuadN = 255; wQuadN >= 0; wQuadN--)
 
654
                {
 
655
                        Quad.rgbBlue = Quad.rgbGreen = Quad.rgbRed = (Word8)wQuadN;
 
656
                        cDIBOut->SetRGBQuad(wQuadN,Quad);
 
657
                }
 
658
        }
 
659
 
 
660
        return TRUE;
 
661
}
 
662
 
 
663
Bool32 CRRotator::DescewGray(PCTDIB cDIBIn, PCTDIB cDIBOut)
 
664
{
 
665
        Bool32 bRet = TRUE;
 
666
        // �������
 
667
        Word32         OutLineLenght = cDIBOut->GetLineWidth();
 
668
        Word32         OunLines      = cDIBOut->GetLinesNumber();
 
669
        Word32         InLineLenght  = cDIBIn->GetLineWidth();
 
670
        Word32         InLines       = cDIBIn->GetLinesNumber();
 
671
        //����������
 
672
        Int32          CurrLAX;
 
673
        Int32          CurrLAY;
 
674
        Int32          CurrGX;
 
675
        Int32          CurrGY;
 
676
        Int32          OldPointX;
 
677
        Int32          OldPointY;
 
678
        Int32          NewPointX;
 
679
        Int32          NewPointY;
 
680
        Int32          GShiftX;
 
681
        Int32          GShiftY;
 
682
        // �������
 
683
        PWord8         pLAPix = NULL;
 
684
        PWord8         pGrayPix = NULL;
 
685
        PWord8         pGrayLine = NULL;
 
686
        Word32         LABitInByte;
 
687
        Word8          Decrement;
 
688
        Word8          Corner = 1;
 
689
        // �����
 
690
        Handle         hMask = NULL;
 
691
        PWord8         pMask = NULL;
 
692
 
 
693
        hMask = RIMAGEDAlloc(OutLineLenght * OunLines, "Rotator::DescewGray - mask");
 
694
        pMask = (PWord8)RIMAGELock(hMask);
 
695
 
 
696
 
 
697
        if ( cDIBOut->GetPixelSize() != 8 )
 
698
        {
 
699
                return FALSE;
 
700
        }
 
701
 
 
702
        if ( pMask )
 
703
        {
 
704
                for ( CurrGY = OunLines - 1; CurrGY >= 0; CurrGY-- )
 
705
                {
 
706
                        pGrayLine = (PWord8)cDIBOut->GetPtrToLine(CurrGY);
 
707
                        memset(pGrayLine, 127, OutLineLenght);
 
708
                        memset((pMask + (CurrGY * OutLineLenght)), 1, OutLineLenght);
 
709
                }
 
710
        }
 
711
        else
 
712
        {
 
713
                for ( CurrGY = OunLines - 1; CurrGY >= 0; CurrGY-- )
 
714
                {
 
715
                        pGrayLine = (PWord8)cDIBOut->GetPtrToLine(CurrGY);
 
716
                        memset(pGrayLine, 255, OutLineLenght);
 
717
                }
 
718
        }
 
719
 
 
720
        for ( CurrLAY = 0; CurrLAY < (Int32)InLines; CurrLAY++)
 
721
        {
 
722
                for ( CurrLAX = 0; CurrLAX < (Int32)InLineLenght; CurrLAX++)
 
723
                {
 
724
                        GetExtCoord(CurrLAX, CurrLAY, &OldPointX, &OldPointY);
 
725
                        RollPoint(OldPointX, OldPointY, &NewPointX, &NewPointY);
 
726
 
 
727
                        NewPointX += AtX * 256;
 
728
                        NewPointY += AtY * 256;
 
729
 
 
730
                        GetGrayCoord(NewPointX, NewPointY, &CurrGX, &CurrGY, &GShiftX, &GShiftY);
 
731
 
 
732
                        //CurrGX += AtX;
 
733
                        //CurrGY += AtY;
 
734
 
 
735
                        if ( CurrGX < (Int32)OutLineLenght &&
 
736
                                 CurrGY < (Int32)OunLines)
 
737
                        {
 
738
                                pGrayPix = (PWord8)cDIBOut->GetPtrToPixel(CurrGX, CurrGY);
 
739
 
 
740
                                if ( !pGrayPix )
 
741
                                        continue;
 
742
                        }
 
743
                        else
 
744
                                continue;
 
745
 
 
746
                        if ( pMask )
 
747
                        {
 
748
                                UnmaskPixels(pMask, pGrayPix, CurrGX, CurrGY, OutLineLenght, GShiftX, GShiftY);
 
749
                        }
 
750
 
 
751
                        //����� �����-����� ������
 
752
                        if ( CurrLAX < (Int32)InLineLenght &&
 
753
                                 CurrLAY < (Int32)InLines)
 
754
                        {
 
755
                                pLAPix = (PWord8)cDIBIn->GetPtrToPixel(CurrLAX, CurrLAY);
 
756
 
 
757
                                if ( !pLAPix )
 
758
                                        continue;
 
759
 
 
760
                        }
 
761
                        else
 
762
                                continue;
 
763
 
 
764
                        // ����������� �� ������
 
765
                        LABitInByte = CurrLAX - ((CurrLAX / 8) * 8);
 
766
                        if ( ((*pLAPix) & OneBitMask[LABitInByte]) == 0 )
 
767
                        {
 
768
                                Decrement = ((256 - abs(GShiftX)) * (256 - abs(GShiftY))) / 256;
 
769
                                AddBlackToGray(CurrGX, CurrGY, Decrement);
 
770
                                Corner = 1;
 
771
 
 
772
                                if ( GShiftX != 0)
 
773
                                {
 
774
                                        Decrement = ( abs(GShiftX) * (256 - abs(GShiftY))) / 256;
 
775
 
 
776
                                        if ( GShiftX < 0 )
 
777
                                        {
 
778
                                                AddBlackToGray(CurrGX - 1, CurrGY, Decrement);
 
779
                                                Corner *= 2;
 
780
                                        }
 
781
                                        else
 
782
                                        {
 
783
                                                AddBlackToGray(CurrGX + 1, CurrGY, Decrement);
 
784
                                                Corner *= 3;
 
785
                                        }
 
786
                                }
 
787
 
 
788
                                if (GShiftY != 0)
 
789
                                {
 
790
                                        Decrement = ( abs(GShiftY) * (256 - abs(GShiftX))) / 256;
 
791
 
 
792
                                        if ( GShiftY < 0 )
 
793
                                        {
 
794
                                                AddBlackToGray(CurrGX , CurrGY - 1, Decrement);
 
795
                                                Corner *= 4;
 
796
                                        }
 
797
                                        else
 
798
                                        {
 
799
                                                AddBlackToGray(CurrGX, CurrGY + 1, Decrement);
 
800
                                                Corner *= 5;
 
801
                                        }
 
802
 
 
803
                                }
 
804
 
 
805
                                Decrement = ( abs(GShiftY) * (256 - abs(GShiftX))) / 256;
 
806
                                switch (Corner)
 
807
                                {
 
808
                                case 8:
 
809
                                        AddBlackToGray(CurrGX - 1, CurrGY - 1, Decrement);
 
810
                                        break;
 
811
                                case 12:
 
812
                                        AddBlackToGray(CurrGX + 1, CurrGY - 1, Decrement);
 
813
                                        break;
 
814
                                case 15:
 
815
                                        AddBlackToGray(CurrGX + 1, CurrGY + 1, Decrement);
 
816
                                        break;
 
817
                                case 10:
 
818
                                        AddBlackToGray(CurrGX - 1, CurrGY + 1, Decrement);
 
819
                                        break;
 
820
                                default:
 
821
                                        pGrayPix = NULL;
 
822
                                }
 
823
                        }
 
824
 
 
825
                }
 
826
        }
 
827
 
 
828
        RIMAGEUnlock( hMask );
 
829
        RIMAGEFree( hMask );
 
830
 
 
831
        return bRet;
 
832
}
 
833
 
 
834
Bool32 CRRotator::GetExtCoord(Int32 X, Int32 Y, PInt32 peX, PInt32 peY)
 
835
{
 
836
        if ( peX )
 
837
        {
 
838
                *peX = 128 + X * 256;
 
839
        }
 
840
 
 
841
        if ( peY )
 
842
        {
 
843
                *peY = 128 + Y * 256;
 
844
        }
 
845
 
 
846
        return TRUE;
 
847
}
 
848
 
 
849
Bool32 CRRotator::RollPoint(Int32 X, Int32 Y, PInt32 pnX, PInt32 pnY)
 
850
{
 
851
        if ( pnX )
 
852
        {
 
853
                *pnX = (Int32)(((Float80)X * mfCos) + ((Float80)Y * mfSin));
 
854
        }
 
855
 
 
856
        if ( pnY )
 
857
        {
 
858
                *pnY = (Int32)(((Float80)Y * mfCos) - ((Float80)X * mfSin));
 
859
        }
 
860
 
 
861
        return TRUE;
 
862
}
 
863
 
 
864
Bool32 CRRotator::GetGrayCoord(Int32 eX, Int32 eY, PInt32 pgX, PInt32 pgY, PInt32 psX, PInt32 psY)
 
865
{
 
866
        if ( pgX )
 
867
        {
 
868
                *pgX = (Int32)(eX / 256);
 
869
 
 
870
                if ( psX )
 
871
                        *psX = (Int32)(eX - (*pgX * 256) - 128);
 
872
        }
 
873
 
 
874
        if ( pgY )
 
875
        {
 
876
                *pgY = (Int32)(eY / 256);
 
877
 
 
878
                if ( psY )
 
879
                        *psY = (Int32)(eY - (*pgY * 256) - 128);
 
880
        }
 
881
 
 
882
        return TRUE;
 
883
}
 
884
 
 
885
 
 
886
 
 
887
Bool32 CRRotator::UnmaskPixels(PWord8 pMask, PWord8 pGaryPix, Int32 X, Int32 Y, Word32 wLineLen, Int32 ShiftX, Int32 ShiftY)
 
888
{
 
889
        if ( *(pMask + (Y * wLineLen + X)) )
 
890
        {
 
891
                *(pMask + (Y * wLineLen + X)) = 0;
 
892
                *pGaryPix = 255;
 
893
        }
 
894
 
 
895
        if ( ShiftX > 0 && X < (Int32)(wLineLen - 1) )
 
896
        {
 
897
                if ( *(pMask + (Y * wLineLen + X + 1)) )
 
898
                {
 
899
                        *(pMask + (Y * wLineLen + X + 1)) = 0;
 
900
                        *( pGaryPix + 1 ) = 255;
 
901
                }
 
902
        }
 
903
 
 
904
        if ( ShiftX < 0 && X > 1 )
 
905
        {
 
906
                if ( *(pMask + (Y * wLineLen + X - 1)) )
 
907
                {
 
908
                        *(pMask + (Y * wLineLen + X - 1)) = 0;
 
909
                        *( pGaryPix - 1 ) = 255;
 
910
                }
 
911
        }
 
912
 
 
913
        return TRUE;
 
914
}
 
915
 
 
916
Bool32 CRRotator::AddBlackToGray(Int32 X, Int32 Y, Word8 Gray)
 
917
{
 
918
        static PWord8 pGrayPixel;
 
919
 
 
920
        pGrayPixel = (PWord8)mdDIBOut->GetPtrToPixel(X, Y);
 
921
 
 
922
        if ( pGrayPixel )
 
923
        {
 
924
                *pGrayPixel = (Gray > *pGrayPixel ? 0 : *pGrayPixel - Gray);
 
925
                return TRUE;
 
926
        }
 
927
 
 
928
        return FALSE;
 
929
}
 
930
 
 
931
void CRRotator::AllocWorkBuffers(Word32 wStringBufferRange)
 
932
{
 
933
        if (mwTablesRange)
 
934
        {
 
935
                hHShiftTable   = RIMAGEDAlloc((mwTablesRange + 1)*4,"Rotator::AllocWorkBuffer - hor shift table");
 
936
                HShiftTable    = (PInt32)RIMAGELock(hHShiftTable);
 
937
                hVShiftTable   = RIMAGEDAlloc((mwTablesRange + 1)*4,"Rotator::AllocWorkBuffer - vert shift table");
 
938
                VShiftTable    = (PWord32)RIMAGELock(hVShiftTable);
 
939
                hVShiftLenght  = RIMAGEDAlloc((mwTablesRange + 1)*4,"Rotator::AllocWorkBuffer - vl shift table");
 
940
                VShiftLenght   = (PWord32)RIMAGELock(hVShiftLenght);
 
941
        }
 
942
 
 
943
        if ( wStringBufferRange )
 
944
        {
 
945
                //hBufferForGray = RIMAGEAlloc( wLineBytesWTo + HorisontalShiftInBytes * 2 + ( VShiftLenght[0] * 2 )  );     //����� ��� �������� ��������
 
946
                hBufferForGray = RIMAGEDAlloc( wWorkGrayBufferLenght = ( mwDescewedWidth * 4 ), "Rotator::AllocWorkBuffer - buffer for gray");     //����� ��� �������� ��������
 
947
                BufferForGray  = (PWord8)RIMAGELock(hBufferForGray);
 
948
        }
 
949
 
 
950
}
 
951
 
 
952
 
 
953
void CRRotator::FreeWorkBuffers()
 
954
{
 
955
        mwTablesRange = 0;
 
956
 
 
957
        if ( hHShiftTable )
 
958
        {
 
959
                RIMAGEFree(hHShiftTable);
 
960
                hHShiftTable   = NULL;
 
961
                HShiftTable    = NULL;
 
962
        }
 
963
 
 
964
        if ( hVShiftTable )
 
965
        {
 
966
                RIMAGEFree(hVShiftTable);
 
967
                hVShiftTable   = NULL;
 
968
                VShiftTable    = NULL;
 
969
        }
 
970
 
 
971
        if ( hVShiftLenght )
 
972
        {
 
973
                RIMAGEFree(hVShiftLenght);
 
974
                hVShiftLenght  = NULL;
 
975
                VShiftLenght   = NULL;
 
976
        }
 
977
 
 
978
        if (hBufferForGray)
 
979
        {
 
980
                RIMAGEFree(hBufferForGray);
 
981
                hBufferForGray = NULL;
 
982
                BufferForGray  = NULL;
 
983
        }
 
984
}
 
985
 
 
986
Bool32 CRRotator::RotatePoint(Int32 iX, Int32 iY, PInt32 prX, PInt32 prY)
 
987
{
 
988
        Int32 tY;
 
989
 
 
990
        if ( VShiftTable == NULL ||  HShiftTable == NULL)
 
991
        {
 
992
                return FALSE;
 
993
        }
 
994
 
 
995
        if ( iX > -1 && iX < (Int32)mwOriginalWidth &&
 
996
                 iY > -1 && iY < (Int32)mwOriginalHeight    )
 
997
        {
 
998
                if ( mfTang > 0)
 
999
                {
 
1000
                        *prY = iY - VShiftTable[iX] + AtY;
 
1001
 
 
1002
                        if ( *prY < 0 || *prY >= (Int32)mwTablesRange )
 
1003
                        {
 
1004
                                *prX = -1;
 
1005
                                *prY = -1;
 
1006
                                return FALSE;
 
1007
                        }
 
1008
 
 
1009
                        *prX = iX + HShiftTable[*prY] + AtX;
 
1010
                        return TRUE;
 
1011
                }
 
1012
                else
 
1013
                {
 
1014
                        tY = mwOriginalHeight - (iY + 1);
 
1015
                        tY = tY - VShiftTable[iX] + AtY;
 
1016
 
 
1017
                        if ( tY < 0 || tY >= (Int32)mwTablesRange )
 
1018
                        {
 
1019
                                *prX = -1;
 
1020
                                *prY = -1;
 
1021
                                return FALSE;
 
1022
                        }
 
1023
 
 
1024
                        *prX = iX + HShiftTable[tY] + AtX;
 
1025
                        *prY = mwDescewedHeight - (tY + 2);
 
1026
                        return TRUE;
 
1027
                }
 
1028
        }
 
1029
        return FALSE;
 
1030
}
 
1031
 
 
1032
void CRRotator::ComposeLineG(PCTDIB cDIBIn, Int32 iDirect, Word32 wLine, Word32 wBuffLen)
 
1033
{
 
1034
        Word32 j;
 
1035
        Word32 StartByte;
 
1036
        Word32 EndByte;
 
1037
        Word32 FulBytes;
 
1038
        Word32 PixelSize = cDIBIn->GetPixelSize() / 8;
 
1039
        Int32  PosInBuff;
 
1040
        Word32 Copy = 0;
 
1041
        PWord8 PixFrom;
 
1042
        Word32 wLines = cDIBIn->GetLinesNumber();
 
1043
 
 
1044
        for ( j = 0; j < wBuffLen; )
 
1045
        {
 
1046
                StartByte = j * PixelSize; //������ ������
 
1047
                EndByte   = (j + VShiftLenght[j]) * PixelSize; //��������� ����������
 
1048
 
 
1049
                FulBytes = EndByte - StartByte + 1;
 
1050
 
 
1051
                if ( VShiftLenght[j] == 0 )
 
1052
                {
 
1053
                        j++;
 
1054
                        continue;
 
1055
                }
 
1056
 
 
1057
                // ���� ���� ������ �������� ��������
 
1058
                PixFrom = NULL;
 
1059
                PosInBuff = ( HShiftTable[wLine] * PixelSize) + StartByte;
 
1060
 
 
1061
                if ( wLine + VShiftTable[j] >= AtY && wLine + VShiftTable[j] < ToY )
 
1062
                {
 
1063
                        if ( iDirect > 0 )
 
1064
                        {
 
1065
                                PixFrom = (PWord8)cDIBIn->GetPtrToPixel(j,wLine + VShiftTable[j] - AtY);
 
1066
                        }
 
1067
                        else
 
1068
                        {
 
1069
                                PixFrom = (PWord8)cDIBIn->GetPtrToPixel(j,wLines - (wLine + VShiftTable[j] - AtY));
 
1070
                        }
 
1071
                }
 
1072
        // Allex  27.03.00
 
1073
        // ������ �����. �� ��������� ������ ��������� ������� � ������������ � BufferForGray - �������� ��������
 
1074
        // ���� ������ ��� ����� �����. �������� �������� � �������� ������� � ������� �����.
 
1075
        if ( PosInBuff < (Int32)wWorkGrayBufferLenght )
 
1076
        {
 
1077
            FulBytes = FulBytes > wWorkGrayBufferLenght - PosInBuff ? wWorkGrayBufferLenght - PosInBuff : FulBytes;
 
1078
 
 
1079
                    if ( PixFrom )
 
1080
                    {
 
1081
                            // �������� ��������� �����
 
1082
                            memcpy(BufferForGray + PosInBuff,PixFrom, FulBytes );
 
1083
                    }
 
1084
                    else  //  if ( pixfrom )
 
1085
                    {
 
1086
                            memset(BufferForGray + PosInBuff,BitFillforGray, FulBytes );
 
1087
                    }
 
1088
        }
 
1089
 
 
1090
                Copy += FulBytes;
 
1091
                j+= VShiftLenght[j];
 
1092
        }
 
1093
}
 
1094
//////////////////////////////////////////////////////////////////////////////////////////////////////////
 
1095
// end of file