|
1 // Copyright (c) 2008-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 <imageprocessor/imageprocessorpreview.h> |
|
17 #include <imageprocessor/imageprocessorpreviewintf.h> |
|
18 #include "imageprocessorimpl.h" |
|
19 |
|
20 #include <imageframe.h> |
|
21 |
|
22 namespace ImageProcessor |
|
23 { |
|
24 |
|
25 const TBool TPreview::iValidStates[TPreview::EStatesCount][TPreview::EStatesCount] = |
|
26 { |
|
27 // EUninitialized EInitializing EInitialized ERendering |
|
28 { |
|
29 ETrue, ETrue, EFalse, EFalse //EUninitialized |
|
30 }, |
|
31 { |
|
32 ETrue, ETrue, ETrue, EFalse //EInitializing |
|
33 }, |
|
34 { |
|
35 ETrue, EFalse, ETrue, ETrue //EInitialized |
|
36 }, |
|
37 { |
|
38 EFalse, EFalse, ETrue, ETrue //ERendering |
|
39 } |
|
40 }; |
|
41 |
|
42 /** |
|
43 Gets the supported output formats for the preview. |
|
44 |
|
45 @return The supported output image formats. |
|
46 */ |
|
47 EXPORT_C void TPreview::SupportedImageFrameFormatsL(RArray<TUid>& aFormats) const |
|
48 { |
|
49 aFormats = iImageProcessorImpl.PreviewOutputImageFrameFormatsL(); |
|
50 } |
|
51 |
|
52 /** |
|
53 Gets the supported output display modes for the preview. |
|
54 |
|
55 @return The supported output display modes. |
|
56 */ |
|
57 EXPORT_C void TPreview::SupportedOutputDisplayModesL(RArray<TDisplayMode>& aDisplayModes) const |
|
58 { |
|
59 aDisplayModes = iImageProcessorImpl.PreviewOutputDisplayModesL(); |
|
60 } |
|
61 |
|
62 /** |
|
63 Sets CFbsBitmap as the output bitmap of the preview. |
|
64 |
|
65 @param aBitmap |
|
66 The output bitmap |
|
67 |
|
68 @leave KErrNotReady |
|
69 The current state is not EInitialized or the ImageProcessor is busy |
|
70 |
|
71 @leave A range of system wide error codes |
|
72 |
|
73 */ |
|
74 EXPORT_C void TPreview::SetOutputL(CFbsBitmap& aBitmap) |
|
75 { |
|
76 __ASSERT_ALWAYS((iState == TPreview::EInitialized), User::Leave(KErrNotReady)); |
|
77 |
|
78 if (aBitmap.SizeInPixels() == TSize(0,0)) |
|
79 { |
|
80 User::Leave(KErrArgument); |
|
81 } |
|
82 |
|
83 if(aBitmap.Handle()!=0 && aBitmap.ExtendedBitmapType()!=KNullUid) |
|
84 { |
|
85 User::Leave(KErrNotSupported); |
|
86 } |
|
87 |
|
88 iPreviewImpl.SetOutputL(aBitmap); |
|
89 iIsOutputSet = ETrue; |
|
90 } |
|
91 |
|
92 /** |
|
93 Sets an image frame as the output bitmap of the preview. |
|
94 |
|
95 @param aPixelBuffer |
|
96 The CImageFrame buffer. |
|
97 |
|
98 @leave KErrNotReady |
|
99 The current state is not EInitialized or the ImageProcessor is busy |
|
100 |
|
101 @leave Other |
|
102 A range of system wide error codes. |
|
103 */ |
|
104 EXPORT_C void TPreview::SetOutputL(CImageFrame& aPixelBuffer) |
|
105 { |
|
106 __ASSERT_ALWAYS((iState == TPreview::EInitialized), User::Leave(KErrNotReady)); |
|
107 |
|
108 if (aPixelBuffer.FrameSizeInPixels() == TSize(0,0)) |
|
109 { |
|
110 User::Leave(KErrArgument); |
|
111 } |
|
112 |
|
113 iPreviewImpl.SetOutputL(aPixelBuffer); |
|
114 iIsOutputSet = ETrue; |
|
115 } |
|
116 |
|
117 /** |
|
118 Creates an internal pixel buffer for output. Internal buffer size is calculated using aPixelBuffer properties (size, scanline length, display mode). |
|
119 |
|
120 @param aFrameSize |
|
121 A reference to a TSize object that defines the frame size in pixels of the CImageFrame object. |
|
122 |
|
123 @param aFrameFormat |
|
124 A reference to a TFrameFormatBase object that defines the format of the CImageFrame object. |
|
125 |
|
126 @param aFrameLayout |
|
127 A reference to a TFrameLayoutBase object that defines the memory layout of the CImageFrame object. |
|
128 |
|
129 @leave KErrNotReady |
|
130 The current state is not EInitialized or the ImageProcessor is busy |
|
131 |
|
132 @leave Other |
|
133 A range of system wide error codes. |
|
134 |
|
135 @return CImageFrame instance containing newly created pixel buffer. The image frame is owned by the client and deleting it does not delete the pixel buffer which is owned by the image processor framework. |
|
136 The pixel buffer becomes invalid if TPreview::CreateOutputL(const TSize &aFrameSize, const TFrameFormatBase &aFrameFormat, const TFrameLayoutBase &aFrameLayout) or TPreview::SetOutputL(CFbsBitmap& aBitmap) or TPreview::SetOutputL(CImageFrame& aPixelBuffer) calls are made. |
|
137 */ |
|
138 EXPORT_C CImageFrame* TPreview::CreateOutputL(const TSize &aFrameSize, const TFrameFormatBase &aFrameFormat, const TFrameLayoutBase &aFrameLayout) |
|
139 { |
|
140 __ASSERT_ALWAYS((iState == TPreview::EInitialized), User::Leave(KErrNotReady)); |
|
141 |
|
142 if (aFrameSize == TSize(0,0)) |
|
143 { |
|
144 User::Leave(KErrArgument); |
|
145 } |
|
146 |
|
147 CImageFrame* imageFrame = iPreviewImpl.CreateOutputL(aFrameSize, aFrameFormat, aFrameLayout); |
|
148 |
|
149 iIsOutputSet = ETrue; |
|
150 return imageFrame; |
|
151 } |
|
152 |
|
153 /** |
|
154 Initializes the preview. |
|
155 |
|
156 @leave KErrNorReady if preview is not in state TPreview::EUninitialized |
|
157 |
|
158 @leave A range of system wide error code. |
|
159 */ |
|
160 EXPORT_C void TPreview::InitializeL() |
|
161 { |
|
162 SetStateL(TPreview::EInitializing); |
|
163 |
|
164 TRAPD(err, iPreviewImpl.InitializeL()); |
|
165 |
|
166 if (err != KErrNone || (iImageProcessorImpl.Options() & CImgProcessor::EOptionSyncProcessing) != 0) |
|
167 { |
|
168 if (err != KErrNone) |
|
169 { |
|
170 iState = TPreview::EUninitialized; |
|
171 } |
|
172 else |
|
173 { |
|
174 iState = TPreview::EInitialized; |
|
175 } |
|
176 |
|
177 iImageProcessorImpl.RestoreStateL(); |
|
178 if (err != KErrNone) |
|
179 { |
|
180 User::Leave(err); |
|
181 } |
|
182 } |
|
183 } |
|
184 |
|
185 /** |
|
186 Uninitializes the preview. |
|
187 |
|
188 @leave KErrNotReady |
|
189 The current state is not EInitialized or the ImageProcessor is busy |
|
190 |
|
191 @leave Other |
|
192 A range of system wide error codes. |
|
193 */ |
|
194 EXPORT_C void TPreview::UninitializeL() |
|
195 { |
|
196 __ASSERT_ALWAYS((iState == TPreview::EInitialized), User::Leave(KErrNotReady)); |
|
197 iPreviewImpl.UninitializeL(); |
|
198 iState = TPreview::EUninitialized; |
|
199 iIsOutputSet = EFalse; |
|
200 } |
|
201 |
|
202 /** |
|
203 Gets the current state of the preview. |
|
204 |
|
205 @return The current state of the preview. |
|
206 */ |
|
207 EXPORT_C TPreview::TState TPreview::State() const |
|
208 { |
|
209 return iState; |
|
210 } |
|
211 |
|
212 /** |
|
213 Gets the id of the preview. |
|
214 |
|
215 @return The id of the preview. |
|
216 */ |
|
217 EXPORT_C TInt TPreview::PreviewId() const |
|
218 { |
|
219 return iPreviewImpl.PreviewId(); |
|
220 } |
|
221 |
|
222 /** |
|
223 Specifies the id of the preview. |
|
224 |
|
225 @param aPreviewId |
|
226 The id of the current preview |
|
227 */ |
|
228 EXPORT_C void TPreview::SetPreviewId(TInt aPreviewId) |
|
229 { |
|
230 iPreviewImpl.SetPreviewId(aPreviewId); |
|
231 } |
|
232 |
|
233 /** |
|
234 Starts the rendering. The preview state is set to ERendering |
|
235 |
|
236 @leave KErrNotReady |
|
237 The current state is not EInitialized or the ImageProcessor is busy or input is not set or output is not set. |
|
238 |
|
239 @leave Other |
|
240 A range of system wide error codes. |
|
241 */ |
|
242 EXPORT_C void TPreview::RenderL() |
|
243 { |
|
244 __ASSERT_ALWAYS(((!iImageProcessorImpl.IsBusy(iImageProcessorImpl.State())) && |
|
245 (iImageProcessorImpl.IsInputSet()) && |
|
246 (iState == TPreview::EInitialized) && |
|
247 (iIsOutputSet)), |
|
248 User::Leave(KErrNotReady)); |
|
249 |
|
250 SetStateL(TPreview::ERendering); |
|
251 |
|
252 TRAPD(err, iPreviewImpl.RenderL()); |
|
253 |
|
254 if (err != KErrNone || (iImageProcessorImpl.Options() & CImgProcessor::EOptionSyncProcessing) != 0) |
|
255 { |
|
256 iState = TPreview::EInitialized; |
|
257 iImageProcessorImpl.RestoreStateL(); |
|
258 if (err != KErrNone) |
|
259 { |
|
260 User::Leave(err); |
|
261 } |
|
262 } |
|
263 } |
|
264 |
|
265 /** |
|
266 Cancels the preview rendering if the preview state is EInitializing or |
|
267 ERendering, unconditionally aborts the operation. |
|
268 */ |
|
269 EXPORT_C void TPreview::Cancel() |
|
270 { |
|
271 if (iState == TPreview::EInitializing || iState == TPreview::ERendering) |
|
272 { |
|
273 iPreviewImpl.Cancel(); |
|
274 iState = TPreview::EInitialized; |
|
275 TRAPD(err, iImageProcessorImpl.RestoreStateL()); |
|
276 if (err)//ignore error for now |
|
277 { |
|
278 } |
|
279 } |
|
280 } |
|
281 |
|
282 /** |
|
283 Resets the preview parameters and state. |
|
284 */ |
|
285 EXPORT_C void TPreview::ResetL() |
|
286 { |
|
287 Cancel(); |
|
288 iIsOutputSet = EFalse; |
|
289 iPreviewImpl.ResetL(); |
|
290 } |
|
291 |
|
292 /** |
|
293 Retrieves the zoom level range. |
|
294 |
|
295 @param aMinimumLevel |
|
296 The minimum value of the zoom factor. |
|
297 |
|
298 @param aMaximumLevel |
|
299 The maximum value of the zoom factor. |
|
300 */ |
|
301 EXPORT_C void TPreview::GetZoomLevelSettings(TReal32& aMinimumLevel, TReal32& aMaximumLevel) |
|
302 { |
|
303 iPreviewImpl.GetZoomLevelSettings(aMinimumLevel, aMaximumLevel); |
|
304 } |
|
305 |
|
306 /** |
|
307 Specifies the zoom factor for the preview screen. The screen will be zoomed after rendering. |
|
308 |
|
309 @param aZoom |
|
310 The zoom factor for the current preview, 1.0f to infinite. |
|
311 |
|
312 @leave KErrNotReady |
|
313 The current state is not EInitialized or the ImageProcessor is busy. |
|
314 |
|
315 @leave Other |
|
316 A range of system wide error codes. |
|
317 */ |
|
318 EXPORT_C void TPreview::SetZoomL(TReal32 aZoom) |
|
319 { |
|
320 __ASSERT_ALWAYS((iState == TPreview::EInitialized), User::Leave(KErrNotReady)); |
|
321 iPreviewImpl.SetZoomL(aZoom); |
|
322 } |
|
323 |
|
324 /** |
|
325 Gets the current zoom factor of the preview screen. |
|
326 |
|
327 @return The current zoom factor of the preview screen. |
|
328 |
|
329 @leave KErrNotReady |
|
330 The current state is EUninitialized or the ImageProcessor is busy. |
|
331 |
|
332 @leave Other |
|
333 A range of system wide error codes. |
|
334 */ |
|
335 EXPORT_C TReal32 TPreview::ZoomL() const |
|
336 { |
|
337 __ASSERT_ALWAYS((iState != TPreview::EUninitialized), User::Leave(KErrNotReady)); |
|
338 return iPreviewImpl.ZoomL(); |
|
339 } |
|
340 |
|
341 /** |
|
342 Retrieves the pan level range. |
|
343 |
|
344 @param aMinimumLevel |
|
345 The minimum value of the pan factor. |
|
346 |
|
347 @param aMaximumLevel |
|
348 The maximum value of the pan factor. |
|
349 */ |
|
350 EXPORT_C void TPreview::GetPanLevelSettings(TReal32& aMinimumLevel, TReal32& aMaximumLevel) |
|
351 { |
|
352 iPreviewImpl.GetPanLevelSettings(aMinimumLevel, aMaximumLevel); |
|
353 } |
|
354 |
|
355 /** |
|
356 Specifies the pan factor for the preview screen. The zoomed screen will be panned to the new |
|
357 coordinate after rendering. |
|
358 |
|
359 @param aPanX |
|
360 The horizontal pan factor for the current preview, -1.0f to 1.0f. |
|
361 |
|
362 @param aPanY |
|
363 The vertical pan factor for the current preview, -1.0f to 1.0f. |
|
364 |
|
365 @leave KErrNotReady |
|
366 The current state is not EInitialized or the ImageProcessor is busy |
|
367 |
|
368 @leave KErrArgument |
|
369 The pan factor is out of range. |
|
370 |
|
371 @leave Other |
|
372 A range of system wide error codes. |
|
373 */ |
|
374 EXPORT_C void TPreview::SetPanL(TReal32 aPanX, TReal32 aPanY) |
|
375 { |
|
376 __ASSERT_ALWAYS((iState == TPreview::EInitialized), User::Leave(KErrNotReady)); |
|
377 iPreviewImpl.SetPanL(aPanX, aPanY); |
|
378 } |
|
379 |
|
380 /** |
|
381 Gets the current pan factor of the preview screen. |
|
382 |
|
383 @leave KErrNotReady |
|
384 The current state is EUninitialized or the ImageProcessor is busy. |
|
385 |
|
386 @leave Other |
|
387 A range of system wide error codes. |
|
388 */ |
|
389 EXPORT_C void TPreview::PanL(TReal32& aPanX, TReal32& aPanY) const |
|
390 { |
|
391 __ASSERT_ALWAYS((iState != TPreview::EUninitialized), User::Leave(KErrNotReady)); |
|
392 iPreviewImpl.PanL(aPanX, aPanY); |
|
393 } |
|
394 |
|
395 /** |
|
396 Gets the current size of the preview screen. |
|
397 |
|
398 @return The current size of the preview screen. |
|
399 |
|
400 @leave KErrNotReady |
|
401 The current state is EUninitialized. |
|
402 |
|
403 @leave Other |
|
404 A range of system wide error codes. |
|
405 */ |
|
406 EXPORT_C TSize TPreview::SizeL() const |
|
407 { |
|
408 __ASSERT_ALWAYS((iState != TPreview::EUninitialized), User::Leave(KErrNotReady)); |
|
409 return iPreviewImpl.SizeL(); |
|
410 } |
|
411 |
|
412 /** |
|
413 Gets the current canvas as TRect in the given screen |
|
414 |
|
415 @return The current canvas of the preview screen. |
|
416 |
|
417 @leave KErrNotReady |
|
418 The current state is EUninitialized. |
|
419 |
|
420 @leave Other |
|
421 A range of system wide error codes. |
|
422 */ |
|
423 EXPORT_C TRect TPreview::CanvasAreaL() const |
|
424 { |
|
425 __ASSERT_ALWAYS((iState == TPreview::EInitialized), User::Leave(KErrNotReady)); |
|
426 return iPreviewImpl.CanvasAreaL(); |
|
427 } |
|
428 |
|
429 /** |
|
430 Converts a coordinate from preview screen to current coordinate system. |
|
431 |
|
432 @param aPreviewPoint |
|
433 A TPoint pointer specifying the preview screen from which to convert the coordinate. |
|
434 |
|
435 @param aCurrentPoint |
|
436 Pointer to a TPoint object with the coordinate to convert. The converted coordinate is stored back into the object. |
|
437 |
|
438 @leave KErrNotReady |
|
439 The current state is EUninitialized. |
|
440 |
|
441 @leave Other |
|
442 A range of system wide error codes. |
|
443 */ |
|
444 EXPORT_C void TPreview::PreviewToCurrentCoordL(const TPoint& aPreviewPoint, TPoint& aCurrentPoint) const |
|
445 { |
|
446 __ASSERT_ALWAYS((iState == TPreview::EInitialized), User::Leave(KErrNotReady)); |
|
447 iPreviewImpl.PreviewToCurrentCoordL(aPreviewPoint, aCurrentPoint); |
|
448 } |
|
449 |
|
450 /** |
|
451 Converts a coordinate from canvas to current coordinate system. |
|
452 |
|
453 @param aCanvasPoint |
|
454 A TPoint pointer specifying a screen in which the canvas from which to convert the coordinate is located. |
|
455 |
|
456 @param aCurrentPoint |
|
457 Pointer to a TPoint object with the coordinate to convert. The converted coordinate is stored back into the object. |
|
458 |
|
459 @leave KErrNotReady |
|
460 The current state is EUninitialized. |
|
461 |
|
462 @leave Other |
|
463 A range of system wide error codes. |
|
464 */ |
|
465 EXPORT_C void TPreview::CanvasToCurrentCoordL(const TPoint& aCanvasPoint, TPoint& aCurrentPoint) const |
|
466 { |
|
467 __ASSERT_ALWAYS((iState == TPreview::EInitialized), User::Leave(KErrNotReady)); |
|
468 iPreviewImpl.CanvasToCurrentCoordL(aCanvasPoint, aCurrentPoint); |
|
469 } |
|
470 |
|
471 // internal functions |
|
472 TPreview::TPreview(Plugin::MPreview& aPreviewImpl, CImageProcessorImpl& aImageProcessorImpl) : |
|
473 iImageProcessorImpl(aImageProcessorImpl), |
|
474 iPreviewImpl(aPreviewImpl), |
|
475 iState(TPreview::EUninitialized), |
|
476 iIsOutputSet(EFalse), |
|
477 iReserved(0) |
|
478 { |
|
479 } |
|
480 |
|
481 void TPreview::SetStateL(TPreview::TState aState) |
|
482 { |
|
483 if(iState != aState) |
|
484 { |
|
485 if (!iValidStates[iState][aState]) |
|
486 { |
|
487 User::Leave(KErrNotReady); |
|
488 } |
|
489 |
|
490 if (aState == TPreview::EInitializing) |
|
491 { |
|
492 iImageProcessorImpl.SetStateL(CImgProcessor::EPreviewInitializing); |
|
493 } |
|
494 else if (aState == TPreview::ERendering) |
|
495 { |
|
496 iImageProcessorImpl.SetStateL(CImgProcessor::EPreviewRendering); |
|
497 } |
|
498 |
|
499 iState = aState; |
|
500 } |
|
501 } |
|
502 |
|
503 }//namespace ImageProcessor |
|
504 |
|
505 //EOF |