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.
24 #include <FBaseSysLog.h>
25 #include <FMediaImage.h>
26 #include <FGrpBitmap.h>
27 #include <FCntImageMetadata.h>
28 #include <FCnt_ImageMetadataImpl.h>
29 #include <FIo_FileImpl.h>
30 #include <FMedia_ImageImpl.h>
33 using namespace Tizen::Base;
34 using namespace Tizen::Io;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Media;
38 namespace Tizen { namespace Content
41 static const int THUMBNAIL_IMAGE_WIDTH = 320;
42 static const int THUMBNAIL_IMAGE_HEIGHT = 240;
43 static const double DEFAULT_COORDINATE = -200.0;
45 _ImageMetadataImpl::_ImageMetadataImpl(void)
48 unique_ptr<ImageMeta, ImageMetaDeleter> pNewImageMeta(new (nothrow) ImageMeta());
49 if (pNewImageMeta != null)
51 __pImageMeta = move(pNewImageMeta);
56 SysLog(NID_CNT, "The memory is insufficient.");
60 _ImageMetadataImpl::~_ImageMetadataImpl(void)
66 _ImageMetadataImpl::GetInstance(ImageMetadata& imageMetadata)
68 return imageMetadata.__pImpl;
71 const _ImageMetadataImpl*
72 _ImageMetadataImpl::GetInstance(const ImageMetadata& imageMetadata)
74 return imageMetadata.__pImpl;
78 _ImageMetadataImpl::SetImageMetadata(const ImageMeta* pImageMeta)
82 SysTryReturnResult(NID_CNT, pImageMeta != null, E_INVALID_ARG, "pImageMeta is null.");
84 __pImageMeta->width = pImageMeta->width;
85 __pImageMeta->height = pImageMeta->height;
86 __pImageMeta->orientation = pImageMeta->orientation;
87 __pImageMeta->latitude = pImageMeta->latitude;
88 __pImageMeta->longitude = pImageMeta->longitude;
89 __pImageMeta->contentPath = pImageMeta->contentPath;
91 if (pImageMeta->pManufacturer != null)
93 __pImageMeta->pManufacturer = new (nothrow) String(*(pImageMeta->pManufacturer));
94 SysTryReturnResult(NID_CNT, __pImageMeta->pManufacturer != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
96 if (pImageMeta->pModel != null)
98 __pImageMeta->pModel = new (nothrow) String(*(pImageMeta->pModel));
99 SysTryReturnResult(NID_CNT, __pImageMeta->pModel != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
101 if (pImageMeta->pDateTime != null)
103 __pImageMeta->pDateTime = new (nothrow) String(*(pImageMeta->pDateTime));
104 SysTryReturnResult(NID_CNT, __pImageMeta->pDateTime != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
106 if (pImageMeta->pSoftware != null)
108 __pImageMeta->pSoftware = new (nothrow) String(*(pImageMeta->pSoftware));
109 SysTryReturnResult(NID_CNT, __pImageMeta->pSoftware != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
111 if (pImageMeta->pWhiteBalance != null)
113 __pImageMeta->pWhiteBalance = new (nothrow) String(*(pImageMeta->pWhiteBalance));
114 SysTryReturnResult(NID_CNT, __pImageMeta->pWhiteBalance != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
121 _ImageMetadataImpl::GetImageMetadata(void) const
123 return __pImageMeta.get();
126 _ImageMetadataImpl::_ImageMetadataImpl(const _ImageMetadataImpl& rhs)
129 unique_ptr<ImageMeta, ImageMetaDeleter> pNewImageMeta(new (nothrow) ImageMeta());
130 if (pNewImageMeta != null)
132 pNewImageMeta->width = (rhs.__pImageMeta)->width;
133 pNewImageMeta->height = (rhs.__pImageMeta)->height;
134 pNewImageMeta->orientation = (rhs.__pImageMeta)->orientation;
135 pNewImageMeta->latitude = (rhs.__pImageMeta)->latitude;
136 pNewImageMeta->longitude = (rhs.__pImageMeta)->longitude;
137 pNewImageMeta->contentPath = (rhs.__pImageMeta)->contentPath;
139 if ((rhs.__pImageMeta)->pManufacturer != null)
141 pNewImageMeta->pManufacturer = new (nothrow) String(*((rhs.__pImageMeta)->pManufacturer));
142 if (pNewImageMeta->pManufacturer == null)
144 SysLog(NID_CNT, "The memory is insufficient.");
148 if ((rhs.__pImageMeta)->pModel != null)
150 pNewImageMeta->pModel = new (nothrow) String(*((rhs.__pImageMeta)->pModel));
151 if (pNewImageMeta->pModel == null)
153 SysLog(NID_CNT, "The memory is insufficient.");
157 if ((rhs.__pImageMeta)->pDateTime != null)
159 pNewImageMeta->pDateTime = new (nothrow) String(*((rhs.__pImageMeta)->pDateTime));
160 if (pNewImageMeta->pDateTime == null)
162 SysLog(NID_CNT, "The memory is insufficient.");
166 if ((rhs.__pImageMeta)->pSoftware != null)
168 pNewImageMeta->pSoftware = new (nothrow) String(*((rhs.__pImageMeta)->pSoftware));
169 if (pNewImageMeta->pSoftware == null)
171 SysLog(NID_CNT, "The memory is insufficient.");
175 if ((rhs.__pImageMeta)->pWhiteBalance != null)
177 pNewImageMeta->pWhiteBalance = new (nothrow) String(*((rhs.__pImageMeta)->pWhiteBalance));
178 if (pNewImageMeta->pWhiteBalance == null)
180 SysLog(NID_CNT, "The memory is insufficient.");
185 __pImageMeta = move(pNewImageMeta);
190 SysLog(NID_CNT, "The memory is insufficient.");
195 _ImageMetadataImpl::operator =(const _ImageMetadataImpl& rhs)
197 // check for self-assignment
204 if (__pImageMeta != null && (rhs.__pImageMeta) != null)
206 // DeleteMetadata(__pImageMeta);
207 // __pImageMeta = new (nothrow) ImageMeta;
209 __pImageMeta.reset(new (nothrow) ImageMeta);
211 else if (__pImageMeta != null)
213 //DeleteMetadata(__pImageMeta);
215 __pImageMeta.reset(null);
218 else if ((rhs.__pImageMeta) != null)
220 //__pImageMeta = new (nothrow) ImageMeta;
222 __pImageMeta.reset(new (nothrow) ImageMeta);
226 // __pImageMeta and rhs.__pImageMeta are null.
230 __pImageMeta->width = (rhs.__pImageMeta)->width;
231 __pImageMeta->height = (rhs.__pImageMeta)->height;
232 __pImageMeta->orientation = (rhs.__pImageMeta)->orientation;
233 __pImageMeta->latitude = (rhs.__pImageMeta)->latitude;
234 __pImageMeta->longitude = (rhs.__pImageMeta)->longitude;
235 __pImageMeta->contentPath = (rhs.__pImageMeta)->contentPath;
238 if (__pImageMeta->pManufacturer != null && (rhs.__pImageMeta)->pManufacturer != null)
240 // delete previous data
241 delete __pImageMeta->pManufacturer;
242 __pImageMeta->pManufacturer = null;
244 __pImageMeta->pManufacturer = new (nothrow) String(*((rhs.__pImageMeta)->pManufacturer));
246 else if (__pImageMeta->pManufacturer != null)
248 delete __pImageMeta->pManufacturer;
249 __pImageMeta->pManufacturer = null;
251 else if ((rhs.__pImageMeta)->pManufacturer != null)
253 __pImageMeta->pManufacturer = new (nothrow) String(*((rhs.__pImageMeta)->pManufacturer));
257 if (__pImageMeta->pModel != null && (rhs.__pImageMeta)->pModel != null)
259 // delete previous data
260 delete __pImageMeta->pModel;
261 __pImageMeta->pModel = null;
263 __pImageMeta->pModel = new (nothrow) String(*((rhs.__pImageMeta)->pModel));
265 else if (__pImageMeta->pModel != null)
267 delete __pImageMeta->pModel;
268 __pImageMeta->pModel = null;
270 else if ((rhs.__pImageMeta)->pModel != null)
272 __pImageMeta->pModel = new (nothrow) String(*((rhs.__pImageMeta)->pModel));
276 if (__pImageMeta->pDateTime != null && (rhs.__pImageMeta)->pDateTime != null)
278 // delete previous data
279 delete __pImageMeta->pDateTime;
280 __pImageMeta->pDateTime = null;
282 __pImageMeta->pDateTime = new (nothrow) String(*((rhs.__pImageMeta)->pDateTime));
284 else if (__pImageMeta->pDateTime != null)
286 delete __pImageMeta->pDateTime;
287 __pImageMeta->pDateTime = null;
289 else if ((rhs.__pImageMeta)->pDateTime != null)
291 __pImageMeta->pDateTime = new (nothrow) String(*((rhs.__pImageMeta)->pDateTime));
295 if (__pImageMeta->pSoftware != null && (rhs.__pImageMeta)->pSoftware != null)
297 // delete previous data
298 delete __pImageMeta->pSoftware;
299 __pImageMeta->pSoftware = null;
301 __pImageMeta->pSoftware = new (nothrow) String(*((rhs.__pImageMeta)->pSoftware));
303 else if (__pImageMeta->pSoftware != null)
305 delete __pImageMeta->pSoftware;
306 __pImageMeta->pSoftware = null;
308 else if ((rhs.__pImageMeta)->pSoftware != null)
310 __pImageMeta->pSoftware = new (nothrow) String(*((rhs.__pImageMeta)->pSoftware));
314 if (__pImageMeta->pWhiteBalance != null && (rhs.__pImageMeta)->pWhiteBalance != null)
316 // delete previous data
317 delete __pImageMeta->pWhiteBalance;
318 __pImageMeta->pWhiteBalance = null;
320 __pImageMeta->pWhiteBalance = new (nothrow) String(*((rhs.__pImageMeta)->pWhiteBalance));
322 else if (__pImageMeta->pWhiteBalance != null)
324 delete __pImageMeta->pWhiteBalance;
325 __pImageMeta->pWhiteBalance = null;
327 else if ((rhs.__pImageMeta)->pWhiteBalance != null)
329 __pImageMeta->pWhiteBalance = new (nothrow) String(*((rhs.__pImageMeta)->pWhiteBalance));
332 SysLog(NID_CNT, "_ImageMetadataImpl::operator =(const _ImageMetadataImpl& rhs) is called.");
337 _ImageMetadataImpl::Equals(const Tizen::Base::Object& rhs) const
339 const _ImageMetadataImpl* pRhs = dynamic_cast <const _ImageMetadataImpl*>(&rhs);
345 if (!((this->GetCameraManufacturer()).Equals(pRhs->GetCameraManufacturer())))
349 if (!((this->GetCameraModel()).Equals(pRhs->GetCameraModel())))
353 if (!((this->GetDateTime()).Equals(pRhs->GetDateTime())))
357 if (this->GetHeight() != pRhs->GetHeight())
361 if (Double::Compare(this->GetLatitude(), pRhs->GetLatitude()) != 0)
365 if (Double::Compare(this->GetLongitude(), pRhs->GetLongitude()) != 0)
369 if (this->GetOrientation() != pRhs->GetOrientation())
373 if (!((this->GetSoftware()).Equals(pRhs->GetSoftware())))
377 if (!((this->GetWhiteBalance()).Equals(pRhs->GetWhiteBalance())))
381 if (this->GetWidth() != pRhs->GetWidth())
390 _ImageMetadataImpl::GetHashCode(void) const
392 return (this->GetCameraManufacturer()).GetHashCode()
393 ^ (this->GetCameraModel()).GetHashCode()
394 ^ (this->GetDateTime()).GetHashCode()
395 ^ Integer::GetHashCode(this->GetHeight())
396 ^ Double::GetHashCode(this->GetLatitude())
397 ^ Double::GetHashCode(this->GetLongitude())
398 ^ Integer::GetHashCode(this->GetOrientation())
399 ^ (this->GetSoftware()).GetHashCode()
400 ^ (this->GetWhiteBalance()).GetHashCode()
401 ^ Integer::GetHashCode(this->GetWidth());
405 _ImageMetadataImpl::GetWidth(void) const
407 if (__pImageMeta == null)
409 SysLog(NID_CNT, "__pImageMeta is null.");
412 return __pImageMeta->width;
416 _ImageMetadataImpl::GetHeight(void) const
418 if (__pImageMeta == null)
420 SysLog(NID_CNT, "__pImageMeta is null.");
423 return __pImageMeta->height;
427 _ImageMetadataImpl::GetCameraManufacturer(void) const
429 if (__pImageMeta == null || __pImageMeta->pManufacturer == null)
431 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pManufacturer is null.");
434 return *(__pImageMeta->pManufacturer);
438 _ImageMetadataImpl::GetCameraModel(void) const
440 if (__pImageMeta == null || __pImageMeta->pModel == null)
442 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pModel is null.");
445 return *(__pImageMeta->pModel);
449 _ImageMetadataImpl::GetSoftware(void) const
451 if (__pImageMeta == null || __pImageMeta->pSoftware == null)
453 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pSoftware is null.");
456 return *(__pImageMeta->pSoftware);
460 _ImageMetadataImpl::GetDateTime(void) const
462 if (__pImageMeta == null || __pImageMeta->pDateTime == null)
464 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pDateTime is null.");
467 return *(__pImageMeta->pDateTime);
471 _ImageMetadataImpl::GetLatitude(void) const
473 if (__pImageMeta == null)
475 SysLog(NID_CNT, "__pImageMeta is null.");
476 return DEFAULT_COORDINATE;
478 return __pImageMeta->latitude;
482 _ImageMetadataImpl::GetLongitude(void) const
484 if (__pImageMeta == null)
486 SysLog(NID_CNT, "__pImageMeta is null.");
487 return DEFAULT_COORDINATE;
489 return __pImageMeta->longitude;
493 _ImageMetadataImpl::GetOrientation(void) const
495 if (__pImageMeta == null)
497 SysLog(NID_CNT, "__pImageMeta is null.");
498 return IMAGE_ORIENTATION_TYPE_UNKNOWN;
500 return __pImageMeta->orientation;
504 _ImageMetadataImpl::GetWhiteBalance(void) const
506 if (__pImageMeta == null || __pImageMeta->pWhiteBalance == null)
508 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pWhiteBalance is null.");
511 return *(__pImageMeta->pWhiteBalance);
520 _ImageMetadataImpl::GetThumbnailN(void) const
524 SysTryReturn(NID_CNT, __pImageMeta != null, null, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN failed.");
525 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(__pImageMeta->contentPath), null, E_DATA_NOT_FOUND,
526 "[E_DATA_NOT_FOUND] GetThumbnailN failed [%ls].", (__pImageMeta->contentPath).GetPointer());
529 result r = image.Construct();
530 SysTryReturn(NID_CNT, !IsFailed(r), null, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN failed.");
532 Bitmap* pBitmap = image.DecodeN(__pImageMeta->contentPath, BITMAP_PIXEL_FORMAT_ARGB8888, THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT);
537 if (r == E_OUT_OF_MEMORY)
539 SysLogException(NID_CNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetThumbnailN failed.");
543 SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN failed.");