patch for rc20
[framework/osp/vision.git] / src / FUixVision_QrCodeRecognizerImpl.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 "FUixVision_QrCodeRecognizerImpl.h"
19 #include "FUixVision_QrCodeObjectImpl.h"
20
21 namespace Tizen { namespace Uix { namespace Vision
22 {
23
24 _QrCodeRecognizerImpl::_QrCodeRecognizerImpl(void)
25     : __objectStorage(0)
26 {
27     __objectStorage = _QrCodeObjectImpl::CreateQRCodeObjectStorageN(MAX_TRACKABLE_OBJECTS);
28 }
29
30 _QrCodeRecognizerImpl::~_QrCodeRecognizerImpl(void)
31 {
32     _QrCodeObjectImpl::ReleaseQrCodeObjectArray(__objectStorage);
33 }
34
35 bool
36 _QrCodeRecognizerImpl::SetFrameSize(int width, int height)
37 {
38         __width = width;
39         __height = height;
40     return __qrCodeRecognizer.setFrameSize(width, height);
41 }
42
43 bool
44 _QrCodeRecognizerImpl::ProcessFrame(const unsigned char* raw)
45 {
46     return __qrCodeRecognizer.processFrame(raw);
47 }
48
49 bool
50 _QrCodeRecognizerImpl::GetROI(int* roi)
51 {
52
53         static float array[4] = {0.};
54         result r = __qrCodeRecognizer.getROI(array) ? E_SUCCESS : E_FAILURE;
55
56         if (E_SUCCESS == r)
57         {
58                 roi[0] = ((1. + array[0]) / 2.) * __width;
59                 roi[1] = ((1. + array[1]) / 2.) * __height;
60                 roi[2] = ((1. + array[2]) / 2.) * __width;
61                 roi[3] = ((1. + array[3]) / 2.) * __height;
62         }
63
64     return E_SUCCESS == r;
65 }
66
67 void
68 _QrCodeRecognizerImpl::SetSceneTransform(const float* left, const float* right)
69 {
70     __qrCodeRecognizer.setSceneTransform(left, right);
71 }
72
73 void
74 _QrCodeRecognizerImpl::FillObjectStorage(void)
75 {
76     __objectStorageSize = 0;
77     for (const sari2::QRCodeRecognitionInfo *o = __qrCodeRecognizer.objectsBegin(), *e = __qrCodeRecognizer.objectsEnd(); o != e; ++o)
78     {
79         Tizen::Uix::Vision::QrCodeObject& to = __objectStorage[__objectStorageSize++];
80         _QrCodeObjectImpl::GetInstance(&to)->SetSariPointer(*o);
81     }
82 }
83
84 const
85 QrCodeObject* _QrCodeRecognizerImpl::QRCodeObjectsBegin(void)
86 {
87     return __objectStorage;
88 }
89
90 const
91 QrCodeObject* _QrCodeRecognizerImpl::QRCodeObjectsEnd(void)
92 {
93     return __objectStorage + __objectStorageSize;
94 }
95
96 int _QrCodeRecognizerImpl::GetRecognizedObjectsCount(void)
97 {
98     return __objectStorageSize;
99 }
100
101 const QrCodeObject*
102 _QrCodeRecognizerImpl::GetQrCodeObject(int index)
103 {
104     ClearLastResult();
105     if (index < __objectStorageSize)
106     {
107         return &__objectStorage[index];
108     }
109     else
110     {
111         SetLastResult(E_INVALID_ARG);
112         return null;
113     }
114 }
115
116 _QrCodeRecognizerImpl* _QrCodeRecognizerImpl::GetInstance(QrCodeRecognizer* pQrRecognizer)
117 {
118     return pQrRecognizer->__pQrCodeRecognizerImpl;
119 }
120
121 const _QrCodeRecognizerImpl* _QrCodeRecognizerImpl::GetInstance(const QrCodeRecognizer* pQrRecognizer)
122 {
123     return pQrRecognizer->__pQrCodeRecognizerImpl;
124 }
125
126 bool
127 _QrCodeRecognizerImpl::Init(void)
128 {
129     return __qrCodeRecognizer.init();
130 }
131
132 bool
133 _QrCodeRecognizerImpl::Destroy(void)
134 {
135     return __qrCodeRecognizer.destroy();
136 }
137
138 } } } //Tizen::Uix::Vision