3 // Open Service Platform
4 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
5 // All rights reserved.
7 // This software contains confidential and proprietary information
8 // of Samsung Electronics Co., Ltd.
9 // The user of this software agrees not to disclose, disseminate or copy such
10 // Confidential Information and shall use the software only in accordance with
11 // the terms of the license agreement the user entered into with Samsung.
14 #include "CameraTools.h"
17 using namespace Tizen::Base;
18 using namespace Tizen::Media;
19 using namespace Tizen::Ui;
20 using namespace Tizen::Ui::Controls;
22 Camera* CameraTools::__pCamera(null);
23 Tizen::Graphics::Dimension CameraTools::__choosenResolution;
24 int CameraTools::__width;
25 int CameraTools::__height;
27 const char* pTag = "CameraTools";
30 CameraTools::StartCamera(ICameraEventListener &listener,
31 const unsigned int width, const unsigned int height)
34 __choosenResolution = Tizen::Graphics::Dimension(width, height);
41 __pCamera = new (std::nothrow) Camera();
42 if (null == __pCamera)
47 if (IsFailed(__pCamera->Construct(listener, CAMERA_PRIMARY)))
49 AppLogExceptionTag(pTag, "Construct failed with %s", GetErrorMessage(GetLastResult()));
55 if (IsFailed(__pCamera->PowerOn()))
57 AppLogExceptionTag(pTag, "PowerOn failed with %s", GetErrorMessage(GetLastResult()));
61 if (IsFailed(__pCamera->SetPreviewFormat(Tizen::Graphics::PIXEL_FORMAT_YCbCr420_PLANAR)))
63 AppLogExceptionTag(pTag, "SetPreviewFormat failed with %s", GetErrorMessage(GetLastResult()));
67 if (IsFailed(__pCamera->SetPreviewFrameRate(30)))
69 AppLogExceptionTag(pTag, "SetPreviewFrameRate failed with %s", GetErrorMessage(GetLastResult()));
73 Tizen::Base::Collection::IList* _pList = __pCamera->GetSupportedPreviewResolutionListN();
77 int _count = _pList->GetCount();
80 Tizen::Base::Collection::IEnumerator* _pEnum = _pList->GetEnumeratorN();
83 result _res = E_SUCCESS;
84 int _area; //area of camera preview image
86 while (E_SUCCESS == _res)
88 _res = _pEnum->MoveNext();
93 Tizen::Graphics::Dimension* _pSupportedDim = (Tizen::Graphics::Dimension*) _pEnum->GetCurrent();
96 if (_pSupportedDim->width <= width && _pSupportedDim->height <= height)
98 int _supportedArea = _pSupportedDim->width * _pSupportedDim->height;
99 if (_supportedArea > _area)
101 __choosenResolution = *_pSupportedDim;
102 _area = _supportedArea;
110 case E_INVALID_OPERATION:
123 if (IsFailed(__pCamera->SetPreviewResolution(__choosenResolution)))
125 AppLogExceptionTag(pTag, "SetPreviewResolution failed with %s", GetErrorMessage(GetLastResult()));
129 if (IsFailed(__pCamera->SetFocusMode(Tizen::Media::CAMERA_FOCUS_MODE_NORMAL)))
131 AppLogExceptionTag(pTag, "SetFocusMode CAMERA_FOCUS_MODE_NORMAL failed with %s", GetErrorMessage(GetLastResult()));
134 __width = __pCamera->GetPreviewResolution().width;
135 __height = __pCamera->GetPreviewResolution().height;
141 CameraTools::StopCamera(void)
143 if (__pCamera && __pCamera->IsPoweredOn())
146 if (IsFailed(__pCamera->PowerOff()))
148 AppLogExceptionTag(pTag, "PowerOff failed with %s", GetErrorMessage(GetLastResult()));
157 CameraTools::Suspend(void)
159 if (__pCamera && __pCamera->IsPoweredOn())
161 if (CAMERA_STATE_PREVIEW == __pCamera->GetState() || CAMERA_STATE_AUTO_FOCUSING == __pCamera->GetState())
163 if (IsFailed(__pCamera->StopPreview()))
165 AppLogExceptionTag(pTag, "StopPreview failed with %s", GetErrorMessage(GetLastResult()));
170 AppLogExceptionTag(pTag, "StopPreview camera state %i", __pCamera->GetState());
176 CameraTools::Restart(void)
178 if (__pCamera && __pCamera->IsPoweredOn())
180 AppLogExceptionTag(pTag, "Restart camera state %i", __pCamera->GetState());
183 switch(__pCamera->GetState())
185 case CAMERA_STATE_INITIALIZED:
187 case CAMERA_STATE_CAPTURED:
188 if (IsFailed(__pCamera->StartPreview(null, true)))
190 AppLogExceptionTag(pTag, "StartPreview failed with %s", GetErrorMessage(GetLastResult()));
194 case CAMERA_STATE_PREVIEW:
196 case CAMERA_STATE_AUTO_FOCUSING:
198 case CAMERA_STATE_ERROR:
199 AppLogExceptionTag(pTag, "Camera is in error state");
203 AppLogExceptionTag(pTag, "Camera is in state %i", __pCamera->GetState());
214 msgBox.Construct("Warning", "Camera error occurred. Terminating application.", MSGBOX_STYLE_OK, 0);
215 msgBox.ShowAndWait(r);
219 case MSGBOX_RESULT_OK:
220 Tizen::App::Application::GetInstance()->Terminate();
232 CameraTools::ZoomIn(void)
234 if (__pCamera && __pCamera->IsPoweredOn())
236 if (IsFailed(__pCamera->ZoomIn()))
238 AppLogExceptionTag(pTag, "ZoomIn failed with %s", GetErrorMessage(GetLastResult()));
244 CameraTools::ZoomOut(void)
246 if (__pCamera && __pCamera->IsPoweredOn())
248 if (IsFailed(__pCamera->ZoomOut()))
250 AppLogExceptionTag(pTag, "ZoomIn failed with %s", GetErrorMessage(GetLastResult()));
256 CameraTools::GetCamera(void)
262 CameraTools::GetWidth(void)
268 CameraTools::GetHeight(void)