|
1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __TIFFCODEC_H__ |
|
17 #define __TIFFCODEC_H__ |
|
18 |
|
19 #include <bitdev.h> |
|
20 #include <icl/imageprocessor.h> |
|
21 #include <icl/imagecodec.h> |
|
22 #include <icl/imagecodecdata.h> |
|
23 |
|
24 #include "TIFFConvert.h" |
|
25 #include "../recordtable.h" |
|
26 |
|
27 // Constants. |
|
28 const TInt KTiffIfdEntryTagOffset = 0; |
|
29 const TInt KTiffIfdEntryTypeOffset = 2; |
|
30 const TInt KTiffIfdEntryCountOffset = 4; |
|
31 const TInt KTiffIfdEntryValueOffset = 8; |
|
32 const TInt KTiffIfdEntryLength = 12; |
|
33 |
|
34 // Helper classes. |
|
35 // TTiffImageStrip |
|
36 class TTiffImageStrip |
|
37 { |
|
38 public: |
|
39 TInt iOffset; |
|
40 TInt iLength; |
|
41 }; |
|
42 |
|
43 // Tiff Image File Directory (IFD) class |
|
44 class TTiffIfdEntry |
|
45 { |
|
46 public: |
|
47 enum TId |
|
48 { |
|
49 ENewSubfileType = 0xFE, |
|
50 ESubfileType = 0xFF, |
|
51 EImageWidth = 0x100, |
|
52 EImageLength = 0x101, |
|
53 EBitsPerSample = 0x102, |
|
54 ECompression = 0x103, |
|
55 EPhotometricInterpretation = 0x106, |
|
56 EFillOrder = 0x10A, |
|
57 EStripOffsets = 0x111, |
|
58 ESamplesPerPixel = 0x115, |
|
59 ERowsPerStrip = 0x116, |
|
60 EStripByteCounts = 0x117, |
|
61 EXResolution = 0x11a, |
|
62 EYResolution = 0x11b, |
|
63 ET4Options = 0x124, |
|
64 ET6Options = 0x125, |
|
65 EResolutionUnit = 0x128, |
|
66 }; |
|
67 enum TType |
|
68 { |
|
69 EByte = 1, |
|
70 EAscii = 2, |
|
71 EShort = 3, |
|
72 ELong = 4, |
|
73 ERational = 5, |
|
74 ESbyte = 6, |
|
75 EUndefined = 7, |
|
76 ESshort = 8, |
|
77 ESlong = 9, |
|
78 ESrational = 10, |
|
79 EFloat = 11, |
|
80 EDouble = 12, |
|
81 }; |
|
82 enum TT4Options |
|
83 { |
|
84 ET4TwoDimentionalCoding = 0x1, |
|
85 ET4ContainsUncompressedData = 0x2, |
|
86 ET4ContainsPaddedEols = 0x4 |
|
87 }; |
|
88 enum TT6Options |
|
89 { |
|
90 ET6ContainsUncompressedData = 0x2, |
|
91 }; |
|
92 enum TCompression |
|
93 { |
|
94 EUncompressed = 1, |
|
95 ECcitt1dCompression = 2, |
|
96 EGroup3FaxCompression = 3, |
|
97 EGroup4FaxCompression = 4, |
|
98 ELzwCompression = 5, |
|
99 EJpegCompression = 6, |
|
100 EPackBitsCompression = 32773, |
|
101 }; |
|
102 enum TPhotometricInterpretation |
|
103 { |
|
104 EWhiteIsZero = 0, |
|
105 EBlackIsZero = 1, |
|
106 ERgb = 2, |
|
107 ERgbPalette = 3, |
|
108 ETransparencyMask = 4, |
|
109 ECmyk = 5, |
|
110 EYCbCr = 6, |
|
111 ECieLab = 8, |
|
112 }; |
|
113 public: |
|
114 TInt TypeSize() const; |
|
115 public: |
|
116 TId iId; |
|
117 TType iType; |
|
118 TInt iCount; |
|
119 TUint32 iValue; |
|
120 TUint8* iValuePtr; |
|
121 }; |
|
122 |
|
123 |
|
124 // Read codec. |
|
125 class CTiffDecoder; |
|
126 class CTiffReadSubCodec : public CBase |
|
127 { |
|
128 public: |
|
129 virtual void DoNewFrameL(CFbsBitmap& aBitmap, TBool aDisableErrorDiffusion, TInt aReductionFactor) = 0; |
|
130 virtual void NewStripL(TInt aNumBytes) = 0; |
|
131 virtual TBool ProcessStripL(TBufPtr8* aSrc) = 0; |
|
132 }; |
|
133 |
|
134 class CTiffReadCodec : public CImageReadCodec |
|
135 { |
|
136 public: |
|
137 |
|
138 static CTiffReadCodec* NewL(TTiffFormatInfo aFormatInfo, CTiffDecoder& aPlugin); |
|
139 |
|
140 // from CImageReadCodec |
|
141 virtual void InitFrameL(TFrameInfo& aFrameInfo, CFrameImageData& aFrameImageData, TBool aDisableErrorDiffusion, CFbsBitmap& aDestination, CFbsBitmap* aDestinationMask); |
|
142 virtual void InitFrameHeader(TFrameInfo& aFrameSettings, CFrameImageData& aFrameImageData); |
|
143 |
|
144 TFrameState ProcessFrameHeaderL(TBufPtr8& aData); |
|
145 TFrameState ProcessFrameL(TBufPtr8& aSrc); |
|
146 void GetNewDataPosition(TInt& aPosition, TInt& aLength); |
|
147 |
|
148 protected: |
|
149 ~CTiffReadCodec(); |
|
150 |
|
151 private: |
|
152 CTiffReadCodec(TTiffFormatInfo aFormatInfo, CTiffDecoder& aPlugin); |
|
153 |
|
154 |
|
155 private: |
|
156 TInt ReadIfdL(const TUint8*& aPtr,const TUint8* aPtrLimit, TInt& aIfdLengthInBytes); |
|
157 void ReadIfdEntryL(TTiffIfdEntry& aEntry,const TUint8*const aPtr); |
|
158 TInt ReadLongValuesL(const TUint8*& aPtr, const TUint8*const aPtrLimit); |
|
159 void ProcessIfdL(); |
|
160 void ProcessIfdEntryL(const TTiffIfdEntry& aEntry); |
|
161 TInt IntegerIfdEntryValueL(const TTiffIfdEntry& aEntry) const; |
|
162 TInt IntegerIfdEntryValueL(const TTiffIfdEntry& aEntry,TInt aIndex) const; |
|
163 TReal RationalIfdEntryValueL(const TTiffIfdEntry& aEntry) const; |
|
164 void NewStripL(); |
|
165 private: |
|
166 enum TProcessHeaderState |
|
167 { |
|
168 EReadIfd, |
|
169 EReadLongValues, |
|
170 EProcessIfd, |
|
171 EFinish |
|
172 }; |
|
173 private: |
|
174 // Local frame settings. |
|
175 TFrameInfo *iImageInfo; |
|
176 CFrameImageData *iImageData; |
|
177 |
|
178 TTiffImageData* iFrameImageData; |
|
179 TTiffImageData* iTiffImageData; |
|
180 TTiffImageStrip* iStripInfo; |
|
181 |
|
182 TInt iNewPosition; |
|
183 |
|
184 TTiffFormatInfo iFormatInfo; |
|
185 TTiffValueReader iValueReader; |
|
186 TInt iNextIfdOffset; |
|
187 |
|
188 TProcessHeaderState iProcessHeaderState; |
|
189 |
|
190 HBufC8* iIfdBuffer; |
|
191 TTiffIfdEntry* iIfdEntries; |
|
192 TInt iNumIfdEntries; |
|
193 |
|
194 HBufC8* iLongValuesBuffer; |
|
195 TUint8* iLongValues; |
|
196 TInt iLongValuesSize; |
|
197 TInt iLoadedLongValuesSize; |
|
198 TInt iLongValuesStartOffset; |
|
199 TInt iLongValuesEndOffset; |
|
200 |
|
201 TBool iNewStrip; |
|
202 TInt iCurrentStrip; |
|
203 |
|
204 CTiffReadSubCodec* iDecoder; |
|
205 CTiffDecoder& iPlugin; |
|
206 TInt iIfdOffset; |
|
207 TInt iIfdSize; |
|
208 CRecordTable* iRecordTable; |
|
209 }; |
|
210 |
|
211 #endif // __TIFFCODEC_H__ |
|
212 |