2
Copyright (c) 1993-2008, Cognitive Technologies
5
����������� ��������� ��������������� � ������������� ��� � ���� ��������� ����,
6
��� � � �������� �����, � ����������� ��� ���, ��� ���������� ��������� �������:
8
* ��� ��������� ��������������� ��������� ���� ������ ���������� ���������
9
���� ����������� �� ��������� �����, ���� ������ ������� � �����������
11
* ��� ��������� ��������������� ��������� ���� � ������������ �/��� �
12
������ ����������, ������������ ��� ���������������, ������ �����������
13
��������� ���� ���������� �� ��������� �����, ���� ������ ������� �
14
����������� ����� �� ��������.
15
* �� �������� Cognitive Technologies, �� ����� �� ����������� �� �����
16
���� ������������ � �������� �������� ��������� �/��� �����������
17
���������, ���������� �� ���� ��, ��� ���������������� �����������
20
��� ��������� ������������� ����������� ��������� ���� �/��� ������� ������ "���
21
��� ����" ��� ������-���� ���� ��������, ���������� ���� ��� ���������������,
22
������� �������� ������������ �������� � ����������� ��� ���������� ����, �� ��
23
������������� ���. �� �������� ��������� ���� � �� ���� ������ ����, �������
24
����� �������� �/��� �������� �������������� ���������, �� � ���� ������ ��
25
��Ѩ� ���������������, ������� ����� �����, ���������, ����������� ���
26
������������� ������, ��������� � �������������� ��� ���������� ����������
27
������������� ������������� ��������� (������� ������ ������, ��� ������,
28
������� ���������, ��� ������ �/��� ������ �������, ���������� ��-�� ��������
29
������� ��� �/��� ������ ��������� �������� ��������� � ������� �����������,
30
�� �� ������������� ����� ��������), �� �� ������������� ���, ���� ���� �����
31
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
33
Redistribution and use in source and binary forms, with or without modification,
34
are permitted provided that the following conditions are met:
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.
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.
57
// CRRotator.cpp: implementation of the CRRotator class.
59
//////////////////////////////////////////////////////////////////////
65
#include "crrotator.h"
66
#include "crimemory.h"
70
//////////////////////////////////////////////////////////////////////
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 };
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,
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
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
98
static Word8 MaskForRightShift[9] =
100
// 00000000 00000001 00000011 00000111 00001111
101
0x00, 0x01, 0x03, 0x07, 0xf,
102
// 00011111 00111111 01111111 11111111
103
0x1f, 0x3f, 0x7f, 0xff
105
static Word8 MaskForLeftShift[9] =
107
// 00000000 10000000 11000000 11100000 11110000
108
0x00, 0x80, 0xc0, 0xe0, 0xf0,
109
// 11111000 11111100 11111110 11111111
110
0xf8, 0xfc, 0xfe, 0xff
112
static Word8 OneBitMask[8] =
115
// 00000001 00000010 00000100 00001000
116
// 0x01, 0x02, 0x04, 0x08,
117
// 00010000 00100000 01000000 10000000
118
// 0x10, 0x20, 0x40, 0x80
120
// 10000000 01000000 00100000 00010000
121
0x80, 0x40, 0x20, 0x10,
122
// 00001000 00000100 00000010 00000001
123
0x08, 0x04, 0x02, 0x01
125
//////////////////////////////////////////////////////////////////////
126
// Construction/Destruction
127
//////////////////////////////////////////////////////////////////////
130
void CRRotator::ResetItself()
139
mwDescewedHeight = 0;
141
mwOriginalHeight = 0;
148
BufferForGray = NULL;
149
hBufferForGray = NULL;
155
hVShiftLenght = NULL;
159
CRRotator::CRRotator()
163
//////////////////////////////////////////////////////////////////////
165
CRRotator::CRRotator(PCRProgressor pProgressIndicator)
168
mpProgressor = pProgressIndicator;
170
///////////////////////////////////////////////////////////////////////////////////////
172
CRRotator::~CRRotator()
176
///////////////////////////////////////////////////////////////////////////////////////
179
Bool32 CRRotator::Rotate(PCTDIB cDIBIn, PCTDIB cDIBOut, Int32 Num, Int32 Denum)
182
Float80 fNum = (Float80)Num;
183
Float80 fDenum = (Float80)Denum;
184
Float80 fG = sqrt( fNum * fNum + fDenum * fDenum );
186
if ( Num == 0 || Denum == 0)
188
SetReturnCode_rimage(IDS_RIMAGE_ZERO_NUMERATOR_OR_DENUMERATOR);
193
if ( cDIBIn->GetPixelSize() == 4 )
195
SetReturnCode_rimage(IDS_RIMAGE_UNDER_CONSTRUCTION);
200
mfTang= fNum / fDenum;
204
if ( fabs(mfTang) > CTROTATOR_MAX_TANG )
206
SetReturnCode_rimage(IDS_RIMAGE_ANGLE_GREAT_MAXIMUM);
210
if ( fabs(mfTang) < CTROTATOR_MIN_TANG )
212
SetReturnCode_rimage(IDS_RIMAGE_ANGLE_LEAST_MINIMUM);
216
if ( !ConstructOutDIB(cDIBIn, cDIBOut, FALSE) )
221
Ret = Descew(cDIBIn, cDIBOut);
224
catch ( Word32 wExit )
226
if ( wExit = IDS_RIMAGE_EXIT_BY_USER)
228
SetReturnCode_rimage(IDS_RIMAGE_EXIT_BY_USER);
232
SetReturnCode_rimage(IDS_RIMAGE_UNKNOWN_ERROR);
241
/////////////////////////////////////////////////////////////////////////////////////////////////////
242
Bool32 CRRotator::Descew(PCTDIB cDIBIn, PCTDIB cDIBOut )
245
# define MAX(a,b) ( (a) > (b) ? (a) : (b) )
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);
259
mwOriginalHeight = cDIBIn->GetLinesNumber();
260
mwOriginalWidth = cDIBIn->GetLineWidth();
261
mwDescewedHeight = cDIBOut->GetLinesNumber();
262
mwDescewedWidth = cDIBOut->GetLineWidth();
263
mwTablesRange = MAX (mwDescewedHeight, mwDescewedWidth);
266
AllocWorkBuffers(TRUE);
267
PrepareTables(mwTablesRange, mwDescewedWidth - 1);
271
mpProgressor->Start();
273
for ( Line = 0; Line < mwDescewedHeight; Line++)
276
if ( mpProgressor->SetStep( (Line / mwDescewedHeight) * 100 ) )
278
mpProgressor->Finish();
279
throw IDS_RIMAGE_EXIT_BY_USER;
282
memset(BufferForGray, BitFillforGray, HorisontalShiftInBytes);
283
memset(BufferForGray + wLineBytesWTo - HorisontalShiftInBytes, BitFillforGray, HorisontalShiftInBytes);
285
switch ( wBitLenght )
290
ComposeLineG(cDIBIn, Direction, Line, mwDescewedWidth);
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
303
ShiftLineLA(ToShift, wLineBytesWTo + HorisontalShiftInBytes - 1);
307
ComposeLine4(cDIBIn, Direction, Line, mwDescewedWidth);
311
// �������� ������ � �������� ���
312
pToCopy = (PWord8)(Direction > 0 ? cDIBOut->GetPtrToLine(Line) :
313
cDIBOut->GetPtrToLine(mwDescewedHeight - Line - 1));
316
memcpy(pToCopy, BufferForGray, wLineBytesWTo);
320
mpProgressor->Finish();
325
void CRRotator::ComposeLineLA(PCTDIB cDIBIn, Int32 iDirect, Word32 wLine, Word32 wBuffLen)
336
Word32 wLines = cDIBIn->GetLinesNumber();
338
for ( j = 0; j < wBuffLen; )
340
StartByte = j / 8; //������ ������
341
// EndByte = (j + VShiftLenght[j])/8; //��������� ����������
342
EndByte = (j - 1 + VShiftLenght[j])/8; //��������� ����������
344
FulBytes = EndByte - StartByte + 1;
345
// Bits = (j + VShiftLenght[j]) - EndByte * 8;
346
Bits = j - StartByte * 8;
348
if ( VShiftLenght[j] == 0 )
354
// ���� ���� ������ �������� ��������
356
PosInBuff = ( HShiftTable[wLine]) / 8 + StartByte;
357
if ( wLine + VShiftTable[j] >= AtY && wLine + VShiftTable[j] < ToY )
361
PixFrom = (PWord8)cDIBIn->GetPtrToPixel(j,wLine + VShiftTable[j] - AtY);
365
PixFrom = (PWord8)cDIBIn->GetPtrToPixel(j,wLines - (wLine + VShiftTable[j] - AtY));
368
//����� ������������ ������ ���������� ������ ����
369
if ( j != 0 && Bits > 0 && mbEnableVSS)
372
LastByte |= *(BufferForGray + PosInBuff)&MaskForLeftShift[Bits];
377
// �������� ��������� �����
378
if (EndByte > cDIBIn->GetUsedLineWidthInBytes() - 1)
380
EndByte = cDIBIn->GetUsedLineWidthInBytes() - 1;
381
FulBytes = EndByte - StartByte + 1;
384
memcpy(BufferForGray + PosInBuff,PixFrom, FulBytes );
386
else // if ( pixfrom )
388
memset(BufferForGray + PosInBuff,BitFillforGray, FulBytes );
390
//�� ����� ��������� �������
391
if ( Bits > 0 && j != 0 && mbEnableVSS)
393
LastByte |= *(BufferForGray + PosInBuff)&MaskForRightShift[8 - Bits];
394
*(BufferForGray + PosInBuff) = LastByte;
397
Copy += FulBytes * 8;
402
void CRRotator::ComposeLine4(PCTDIB cDIBIn, Int32 iDirect, Word32 wLine, Word32 wBuffLen)
413
Word32 wLines = cDIBIn->GetLinesNumber();
415
for ( j = 0; j < wBuffLen; )
417
StartByte = j / 2; //������ ������
418
EndByte = (j + VShiftLenght[j])/2; //��������� ����������
420
FulBytes = EndByte - StartByte + 1;
421
Pixels = (j + VShiftLenght[j]) - EndByte * 2;
424
if ( VShiftLenght[j] == 0 )
430
// ���� ���� ������ �������� ��������
432
PosInBuff = ( HShiftTable[wLine]) / 2 + StartByte;
434
if ( wLine + VShiftTable[j] >= AtY && wLine + VShiftTable[j] < ToY )
438
PixFrom = (PWord8)cDIBIn->GetPtrToPixel(j,wLine + VShiftTable[j] - AtY);
442
PixFrom = (PWord8)cDIBIn->GetPtrToPixel(j,wLines - (wLine + VShiftTable[j] - AtY));
445
//����� ������������ ������ ���������� ������ ����
446
if ( j != 0 && Pixels > 0 && mbEnableVSS)
449
LastByte |= *(BufferForGray + PosInBuff)&MaskForLeftShift[Pixels];
454
// �������� ��������� �����
455
memcpy(BufferForGray + PosInBuff,PixFrom, FulBytes );
457
else // if ( pixfrom )
459
memset(BufferForGray + PosInBuff,BitFillforGray, FulBytes );
461
//�� ����� ��������� �������
462
if ( Pixels > 0 && j != 0 && mbEnableVSS)
464
LastByte |= *(BufferForGray + PosInBuff)&MaskForRightShift[8 - Pixels];
465
*(BufferForGray + PosInBuff) = LastByte;
468
Copy += FulBytes * 2;
473
void CRRotator::SetEndLineLA(Word32 Line, Word32 wLineW, Word32 wLineBytes)
475
Word32 StartByte = wLineW/8 + HShiftTable[Line]/8;
476
Word32 EndByte = wLineBytes;
477
Word32 Bits = wLineW + (HShiftTable[Line]/8)*8 - StartByte*8;
483
LastByte |= *(BufferForGray + StartByte)&MaskForLeftShift[Bits];
484
LastByte |= BitFillforGray&MaskForRightShift[8 - Bits];
487
if ( (Int32)(EndByte - StartByte) > 0)
488
memset(BufferForGray + StartByte, BitFillforGray, (EndByte - StartByte));
491
*(BufferForGray + StartByte) = LastByte;
494
void CRRotator::PrepareTables( Word32 wMax, Word32 wCheck)
500
Float80 dmTan = (mfTang > 0 ? mfTang : -mfTang);
502
for (PrevS = PrevI = i = 0; i < wMax; i++ )
504
Shift = (Int32)( (i * dmTan) + 0.5) ;
507
HShiftTable[i] = Shift;
509
Shift = (Shift < 0 ? 0 : Shift);
511
HShiftTable[i] = Shift /*( Shift < HorisontalShift ? Shift : HorisontalShift )*/;
513
VShiftTable[i] = ( Shift < VerticalShift ? Shift : VerticalShift );
516
if ( PrevS != Shift || i == wCheck)
518
VShiftLenght[PrevI] = i - PrevI;
526
void CRRotator::ShiftLineLA(Word32 LocalShift, Word32 wBytesTo )
528
Word32 LocalUnshift = 8 - LocalShift;
531
for ( ShiftedByte = wBytesTo;
535
BufferForGray[ShiftedByte] = BufferForGray[ShiftedByte]>>LocalShift;
536
BufferForGray[ShiftedByte] &= MaskForRightShift[LocalUnshift];
537
BufferForGray[ShiftedByte] |= ( BufferForGray[ShiftedByte - 1]<<LocalUnshift )&MaskForLeftShift[LocalShift];
540
BufferForGray[0] |= BitFillforGray&MaskForLeftShift[LocalShift];
544
///////////////////////////////////////////////////////////////////////////////////////
546
///////////////////////////////////////////////////////////////////////////////////////////////////
547
Bool32 CRRotator::Roll(PCTDIB cDIBIn, PCTDIB cDIBOut, Int32 Num, Int32 Denum)
549
Float80 fNum = (Float80)Num;
550
Float80 fDenum = (Float80)Denum;
551
Float80 fG = sqrt( fNum * fNum + fDenum * fDenum );
553
mfTang = fNum / fDenum;
559
if ( mfTang > CTROTATOR_MAX_TANG || mfTang < CTROTATOR_MIN_TANG )
563
if ( !ConstructOutDIB(cDIBIn, cDIBOut, TRUE) )
566
if ( !DescewGray( cDIBIn, cDIBOut) )
573
/////////////////////////////////////////////////////////////////////////////////////////////////////
574
Bool32 CRRotator::ConstructOutDIB(PCTDIB cDIBIn, PCTDIB cDIBOut, Bool32 Gray)
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);
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 );
597
AtY = (Int32)(cDIBIn->GetLineWidth() * mfSin); //VerticalShift;
601
AtX = (Int32)(cDIBIn->GetLinesNumber() * mfSin); //HorisontalShift;
609
HorisontalShift = (Word32)((cDIBIn->GetLinesNumber() * fabs(mfTang)) + 0.5);
610
VerticalShift = (Word32)((cDIBIn->GetLineWidth() * fabs(mfTang)) + 0.5);
614
ToX = AtX + cDIBIn->GetLineWidth();
615
ToY = AtY + cDIBIn->GetLinesNumber();
617
NewWidth = cDIBIn->GetLineWidth() + HorisontalShift;
618
NewHeigth = cDIBIn->GetLinesNumber() + VerticalShift;
621
RIMAGEComment("ConstructOutDIB - out DIB");
622
if ( !cDIBOut->SetExternals(RIMAGEAlloc, RIMAGEFree, RIMAGELock, RIMAGEUnlock) ||
623
!cDIBOut->CreateDIBBegin(NewWidth,
625
Gray ? 8 : cDIBIn->GetPixelSize(),
627
cDIBIn->GetVersion()) )
630
cDIBIn->GetResolutionDPM( &dpmX, &dpmY );
631
cDIBOut->SetResolutionDPM( dpmX, dpmY );
633
cDIBOut->CreateDIBEnd();
635
cDIBOut->CopyPalleteFromDIB(cDIBIn);
637
BitFillforGray = (Word8)cDIBIn->GetWhitePixel();
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 );
653
for ( wQuadN = 255; wQuadN >= 0; wQuadN--)
655
Quad.rgbBlue = Quad.rgbGreen = Quad.rgbRed = (Word8)wQuadN;
656
cDIBOut->SetRGBQuad(wQuadN,Quad);
663
Bool32 CRRotator::DescewGray(PCTDIB cDIBIn, PCTDIB cDIBOut)
667
Word32 OutLineLenght = cDIBOut->GetLineWidth();
668
Word32 OunLines = cDIBOut->GetLinesNumber();
669
Word32 InLineLenght = cDIBIn->GetLineWidth();
670
Word32 InLines = cDIBIn->GetLinesNumber();
683
PWord8 pLAPix = NULL;
684
PWord8 pGrayPix = NULL;
685
PWord8 pGrayLine = NULL;
693
hMask = RIMAGEDAlloc(OutLineLenght * OunLines, "Rotator::DescewGray - mask");
694
pMask = (PWord8)RIMAGELock(hMask);
697
if ( cDIBOut->GetPixelSize() != 8 )
704
for ( CurrGY = OunLines - 1; CurrGY >= 0; CurrGY-- )
706
pGrayLine = (PWord8)cDIBOut->GetPtrToLine(CurrGY);
707
memset(pGrayLine, 127, OutLineLenght);
708
memset((pMask + (CurrGY * OutLineLenght)), 1, OutLineLenght);
713
for ( CurrGY = OunLines - 1; CurrGY >= 0; CurrGY-- )
715
pGrayLine = (PWord8)cDIBOut->GetPtrToLine(CurrGY);
716
memset(pGrayLine, 255, OutLineLenght);
720
for ( CurrLAY = 0; CurrLAY < (Int32)InLines; CurrLAY++)
722
for ( CurrLAX = 0; CurrLAX < (Int32)InLineLenght; CurrLAX++)
724
GetExtCoord(CurrLAX, CurrLAY, &OldPointX, &OldPointY);
725
RollPoint(OldPointX, OldPointY, &NewPointX, &NewPointY);
727
NewPointX += AtX * 256;
728
NewPointY += AtY * 256;
730
GetGrayCoord(NewPointX, NewPointY, &CurrGX, &CurrGY, &GShiftX, &GShiftY);
735
if ( CurrGX < (Int32)OutLineLenght &&
736
CurrGY < (Int32)OunLines)
738
pGrayPix = (PWord8)cDIBOut->GetPtrToPixel(CurrGX, CurrGY);
748
UnmaskPixels(pMask, pGrayPix, CurrGX, CurrGY, OutLineLenght, GShiftX, GShiftY);
751
//����� �����-����� ������
752
if ( CurrLAX < (Int32)InLineLenght &&
753
CurrLAY < (Int32)InLines)
755
pLAPix = (PWord8)cDIBIn->GetPtrToPixel(CurrLAX, CurrLAY);
764
// ����������� �� ������
765
LABitInByte = CurrLAX - ((CurrLAX / 8) * 8);
766
if ( ((*pLAPix) & OneBitMask[LABitInByte]) == 0 )
768
Decrement = ((256 - abs(GShiftX)) * (256 - abs(GShiftY))) / 256;
769
AddBlackToGray(CurrGX, CurrGY, Decrement);
774
Decrement = ( abs(GShiftX) * (256 - abs(GShiftY))) / 256;
778
AddBlackToGray(CurrGX - 1, CurrGY, Decrement);
783
AddBlackToGray(CurrGX + 1, CurrGY, Decrement);
790
Decrement = ( abs(GShiftY) * (256 - abs(GShiftX))) / 256;
794
AddBlackToGray(CurrGX , CurrGY - 1, Decrement);
799
AddBlackToGray(CurrGX, CurrGY + 1, Decrement);
805
Decrement = ( abs(GShiftY) * (256 - abs(GShiftX))) / 256;
809
AddBlackToGray(CurrGX - 1, CurrGY - 1, Decrement);
812
AddBlackToGray(CurrGX + 1, CurrGY - 1, Decrement);
815
AddBlackToGray(CurrGX + 1, CurrGY + 1, Decrement);
818
AddBlackToGray(CurrGX - 1, CurrGY + 1, Decrement);
828
RIMAGEUnlock( hMask );
834
Bool32 CRRotator::GetExtCoord(Int32 X, Int32 Y, PInt32 peX, PInt32 peY)
838
*peX = 128 + X * 256;
843
*peY = 128 + Y * 256;
849
Bool32 CRRotator::RollPoint(Int32 X, Int32 Y, PInt32 pnX, PInt32 pnY)
853
*pnX = (Int32)(((Float80)X * mfCos) + ((Float80)Y * mfSin));
858
*pnY = (Int32)(((Float80)Y * mfCos) - ((Float80)X * mfSin));
864
Bool32 CRRotator::GetGrayCoord(Int32 eX, Int32 eY, PInt32 pgX, PInt32 pgY, PInt32 psX, PInt32 psY)
868
*pgX = (Int32)(eX / 256);
871
*psX = (Int32)(eX - (*pgX * 256) - 128);
876
*pgY = (Int32)(eY / 256);
879
*psY = (Int32)(eY - (*pgY * 256) - 128);
887
Bool32 CRRotator::UnmaskPixels(PWord8 pMask, PWord8 pGaryPix, Int32 X, Int32 Y, Word32 wLineLen, Int32 ShiftX, Int32 ShiftY)
889
if ( *(pMask + (Y * wLineLen + X)) )
891
*(pMask + (Y * wLineLen + X)) = 0;
895
if ( ShiftX > 0 && X < (Int32)(wLineLen - 1) )
897
if ( *(pMask + (Y * wLineLen + X + 1)) )
899
*(pMask + (Y * wLineLen + X + 1)) = 0;
900
*( pGaryPix + 1 ) = 255;
904
if ( ShiftX < 0 && X > 1 )
906
if ( *(pMask + (Y * wLineLen + X - 1)) )
908
*(pMask + (Y * wLineLen + X - 1)) = 0;
909
*( pGaryPix - 1 ) = 255;
916
Bool32 CRRotator::AddBlackToGray(Int32 X, Int32 Y, Word8 Gray)
918
static PWord8 pGrayPixel;
920
pGrayPixel = (PWord8)mdDIBOut->GetPtrToPixel(X, Y);
924
*pGrayPixel = (Gray > *pGrayPixel ? 0 : *pGrayPixel - Gray);
931
void CRRotator::AllocWorkBuffers(Word32 wStringBufferRange)
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);
943
if ( wStringBufferRange )
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);
953
void CRRotator::FreeWorkBuffers()
959
RIMAGEFree(hHShiftTable);
966
RIMAGEFree(hVShiftTable);
973
RIMAGEFree(hVShiftLenght);
974
hVShiftLenght = NULL;
980
RIMAGEFree(hBufferForGray);
981
hBufferForGray = NULL;
982
BufferForGray = NULL;
986
Bool32 CRRotator::RotatePoint(Int32 iX, Int32 iY, PInt32 prX, PInt32 prY)
990
if ( VShiftTable == NULL || HShiftTable == NULL)
995
if ( iX > -1 && iX < (Int32)mwOriginalWidth &&
996
iY > -1 && iY < (Int32)mwOriginalHeight )
1000
*prY = iY - VShiftTable[iX] + AtY;
1002
if ( *prY < 0 || *prY >= (Int32)mwTablesRange )
1009
*prX = iX + HShiftTable[*prY] + AtX;
1014
tY = mwOriginalHeight - (iY + 1);
1015
tY = tY - VShiftTable[iX] + AtY;
1017
if ( tY < 0 || tY >= (Int32)mwTablesRange )
1024
*prX = iX + HShiftTable[tY] + AtX;
1025
*prY = mwDescewedHeight - (tY + 2);
1032
void CRRotator::ComposeLineG(PCTDIB cDIBIn, Int32 iDirect, Word32 wLine, Word32 wBuffLen)
1038
Word32 PixelSize = cDIBIn->GetPixelSize() / 8;
1042
Word32 wLines = cDIBIn->GetLinesNumber();
1044
for ( j = 0; j < wBuffLen; )
1046
StartByte = j * PixelSize; //������ ������
1047
EndByte = (j + VShiftLenght[j]) * PixelSize; //��������� ����������
1049
FulBytes = EndByte - StartByte + 1;
1051
if ( VShiftLenght[j] == 0 )
1057
// ���� ���� ������ �������� ��������
1059
PosInBuff = ( HShiftTable[wLine] * PixelSize) + StartByte;
1061
if ( wLine + VShiftTable[j] >= AtY && wLine + VShiftTable[j] < ToY )
1065
PixFrom = (PWord8)cDIBIn->GetPtrToPixel(j,wLine + VShiftTable[j] - AtY);
1069
PixFrom = (PWord8)cDIBIn->GetPtrToPixel(j,wLines - (wLine + VShiftTable[j] - AtY));
1073
// ������ �����. �� ��������� ������ ��������� ������� � ������������ � BufferForGray - �������� ��������
1074
// ���� ������ ��� ����� �����. �������� �������� � �������� ������� � ������� �����.
1075
if ( PosInBuff < (Int32)wWorkGrayBufferLenght )
1077
FulBytes = FulBytes > wWorkGrayBufferLenght - PosInBuff ? wWorkGrayBufferLenght - PosInBuff : FulBytes;
1081
// �������� ��������� �����
1082
memcpy(BufferForGray + PosInBuff,PixFrom, FulBytes );
1084
else // if ( pixfrom )
1086
memset(BufferForGray + PosInBuff,BitFillforGray, FulBytes );
1091
j+= VShiftLenght[j];
1094
//////////////////////////////////////////////////////////////////////////////////////////////////////////