|
1 /* |
|
2 * Copyright (c) 2009 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: Juha Kauppinen, Mika Hokkanen |
|
13 * |
|
14 * Description: Photo Browser |
|
15 * |
|
16 */ |
|
17 |
|
18 // Include files |
|
19 #include "IEImageDecoder.h" |
|
20 |
|
21 // ========================== MEMBER FUNCTIONS ============================= // |
|
22 |
|
23 CIEImageDecoder* CIEImageDecoder::NewL(RFs& aFileServer, MDecodingObserver& aObserver) |
|
24 { |
|
25 CIEImageDecoder* self = new (ELeave) CIEImageDecoder(aFileServer, aObserver); |
|
26 CleanupStack::PushL(self); |
|
27 self->ConstructL(); |
|
28 CleanupStack::Pop(); |
|
29 return self; |
|
30 } |
|
31 |
|
32 CIEImageDecoder::~CIEImageDecoder() |
|
33 { |
|
34 if(iImageDecoder) |
|
35 { |
|
36 delete iImageDecoder; |
|
37 iImageDecoder = NULL; |
|
38 } |
|
39 |
|
40 if(iExtImageDecoder) |
|
41 { |
|
42 delete iExtImageDecoder; |
|
43 iExtImageDecoder = NULL; |
|
44 } |
|
45 |
|
46 if(iVisualFrame) |
|
47 { |
|
48 delete iVisualFrame; |
|
49 iVisualFrame = NULL; |
|
50 } |
|
51 } |
|
52 |
|
53 //EPriorityIdle, EPriorityLow, EPriorityStandard, EPriorityUserInput, EPriorityHigh |
|
54 CIEImageDecoder::CIEImageDecoder(RFs& aFileServer, MDecodingObserver& aObserver) |
|
55 : CActive(EPriorityStandard), iFileServer(aFileServer), iObserver(aObserver), iSrcPtr(NULL, 0, 0) |
|
56 { |
|
57 } |
|
58 |
|
59 void CIEImageDecoder::ConstructL() |
|
60 { |
|
61 CActiveScheduler::Add(this); |
|
62 |
|
63 iDecoderBusy = EFalse; |
|
64 iDecode2Yuv = EFalse; |
|
65 iDecode2Bitmap = EFalse; |
|
66 |
|
67 iNumOfBitmaps = 0; |
|
68 } |
|
69 |
|
70 void CIEImageDecoder::RunL() |
|
71 { |
|
72 /* |
|
73 TPtr8 ptr = iVisualFrame->DataPtrL(); |
|
74 TInt dataSize = ptr.Size(); |
|
75 TUint8* bufU = (TUint8*) ptr.Ptr(); |
|
76 */ |
|
77 if(iDecode2Yuv) |
|
78 { |
|
79 iDecode2Yuv = EFalse; |
|
80 |
|
81 if(iExtImageDecoder) |
|
82 { |
|
83 delete iExtImageDecoder; |
|
84 iExtImageDecoder = NULL; |
|
85 } |
|
86 |
|
87 //iObserver.YuvImageReady(iStatus.Int()); |
|
88 } |
|
89 |
|
90 if(iDecode2Bitmap) |
|
91 { |
|
92 iDecode2Bitmap = EFalse; |
|
93 |
|
94 if(iImageDecoder) |
|
95 { |
|
96 delete iImageDecoder; |
|
97 iImageDecoder = NULL; |
|
98 } |
|
99 |
|
100 iObserver.BitmapReady(iStatus.Int()); |
|
101 } |
|
102 |
|
103 iDecoderBusy = EFalse; |
|
104 } |
|
105 |
|
106 void CIEImageDecoder::DoCancel() |
|
107 { |
|
108 |
|
109 } |
|
110 |
|
111 void CIEImageDecoder::GetImageSizeL(const TFileName aFileName, TSize& aSize) |
|
112 { |
|
113 if(iImageDecoder) |
|
114 { |
|
115 delete iImageDecoder; |
|
116 iImageDecoder = NULL; |
|
117 } |
|
118 |
|
119 iImageDecoder = CImageDecoder::FileNewL(iFileServer, aFileName); |
|
120 TFrameInfo frameInfo = iImageDecoder->FrameInfo(); |
|
121 |
|
122 aSize.iWidth = frameInfo.iOverallSizeInPixels.iWidth; |
|
123 aSize.iHeight = frameInfo.iOverallSizeInPixels.iHeight; |
|
124 |
|
125 delete iImageDecoder; |
|
126 iImageDecoder = NULL; |
|
127 } |
|
128 |
|
129 void CIEImageDecoder::ConvertJpeg2YuvL(const TDesC& aSourceFile, |
|
130 HBufC8& aBuffer) |
|
131 { |
|
132 TInt fileSize = 0; |
|
133 TInt blocks = 0; |
|
134 |
|
135 iDecoderBusy = ETrue; |
|
136 iDecode2Yuv = ETrue; |
|
137 |
|
138 if(iExtImageDecoder) |
|
139 { |
|
140 delete iExtImageDecoder; |
|
141 iExtImageDecoder = NULL; |
|
142 } |
|
143 |
|
144 iExtImageDecoder = CExtJpegDecoder::FileNewL(iFileServer, aSourceFile); |
|
145 |
|
146 TFrameInfo frameInfo = iExtImageDecoder->FrameInfo(); |
|
147 |
|
148 TInt width = frameInfo.iOverallSizeInPixels.iWidth; |
|
149 TInt height = frameInfo.iOverallSizeInPixels.iHeight; |
|
150 |
|
151 /*if(width%2 != 0) |
|
152 width++; |
|
153 if(height%2 != 0) |
|
154 height++;*/ |
|
155 |
|
156 TPtr8 bufPtr = aBuffer.Des(); |
|
157 |
|
158 iBufU = (TUint8*)bufPtr.Ptr(); |
|
159 |
|
160 if(iVisualFrame) |
|
161 { |
|
162 delete iVisualFrame; |
|
163 iVisualFrame = NULL; |
|
164 } |
|
165 |
|
166 iVisualFrame = CVisualFrame::NewL(bufPtr, |
|
167 TSize(width, height), |
|
168 CVisualFrame::EFormatYUV420Planar); |
|
169 |
|
170 |
|
171 iExtImageDecoder->ConvertL(&iStatus, iVisualFrame, blocks); |
|
172 |
|
173 if(!IsActive()) |
|
174 SetActive(); |
|
175 |
|
176 } |
|
177 |
|
178 |
|
179 void CIEImageDecoder::ConvertJpeg2BitmapL(CFbsBitmap& aDestBitmap, TDesC8& aSourceData) |
|
180 { |
|
181 TInt frameNumber = 0; |
|
182 |
|
183 iDecoderBusy = ETrue; |
|
184 iDecode2Bitmap = ETrue; |
|
185 |
|
186 TInt dataSize = aSourceData.Size(); |
|
187 |
|
188 iSrcPtr.Set((TUint8*)aSourceData.Ptr(), aSourceData.Size(), aSourceData.Size()); |
|
189 |
|
190 if(iImageDecoder) |
|
191 { |
|
192 delete iImageDecoder; |
|
193 iImageDecoder = NULL; |
|
194 } |
|
195 |
|
196 iImageDecoder = CImageDecoder::DataNewL(iFileServer, iSrcPtr); |
|
197 |
|
198 iImageDecoder->Convert(&iStatus, aDestBitmap, frameNumber); |
|
199 |
|
200 iNumOfBitmaps++; |
|
201 |
|
202 if(!IsActive()) |
|
203 SetActive(); |
|
204 } |
|
205 |
|
206 |
|
207 TPtr8 CIEImageDecoder::GetVisualFrame() |
|
208 { |
|
209 return iVisualFrame->DataPtrL(); |
|
210 } |
|
211 |
|
212 void CIEImageDecoder::CancelDecoding() |
|
213 { |
|
214 if(iDecoderBusy) |
|
215 { |
|
216 if(iImageDecoder) |
|
217 iImageDecoder->Cancel(); |
|
218 |
|
219 if(iExtImageDecoder) |
|
220 iExtImageDecoder->Cancel(); |
|
221 } |
|
222 |
|
223 if(IsActive()) |
|
224 Cancel(); |
|
225 } |
|
226 |
|
227 |
|
228 // EOF |