1278ccb5bdd6a62ae85f0406d3fbf21636058558
[platform/framework/native/vision.git] / src / FUixVisionQrCodeRecognizer.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <FUixVisionQrCodeRecognizer.h>
19 #include "FUixVision_QrCodeRecognizerImpl.h"
20 #include <FBaseSysLog.h>
21
22 namespace Tizen { namespace Uix { namespace Vision
23 {
24
25 QrCodeRecognizer::QrCodeRecognizer(void)
26     : __pQrCodeRecognizerImpl(0)
27 {
28 }
29
30 QrCodeRecognizer::~QrCodeRecognizer(void)
31 {
32     if (__pQrCodeRecognizerImpl != null)
33     {
34         delete __pQrCodeRecognizerImpl;
35         __pQrCodeRecognizerImpl = null;
36     }
37 }
38
39 result
40 QrCodeRecognizer::Construct(void)
41 {
42     SysAssertf(__pQrCodeRecognizerImpl == null, "Already constructed! ",
43             "Calling Construct() twice or more on a same instance is not allowed for this class.");
44
45     std::unique_ptr<_QrCodeRecognizerImpl> pQrCodeRecognizerImpl(new (std::nothrow) _QrCodeRecognizerImpl());
46     SysTryReturn(NID_UIX, pQrCodeRecognizerImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
47     __pQrCodeRecognizerImpl = pQrCodeRecognizerImpl.release();
48
49     return __pQrCodeRecognizerImpl->Init() ? E_SUCCESS : E_FAILURE;
50 }
51
52 result
53 QrCodeRecognizer::SetImageSize(int width, int height)
54 {
55     SysAssertf(__pQrCodeRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
56
57     SysTryReturn(NID_UIX, width > 0 && height > 0, false, E_INVALID_ARG,
58             "width and height must be greater then 0. [E_INVALID_ARG]");
59
60     return __pQrCodeRecognizerImpl->SetFrameSize(width, height) ? E_SUCCESS : E_FAILURE;
61 }
62
63 result
64 QrCodeRecognizer::GetFocusRoi(Tizen::Graphics::Rectangle& roi)
65 {
66     SysAssertf(__pQrCodeRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
67
68     static int array[4] = {0};
69     result r = __pQrCodeRecognizerImpl->GetROI(array) ? E_SUCCESS : E_FAILURE;
70
71     if (r == E_SUCCESS)
72     {
73         roi.SetBounds(array[0], array[1], array[2] - array[0], array[3] - array[1]);
74     }
75     return r;
76 }
77
78 int
79 QrCodeRecognizer::GetRecognizedObjectCount(void)
80 {
81     SysAssertf(__pQrCodeRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
82     __pQrCodeRecognizerImpl->FillObjectStorage();
83     return __pQrCodeRecognizerImpl->GetRecognizedObjectsCount();
84 }
85
86 const QrCodeObject*
87 QrCodeRecognizer::GetRecognizedObject(int index) const
88 {
89     SysAssertf(__pQrCodeRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
90     return __pQrCodeRecognizerImpl->GetQrCodeObject(index);
91 }
92
93 result
94 QrCodeRecognizer::ProcessImage(const Tizen::Base::ByteBuffer& imageBuffer)
95 {
96     SysAssertf(__pQrCodeRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
97
98     SysTryReturn(NID_UIX, imageBuffer.GetPointer(), false, E_INVALID_ARG,
99             "image buffer must not be null. [E_INVALID_ARG]");
100
101     return __pQrCodeRecognizerImpl->ProcessFrame((unsigned char*) imageBuffer.GetPointer()) ? E_SUCCESS : E_FAILURE;
102 }
103
104 } } } //Tizen::Uix::Vision