2 // Open Service Platform
3 // Copyright (c) 2012 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 * @file FCnt_ImageMetadataImpl.cpp
19 * @brief This is the implementation file for the %_ImageMetadataImpl class.
21 * This file contains implementation of the %_ImageMetadataImpl class.
25 #include <FBaseSysLog.h>
26 #include <FMediaImage.h>
27 #include <FGrpBitmap.h>
28 #include <FCntImageMetadata.h>
29 #include <FCnt_ImageMetadataImpl.h>
30 #include <FIo_FileImpl.h>
31 #include <FMedia_ImageImpl.h>
35 using namespace Tizen::Base;
36 using namespace Tizen::Io;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Media;
40 namespace Tizen { namespace Content
43 static const int THUMBNAIL_IMAGE_WIDTH = 320;
44 static const int THUMBNAIL_IMAGE_HEIGHT = 240;
45 static const double DEFAULT_COORDINATE = -200.0;
47 _ImageMetadataImpl::_ImageMetadataImpl(void)
50 unique_ptr<ImageMeta, ImageMetaDeleter> pNewImageMeta(new (nothrow) ImageMeta());
51 if (pNewImageMeta != null)
53 __pImageMeta = move(pNewImageMeta);
58 SysLog(NID_CNT, "The memory is insufficient.");
62 _ImageMetadataImpl::~_ImageMetadataImpl(void)
68 _ImageMetadataImpl::GetInstance(ImageMetadata& imageMetadata)
70 return imageMetadata.__pImpl;
73 const _ImageMetadataImpl*
74 _ImageMetadataImpl::GetInstance(const ImageMetadata& imageMetadata)
76 return imageMetadata.__pImpl;
80 _ImageMetadataImpl::SetImageMetadata(const ImageMeta* pImageMeta)
84 SysTryReturnResult(NID_CNT, pImageMeta != null, E_INVALID_ARG, "pImageMeta is null.");
86 __pImageMeta->width = pImageMeta->width;
87 __pImageMeta->height = pImageMeta->height;
88 __pImageMeta->orientation = pImageMeta->orientation;
89 __pImageMeta->latitude = pImageMeta->latitude;
90 __pImageMeta->longitude = pImageMeta->longitude;
91 __pImageMeta->contentPath = pImageMeta->contentPath;
93 if (pImageMeta->pManufacturer != null)
95 __pImageMeta->pManufacturer = new (nothrow) String(*(pImageMeta->pManufacturer));
96 SysTryReturnResult(NID_CNT, __pImageMeta->pManufacturer != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
98 if (pImageMeta->pModel != null)
100 __pImageMeta->pModel = new (nothrow) String(*(pImageMeta->pModel));
101 SysTryReturnResult(NID_CNT, __pImageMeta->pModel != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
103 if (pImageMeta->pDateTime != null)
105 __pImageMeta->pDateTime = new (nothrow) String(*(pImageMeta->pDateTime));
106 SysTryReturnResult(NID_CNT, __pImageMeta->pDateTime != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
108 if (pImageMeta->pSoftware != null)
110 __pImageMeta->pSoftware = new (nothrow) String(*(pImageMeta->pSoftware));
111 SysTryReturnResult(NID_CNT, __pImageMeta->pSoftware != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
113 if (pImageMeta->pWhiteBalance != null)
115 __pImageMeta->pWhiteBalance = new (nothrow) String(*(pImageMeta->pWhiteBalance));
116 SysTryReturnResult(NID_CNT, __pImageMeta->pWhiteBalance != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
123 _ImageMetadataImpl::GetImageMetadata(void) const
125 return __pImageMeta.get();
128 _ImageMetadataImpl::_ImageMetadataImpl(const _ImageMetadataImpl& rhs)
131 unique_ptr<ImageMeta, ImageMetaDeleter> pNewImageMeta(new (nothrow) ImageMeta());
132 if (pNewImageMeta != null)
134 pNewImageMeta->width = (rhs.__pImageMeta)->width;
135 pNewImageMeta->height = (rhs.__pImageMeta)->height;
136 pNewImageMeta->orientation = (rhs.__pImageMeta)->orientation;
137 pNewImageMeta->latitude = (rhs.__pImageMeta)->latitude;
138 pNewImageMeta->longitude = (rhs.__pImageMeta)->longitude;
139 pNewImageMeta->contentPath = (rhs.__pImageMeta)->contentPath;
141 if ((rhs.__pImageMeta)->pManufacturer != null)
143 pNewImageMeta->pManufacturer = new (nothrow) String(*((rhs.__pImageMeta)->pManufacturer));
144 if (pNewImageMeta->pManufacturer == null)
146 SysLog(NID_CNT, "The memory is insufficient.");
150 if ((rhs.__pImageMeta)->pModel != null)
152 pNewImageMeta->pModel = new (nothrow) String(*((rhs.__pImageMeta)->pModel));
153 if (pNewImageMeta->pModel == null)
155 SysLog(NID_CNT, "The memory is insufficient.");
159 if ((rhs.__pImageMeta)->pDateTime != null)
161 pNewImageMeta->pDateTime = new (nothrow) String(*((rhs.__pImageMeta)->pDateTime));
162 if (pNewImageMeta->pDateTime == null)
164 SysLog(NID_CNT, "The memory is insufficient.");
168 if ((rhs.__pImageMeta)->pSoftware != null)
170 pNewImageMeta->pSoftware = new (nothrow) String(*((rhs.__pImageMeta)->pSoftware));
171 if (pNewImageMeta->pSoftware == null)
173 SysLog(NID_CNT, "The memory is insufficient.");
177 if ((rhs.__pImageMeta)->pWhiteBalance != null)
179 pNewImageMeta->pWhiteBalance = new (nothrow) String(*((rhs.__pImageMeta)->pWhiteBalance));
180 if (pNewImageMeta->pWhiteBalance == null)
182 SysLog(NID_CNT, "The memory is insufficient.");
187 __pImageMeta = move(pNewImageMeta);
192 SysLog(NID_CNT, "The memory is insufficient.");
197 _ImageMetadataImpl::operator =(const _ImageMetadataImpl& rhs)
199 // check for self-assignment
206 if (__pImageMeta != null && (rhs.__pImageMeta) != null)
208 // DeleteMetadata(__pImageMeta);
209 // __pImageMeta = new (nothrow) ImageMeta;
211 __pImageMeta.reset(new (nothrow) ImageMeta);
213 else if (__pImageMeta != null)
215 //DeleteMetadata(__pImageMeta);
217 __pImageMeta.reset(null);
220 else if ((rhs.__pImageMeta) != null)
222 //__pImageMeta = new (nothrow) ImageMeta;
224 __pImageMeta.reset(new (nothrow) ImageMeta);
228 // __pImageMeta and rhs.__pImageMeta are null.
232 __pImageMeta->width = (rhs.__pImageMeta)->width;
233 __pImageMeta->height = (rhs.__pImageMeta)->height;
234 __pImageMeta->orientation = (rhs.__pImageMeta)->orientation;
235 __pImageMeta->latitude = (rhs.__pImageMeta)->latitude;
236 __pImageMeta->longitude = (rhs.__pImageMeta)->longitude;
237 __pImageMeta->contentPath = (rhs.__pImageMeta)->contentPath;
240 if (__pImageMeta->pManufacturer != null && (rhs.__pImageMeta)->pManufacturer != null)
242 // delete previous data
243 delete __pImageMeta->pManufacturer;
244 __pImageMeta->pManufacturer = null;
246 __pImageMeta->pManufacturer = new (nothrow) String(*((rhs.__pImageMeta)->pManufacturer));
248 else if (__pImageMeta->pManufacturer != null)
250 delete __pImageMeta->pManufacturer;
251 __pImageMeta->pManufacturer = null;
253 else if ((rhs.__pImageMeta)->pManufacturer != null)
255 __pImageMeta->pManufacturer = new (nothrow) String(*((rhs.__pImageMeta)->pManufacturer));
259 if (__pImageMeta->pModel != null && (rhs.__pImageMeta)->pModel != null)
261 // delete previous data
262 delete __pImageMeta->pModel;
263 __pImageMeta->pModel = null;
265 __pImageMeta->pModel = new (nothrow) String(*((rhs.__pImageMeta)->pModel));
267 else if (__pImageMeta->pModel != null)
269 delete __pImageMeta->pModel;
270 __pImageMeta->pModel = null;
272 else if ((rhs.__pImageMeta)->pModel != null)
274 __pImageMeta->pModel = new (nothrow) String(*((rhs.__pImageMeta)->pModel));
278 if (__pImageMeta->pDateTime != null && (rhs.__pImageMeta)->pDateTime != null)
280 // delete previous data
281 delete __pImageMeta->pDateTime;
282 __pImageMeta->pDateTime = null;
284 __pImageMeta->pDateTime = new (nothrow) String(*((rhs.__pImageMeta)->pDateTime));
286 else if (__pImageMeta->pDateTime != null)
288 delete __pImageMeta->pDateTime;
289 __pImageMeta->pDateTime = null;
291 else if ((rhs.__pImageMeta)->pDateTime != null)
293 __pImageMeta->pDateTime = new (nothrow) String(*((rhs.__pImageMeta)->pDateTime));
297 if (__pImageMeta->pSoftware != null && (rhs.__pImageMeta)->pSoftware != null)
299 // delete previous data
300 delete __pImageMeta->pSoftware;
301 __pImageMeta->pSoftware = null;
303 __pImageMeta->pSoftware = new (nothrow) String(*((rhs.__pImageMeta)->pSoftware));
305 else if (__pImageMeta->pSoftware != null)
307 delete __pImageMeta->pSoftware;
308 __pImageMeta->pSoftware = null;
310 else if ((rhs.__pImageMeta)->pSoftware != null)
312 __pImageMeta->pSoftware = new (nothrow) String(*((rhs.__pImageMeta)->pSoftware));
316 if (__pImageMeta->pWhiteBalance != null && (rhs.__pImageMeta)->pWhiteBalance != null)
318 // delete previous data
319 delete __pImageMeta->pWhiteBalance;
320 __pImageMeta->pWhiteBalance = null;
322 __pImageMeta->pWhiteBalance = new (nothrow) String(*((rhs.__pImageMeta)->pWhiteBalance));
324 else if (__pImageMeta->pWhiteBalance != null)
326 delete __pImageMeta->pWhiteBalance;
327 __pImageMeta->pWhiteBalance = null;
329 else if ((rhs.__pImageMeta)->pWhiteBalance != null)
331 __pImageMeta->pWhiteBalance = new (nothrow) String(*((rhs.__pImageMeta)->pWhiteBalance));
334 SysLog(NID_CNT, "_ImageMetadataImpl::operator =(const _ImageMetadataImpl& rhs) is called.");
339 _ImageMetadataImpl::Equals(const Tizen::Base::Object& rhs) const
341 const _ImageMetadataImpl* pRhs = dynamic_cast <const _ImageMetadataImpl*>(&rhs);
347 if (!((this->GetCameraManufacturer()).Equals(pRhs->GetCameraManufacturer())))
351 if (!((this->GetCameraModel()).Equals(pRhs->GetCameraModel())))
355 if (!((this->GetDateTime()).Equals(pRhs->GetDateTime())))
359 if (this->GetHeight() != pRhs->GetHeight())
363 if (Double::Compare(this->GetLatitude(), pRhs->GetLatitude()) != 0)
367 if (Double::Compare(this->GetLongitude(), pRhs->GetLongitude()) != 0)
371 if (this->GetOrientation() != pRhs->GetOrientation())
375 if (!((this->GetSoftware()).Equals(pRhs->GetSoftware())))
379 if (!((this->GetWhiteBalance()).Equals(pRhs->GetWhiteBalance())))
383 if (this->GetWidth() != pRhs->GetWidth())
392 _ImageMetadataImpl::GetHashCode(void) const
396 hash += (this->GetCameraManufacturer()).GetHashCode();
397 hash += (this->GetCameraModel()).GetHashCode();
398 hash += (this->GetDateTime()).GetHashCode();
399 hash += Integer::GetHashCode(this->GetHeight());
400 hash += Double::GetHashCode(this->GetLatitude());
401 hash += Double::GetHashCode(this->GetLongitude());
402 hash += Integer::GetHashCode(this->GetOrientation());
403 hash += (this->GetSoftware()).GetHashCode();
404 hash += (this->GetWhiteBalance()).GetHashCode();
405 hash += Integer::GetHashCode(this->GetWidth());
411 _ImageMetadataImpl::GetWidth(void) const
413 if (__pImageMeta == null)
415 SysLog(NID_CNT, "__pImageMeta is null.");
418 return __pImageMeta->width;
422 _ImageMetadataImpl::GetHeight(void) const
424 if (__pImageMeta == null)
426 SysLog(NID_CNT, "__pImageMeta is null.");
429 return __pImageMeta->height;
433 _ImageMetadataImpl::GetCameraManufacturer(void) const
435 if (__pImageMeta == null || __pImageMeta->pManufacturer == null)
437 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pManufacturer is null.");
440 return *(__pImageMeta->pManufacturer);
444 _ImageMetadataImpl::GetCameraModel(void) const
446 if (__pImageMeta == null || __pImageMeta->pModel == null)
448 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pModel is null.");
451 return *(__pImageMeta->pModel);
455 _ImageMetadataImpl::GetSoftware(void) const
457 if (__pImageMeta == null || __pImageMeta->pSoftware == null)
459 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pSoftware is null.");
462 return *(__pImageMeta->pSoftware);
466 _ImageMetadataImpl::GetDateTime(void) const
468 if (__pImageMeta == null || __pImageMeta->pDateTime == null)
470 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pDateTime is null.");
473 return *(__pImageMeta->pDateTime);
477 _ImageMetadataImpl::GetLatitude(void) const
479 if (__pImageMeta == null)
481 SysLog(NID_CNT, "__pImageMeta is null.");
482 return DEFAULT_COORDINATE;
484 return __pImageMeta->latitude;
488 _ImageMetadataImpl::GetLongitude(void) const
490 if (__pImageMeta == null)
492 SysLog(NID_CNT, "__pImageMeta is null.");
493 return DEFAULT_COORDINATE;
495 return __pImageMeta->longitude;
499 _ImageMetadataImpl::GetOrientation(void) const
501 if (__pImageMeta == null)
503 SysLog(NID_CNT, "__pImageMeta is null.");
504 return IMAGE_ORIENTATION_TYPE_UNKNOWN;
506 return __pImageMeta->orientation;
510 _ImageMetadataImpl::GetWhiteBalance(void) const
512 if (__pImageMeta == null || __pImageMeta->pWhiteBalance == null)
514 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pWhiteBalance is null.");
517 return *(__pImageMeta->pWhiteBalance);
526 _ImageMetadataImpl::GetThumbnailN(void) const
530 SysTryReturn(NID_CNT, __pImageMeta != null, null, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN failed.");
531 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(__pImageMeta->contentPath), null, E_DATA_NOT_FOUND,
532 "[E_DATA_NOT_FOUND] GetThumbnailN failed [%ls].", (__pImageMeta->contentPath).GetPointer());
535 result r = image.Construct();
536 SysTryReturn(NID_CNT, !IsFailed(r), null, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN failed.");
538 Bitmap* pBitmap = image.DecodeN(__pImageMeta->contentPath, BITMAP_PIXEL_FORMAT_ARGB8888, THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT);
543 if (r == E_OUT_OF_MEMORY)
545 SysLogException(NID_CNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetThumbnailN failed.");
549 SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN failed.");