|
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 <101F45D3_extra.rsg> |
|
22 #include "ICOCodec.h" |
|
23 #include "icl/ICL_UIDS.hrh" |
|
24 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
25 #include <icl/icl_uids_const.hrh> |
|
26 #include <icl/icl_uids_def.hrh> |
|
27 #include <icl/imagecodecdef.h> |
|
28 #endif |
|
29 |
|
30 const TInt KIcoFileHeaderSize = 6; |
|
31 const TInt KIcoImageHeaderSize = 16; |
|
32 |
|
33 |
|
34 _LIT(KICOPanicCategory, "ICOConvertPlugin"); |
|
35 |
|
36 // Global panic function |
|
37 GLDEF_C void Panic(TIclPanic aError) |
|
38 { |
|
39 User::Panic(KICOPanicCategory, aError); |
|
40 } |
|
41 |
|
42 // Ico decoder. |
|
43 CIcoDecoder* CIcoDecoder::NewL() |
|
44 { |
|
45 return new(ELeave) CIcoDecoder; |
|
46 } |
|
47 |
|
48 CIcoDecoder::CIcoDecoder() |
|
49 {} |
|
50 |
|
51 CIcoDecoder::~CIcoDecoder() |
|
52 { |
|
53 Cleanup(); |
|
54 } |
|
55 |
|
56 void CIcoDecoder::Cleanup() |
|
57 { |
|
58 // Delete any objects we should get rid of |
|
59 |
|
60 // Base class included |
|
61 CImageDecoderPlugin::Cleanup(); |
|
62 } |
|
63 |
|
64 void CIcoDecoder::ImageType(TInt aFrameNumber, TUid& aImageType, TUid& aImageSubType) const |
|
65 { |
|
66 __ASSERT_ALWAYS((aFrameNumber >= 0) && (aFrameNumber < NumberOfFrames()), Panic(EFrameNumberOutOfRange)); |
|
67 aImageType = KImageTypeICOUid; |
|
68 aImageSubType = KNullUid; |
|
69 } |
|
70 |
|
71 // Scan header. |
|
72 // Validate that format is correct. |
|
73 // Create codec. |
|
74 // Fill in image info. (All frames) |
|
75 void CIcoDecoder::ScanDataL() |
|
76 { |
|
77 ReadFormatL(); |
|
78 |
|
79 ASSERT(ImageReadCodec() == NULL); |
|
80 |
|
81 CIcoReadCodec* imageReadCodec; |
|
82 imageReadCodec = CIcoReadCodec::NewL(iIconCount); |
|
83 |
|
84 SetImageReadCodec(imageReadCodec); |
|
85 |
|
86 |
|
87 |
|
88 ReadFrameHeadersL(); |
|
89 } |
|
90 |
|
91 void CIcoDecoder::ReadFormatL() |
|
92 { |
|
93 TPtrC8 bufferDes; |
|
94 |
|
95 ReadDataL(0, bufferDes, KIcoFileHeaderSize); |
|
96 |
|
97 // Validate the header. |
|
98 if (bufferDes.Length() < KIcoFileHeaderSize) |
|
99 User::Leave(KErrUnderflow); |
|
100 |
|
101 const TUint8* ptr = &bufferDes[0]; |
|
102 iIconCount = ptr[4] | (ptr[5] << 8); |
|
103 if (iIconCount <= 0) |
|
104 User::Leave(KErrNotFound); |
|
105 |
|
106 SetStartPosition(KIcoFileHeaderSize + (KIcoImageHeaderSize * iIconCount)); |
|
107 SetDataLength(KMaxTInt); |
|
108 } |
|
109 |
|
110 CFrameInfoStrings* CIcoDecoder::FrameInfoStringsL(RFs& aFs, TInt aFrameNumber) |
|
111 { |
|
112 |
|
113 const TUid KIcoCodecDllUid = {KICOCodecDllUidValue}; |
|
114 |
|
115 RResourceFile resourceFile; |
|
116 OpenExtraResourceFileLC(aFs,KIcoCodecDllUid,resourceFile); |
|
117 |
|
118 HBufC8* resourceInfo = resourceFile.AllocReadLC(THEDECODERINFO); |
|
119 TResourceReader resourceReader; |
|
120 resourceReader.SetBuffer(resourceInfo); |
|
121 |
|
122 TBuf<KCodecResourceStringMax> info; |
|
123 TBuf<KCodecResourceStringMax> templte; |
|
124 |
|
125 const TFrameInfo& frameInfo = FrameInfo(aFrameNumber); |
|
126 CFrameInfoStrings* frameInfoStrings = CFrameInfoStrings::NewLC(); |
|
127 |
|
128 info = resourceReader.ReadTPtrC(); |
|
129 frameInfoStrings->SetDecoderL(info); |
|
130 |
|
131 info = resourceReader.ReadTPtrC(); |
|
132 frameInfoStrings->SetFormatL(info); |
|
133 |
|
134 TInt width = frameInfo.iOverallSizeInPixels.iWidth; |
|
135 TInt height = frameInfo.iOverallSizeInPixels.iHeight; |
|
136 TInt depth = frameInfo.iBitsPerPixel; |
|
137 |
|
138 templte = resourceReader.ReadTPtrC(); |
|
139 info.Format(templte, width, height); |
|
140 frameInfoStrings->SetDimensionsL(info); |
|
141 |
|
142 CDesCArrayFlat* resourceArray = resourceReader.ReadDesCArrayL(); |
|
143 CleanupStack::PushL(resourceArray); |
|
144 TUint formatIndex = (frameInfo.iFlags & TFrameInfo::EColor) ? 1 : 0; |
|
145 templte = (*resourceArray)[formatIndex]; |
|
146 CleanupStack::PopAndDestroy(resourceArray); |
|
147 info.Format(templte, depth); |
|
148 frameInfoStrings->SetDepthL(info); |
|
149 |
|
150 // leave details blank |
|
151 |
|
152 CleanupStack::Pop(frameInfoStrings); |
|
153 CleanupStack::PopAndDestroy(2); // resourceInfo + resourceFile |
|
154 return frameInfoStrings; |
|
155 } |
|
156 |
|
157 |