|
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 #include <barsc.h> |
|
17 #include <barsread.h> |
|
18 #include <bautils.h> |
|
19 #include <imageconversion.h> |
|
20 #include "ImageClientMain.h" |
|
21 #include <101F45CA_extra.rsg> |
|
22 #include "icl/ICL_UIDS.hrh" |
|
23 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
24 #include <icl/icl_uids_const.hrh> |
|
25 #include <icl/icl_uids_def.hrh> |
|
26 #include <icl/imagecodecdef.h> |
|
27 #endif |
|
28 #include "MBMCodec.h" |
|
29 #include "ImageUtils.h" |
|
30 |
|
31 // Mbm decoder. |
|
32 CMbmDecoder* CMbmDecoder::NewL() |
|
33 { |
|
34 return new(ELeave) CMbmDecoder; |
|
35 } |
|
36 |
|
37 CMbmDecoder::CMbmDecoder() |
|
38 {} |
|
39 |
|
40 CMbmDecoder::~CMbmDecoder() |
|
41 { |
|
42 Cleanup(); |
|
43 } |
|
44 |
|
45 void CMbmDecoder::ImageType(TInt aFrameNumber, TUid& aImageType, TUid& aImageSubType) const |
|
46 { |
|
47 __ASSERT_ALWAYS((aFrameNumber >= 0) && (aFrameNumber < NumberOfFrames()), Panic(EFrameNumberOutOfRange)); |
|
48 aImageType = KImageTypeMBMUid; |
|
49 aImageSubType = KNullUid; |
|
50 } |
|
51 |
|
52 // Scan header. |
|
53 // Validate that format is correct. |
|
54 // Create codec. |
|
55 // Fill in image info. (All frames) |
|
56 void CMbmDecoder::ScanDataL() |
|
57 { |
|
58 ReadFormatL(); |
|
59 |
|
60 ASSERT(ImageReadCodec() == NULL); |
|
61 |
|
62 CMbmReadCodec* imageReadCodec = CMbmReadCodec::NewL(iRootStreamOffset); |
|
63 |
|
64 SetImageReadCodec(imageReadCodec); |
|
65 |
|
66 ReadFrameHeadersL(); |
|
67 } |
|
68 |
|
69 const TInt KMbmSignatureSize = 20; |
|
70 const TInt KMbmSigBytes = 16; // no of bytes used in comparisons |
|
71 LOCAL_D const TUint8 KMbmSignature[KMbmSignatureSize] = {0x37, 0x00, 0x00, 0x10, 0x42, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x39, 0x64, 0x39, 0x47}; |
|
72 void CMbmDecoder::ReadFormatL() |
|
73 { |
|
74 TPtrC8 bufferDes; |
|
75 |
|
76 ReadDataL(0, bufferDes, KMbmSignatureSize); |
|
77 |
|
78 // Validate the header. |
|
79 if (bufferDes.Length() < KMbmSignatureSize) |
|
80 User::Leave(KErrUnderflow); |
|
81 |
|
82 const TUint8* ptr = bufferDes.Ptr(); |
|
83 if (Mem::Compare(ptr, KMbmSigBytes, KMbmSignature, KMbmSigBytes)!=0) |
|
84 User::Leave(KErrCorrupt); |
|
85 |
|
86 // Store the RootStreamOffset |
|
87 iRootStreamOffset = PtrReadUtil::ReadUint32(ptr+4*sizeof(TUint32)) - KMbmFirstBitmapOffset; |
|
88 // the 4th 32-bit value is used to give us the effective root stream offset |
|
89 |
|
90 // Set start position. |
|
91 SetStartPosition(KMbmFirstBitmapOffset); |
|
92 |
|
93 // Get this from the header? |
|
94 SetDataLength(KMaxTInt); |
|
95 } |
|
96 |
|
97 CFrameInfoStrings* CMbmDecoder::FrameInfoStringsL(RFs& aFs, TInt aFrameNumber) |
|
98 { |
|
99 const TUid KMbmCodecDllUid = {KMBMCodecDllUidValue}; |
|
100 |
|
101 RResourceFile resourceFile; |
|
102 OpenExtraResourceFileLC(aFs, KMbmCodecDllUid, resourceFile); |
|
103 |
|
104 HBufC8* resourceInfo = resourceFile.AllocReadLC(THEDECODERINFO); |
|
105 TResourceReader resourceReader; |
|
106 resourceReader.SetBuffer(resourceInfo); |
|
107 |
|
108 TBuf<KCodecResourceStringMax> info; |
|
109 TBuf<KCodecResourceStringMax> templte; |
|
110 |
|
111 const TFrameInfo& frameInfo = FrameInfo(aFrameNumber); |
|
112 const CFrameImageData& frameData = FrameData(aFrameNumber); |
|
113 CFrameInfoStrings* frameInfoStrings = CFrameInfoStrings::NewLC(); |
|
114 const TMbmDecodeData* compressionImageData = STATIC_CAST(const TMbmDecodeData*, frameData.GetFrameData(0)); |
|
115 |
|
116 info = resourceReader.ReadTPtrC(); |
|
117 frameInfoStrings->SetDecoderL(info); |
|
118 |
|
119 info = resourceReader.ReadTPtrC(); |
|
120 frameInfoStrings->SetFormatL(info); |
|
121 |
|
122 TInt width = frameInfo.iOverallSizeInPixels.iWidth; |
|
123 TInt height = frameInfo.iOverallSizeInPixels.iHeight; |
|
124 TInt depth = frameInfo.iBitsPerPixel; |
|
125 |
|
126 templte = resourceReader.ReadTPtrC(); |
|
127 info.Format(templte, width, height); |
|
128 frameInfoStrings->SetDimensionsL(info); |
|
129 |
|
130 CDesCArrayFlat* resourceArray = resourceReader.ReadDesCArrayL(); |
|
131 CleanupStack::PushL(resourceArray); |
|
132 TUint formatIndex = (frameInfo.iFlags & TFrameInfo::EColor) ? 1 : 0; |
|
133 formatIndex += (frameInfo.iFlags & TFrameInfo::EAlphaChannel) ? 1 : 0; |
|
134 templte = (*resourceArray)[formatIndex]; |
|
135 CleanupStack::PopAndDestroy(resourceArray); |
|
136 info.Format(templte, depth); |
|
137 frameInfoStrings->SetDepthL(info); |
|
138 |
|
139 resourceArray = resourceReader.ReadDesCArrayL(); |
|
140 CleanupStack::PushL(resourceArray); |
|
141 formatIndex = (compressionImageData->iCompressed) ? 1 : 0; |
|
142 info = (*resourceArray)[formatIndex]; |
|
143 CleanupStack::PopAndDestroy(resourceArray); |
|
144 frameInfoStrings->SetDetailsL(info); |
|
145 |
|
146 CleanupStack::Pop(frameInfoStrings); |
|
147 CleanupStack::PopAndDestroy(2); // resourceInfo + resourceFile |
|
148 return frameInfoStrings; |
|
149 } |
|
150 |
|
151 // Mbm encoder. |
|
152 CMbmEncoder* CMbmEncoder::NewL() |
|
153 { |
|
154 return new(ELeave) CMbmEncoder; |
|
155 } |
|
156 |
|
157 CMbmEncoder::CMbmEncoder() |
|
158 { |
|
159 } |
|
160 |
|
161 CMbmEncoder::~CMbmEncoder() |
|
162 { |
|
163 Cleanup(); |
|
164 } |
|
165 |
|
166 void CMbmEncoder::PrepareEncoderL(const CFrameImageData* aFrameImageData) |
|
167 { |
|
168 iWriteDisplayMode = ENone; |
|
169 |
|
170 TInt index; |
|
171 TInt count = (aFrameImageData) ? aFrameImageData->FrameDataCount() : 0; |
|
172 |
|
173 if (count == 0) |
|
174 iWriteDisplayMode = Source().DisplayMode(); // default value |
|
175 |
|
176 for (index = 0 ; index<count ; index++) |
|
177 { |
|
178 const TFrameDataBlock* encoderData = aFrameImageData->GetFrameData(index); |
|
179 if (encoderData->DataType() == KMBMEncodeDataUid) |
|
180 { |
|
181 if (iWriteDisplayMode != ENone) |
|
182 User::Leave(KErrCorrupt); |
|
183 |
|
184 const TMbmEncodeData* mbmEncodeData = STATIC_CAST(const TMbmEncodeData*, encoderData); |
|
185 iWriteDisplayMode = mbmEncodeData->iDisplayMode; |
|
186 } |
|
187 else |
|
188 User::Leave(KErrCorrupt); |
|
189 } |
|
190 |
|
191 // Create codec. |
|
192 StartPosition() = KMbmFirstBitmapOffset; |
|
193 |
|
194 CMbmWriteCodec* imageWriteCodec = CMbmWriteCodec::NewL(iWriteDisplayMode); |
|
195 |
|
196 SetImageWriteCodec(imageWriteCodec); |
|
197 |
|
198 } |
|
199 |
|
200 const TUint8 KMbmBitmapFileHeader[] = {0x37, 0, 0, 0x10, 0x42, 0, 0, 0x10, 0, 0, 0, 0, 0x39, 0x64, 0x39, 0x47}; |
|
201 void CMbmEncoder::UpdateHeaderL() |
|
202 { |
|
203 TBuf8<sizeof(KMbmBitmapFileHeader) + sizeof(TUint32)> mbmHeader; |
|
204 TPtrC8 mbmHeaderPtr(KMbmBitmapFileHeader, sizeof(KMbmBitmapFileHeader)); |
|
205 mbmHeader.Append(mbmHeaderPtr); |
|
206 |
|
207 TUint32 mbmRootStreamOffset = (Position() + KMbmFirstBitmapOffset) - 8; // Set root stream offset. |
|
208 TPtrC8 mbmRootStreamOffsetPtr(REINTERPRET_CAST(TUint8*, &mbmRootStreamOffset), sizeof(TUint32)); |
|
209 mbmHeader.Append(mbmRootStreamOffsetPtr); |
|
210 |
|
211 WriteDataL(0,mbmHeader); |
|
212 } |
|
213 |
|
214 |