|
1 /* |
|
2 * Copyright (c) 2008 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: Utility class for asynchronously decoding the header thumbnail image |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cvimpstdetailsimagedecoder.h" |
|
20 |
|
21 #include "cvimpstdetailsheadercontrol.h" |
|
22 |
|
23 #include <cbsbitmap.h> |
|
24 #include <imageconversion.h> |
|
25 #include <bitmaptransforms.h> |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // CVIMPSTDetailsImageDecoder::NewL |
|
29 // Two-phase construction |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 CVIMPSTDetailsImageDecoder* CVIMPSTDetailsImageDecoder::NewL(CVIMPSTDetailsHeaderControl& aHeader, const TDesC8& aBitmapData) |
|
33 { |
|
34 CVIMPSTDetailsImageDecoder* self = new (ELeave) CVIMPSTDetailsImageDecoder(aHeader); |
|
35 CleanupStack::PushL(self); |
|
36 self->ConstructL(aBitmapData); |
|
37 CleanupStack::Pop(self); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CVIMPSTDetailsImageDecoder::CVIMPSTDetailsImageDecoder |
|
43 // First phase (C++) constructor |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CVIMPSTDetailsImageDecoder::CVIMPSTDetailsImageDecoder(CVIMPSTDetailsHeaderControl& aHeader) : |
|
47 CActive( CActive::EPriorityStandard ), iHeader(aHeader) |
|
48 { |
|
49 CActiveScheduler::Add(this); |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // CVIMPSTDetailsImageDecoder::ConstructL |
|
54 // ConstructL, second phase constructor |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 void CVIMPSTDetailsImageDecoder::ConstructL(const TDesC8& aBitmapData) |
|
58 { |
|
59 iBitmapData = aBitmapData.AllocL(); |
|
60 User::LeaveIfError( iFs.Connect() ); |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CVIMPSTDetailsImageDecoder::~CVIMPSTDetailsImageDecoder |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CVIMPSTDetailsImageDecoder::~CVIMPSTDetailsImageDecoder() |
|
68 { |
|
69 DoCancel(); |
|
70 if (iImgDecoder) |
|
71 { |
|
72 delete iImgDecoder; |
|
73 iImgDecoder = NULL; |
|
74 } |
|
75 if (iBitmap) |
|
76 { |
|
77 delete iBitmap; |
|
78 iBitmap = NULL; |
|
79 } |
|
80 if (iBitmapData) |
|
81 { |
|
82 delete iBitmapData; |
|
83 iBitmapData = NULL; |
|
84 } |
|
85 if (iBitmapScaler) |
|
86 { |
|
87 delete iBitmapScaler; |
|
88 iBitmapScaler = NULL; |
|
89 } |
|
90 |
|
91 iFs.Close(); |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CVIMPSTDetailsImageDecoder::Start |
|
96 // Starts the decoding process |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 void CVIMPSTDetailsImageDecoder::StartL(TSize aBitmapSize) |
|
100 { |
|
101 iDecoderState = ECcaConvertThumbnailImage; |
|
102 iBitmapSize = aBitmapSize; |
|
103 CreateBitmapL(); |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // CVIMPSTDetailsImageDecoder::RunL |
|
108 // Called by the active object framework when the decoding (request) is |
|
109 // completed. |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CVIMPSTDetailsImageDecoder::RunL() |
|
113 { |
|
114 User::LeaveIfError( iStatus.Int() ); |
|
115 switch ( iDecoderState ) |
|
116 { |
|
117 case ECcaConvertThumbnailImage: |
|
118 { |
|
119 iDecoderState = ECcaScaleThumbnail; |
|
120 ScaleBitmapL(); |
|
121 break; |
|
122 } |
|
123 case ECcaScaleThumbnail: |
|
124 { |
|
125 // don't delete |
|
126 // Ownership of the bitmap is transferred |
|
127 iHeader.SetBitmap(iBitmap, NULL ); |
|
128 iBitmap = NULL; |
|
129 } |
|
130 default: |
|
131 break; |
|
132 } |
|
133 |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // CVIMPSTDetailsImageDecoder::DoCancel |
|
138 // Called when the decoding (request) is cancelled for some reason. |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 void CVIMPSTDetailsImageDecoder::DoCancel() |
|
142 { |
|
143 iImgDecoder->Cancel(); |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // CVIMPSTDetailsImageDecoder::ScaleBitmapL |
|
148 // scaling it to fit to the screen |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 void CVIMPSTDetailsImageDecoder::ScaleBitmapL() |
|
152 { |
|
153 iBitmapScaler = CBitmapScaler::NewL(); |
|
154 iBitmapScaler->Scale( &iStatus, *iBitmap, iBitmapSize ); |
|
155 SetActive(); |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CVIMPSTDetailsImageDecoder::CreateBitmapL |
|
160 // creates the bitmap |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 |
|
164 void CVIMPSTDetailsImageDecoder::CreateBitmapL() |
|
165 { |
|
166 if ( iDecoderState == ECcaConvertThumbnailImage ) |
|
167 { |
|
168 iImgDecoder = CImageDecoder::DataNewL( iFs, *iBitmapData, CImageDecoder::EOptionAlwaysThread ); |
|
169 } |
|
170 if ( !iBitmap ) |
|
171 { |
|
172 TFrameInfo info = iImgDecoder->FrameInfo(); |
|
173 iBitmap = new ( ELeave ) CFbsBitmap; |
|
174 User::LeaveIfError( iBitmap->Create( info.iOverallSizeInPixels, info.iFrameDisplayMode )); |
|
175 } |
|
176 iStatus = KRequestPending; |
|
177 iImgDecoder->Convert( &iStatus, *iBitmap ); |
|
178 SetActive(); |
|
179 } |
|
180 // end of file |