|
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: CJ2kImageWriter class used to perform inverse transformation and |
|
15 * writing decoded image data to bitmap. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef __JP2KIMAGEWRITER_H__ |
|
21 #define __JP2KIMAGEWRITER_H__ |
|
22 |
|
23 // INCLUDES |
|
24 #include <icl/imageprocessor.h> |
|
25 |
|
26 // CONSTANTS |
|
27 const TUint8 KByteBits = 8; // Number of bits in byte |
|
28 const TUint8 KFractionBits = 12; |
|
29 const TUint16 KOffset = (1 << ( KFractionBits - 1 ) ); |
|
30 |
|
31 // Inverse color transform shifted(by 12 bits) coefficients |
|
32 const TInt32 KIctCoefficient11 = 5743; |
|
33 const TInt32 KIctCoefficient21 = -1409; |
|
34 const TInt32 KIctCoefficient22 = -2925; |
|
35 const TInt32 KIctCoefficient31 = 7258; |
|
36 |
|
37 // The ICC profile Tag definitions |
|
38 const TUint8 KICCSkipBytes = 128; // Bytes to skip before reading the ICC profile |
|
39 const TUint32 KRedMatrixTag = 0x7258595A; // Tag indicating the place (in ICC profile) of conversion matrix coefficients for red |
|
40 const TUint32 KGreenMatrixTag = 0x6758595A; // Tag indicating the place of conversion matrix coefficients for green |
|
41 const TUint32 KBlueMatrixTag = 0x6258595A; // Tag indicating the place of conversion matrix coefficients for blue |
|
42 const TUint32 KRedTrcTag = 0x72545243; // Tag indicating the place of Tone Reproduction Curve value for red |
|
43 const TUint32 KGreenTrcTag = 0x67545243; // Tag indicating the place of Tone Reproduction Curve value for green |
|
44 const TUint32 KBlueTrcTag = 0x62545243; // Tag indicating the place of Tone Reproduction Curve value for blue |
|
45 const TUint32 KGrayTrcTag = 0x6B545243; // Tag indicating the place of Tone Reproduction Curve value for gray |
|
46 const TUint32 KPixelsBlock = 256; // The max number of pixel in a block |
|
47 |
|
48 // Define the XYZ to linear sRGB matrix coefficients |
|
49 const TReal KSRGB00 = 3.1337; |
|
50 const TReal KSRGB01 = -1.6173; |
|
51 const TReal KSRGB02 = -0.4907; |
|
52 const TReal KSRGB10 = -0.9785; |
|
53 const TReal KSRGB11 = 1.9162; |
|
54 const TReal KSRGB12 = 0.0334; |
|
55 const TReal KSRGB20 = 0.0720; |
|
56 const TReal KSRGB21 = -0.2290; |
|
57 const TReal KSRGB22 = 1.4056; |
|
58 const TReal KSRGBMax = (TReal)4095; |
|
59 const TInt32 KSRGBMaxInt = (TInt32)4095; |
|
60 const TInt32 KSRGBShift = 4; // The shift for the sRGB maximum value |
|
61 const TInt32 KSRGBMaxIntShifted = (TInt32)( ( 1 << KSRGBShift ) * (TReal)4095 );// The sRGB maximum value shifted by 4 |
|
62 const TInt32 KTRCShift = 12; // The shift used for TRC LUT values for integer computation |
|
63 const TInt32 KTRCShiftMultiplier = (TInt32)( 1 << KTRCShift ); // The shift used for TRC LUT values for integer computation |
|
64 const TUint32 KICCDownshift = KTRCShift + KSRGBShift; // The total shift used for computing the ICC conversion with integers (12 for TRC LUT and 4 for the matrix coefficients) |
|
65 |
|
66 const TReal KDivisor = (TReal)65536; |
|
67 const TReal KGamma = (TReal)256; |
|
68 |
|
69 // Define values for performing the linear RGB -> sRGB (non linear) conversion |
|
70 const TReal KSRGB_CUTOFF = 0.0031308; |
|
71 const TReal KSRGB_SLOPE = 12.92; |
|
72 const TReal KSRGB_EXPONENT = 0.4166666; // ( 1.0 / 2.4 ); |
|
73 const TReal KSRGB_MULTIPLIER = 1.055; |
|
74 const TReal KSRGB_SUBTRACT = 0.055; |
|
75 |
|
76 // DATA TYPES |
|
77 |
|
78 // FUNCTION PROTOTYPES |
|
79 |
|
80 // FORWARD DECLARATIONS |
|
81 class CJ2kImageWriter; |
|
82 class CJ2kImageInfo; |
|
83 class CJ2kTileInfo; |
|
84 class TJ2kInfo; |
|
85 |
|
86 // CLASS DECLARATION |
|
87 |
|
88 /** |
|
89 * CJ2kWriterComponentInfo class is used to store |
|
90 * information about tiles' coordinates for outputting |
|
91 * samples and also to store the output data. |
|
92 * |
|
93 * JP2KCodec.dll |
|
94 * @since 2.6 |
|
95 */ |
|
96 class CJ2kWriterComponentInfo : public CBase |
|
97 { |
|
98 public: // Constructors and destructor |
|
99 |
|
100 /** |
|
101 * Destructor. |
|
102 */ |
|
103 virtual ~CJ2kWriterComponentInfo(); |
|
104 |
|
105 public: // New functions |
|
106 |
|
107 /** |
|
108 * Allocate the 2-D data array with a size |
|
109 * @since 2.6 |
|
110 * @param aSize: the size to allocate. |
|
111 */ |
|
112 void AllocDataL( const TSize& aSize ); |
|
113 |
|
114 /** |
|
115 * Free the 2-D data array |
|
116 * @since 2.6 |
|
117 */ |
|
118 void FreeData(); |
|
119 |
|
120 /** |
|
121 * Get the 2-D data arry |
|
122 * @since 2.6 |
|
123 * @return TPrecInt**: the pointer to pointer. |
|
124 */ |
|
125 TPrecInt** Data(); |
|
126 |
|
127 /** |
|
128 * Get the starting point of a tile |
|
129 * @since 2.6 |
|
130 * @param aTileIndex: the tile index. |
|
131 * @return TPoint&: a reference to the start point of the tile. |
|
132 */ |
|
133 TPoint& TileStartAt( TUint16 aTileIndex ); |
|
134 |
|
135 /** |
|
136 * Update the starting point of next tile |
|
137 * @since 2.6 |
|
138 * @param aTileIndex: the tile index. |
|
139 * @param aSize: the size of the tile. |
|
140 * @param aImageInfo: a reference to CJ2kImageInfo object. |
|
141 */ |
|
142 void UpdateNextTileStartAt(TUint16 aTileIndex, const TSize& aSize, CJ2kImageInfo& aImageInfo ); |
|
143 |
|
144 public: // Functions from base classes |
|
145 |
|
146 protected: // New functions |
|
147 |
|
148 protected: // Functions from base classes |
|
149 |
|
150 private: |
|
151 |
|
152 public: // Data |
|
153 |
|
154 protected: // Data |
|
155 |
|
156 private: // Data |
|
157 |
|
158 // Internal 2-D data array |
|
159 TPrecInt **iData; |
|
160 |
|
161 // Start position of each tile |
|
162 RArray<TPoint> iTileStartList; |
|
163 |
|
164 public: // Friend classes |
|
165 friend class CJ2kImageWriter; |
|
166 |
|
167 protected: // Friend classes |
|
168 |
|
169 private: // Friend classes |
|
170 }; |
|
171 |
|
172 /** |
|
173 * CJ2kImageWriter class has methods to perform |
|
174 * color, bitdepth and ICC profile conversions to |
|
175 * produce 8-bit output data. |
|
176 * |
|
177 * JP2KCodec.dll |
|
178 * @since 2.6 |
|
179 */ |
|
180 class CJ2kImageWriter : public CBase |
|
181 { |
|
182 public: // Constructors and destructor |
|
183 |
|
184 /** |
|
185 * Two-phased constructor. |
|
186 */ |
|
187 static CJ2kImageWriter* NewL( CImageProcessor* aImageProcessor, CJ2kImageInfo& aImageInfo, |
|
188 TJ2kInfo& aJ2kInfo ); |
|
189 |
|
190 /** |
|
191 * Destructor. |
|
192 */ |
|
193 virtual ~CJ2kImageWriter(); |
|
194 |
|
195 public: // New functions |
|
196 |
|
197 /** |
|
198 * Get the component of the image writer |
|
199 * @since 2.6 |
|
200 * @param aIndex: the component index. |
|
201 * @return CJ2kWriterComponentInfo&: a reference to CJ2kWriterComponentInfo. |
|
202 */ |
|
203 const CJ2kWriterComponentInfo& WriterComponentAt( TUint16 aIndex ) const; |
|
204 |
|
205 /** |
|
206 * Output the image related to the component of the tile |
|
207 * @since 2.6 |
|
208 * @param aTile: a reference to CJ2kTileInfo object. |
|
209 * @param aComponentIndex: the component index. |
|
210 */ |
|
211 void OutputImageL( CJ2kTileInfo& aTile, TUint16 aComponentIndex ); |
|
212 |
|
213 /** |
|
214 * Output the image related to the component of the tile |
|
215 * @since 2.6 |
|
216 * @param aTile: a reference to CJ2kTileInfo object. |
|
217 * @param aComponentIndex: the component index. |
|
218 * @param aSize: the size to output. |
|
219 */ |
|
220 void OutputImageL( CJ2kTileInfo& aTile, TUint16 aComponentIndex, |
|
221 const TSize& aSize ); |
|
222 /** |
|
223 * Output the image related to the component of the tile |
|
224 * @param aTile: a reference to CJ2kTileInfo object. |
|
225 * @param aComponentIndex: the component index. |
|
226 * @param aBlockXCoord: the block X coordinate. |
|
227 * @param aBlockYCoord: the block Y coordinate. |
|
228 * @param aFirstCompSize: the size of first component. |
|
229 * @param aThisCompSize: the size of this component. |
|
230 */ |
|
231 void OutputBlockL( CJ2kTileInfo& aTile, TUint16 aComponentIndex, |
|
232 TInt32 aBlockXCoord, TInt32 aBlockYCoord, |
|
233 TSize aFirstCompSize, TSize aThisCompSize ); |
|
234 /** |
|
235 * Set the image processor of the image write |
|
236 * @since 2.6 |
|
237 * @param aImageProcessor: a pointer to CImageProcessor object. |
|
238 */ |
|
239 void SetNewImageProcessor( CImageProcessor* aImageProcessor ); |
|
240 |
|
241 /** |
|
242 * Get the single output file |
|
243 * @since 2.6 |
|
244 * @return TUint8: true if single file output. |
|
245 */ |
|
246 TUint8 SingleFileOutput() const; |
|
247 |
|
248 /** |
|
249 * Get the EnumCS |
|
250 * @since 2.6 |
|
251 * @return TUint8: the CS code. |
|
252 */ |
|
253 TUint8 CSCode() const; |
|
254 |
|
255 public: // Functions from base classes |
|
256 |
|
257 protected: // New functions |
|
258 |
|
259 protected: // Functions from base classes |
|
260 |
|
261 private: |
|
262 |
|
263 /** |
|
264 * C++ default constructor. |
|
265 */ |
|
266 CJ2kImageWriter( CImageProcessor* aImageProcessor, CJ2kImageInfo& aImageInfo, TJ2kInfo& aJ2kInfo ); |
|
267 |
|
268 /** |
|
269 * By default Symbian 2nd phase constructor is private. |
|
270 */ |
|
271 void ConstructL(); |
|
272 |
|
273 /** |
|
274 * Perform the inverse reversible color transformation |
|
275 * @since 2.6 |
|
276 * @param aSize: the size. |
|
277 */ |
|
278 void PerformInverseRCT( const TSize& aSize ); |
|
279 |
|
280 /** |
|
281 * Perform the inverse irreversible color transformation |
|
282 * @since 2.6 |
|
283 * @param aSize: the size. |
|
284 */ |
|
285 void PerformInverseICT( const TSize& aSize ); |
|
286 |
|
287 /** |
|
288 * Inverse irreversible color transformation |
|
289 * @since 2.6 |
|
290 * @param aY: the Y value. |
|
291 * @param aU: the U value. |
|
292 * @param aV: the V value. |
|
293 * @param aR: a reference to red value. |
|
294 * @param aG: a reference to green value. |
|
295 * @param aB: a reference to blue value. |
|
296 */ |
|
297 void InverseICTTransform( TPrecInt aY, TPrecInt aU, TPrecInt aV, |
|
298 TPrecInt& aR, TPrecInt& aG, TPrecInt& aB ); |
|
299 |
|
300 /** |
|
301 * Inverse irreversible color transformation |
|
302 * @since 2.6 |
|
303 * @param aY1: the Y value of the even sample. |
|
304 * @param aY2: the Y value of the odd sample. |
|
305 * @param aU: the U value. |
|
306 * @param aV: the V value. |
|
307 * @param aR1: a reference to even red value. |
|
308 * @param aG1: a reference to even green value. |
|
309 * @param aB1: a reference to even blue value. |
|
310 * @param aR2: a reference to odd red value. |
|
311 * @param aG2: a reference to odd green value. |
|
312 * @param aB2: a reference to odd blue value. |
|
313 */ |
|
314 void InverseICTTransform( TPrecInt aY1, TPrecInt aY2, TPrecInt aU, TPrecInt aV, |
|
315 TPrecInt& aR1, TPrecInt& aG1, TPrecInt& aB1, |
|
316 TPrecInt& aR2, TPrecInt& aG2, TPrecInt& aB2 ); |
|
317 |
|
318 /** |
|
319 * Inverse irreversible color transformation |
|
320 * @since 2.6 |
|
321 * @param aY1: the Y value of the even sample on even row. |
|
322 * @param aY2: the Y value of the odd sample on even row. |
|
323 * @param aY3: the Y value of the even sample on odd row. |
|
324 * @param aY4: the Y value of the odd sample on odd row. |
|
325 * @param aU: the U value. |
|
326 * @param aV: the V value. |
|
327 * @param aR1: a reference to even red value on even row. |
|
328 * @param aG1: a reference to even green value on even row. |
|
329 * @param aB1: a reference to even blue value on even row. |
|
330 * @param aR2: a reference to odd red value on even row. |
|
331 * @param aG2: a reference to odd green value on even row. |
|
332 * @param aB2: a reference to odd blue value on even row. |
|
333 * @param aR3: a reference to even red value on odd row. |
|
334 * @param aG3: a reference to even green value on odd row. |
|
335 * @param aB3: a reference to even blue value on odd row. |
|
336 * @param aR4: a reference to odd red value on odd row. |
|
337 * @param aG4: a reference to odd green value on odd row. |
|
338 * @param aB4: a reference to odd blue value on odd row. |
|
339 */ |
|
340 void InverseICTTransform( TPrecInt aY1, TPrecInt aY2, TPrecInt aY3, TPrecInt aY4, |
|
341 TPrecInt aU, TPrecInt aV, |
|
342 TPrecInt& aR1, TPrecInt& aG1, TPrecInt& aB1, |
|
343 TPrecInt& aR2, TPrecInt& aG2, TPrecInt& aB2, |
|
344 TPrecInt& aR3, TPrecInt& aG3, TPrecInt& aB3, |
|
345 TPrecInt& aR4, TPrecInt& aG4, TPrecInt& aB4 ); |
|
346 |
|
347 /** |
|
348 * Initialize the ICC profile from JP2 file format (iJ2kInfo) |
|
349 * @since 2.6 |
|
350 */ |
|
351 void InitializeICCProfileL(); |
|
352 |
|
353 /** |
|
354 * Initialize the output parameters |
|
355 * @since 2.6 |
|
356 */ |
|
357 void InitializeOutputParametersL(); |
|
358 |
|
359 /** |
|
360 * Perform the XYZ to sRGB conversion using ICC profile. |
|
361 * @since 2.6 |
|
362 * @param aX: sample x to be converted. |
|
363 * @param aY: sample y to be converted. |
|
364 * @param aZ: sample z to be converted. |
|
365 * @param aR: a reference to red value. |
|
366 * @param aG: a reference to green value. |
|
367 * @param aB: a reference to blue value. |
|
368 */ |
|
369 void DoICCConversion( TInt32 aX, TInt32 aY, TInt32 aZ, |
|
370 TPrecInt& aR, TPrecInt& aG, TPrecInt& aB ); |
|
371 /** |
|
372 * Map data less than 8 bits to 8 bits data |
|
373 * @since 2.6 |
|
374 * @param aComponent: a reference to CJ2kWriterComponentInfo object. |
|
375 * @param aSize: the size of component. |
|
376 * @param aBitDepth: the bit depth. |
|
377 */ |
|
378 void MapToEightBits( CJ2kWriterComponentInfo& aComponent, |
|
379 const TSize& aSize, TUint16 aBitDepth ); |
|
380 |
|
381 /** |
|
382 * Map data using the component mapping box from JP2 file format |
|
383 * @since 2.6 |
|
384 * @param aNumCSComp: number of CS component. |
|
385 * @param aReducedLevels: the reduced resolution level. |
|
386 * @param aSize: the size to output. |
|
387 * @param aTile: a reference to CJ2kTileInfo object. |
|
388 */ |
|
389 void MapComponentsL( TUint16 aNumCSComp,TUint16 aReducedLevels, |
|
390 const TSize& aSize, CJ2kTileInfo& aTile ); |
|
391 |
|
392 /** |
|
393 * Write the component to the single output file |
|
394 * @since 2.6 |
|
395 * @param aTile: a reference to CJ2kTileInfo object. |
|
396 * @param aCompIndex: the component index. |
|
397 * @param aSize: the size of component. |
|
398 * @param aBitDepth: the bit depth. |
|
399 */ |
|
400 void WriteOutputFile( CJ2kTileInfo& aTile, TUint16 aCompIndex, const TSize& aSize, |
|
401 TUint16 aBitDepth ); |
|
402 |
|
403 /** |
|
404 * Write all components of the tile to the single output file |
|
405 * @since 2.6 |
|
406 * @param aTile: a reference to CJ2kTileInfo object. |
|
407 * @param aSize: the size to output. |
|
408 */ |
|
409 void CombineOutputFile( CJ2kTileInfo& aTile, const TSize& aSize ); |
|
410 |
|
411 /** |
|
412 * Write out a color pixel |
|
413 * @since 2.6 |
|
414 * @param aR: the red value. |
|
415 * @param aG: the green value. |
|
416 * @param aB: the blue value. |
|
417 */ |
|
418 void WritePixel( TUint8 aR, TUint8 aG, TUint8 aB ); |
|
419 |
|
420 /** |
|
421 * Write out a grayscale pixel |
|
422 * @since 2.6 |
|
423 * @param aGray256: the gray scale value. |
|
424 */ |
|
425 void WritePixel( TUint8 aGray256 ); |
|
426 |
|
427 /** |
|
428 * Set the position of the pixel |
|
429 * @since 2.6 |
|
430 * @param aPosition: the position of next pixel. |
|
431 */ |
|
432 void SetPixelPos( const TPoint& aPosition ); |
|
433 |
|
434 /** |
|
435 * Set the position of the pixel |
|
436 * @since 2.6 |
|
437 * @param aX: the X position of next pixel. |
|
438 * @param aY: the Y position of next pixel. |
|
439 */ |
|
440 void SetPixelPos( const TInt aX, const TInt aY ); |
|
441 |
|
442 public: // Data |
|
443 |
|
444 protected: // Data |
|
445 |
|
446 private: // Data |
|
447 |
|
448 // File type |
|
449 enum TFileType |
|
450 { |
|
451 KOurRGB, //lint !e769 keep here for later use |
|
452 KRGB, |
|
453 KYUV422, |
|
454 KYUV420 |
|
455 }; |
|
456 |
|
457 // Number of components |
|
458 TUint16 iNumComponents; |
|
459 |
|
460 // File type |
|
461 TFileType iFileType; |
|
462 |
|
463 // Is single file output? |
|
464 TUint8 iSingleFileOutput; |
|
465 |
|
466 // Is ICC Profile used? |
|
467 TUint8 iICCProfile; |
|
468 |
|
469 // An array of component infos |
|
470 RPointerArray<CJ2kWriterComponentInfo> iComponents; |
|
471 |
|
472 // Reference to the image processor |
|
473 CImageProcessor* iImageProcessor; |
|
474 |
|
475 // Reference to the image info |
|
476 CJ2kImageInfo& iImageInfo; |
|
477 |
|
478 // Reference to the file format into |
|
479 TJ2kInfo& iJ2kInfo; |
|
480 |
|
481 // ** For ICC Profile ** |
|
482 |
|
483 // Conversion matrix to perform the RGBin->XYZ->sRGB conversion |
|
484 TInt32 iMatrix[9]; |
|
485 |
|
486 // Linear sRGB lookup table for sRGB(lin)->sRGB(non-lin) conversion |
|
487 HBufC8 *iLinearsRGBLut; |
|
488 |
|
489 // Tone reproduction curve LUT for linearizing Gray input sample |
|
490 TInt32 *iGrayTRCLut; |
|
491 |
|
492 // Tone reproduction curve LUT for linearizing Red input sample |
|
493 TInt32 *iRedTRCLut; |
|
494 |
|
495 // Tone reproduction curve LUT for linearizing Green input sample |
|
496 TInt32 *iGreenTRCLut; |
|
497 |
|
498 // Tone reproduction curve LUT for linearizing Blue input sample |
|
499 TInt32 *iBlueTRCLut; |
|
500 |
|
501 // Block containing grayscale pixels |
|
502 TUint32 *iMonoPixelBlock; |
|
503 |
|
504 // Block containing color pixels |
|
505 TRgb *iColorPixelBlock; |
|
506 |
|
507 public: // Friend classes |
|
508 |
|
509 protected: // Friend classes |
|
510 |
|
511 private: // Friend classes |
|
512 |
|
513 }; |
|
514 |
|
515 #endif // __JP2KIMAGEWRITER_H__ |