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)
35 if (__pImageFeatureManagerImpl != null)
37 delete __pImageFeatureManagerImpl;
38 __pImageFeatureManagerImpl = null;
43 ImageFeatureManager::Construct(void)
45 SysAssertf(__pImageFeatureManagerImpl == null, "Already constructed! ",
46 "Calling Construct() twice or more on a same instance is not allowed for this class.");
48 std::unique_ptr<_ImageFeatureManagerImpl> pImageFeatureManagerImpl (new (std::nothrow) _ImageFeatureManagerImpl());
49 SysSecureTryReturn(NID_UIX, pImageFeatureManagerImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
51 __pImageFeatureManagerImpl = pImageFeatureManagerImpl.release();
52 __pImageFeatureManagerImpl->InitDB();
57 ImageFeatureManager::DeleteFeature(int featureIndex)
59 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
61 SysSecureTryReturn(NID_UIX, featureIndex >= 0, E_FAILURE, E_INVALID_ARG,
62 "index should be greater than 0. [E_INVALID_ARG]");
64 return __pImageFeatureManagerImpl->DeleteFeature(featureIndex) ? E_SUCCESS : E_FAILURE;
68 ImageFeatureManager::GetTotalNumberOfFeatures(void)
70 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
71 return __pImageFeatureManagerImpl->GetTotalNumberOfFeatures();
75 ImageFeatureManager::DeleteAllFeatures(void)
77 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
78 SysSecureTryReturnResult(NID_UIX, __pImageFeatureManagerImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
79 __pImageFeatureManagerImpl->ReleaseDB();
80 __pImageFeatureManagerImpl->InitDB();
85 ImageFeatureManager::AddFeature(const Tizen::Base::ByteBuffer& imageBuffer, int width, int height, const Tizen::Base::String& descr)
88 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
90 SysSecureTryReturn(NID_UIX, width > 0 && height > 0, -1, E_INVALID_ARG,
91 "Width and height must me more than 0. [E_INVALID_ARG]");
93 const unsigned char* image = (unsigned char*) imageBuffer.GetPointer();
95 SysSecureTryReturn(NID_UIX, image != null, -1, E_INVALID_ARG,
96 "image pointer must not be null. [E_INVALID_ARG]");
98 return (int) __pImageFeatureManagerImpl->AddFeature(image, width, height, descr);
102 ImageFeatureManager::AddFeature(const Tizen::Base::String& imagePath)
104 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
106 SysSecureTryReturn(NID_UIX, !imagePath.IsEmpty(), -1, E_INVALID_ARG,
107 "image path must not be empty. [E_INVALID_ARG]");
109 SysSecureTryReturn(NID_UIX, Tizen::Io::File::IsFileExist(imagePath), -1, E_INVALID_ARG,
110 "image path must exist. [E_INVALID_ARG]");
112 Tizen::Io::FileAttributes _fileAtt;
114 SysSecureTryReturn(NID_UIX, Tizen::Io::File::GetAttributes(imagePath, _fileAtt) == E_SUCCESS, -1, E_INVALID_ARG,
115 "image file must have attributes. [E_INVALID_ARG]");
117 SysSecureTryReturn(NID_UIX, !_fileAtt.IsDirectory(), -1, E_INVALID_ARG,
118 "image file must exist. [E_INVALID_ARG]");
120 return (int) __pImageFeatureManagerImpl->AddFeature(imagePath);
124 ImageFeatureManager::Flush(const Tizen::Base::String* featureSetFilePath)
126 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
128 return __pImageFeatureManagerImpl->SaveDB(true, featureSetFilePath);
132 ImageFeatureManager::Load(const Tizen::Base::String& featureSetFilePath)
134 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
136 SysSecureTryReturnResult(NID_UIX, !featureSetFilePath.IsEmpty(), E_INVALID_ARG,
137 "feature set path must not be empty. [E_INVALID_ARG]");
139 SysSecureTryReturnResult(NID_UIX, Tizen::Io::File::IsFileExist(featureSetFilePath), E_INVALID_ARG,
140 "feature set path must exist. [E_INVALID_ARG]");
142 Tizen::Io::FileAttributes _fileAtt;
144 SysSecureTryReturnResult(NID_UIX, Tizen::Io::File::GetAttributes(featureSetFilePath, _fileAtt) == E_SUCCESS, E_INVALID_ARG,
145 "feature set file must have attributes. [E_INVALID_ARG]");
147 SysSecureTryReturnResult(NID_UIX, !_fileAtt.IsDirectory(), E_INVALID_ARG,
148 "feature set file must exist. [E_INVALID_ARG]");
150 return __pImageFeatureManagerImpl->OpenDB(featureSetFilePath) ? E_SUCCESS : E_FAILURE;
153 Tizen::Base::Collection::IListT<Tizen::Media::ImageFormat>*
154 ImageFeatureManager::GetSupportedImageFileFormatsListN(void)
156 std::unique_ptr<Tizen::Base::Collection::ArrayListT<Tizen::Media::ImageFormat> > pFormatList(new (std::nothrow) Tizen::Base::Collection::ArrayListT<Tizen::Media::ImageFormat>);
157 SysSecureTryReturn(NID_UIX, pFormatList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
159 pFormatList->Add(Tizen::Media::IMG_FORMAT_BMP);
160 pFormatList->Add(Tizen::Media::IMG_FORMAT_JPG);
161 pFormatList->Add(Tizen::Media::IMG_FORMAT_PNG);
162 return pFormatList.release();
165 const Tizen::Uix::Vision::ImageFeatureInfo*
166 ImageFeatureManager::GetImageFeatureInfo(int index) const
168 SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
169 return __pImageFeatureManagerImpl->GetImageFeatureInfo(index);
172 } } } //Tizen::Uix::Vision