2 // Open Service Platform
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <FUixVisionImageFeatureManager.h>
19 #include "FUixVision_ImageFeatureManagerImpl.h"
21 #include <FGraphics.h>
23 #include <FBaseSysLog.h>
25 namespace Tizen { namespace Uix { namespace Vision
28 ImageFeatureManager::ImageFeatureManager(void)
29 : __pImageFeatureManagerImpl(0)
33 ImageFeatureManager::~ImageFeatureManager(void)
38 ImageFeatureManager::Construct(void)
40 SysAssertf(__pImageFeatureManagerImpl == null, "Already constructed! ",
41 "Calling Construct() twice or more on a same instance is not allowed for this class.");
43 std::unique_ptr<_ImageFeatureManagerImpl> pImageFeatureManagerImpl (new (std::nothrow) _ImageFeatureManagerImpl());
44 SysTryReturn(NID_UIX, pImageFeatureManagerImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
46 __pImageFeatureManagerImpl = pImageFeatureManagerImpl.release();
47 __pImageFeatureManagerImpl->InitDB();
52 ImageFeatureManager::DeleteFeature(int featureIndex)
54 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
56 SysTryReturn(NID_UIX, featureIndex >= 0, E_FAILURE, E_INVALID_ARG,
57 "index should be greater than 0. [E_INVALID_ARG]");
59 return __pImageFeatureManagerImpl->DeleteFeature(featureIndex) ? E_SUCCESS : E_FAILURE;
63 ImageFeatureManager::GetTotalNumberOfFeatures(void)
65 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
66 return __pImageFeatureManagerImpl->GetTotalNumberOfFeatures();
70 ImageFeatureManager::DeleteAllFeatures(void)
72 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
73 SysTryReturnResult(NID_UIX, __pImageFeatureManagerImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
74 __pImageFeatureManagerImpl->ReleaseDB();
75 __pImageFeatureManagerImpl->InitDB();
80 ImageFeatureManager::AddFeature(const Tizen::Base::ByteBuffer& imageBuffer, int width, int height, const Tizen::Base::String& descr)
83 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
85 SysTryReturn(NID_UIX, width > 0 && height > 0, -1, E_INVALID_ARG,
86 "Width and height must me more than 0. [E_INVALID_ARG]");
88 const unsigned char* image = (unsigned char*) imageBuffer.GetPointer();
90 SysTryReturn(NID_UIX, image != null, -1, E_INVALID_ARG,
91 "image pointer must not be null. [E_INVALID_ARG]");
93 return (int) __pImageFeatureManagerImpl->AddFeature(image, width, height, descr);
97 ImageFeatureManager::AddFeature(const Tizen::Base::String& imagePath)
99 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
101 SysTryReturnResult(NID_UIX, !imagePath.IsEmpty(), E_INVALID_ARG,
102 "image path must not be empty. [E_INVALID_ARG]");
104 return (int) __pImageFeatureManagerImpl->AddFeature(imagePath);
108 ImageFeatureManager::Flush(const Tizen::Base::String* featureSetFilePath)
110 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
112 return __pImageFeatureManagerImpl->SaveDB(true, featureSetFilePath);
116 ImageFeatureManager::Load(const Tizen::Base::String& featureSetFilePath)
118 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
120 SysTryReturnResult(NID_UIX, !featureSetFilePath.IsEmpty(), E_INVALID_ARG,
121 "database path must not be empty. [E_INVALID_ARG]");
123 return __pImageFeatureManagerImpl->OpenDB(featureSetFilePath) ? E_SUCCESS : E_FAILURE;
126 Tizen::Base::Collection::IListT<Tizen::Media::ImageFormat>*
127 ImageFeatureManager::GetSupportedImageFileFormatsListN(void)
129 Tizen::Base::Collection::ArrayListT<Tizen::Media::ImageFormat>* formatList = new Tizen::Base::Collection::ArrayListT<Tizen::Media::ImageFormat>;
130 formatList->Add(Tizen::Media::IMG_FORMAT_BMP);
131 formatList->Add(Tizen::Media::IMG_FORMAT_JPG);
132 formatList->Add(Tizen::Media::IMG_FORMAT_PNG);
136 const Tizen::Uix::Vision::ImageFeatureInfo*
137 ImageFeatureManager::GetImageFeatureInfo(int index) const
139 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
140 return __pImageFeatureManagerImpl->GetImageFeatureInfo(index);
143 } } } //Tizen::Uix::Vision