|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // |
|
21 // Jpeg decoder class |
|
22 |
|
23 |
|
24 #ifndef __CJPROTATE_H__ |
|
25 #define __CJPROTATE_H__ |
|
26 |
|
27 #include <e32base.h> |
|
28 //#include <TBitmapHandle.h> |
|
29 #include <f32file.h> |
|
30 |
|
31 class THuffman; |
|
32 |
|
33 |
|
34 class TJpegData |
|
35 { |
|
36 public: |
|
37 TSize iSize; |
|
38 TSize iBlockSize; |
|
39 TSize iSizeInBlocks; |
|
40 }; |
|
41 |
|
42 |
|
43 |
|
44 class TJpegBasicBlock |
|
45 { |
|
46 public: |
|
47 TUint32 iOffset; |
|
48 TUint32 iBuf; |
|
49 TUint8 iBufBits; |
|
50 TInt16 iDc; |
|
51 }; |
|
52 |
|
53 |
|
54 |
|
55 /// Jpeg component information struct |
|
56 /// one for each color component |
|
57 class TComponent |
|
58 { |
|
59 public: |
|
60 char iType; |
|
61 char iXFactor; |
|
62 char iYFactor; |
|
63 char iQuantTable; |
|
64 }; |
|
65 |
|
66 |
|
67 /// save huffman |
|
68 class TSHuffman |
|
69 { |
|
70 public: |
|
71 TInt8 iLength[ 256 ]; |
|
72 TInt8 iCode[ 256 ]; |
|
73 }; |
|
74 |
|
75 |
|
76 class MJpRotateCallBack; |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 /// Main Jpeg decode class |
|
82 class CJpRotate |
|
83 : public CBase |
|
84 { |
|
85 public: |
|
86 static CJpRotate* NewL( RFs& aFs, RFile* aSaveFile, TInt aSaveBufSize ); |
|
87 static CJpRotate* NewLC( RFs& aFs, RFile* aSaveFile, TInt aSaveBufSize ); |
|
88 ~CJpRotate(); |
|
89 |
|
90 private: |
|
91 CJpRotate( RFs& aFs, RFile* aSaveFile, TInt aSaveBufSize ); |
|
92 void ConstructL(); |
|
93 |
|
94 public: |
|
95 |
|
96 void SetCallBack( MJpRotateCallBack* aCallBack ); |
|
97 void RotateL( const TFileName& aFile, TBool aRotate, TBool aFlip, TBool aMirror ); |
|
98 void RotateL( const TPtrC8& aData, TPtrC8& aTarget, TBool aRotate, TBool aFlip, TBool aMirror ); |
|
99 void RotateL( const TPtrC8& aData, TBool aRotate, TBool aFlip, TBool aMirror ); |
|
100 const TJpegData& Info(); |
|
101 TPtrC8 ExifData(); |
|
102 void Cancel(); |
|
103 |
|
104 private: |
|
105 void BufFwd( TInt aBits ); |
|
106 TInt BufBits( TInt aBits ); |
|
107 TInt Buf16(); |
|
108 void BufLoad8(); |
|
109 void DecodeBlockL( TInt aDc ); |
|
110 void DecodeBlock2L(); |
|
111 |
|
112 void WriteHuffmanL( TInt aValue ); |
|
113 void WriteBits( TUint32 aValue, TInt aNumBits ); |
|
114 void CreateSaveHuffmanL( TSHuffman* aHuffman, const TUint8* aBits, const TUint8* aVal ); |
|
115 void ConvertQuants( TUint8* aSrc, TUint8* aTgt ); |
|
116 void WriteSaveBuffer( const TUint8* aSrc, TInt aBytes ); |
|
117 void WriteSaveBuffer( TUint8 aValue ); |
|
118 void WriteSaveBuffer( TUint16 aValue ); |
|
119 |
|
120 void SaveBlocks(); |
|
121 |
|
122 void FlushSaveBuf(); |
|
123 |
|
124 private: |
|
125 |
|
126 TUint8* iBuffer; // contains whole jpeg file now |
|
127 TInt iBufPos; |
|
128 |
|
129 TUint32 iBuf; // Huffman bit buffer |
|
130 TInt iBufBits; // number of bits in bitbuffer |
|
131 |
|
132 THuffman* iHuffman[ 4 ]; // huffman lookup tables |
|
133 TInt iCurrentHuffman; |
|
134 |
|
135 TUint8* iQt[ 4 ]; // Quantization tables |
|
136 TUint8* iCurrentQt; |
|
137 |
|
138 TInt iDct[ 64 ]; // DCT coefficients |
|
139 |
|
140 TBool iRst; // RST flag, might occur on some jpegs |
|
141 // now only supports RST after line of blocks |
|
142 |
|
143 TBool iCancelled; |
|
144 |
|
145 bool iEOF; |
|
146 |
|
147 TJpegData iData; |
|
148 |
|
149 TComponent iComponent[ 4 ]; |
|
150 TInt iNumComponents; |
|
151 |
|
152 TUint8* iExifData; |
|
153 TInt iExifDataLength; |
|
154 |
|
155 TSHuffman* iSaveHuffman[ 4 ]; |
|
156 TSHuffman* iCurrentSaveHuffman; |
|
157 |
|
158 TUint8* iSaveBuf; |
|
159 TInt iSaveBufPos; |
|
160 TInt iSaveBufBitPos; |
|
161 TUint8 iSaveByte; |
|
162 |
|
163 bool iRotate; |
|
164 bool iFlip; |
|
165 bool iMirror; |
|
166 |
|
167 RArray< TJpegBasicBlock >iBasicBlock; |
|
168 |
|
169 RFs& iFs; |
|
170 RFile& iSaveFile; |
|
171 TInt iSaveBufSize; |
|
172 |
|
173 MJpRotateCallBack* iCallBack; |
|
174 |
|
175 bool iOwnBuffer; |
|
176 |
|
177 }; |
|
178 |
|
179 #endif |