|
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: Image processor |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CVIMPSTIMAGEPROCESSOR_H |
|
20 #define CVIMPSTIMAGEPROCESSOR_H |
|
21 |
|
22 #include <f32file.h> |
|
23 #include "mvimpstimageprocessobserver.h" |
|
24 class CImageDecoder; |
|
25 class CBitmapScaler; |
|
26 class CFbsBitmap; |
|
27 class CImageEncoder; |
|
28 // CLASS DECLARATION |
|
29 |
|
30 /** |
|
31 * Image processor |
|
32 * |
|
33 * @lib vimpstutils.dll |
|
34 */ |
|
35 class CVimpstImageProcessor : public CActive |
|
36 { |
|
37 public: |
|
38 /** |
|
39 * Content processing states |
|
40 */ |
|
41 enum TContentProcessState |
|
42 { |
|
43 EContentNotProcessed = 0, |
|
44 EConvertImageDatatoBitmap, |
|
45 EScaleBitmap, |
|
46 EConentFromScaledBitmap, |
|
47 EProcessingComplete |
|
48 }; |
|
49 public: // Construction |
|
50 |
|
51 /** |
|
52 * Construction |
|
53 */ |
|
54 static CVimpstImageProcessor* NewL( MCAImageProcessObserver* aObserver); |
|
55 |
|
56 /** |
|
57 * Destruction |
|
58 */ |
|
59 ~CVimpstImageProcessor(); |
|
60 |
|
61 private: // Construction |
|
62 |
|
63 /** |
|
64 * Constructor |
|
65 */ |
|
66 CVimpstImageProcessor(MCAImageProcessObserver* aObserver); |
|
67 |
|
68 /** |
|
69 * Constructor |
|
70 */ |
|
71 void ConstructL(); |
|
72 |
|
73 private: // From CActive |
|
74 |
|
75 /** |
|
76 * @see CActive |
|
77 */ |
|
78 void RunL(); |
|
79 |
|
80 /** |
|
81 * @see CActive |
|
82 */ |
|
83 void DoCancel(); |
|
84 |
|
85 /** |
|
86 * @see CActive. |
|
87 */ |
|
88 TInt RunError( TInt aError ); |
|
89 |
|
90 public: |
|
91 /** |
|
92 * This is used when the image data is ready |
|
93 * image data is proceesed and the new content is of the image is given |
|
94 * by reducing the image data size |
|
95 * |
|
96 * @param aImageData : Content of the image file |
|
97 * @param aMimeType : Mime type of the file from which the content is passed |
|
98 */ |
|
99 TInt ProcessFromDataL( const TDesC8& aImageData , const TDesC8& aMimeType); |
|
100 /** |
|
101 * This is used when the image data is ready |
|
102 * image data is proceesed and the new content is of the image is given |
|
103 * by reducing the image data size |
|
104 * |
|
105 * @param aFileName : image file name |
|
106 * @param aMimeType : Mime type of the file from which the content is passed |
|
107 */ |
|
108 void ProcessFromFileL( const TDesC& aFileName , const TDesC8& aMimeType); |
|
109 /** |
|
110 * Cancel the image processing operation |
|
111 */ |
|
112 void CancelProcessing(); |
|
113 /** |
|
114 * Register the observer to give callback |
|
115 * once the processing is done |
|
116 * @param aObserver : obeserver |
|
117 */ |
|
118 void RegisterObserver( MCAImageProcessObserver* aObserver ); |
|
119 /** |
|
120 * Retrieve the processed image |
|
121 * Ownership of iContent is transferred to caller |
|
122 * @return processed image |
|
123 */ |
|
124 HBufC8* GetContentData(); |
|
125 /** |
|
126 * Get Bitmap |
|
127 * @return bitmap |
|
128 */ |
|
129 CFbsBitmap& Bitmap(); |
|
130 |
|
131 private: // New helper methods |
|
132 |
|
133 /** |
|
134 * Convert image to bitmap |
|
135 */ |
|
136 void ConvertImageToBitmapL(); |
|
137 /** |
|
138 * Scale Bit map |
|
139 */ |
|
140 void ScaleBitmapL(); |
|
141 /** |
|
142 * store scaled bitmap content into iimageencoder |
|
143 */ |
|
144 void ContentFromScaledBitmapL(); |
|
145 /** |
|
146 * Get new size after decoding. |
|
147 * Scale to nearest (larger or equal) size with ratio 1:1, 1:2, 1:4 or 1:8 |
|
148 * directly when decoding. |
|
149 * |
|
150 * @param aSize Size of original image |
|
151 * @param aTargetSize Size of target image |
|
152 * @param aAnyRatio Set this to ETrue if the decoder is cabable of scaling to any * ratio |
|
153 * @return New size of decoded image |
|
154 */ |
|
155 TSize DecodeSize( const TSize& aSize, const TSize& aTargetSize, |
|
156 TBool aAnyRatio ); |
|
157 |
|
158 /** |
|
159 * Get new size after scaling. If scale not needed return EFalse |
|
160 * Scaled size will be 40x30 if width > height or 30x40 if |
|
161 * height > width. |
|
162 * |
|
163 * @param aSize Original size of image |
|
164 * @param aNewSize New size of scaled image |
|
165 * @return ETrue if scale needed. |
|
166 */ |
|
167 TBool ScaleSize( const TSize& aSize, TSize& aNewSize ); |
|
168 |
|
169 /** |
|
170 * Notify observer for completion and remove message from array |
|
171 */ |
|
172 void CompleteRequestL(); |
|
173 /** |
|
174 * Reset current operation and remove all pending messages from stack. |
|
175 * @param aReason reson for reseting |
|
176 */ |
|
177 void ResetProcessingL( TInt aReason ); |
|
178 |
|
179 /** |
|
180 * Deletes and cancels all processing units ( decoder, encoder etc ). |
|
181 */ |
|
182 void ClearState(); |
|
183 |
|
184 |
|
185 private: // Data |
|
186 |
|
187 /// File system access |
|
188 RFs iFs; |
|
189 |
|
190 // Decoder for image. |
|
191 CImageDecoder* iImageDecoder; |
|
192 CBitmapScaler* iScaler; |
|
193 CImageEncoder* iImageEncoder; |
|
194 /** |
|
195 * Bitmap. Owns. |
|
196 */ |
|
197 CFbsBitmap* iBitmap; |
|
198 /** |
|
199 * Target size for bitmap |
|
200 */ |
|
201 TSize iTargetSize; |
|
202 |
|
203 /** |
|
204 * Thumbnail size for bitmap |
|
205 */ |
|
206 TSize iThumbSize; |
|
207 /** |
|
208 * Doesn't Own |
|
209 */ |
|
210 HBufC8* iContent; |
|
211 |
|
212 /// Owns. |
|
213 HBufC8* iMimeType; |
|
214 TContentProcessState iProcessingState; |
|
215 HBufC* iFilename; |
|
216 |
|
217 MCAImageProcessObserver* iObserver; |
|
218 TInt iScaleSize; |
|
219 TBool isBitmapReturned; |
|
220 }; |
|
221 |
|
222 #endif // CVIMPSTIMAGEPROCESSOR_H |
|
223 |
|
224 // End of File |