|
1 /* |
|
2 * Copyright (c) 2003, 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * |
|
14 * Description: CJ2kSynthesis class used to perform inverse quantization |
|
15 * and inverse DWT |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef __JP2KSYNTHESIS_H__ |
|
21 #define __JP2KSYNTHESIS_H__ |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include "JP2KUtils.h" |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 const TUint8 KFilterShift = 14; // Filter shift for the 9x7 filter taps |
|
30 const TUint8 KWaveletShift = 4; // Shift for the fractional part of wavelet coefficients |
|
31 |
|
32 // The synthesis taps: |
|
33 // 9x7 High-pass synthesis shifted by 14 |
|
34 const TPrecInt KFixedHigh9x70 = 9879; |
|
35 const TPrecInt KFixedHigh9x71 = -4372; |
|
36 const TPrecInt KFixedHigh9x72 = -1282; |
|
37 const TPrecInt KFixedHigh9x73 = 276; |
|
38 const TPrecInt KFixedHigh9x74 = 438; |
|
39 |
|
40 // 9x7 Low-pass synthesis filter |
|
41 const TPrecInt KFixedLow9x70 = 18270; |
|
42 const TPrecInt KFixedLow9x71 = 9687; |
|
43 const TPrecInt KFixedLow9x72 = -943; |
|
44 const TPrecInt KFixedLow9x73 = -1495; |
|
45 |
|
46 const TUint8 KStepBits = 11; |
|
47 const TUint8 KFilterExtension = 4; |
|
48 const TPrecInt KMinimumPrecisionInteger = (TPrecInt)( -1 << ( KImplementationPrecision - 1 ) ); |
|
49 const TPrecInt KMaximumPrecisionInteger = (TPrecInt)( ~KMinimumPrecisionInteger ); |
|
50 |
|
51 // The coefficients we need to perform an inverse wavelet for 256 samples is at most (9x7 filter, first sample is odd) 132. |
|
52 // Thus we allocate 264 sized block to perform the inverse wavelet transform. |
|
53 const TInt32 KMaxBlockSupportSize = 264; |
|
54 const TInt32 KWaveletBlockSize = 256; |
|
55 const TInt32 KWaveletBlockMidPoint = 132; |
|
56 |
|
57 // MACROS |
|
58 |
|
59 // DATA TYPES |
|
60 |
|
61 // FUNCTION PROTOTYPES |
|
62 |
|
63 // FORWARD DECLARATIONS |
|
64 class CJ2kImageWriter; |
|
65 class CJ2kEntropyDecoder; |
|
66 class CJ2kImageInfo; |
|
67 class CJ2kTileInfo; |
|
68 class CJ2kSubband; |
|
69 class CJ2kCodeBlock; |
|
70 class CJ2kComponentInfo; |
|
71 |
|
72 // CLASS DECLARATION |
|
73 |
|
74 |
|
75 /** |
|
76 * CJ2kSynthesis class is used to decode a tile by |
|
77 * perform inverse quantization, inverse DWT, and |
|
78 * send the data to the component mixer. |
|
79 * |
|
80 * JP2KCodec.dll |
|
81 * @since 2.6 |
|
82 */ |
|
83 class CJ2kSynthesis : public CBase |
|
84 { |
|
85 public: // Constructors and destructor |
|
86 |
|
87 /** |
|
88 * C++ default constructor. |
|
89 */ |
|
90 CJ2kSynthesis(); |
|
91 |
|
92 /** |
|
93 * Destructor. |
|
94 */ |
|
95 virtual ~CJ2kSynthesis(); |
|
96 |
|
97 public: // New functions |
|
98 |
|
99 /** |
|
100 * Decode a single tile |
|
101 * @since 2.6 |
|
102 * @param aImageWriter: a reference to CJ2kImageWriter object. |
|
103 * @param aEntropyDecoder: a reference to CJ2kEntropyDecoder object. |
|
104 * @param aImageInfo: a reference to CJ2kImageInfo object. |
|
105 * @param aTile: a reference to CJ2kTileInfo object. |
|
106 */ |
|
107 void DecodeTileL( CJ2kImageWriter& aImageWriter, CJ2kEntropyDecoder& aEntropyDecoder, |
|
108 CJ2kImageInfo& aImageInfo, CJ2kTileInfo& aTile ); |
|
109 |
|
110 /** |
|
111 * Decode a single tile with block-based wavelet transformation |
|
112 * @since 2.6 |
|
113 * @param aImageWriter: a reference to CJ2kImageWriter object. |
|
114 * @param aEntropyDecoder: a reference to CJ2kEntropyDecoder object. |
|
115 * @param aImageInfo: a reference to CJ2kImageInfo object. |
|
116 * @param aTile: a reference to CJ2kTileInfo object. |
|
117 */ |
|
118 void DecodeTileBlockL( CJ2kImageWriter& aImageWriter, CJ2kEntropyDecoder& aEntropyDecoder, |
|
119 CJ2kImageInfo& aImageInfo, CJ2kTileInfo& aTile ); |
|
120 |
|
121 public: // Functions from base classes |
|
122 |
|
123 protected: // New functions |
|
124 |
|
125 protected: // Functions from base classes |
|
126 |
|
127 private: |
|
128 |
|
129 /** |
|
130 * Perform one dimensional synthesis using reversible 5/3 filter |
|
131 * @since 2.6 |
|
132 * @param aStartPos: the start position. |
|
133 * @param aEndPos: the end position. |
|
134 */ |
|
135 void OneDimReversibleFilter( TInt32 aStartPos, TInt32 aEndPos ); |
|
136 |
|
137 /** |
|
138 * Performs one dimensional symmetric extension of the line of pixels |
|
139 * @since 2.6 |
|
140 * @param aStartPos: the start position. |
|
141 * @param aEndPos: the end position. |
|
142 */ |
|
143 void PerformExtension( TInt32 aStartPos, TInt32 aEndPos ); |
|
144 |
|
145 /** |
|
146 * Perform one dimensional synthesis using irreversible 9/7 filter |
|
147 * @since 2.6 |
|
148 * @param aStartPos: the start position. |
|
149 * @param aEndPos: the end position. |
|
150 * @param aLevel: the resolution level. |
|
151 * @param aVertical: flag for the vertical filtering. |
|
152 */ |
|
153 void OneDimIrrevFilter( TInt32 aStartPos, TInt32 aEndPos, TUint8 aLevel, TUint8 aVertical ); |
|
154 |
|
155 /** |
|
156 * Perform one dimensional filtering |
|
157 * @since 2.6 |
|
158 * @param aStartPos: the start position. |
|
159 * @param aEndPos: the end position. |
|
160 * @param aLevel: the resolution level. |
|
161 * @param aVertical: flag for the vertical filtering. |
|
162 */ |
|
163 void OneDimFiltering( TInt32 aStartPos, TInt32 aEndPos, TUint8 aLevel, TUint8 aVertical ); |
|
164 |
|
165 /** |
|
166 * Perform one dimensional horizontal filtering |
|
167 * @since 2.6 |
|
168 * @param aImage: the 2-D image. |
|
169 * @param aRow: the index of row. |
|
170 * @param aXtcSiz: the length of row. |
|
171 * @param aSubband: pointer to CJ2kSubband object. |
|
172 */ |
|
173 void HorizontalFilter( TPrecInt** aImage, TInt32 aRow, TUint32 aXtcSiz, CJ2kSubband* aSubband ); |
|
174 |
|
175 /** |
|
176 * Perform one dimensional vertical filtering |
|
177 * @since 2.6 |
|
178 * @param aImage: the 2-D image. |
|
179 * @param aColumn: the index of column. |
|
180 * @param aYtcSiz: the length of column. |
|
181 * @param aSubband: pointer to CJ2kSubband object. |
|
182 */ |
|
183 void VerticalFilter( TPrecInt** aImage, TInt32 aColumn, TUint32 aYtcSiz, CJ2kSubband* aSubband ); |
|
184 |
|
185 /** |
|
186 * Perform two dimensional inverse wavelet transformation |
|
187 * @since 2.6 |
|
188 * @param aImage: the 2-D image. |
|
189 * @param aXtcSiz: the length of row. |
|
190 * @param aYtcSiz: the length of column. |
|
191 * @param aSubband: pointer to CJ2kSubband object. |
|
192 */ |
|
193 void TwoDimFiltering( TPrecInt** aImage, TInt32 aXtcSiz, TInt32 aYtcSiz, CJ2kSubband* aSubband ); |
|
194 |
|
195 /** |
|
196 * Perform a full inverse wavelet transformation |
|
197 * @since 2.6 |
|
198 * @param aImage: the 2-D image. |
|
199 * @param aSubband: pointer to CJ2kSubband object. |
|
200 */ |
|
201 void FullWaveletInverse( TPrecInt** aImage, CJ2kSubband* aSubband ); |
|
202 |
|
203 /** |
|
204 * Compute the quantization parameters for a particular subband |
|
205 * in the component |
|
206 * @since 2.6 |
|
207 * @param aComponentInfo: a reference to CJ2kComponentInfo object. |
|
208 * @param aBandIndex: the band index. |
|
209 * @param aBandGain: the band gain. |
|
210 * @param aBitdepth: the bit depth. |
|
211 */ |
|
212 void ComputeQuantizationParameters( const CJ2kComponentInfo& aComponentInfo, TInt16 aBandIndex, |
|
213 TUint8 aBandGain, TUint8 aBitDepth ); |
|
214 |
|
215 /** |
|
216 * Apply inverse quantization and ROI shifting on the decoded |
|
217 * codeblock and copy to the image writer |
|
218 * @since 2.6 |
|
219 * @param aEntropyDecoder: a reference to CJ2kEntropyDecoder object. |
|
220 * @param aImageBlock: the 2-D image block. |
|
221 * @param aSubband: a reference to CJ2kSubband object. |
|
222 * @param aCodeblock: a reference to CJ2kCodeBlock object. |
|
223 * @param aQuantizationStyle: the quantization style. |
|
224 */ |
|
225 void CopyDataToImage( CJ2kEntropyDecoder& aEntropyDecoder,TPrecInt** aImageBlock, |
|
226 CJ2kSubband& aSubband, CJ2kCodeBlock& aCodeblock, TUint8 aQuantizationStyle ); |
|
227 |
|
228 /** |
|
229 * Allocate internal buffer based on the requested size |
|
230 * @since 2.6 |
|
231 * @param aSize: the size of buffer to allocate. |
|
232 */ |
|
233 void AllocBufferL( TInt32 aSize ); |
|
234 |
|
235 /** |
|
236 * Perform one dimensional horizontal filtering (block-based) |
|
237 * @since 2.6 |
|
238 * @param aImage: the 2-D image. |
|
239 * @param aRow: the index of row. |
|
240 * @param aXtcSiz: the length of row. |
|
241 * @param aSubband: pointer to CJ2kSubband object. |
|
242 * @param aXOffset: the offset in X position. |
|
243 * @param aCurrentLevel: the current resolution level. |
|
244 */ |
|
245 void HorizontalBlockFilter( TPrecInt** aImage, TInt32 aRow, TUint32 aXtcSiz, CJ2kSubband* aSubband, |
|
246 TInt32 aXOffset, TUint8 aCurrentLevel ); |
|
247 |
|
248 /** |
|
249 * Perform one dimensional vertical filtering (block-based) |
|
250 * @since 2.6 |
|
251 * @param aImage: the 2-D image. |
|
252 * @param aColumn: the index of column. |
|
253 * @param aYtcSiz: the length of column. |
|
254 * @param aSubband: pointer to CJ2kSubband object. |
|
255 * @param aYOffset: the offset in Y position. |
|
256 * @param aCurrentLevel: the current resolution level. |
|
257 */ |
|
258 void VerticalBlockFilter( TPrecInt** aImage, TInt32 aColumn, TUint32 aYtcSiz, CJ2kSubband* aSubband, |
|
259 TInt32 aYOffset, TUint8 aCurrentLevel ); |
|
260 |
|
261 /** |
|
262 * Perform two dimensional inverse wavelet transformation (block-based) |
|
263 * @since 2.6 |
|
264 * @param aImage: the 2-D image. |
|
265 * @param aXtcSiz: the length of row. |
|
266 * @param aYtcSiz: the length of column. |
|
267 * @param aSubband: pointer to CJ2kSubband object. |
|
268 * @param aOffset: the offset in both position. |
|
269 * @param aCurrentLevel: the current resolution level. |
|
270 */ |
|
271 void TwoDimBlockFiltering( TPrecInt** aImage, TSize aRegion, CJ2kSubband* aSubband, |
|
272 TPoint aOffset, TUint8 aCurrentLevel ); |
|
273 |
|
274 /** |
|
275 * Perform a full inverse wavelet transformation (block-based) |
|
276 * @since 2.6 |
|
277 * @param aImage: the 2-D image. |
|
278 * @param aSubband: pointer to CJ2kSubband object. |
|
279 * @param aOffset: the offset in both position. |
|
280 * @param aRegion; the region. |
|
281 * @param aCurrentLevel: the current resolution level. |
|
282 */ |
|
283 void SingleLevelWaveletInverse( TPrecInt** aImage, CJ2kSubband* aSubband, TPoint aOffset, |
|
284 TSize aRegion, TUint8 aCurrentLevel ); |
|
285 |
|
286 /** |
|
287 * Apply inverse quantization and ROI shifting on the decoded |
|
288 * codeblock and copy to the image writer |
|
289 * @since 2.6 |
|
290 * @param aEntropyDecoder: a reference to CJ2kEntropyDecoder object. |
|
291 * @param aImageBlock: the 2-D image block. |
|
292 * @param aSubband: a reference to CJ2kSubband object. |
|
293 * @param aQuantizationStyle: the quantization style. |
|
294 * @param aStartRowCblk: the starting row of codeblock. |
|
295 * @param aStartColCblk: the starting column of codeblock. |
|
296 * @param aStartRowImage: the starting row of image. |
|
297 * @param aStartColImage: the starting column of image. |
|
298 * @param aCblkHeight: the codeblock height. |
|
299 * @param aCblkWidth: the codeblock width. |
|
300 */ |
|
301 void CopyDataToBlock( CJ2kEntropyDecoder& aEntropyDecoder,TPrecInt** aImageBlock, CJ2kSubband& aSubband, |
|
302 TUint8 aQuantizationStyle, TInt32 aStartRowCblk, TInt32 aStartColCblk, |
|
303 TInt32 aStartRowImage, TInt32 aStartColImage, TInt32 aCblkHeight,TInt32 aCblkWidth ); |
|
304 |
|
305 /** |
|
306 * Fill a block in image writer with zeros (corresponding to an |
|
307 * empty block) |
|
308 * @since 2.6 |
|
309 * @param aImageBlock: the 2-D image block. |
|
310 * @param aSubband: a reference to CJ2kSubband object. |
|
311 * @param aStartRowImage: the starting row of image. |
|
312 * @param aStartColImage: the starting column of image. |
|
313 * @param aCblkHeight: the codeblock height. |
|
314 * @param aCblkWidth: the codeblock width. |
|
315 */ |
|
316 void FillDataWithZeros( TPrecInt** aImageBlock, CJ2kSubband& aSubband, TInt32 aStartRowImage, |
|
317 TInt32 aStartColImage, TInt32 aCblkHeight, TInt32 aCblkWidth ); |
|
318 |
|
319 public: // Data |
|
320 |
|
321 protected: // Data |
|
322 |
|
323 private: // Data |
|
324 |
|
325 // Number of filters tap for low-pass and high-pass |
|
326 enum TFilterTap |
|
327 { |
|
328 ELowTap = 4, |
|
329 EHighTap |
|
330 }; |
|
331 |
|
332 // Is transformation reversible? |
|
333 TUint8 iReversible; |
|
334 |
|
335 // Magnitude bits for this band |
|
336 TUint8 iMagnitudeBitsHere; |
|
337 |
|
338 // Resolution level for DWT |
|
339 TInt16 iWaveletLevels; |
|
340 |
|
341 // Amount of shift for ROI |
|
342 TInt32 iROIShift; |
|
343 |
|
344 // Downshift for ROI data samples |
|
345 TInt32 iROIDataShift; |
|
346 |
|
347 // Downshift for data samples |
|
348 TInt32 iDataShift; |
|
349 |
|
350 // Quantization step value |
|
351 TInt32 iStepValue; |
|
352 |
|
353 // Quantization step's exponent |
|
354 TInt32 iStepExponent; |
|
355 |
|
356 // Internal buffer size |
|
357 TInt32 iIOBufferSize; |
|
358 |
|
359 // Internal input buffer |
|
360 TInt32* iInputBuffer; |
|
361 |
|
362 // Internal output buffer |
|
363 TInt32* iOutputBuffer; |
|
364 |
|
365 // Filter taps for irreversible low-pass filtering |
|
366 TPrecInt iTapsLow[ELowTap]; |
|
367 |
|
368 // Filter taps for irreversible high-pass filtering |
|
369 TPrecInt iTapsHigh[EHighTap]; |
|
370 |
|
371 public: // Friend classes |
|
372 |
|
373 protected: // Friend classes |
|
374 |
|
375 private: // Friend classes |
|
376 |
|
377 }; |
|
378 |
|
379 #endif // __JP2KSYNTHESIS_H__ |