|
1 // Copyright (c) 2006-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 JPEGWRITECODEC_H |
|
17 |
|
18 #define JPEGWRITECODEC_H |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalComponent |
|
23 */ |
|
24 //#define PROFILE_JPEG_ENCODER 1 |
|
25 #include "imgpositionprocessor.h" |
|
26 #include "JpegTypes.h" |
|
27 |
|
28 class TPositionProcessor; |
|
29 class CRgbBufferPtr; |
|
30 class CImageFrame; |
|
31 class CJpgImageFrameWriteCodec; |
|
32 class CJpgImageFrameProcessor; |
|
33 class TDataUnit; |
|
34 class TQTable; |
|
35 |
|
36 |
|
37 const TInt KEncDCHTSize = 11; |
|
38 const TInt KEncACHTSize = 0xFA; |
|
39 |
|
40 // CJpgWriteCodec |
|
41 class CJpgWriteCodec : public CImageWriteCodec |
|
42 { |
|
43 public: |
|
44 |
|
45 static CJpgWriteCodec* NewL(const TJpgFrameInfo& aFrameInfo,TInt aQualityFactor,TQTable* aReplacementLumaQTable,TQTable* aReplacementChromaQTable,const RPointerArray<HBufC8>& aComment,RArray<TUint>* aOperationsRequested); |
|
46 |
|
47 virtual ~CJpgWriteCodec(); |
|
48 |
|
49 // Jpg codec support for Image Frame |
|
50 void InitFrameL(TBufPtr8& aDst, const CImageFrame* aFrame, const CFrameImageData* aFrameImageData); |
|
51 |
|
52 // Jpg codec support for Image Frame streaming |
|
53 void InitFrameL(TBufPtr8& aDst, TUid aFormat, TInt aFrameNumber, const TSize& aFrameSizeInPixels, const TSize& aBlockSizeInPixels, const CFrameImageData* aFrameImageData); |
|
54 void AppendFrameBlockL(const CImageFrame& aBlocks, TInt aNumBlocksToAdd); |
|
55 void CompleteFrame(); |
|
56 void SetCompleteFrame(); |
|
57 |
|
58 static void InitTransformCoordinates(TPositionProcessor& aPosProcessor, const TRect& aSourceRect, const TSize& aMCUSize, const RArray<TUint>& aOperationsRequested); |
|
59 static void ValidateBlockSizeL(const TSize& aBlockSizeInPixels, const TSize& aRefSizeInPixels); |
|
60 void SetHighSpeedMode(TBool aHighSpeedMode); |
|
61 protected: |
|
62 CJpgWriteCodec(const TJpgFrameInfo& aFrameInfo,TInt aQualityFactor,TQTable* aReplacementLumaQTable,TQTable* aReplacementChromaQTable,const RPointerArray<HBufC8>& aComment); |
|
63 void ConstructL(RArray<TUint>* aOperationsRequested); |
|
64 |
|
65 virtual TFrameState ProcessFrameL(TBufPtr8& aSrc); |
|
66 virtual void InitFrameL(TBufPtr8& aDst, const CFbsBitmap& aSource); |
|
67 void CodecInfoL(); |
|
68 void WriteInfoL(); |
|
69 void DoProcessL(); |
|
70 void InitCompConfig(); |
|
71 CRgbBufferPtr::TConstRgbBufferPtr GetPixels(const TPoint& aPos); |
|
72 void WriteDataUnitL(const TDataUnit& aDataUnit,const TEncHuffmanTable<KEncDCHTSize+1>& aDCTable,const TEncHuffmanTable<KEncACHTSize+1>& aACTable,TInt& aDCPredictor); |
|
73 inline TUint32 WriteBitsFast(TUint32 aValue, TInt aNumBits, TUint32& aBitBuffer, TInt aBitsUsed); |
|
74 void WriteBits(TUint32 aBitBuffer); |
|
75 |
|
76 void InitTransformationL(TPositionProcessor& aPosProcessor, const TRect& aSourceRect, const TSize& aMCUSize, TJpgFrameInfo& aFrameInfo, const TInt aDataUnitCount); |
|
77 void InitTransformDataUnitIndex(TInt aDataUnitCount); |
|
78 void InitTransformDataUnitCoeff(TUint8* aDestination); |
|
79 void TransformDataUnitCoeff(TDataUnit& aDestination, const TDataUnit& aSource); |
|
80 TInt GetIndexFromPos(const TPoint& aPos); |
|
81 |
|
82 private: |
|
83 typedef TUint32 TBitBufferType; |
|
84 TUint8* iDestPtr; |
|
85 TUint8* iDestPtrLimit; |
|
86 TInt iBitsUsed; |
|
87 //Must be TUint32 |
|
88 TUint32 iBitBuffer; |
|
89 |
|
90 protected: |
|
91 TInt iDCPredictor[KJpgNumberOfComponents]; |
|
92 |
|
93 TRect iSourceRect; |
|
94 TPoint iPos; |
|
95 |
|
96 TInt iQualityFactor; |
|
97 TEncHuffmanTable<KEncDCHTSize+1> iLumaDCHuffmanTable; |
|
98 TEncHuffmanTable<KEncDCHTSize+1> iChromaDCHuffmanTable; |
|
99 TEncHuffmanTable<KEncACHTSize+1> iLumaACHuffmanTable; |
|
100 TEncHuffmanTable<KEncACHTSize+1> iChromaACHuffmanTable; |
|
101 TQTable iLumaQTable; |
|
102 TQTable iChromaQTable; |
|
103 TQTable* iReplacementLumaQTable; |
|
104 TQTable* iReplacementChromaQTable; |
|
105 TDCT iDCT; |
|
106 |
|
107 TSize iMCUSizeInPixels; |
|
108 |
|
109 TDataUnitProcessor* iDataUnitProcessor; |
|
110 TInt iDataUnitCount; |
|
111 |
|
112 // Jpg codec support for Image Frame |
|
113 CJpgImageFrameWriteCodec* iImageFrameCodecPtr; |
|
114 |
|
115 // Jpg support for rotate and flip encode |
|
116 TPositionProcessor iPosProcessor; |
|
117 TUint8 iTransformedDUIdx[KJpgMaxNumOfDataUnits]; |
|
118 RArray<TUint> iOperationsRequested; |
|
119 TUint8 iTransformDUCoeffIdx[KJpgDCTBlockSize]; |
|
120 |
|
121 // Jpg codec support for Image Frame streaming |
|
122 TBool iIsBlockStreaming; |
|
123 class TStreamConfig |
|
124 { |
|
125 public: |
|
126 TInt iNumOfBlocksToAppend; |
|
127 TInt iNumOfBlocksAppended; |
|
128 TInt iNumOfMCUsProcessed; |
|
129 TBool iIsFrameComplete; |
|
130 }; |
|
131 TStreamConfig iStreamConfig; |
|
132 |
|
133 class TSpecialDataUnit: public TDataUnit |
|
134 { |
|
135 public: |
|
136 TDataUnit::TDataUnitElemType iExtraElement; |
|
137 }; |
|
138 |
|
139 class TComponentConfig |
|
140 { |
|
141 public: |
|
142 TEncHuffmanTable<KEncACHTSize+1>* iACTable; |
|
143 TEncHuffmanTable<KEncDCHTSize+1>* iDCTable; |
|
144 TQTable* iQTTable; |
|
145 TInt iDataUnitsCount; |
|
146 TInt iDCPredictorIdx; |
|
147 TInt iFirstDUIdx; |
|
148 }; |
|
149 |
|
150 TComponentConfig iCompConfig[ KJpgNumberOfComponents ]; |
|
151 TSpecialDataUnit iQuantizeTarget[ KJpgMaxNumOfDataUnits ]; |
|
152 TInt iWrittingDUIdx; |
|
153 |
|
154 CRgbBufferPtr* iRgbInputBuffer; |
|
155 TJpgFrameInfo iFrameInfo; |
|
156 const RPointerArray<HBufC8> &iComment; |
|
157 #if defined(PROFILE_JPEG_ENCODER) |
|
158 TUint iGetPixelsTime; |
|
159 TUint iDataUnitProcessTime; |
|
160 TUint iTransforTime; |
|
161 TUint iQuantizeTime; |
|
162 TUint iWriteDataUnitTime; |
|
163 TUint iImageFrameTime; |
|
164 TUint iOverallTime; |
|
165 #endif |
|
166 TBool iHighSpeedMode; // flag for "fast encoding mode" |
|
167 }; |
|
168 |
|
169 |
|
170 // CImageFrameWriteCodec |
|
171 class CJpgImageFrameWriteCodec : public CBase |
|
172 { |
|
173 public: |
|
174 static CJpgImageFrameWriteCodec* NewL(const CImageFrame* aFrame); |
|
175 ~CJpgImageFrameWriteCodec(); |
|
176 |
|
177 void CreateImageProcessorL(); |
|
178 void PrepareFrameInfoL(TJpgFrameInfo& aFrameInfo, const CFrameImageData* aFrameImageData); |
|
179 void SetPosition(TPoint& aPos); |
|
180 void Position(TPoint& aPos); |
|
181 TDataUnit* ProcessL(); |
|
182 TInt DataUnitCount() const; |
|
183 void InitFrameCompInfoL(TJpgFrameInfo& aFrameInfo); |
|
184 TJpegImageData::TColorSampling GetColorSamplingL(TUid aFormat); |
|
185 TUid GetSamplingSchemeL(TUid aFormat); |
|
186 |
|
187 // for streaming |
|
188 void PrepareFrameImageDataInfoL(TJpgFrameInfo& aFrameInfo, TUid aFormat, TInt aFrameNumber, const CFrameImageData* aFrameImageData); |
|
189 void AppendImageFrameBlockL(const CImageFrame* aFrame); |
|
190 TSize ImageFrameSize() const; |
|
191 TUid SamplingScheme() const; |
|
192 |
|
193 private: |
|
194 CJpgImageFrameWriteCodec(const CImageFrame* aFrame); |
|
195 |
|
196 private: |
|
197 const CImageFrame* iSource; |
|
198 CJpgImageFrameProcessor* iImageFrameProcessorPtr; |
|
199 TInt iDataUnitCount; |
|
200 TUid iSampleScheme; |
|
201 }; |
|
202 |
|
203 #endif // ndef JPEGWRITECODEC_H |
|
204 |