2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 * @file FCnt_ImageMetadataImpl.cpp
18 * @brief This is the implementation file for the %_ImageMetadataImpl class.
20 * This file contains implementation of the %_ImageMetadataImpl class.
23 #include <FBaseSysLog.h>
24 #include <FMediaImage.h>
25 #include <FGrpBitmap.h>
26 #include <FCntImageMetadata.h>
27 #include <FCnt_ImageMetadataImpl.h>
28 #include <FIo_FileImpl.h>
29 #include <FMedia_ImageImpl.h>
32 using namespace Tizen::Base;
33 using namespace Tizen::Io;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Media;
37 namespace Tizen { namespace Content
40 static const int THUMBNAIL_IMAGE_WIDTH = 320;
41 static const int THUMBNAIL_IMAGE_HEIGHT = 240;
42 static const double DEFAULT_COORDINATE = -200.0;
44 _ImageMetadataImpl::_ImageMetadataImpl(void)
47 unique_ptr<ImageMeta, ImageMetaDeleter> pNewImageMeta(new (nothrow) ImageMeta());
48 if (pNewImageMeta != null)
50 __pImageMeta = move(pNewImageMeta);
55 SysLog(NID_CNT, "The memory is insufficient.");
59 _ImageMetadataImpl::~_ImageMetadataImpl(void)
65 _ImageMetadataImpl::GetInstance(ImageMetadata& imageMetadata)
67 return imageMetadata.__pImpl;
70 const _ImageMetadataImpl*
71 _ImageMetadataImpl::GetInstance(const ImageMetadata& imageMetadata)
73 return imageMetadata.__pImpl;
77 _ImageMetadataImpl::SetImageMetadata(const ImageMeta* pImageMeta)
81 SysTryReturnResult(NID_CNT, pImageMeta != null, E_INVALID_ARG, "pImageMeta is null.");
83 __pImageMeta->width = pImageMeta->width;
84 __pImageMeta->height = pImageMeta->height;
85 __pImageMeta->orientation = pImageMeta->orientation;
86 __pImageMeta->latitude = pImageMeta->latitude;
87 __pImageMeta->longitude = pImageMeta->longitude;
88 __pImageMeta->contentPath = pImageMeta->contentPath;
90 if (pImageMeta->pManufacturer != null)
92 __pImageMeta->pManufacturer = new (nothrow) String(*(pImageMeta->pManufacturer));
93 SysTryReturnResult(NID_CNT, __pImageMeta->pManufacturer != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
95 if (pImageMeta->pModel != null)
97 __pImageMeta->pModel = new (nothrow) String(*(pImageMeta->pModel));
98 SysTryReturnResult(NID_CNT, __pImageMeta->pModel != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
100 if (pImageMeta->pDateTime != null)
102 __pImageMeta->pDateTime = new (nothrow) String(*(pImageMeta->pDateTime));
103 SysTryReturnResult(NID_CNT, __pImageMeta->pDateTime != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
105 if (pImageMeta->pSoftware != null)
107 __pImageMeta->pSoftware = new (nothrow) String(*(pImageMeta->pSoftware));
108 SysTryReturnResult(NID_CNT, __pImageMeta->pSoftware != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
110 if (pImageMeta->pWhiteBalance != null)
112 __pImageMeta->pWhiteBalance = new (nothrow) String(*(pImageMeta->pWhiteBalance));
113 SysTryReturnResult(NID_CNT, __pImageMeta->pWhiteBalance != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
120 _ImageMetadataImpl::GetImageMetadata(void) const
122 return __pImageMeta.get();
125 _ImageMetadataImpl::_ImageMetadataImpl(const _ImageMetadataImpl& rhs)
128 unique_ptr<ImageMeta, ImageMetaDeleter> pNewImageMeta(new (nothrow) ImageMeta());
129 if (pNewImageMeta != null)
131 pNewImageMeta->width = (rhs.__pImageMeta)->width;
132 pNewImageMeta->height = (rhs.__pImageMeta)->height;
133 pNewImageMeta->orientation = (rhs.__pImageMeta)->orientation;
134 pNewImageMeta->latitude = (rhs.__pImageMeta)->latitude;
135 pNewImageMeta->longitude = (rhs.__pImageMeta)->longitude;
136 pNewImageMeta->contentPath = (rhs.__pImageMeta)->contentPath;
138 if ((rhs.__pImageMeta)->pManufacturer != null)
140 pNewImageMeta->pManufacturer = new (nothrow) String(*((rhs.__pImageMeta)->pManufacturer));
141 if (pNewImageMeta->pManufacturer == null)
143 SysLog(NID_CNT, "The memory is insufficient.");
147 if ((rhs.__pImageMeta)->pModel != null)
149 pNewImageMeta->pModel = new (nothrow) String(*((rhs.__pImageMeta)->pModel));
150 if (pNewImageMeta->pModel == null)
152 SysLog(NID_CNT, "The memory is insufficient.");
156 if ((rhs.__pImageMeta)->pDateTime != null)
158 pNewImageMeta->pDateTime = new (nothrow) String(*((rhs.__pImageMeta)->pDateTime));
159 if (pNewImageMeta->pDateTime == null)
161 SysLog(NID_CNT, "The memory is insufficient.");
165 if ((rhs.__pImageMeta)->pSoftware != null)
167 pNewImageMeta->pSoftware = new (nothrow) String(*((rhs.__pImageMeta)->pSoftware));
168 if (pNewImageMeta->pSoftware == null)
170 SysLog(NID_CNT, "The memory is insufficient.");
174 if ((rhs.__pImageMeta)->pWhiteBalance != null)
176 pNewImageMeta->pWhiteBalance = new (nothrow) String(*((rhs.__pImageMeta)->pWhiteBalance));
177 if (pNewImageMeta->pWhiteBalance == null)
179 SysLog(NID_CNT, "The memory is insufficient.");
184 __pImageMeta = move(pNewImageMeta);
189 SysLog(NID_CNT, "The memory is insufficient.");
194 _ImageMetadataImpl::operator =(const _ImageMetadataImpl& rhs)
196 // check for self-assignment
203 if (__pImageMeta != null && (rhs.__pImageMeta) != null)
205 // DeleteMetadata(__pImageMeta);
206 // __pImageMeta = new (nothrow) ImageMeta;
208 __pImageMeta.reset(new (nothrow) ImageMeta);
210 else if (__pImageMeta != null)
212 //DeleteMetadata(__pImageMeta);
214 __pImageMeta.reset(null);
217 else if ((rhs.__pImageMeta) != null)
219 //__pImageMeta = new (nothrow) ImageMeta;
221 __pImageMeta.reset(new (nothrow) ImageMeta);
225 // __pImageMeta and rhs.__pImageMeta are null.
229 __pImageMeta->width = (rhs.__pImageMeta)->width;
230 __pImageMeta->height = (rhs.__pImageMeta)->height;
231 __pImageMeta->orientation = (rhs.__pImageMeta)->orientation;
232 __pImageMeta->latitude = (rhs.__pImageMeta)->latitude;
233 __pImageMeta->longitude = (rhs.__pImageMeta)->longitude;
234 __pImageMeta->contentPath = (rhs.__pImageMeta)->contentPath;
237 if (__pImageMeta->pManufacturer != null && (rhs.__pImageMeta)->pManufacturer != null)
239 // delete previous data
240 delete __pImageMeta->pManufacturer;
241 __pImageMeta->pManufacturer = null;
243 __pImageMeta->pManufacturer = new (nothrow) String(*((rhs.__pImageMeta)->pManufacturer));
245 else if (__pImageMeta->pManufacturer != null)
247 delete __pImageMeta->pManufacturer;
248 __pImageMeta->pManufacturer = null;
250 else if ((rhs.__pImageMeta)->pManufacturer != null)
252 __pImageMeta->pManufacturer = new (nothrow) String(*((rhs.__pImageMeta)->pManufacturer));
256 if (__pImageMeta->pModel != null && (rhs.__pImageMeta)->pModel != null)
258 // delete previous data
259 delete __pImageMeta->pModel;
260 __pImageMeta->pModel = null;
262 __pImageMeta->pModel = new (nothrow) String(*((rhs.__pImageMeta)->pModel));
264 else if (__pImageMeta->pModel != null)
266 delete __pImageMeta->pModel;
267 __pImageMeta->pModel = null;
269 else if ((rhs.__pImageMeta)->pModel != null)
271 __pImageMeta->pModel = new (nothrow) String(*((rhs.__pImageMeta)->pModel));
275 if (__pImageMeta->pDateTime != null && (rhs.__pImageMeta)->pDateTime != null)
277 // delete previous data
278 delete __pImageMeta->pDateTime;
279 __pImageMeta->pDateTime = null;
281 __pImageMeta->pDateTime = new (nothrow) String(*((rhs.__pImageMeta)->pDateTime));
283 else if (__pImageMeta->pDateTime != null)
285 delete __pImageMeta->pDateTime;
286 __pImageMeta->pDateTime = null;
288 else if ((rhs.__pImageMeta)->pDateTime != null)
290 __pImageMeta->pDateTime = new (nothrow) String(*((rhs.__pImageMeta)->pDateTime));
294 if (__pImageMeta->pSoftware != null && (rhs.__pImageMeta)->pSoftware != null)
296 // delete previous data
297 delete __pImageMeta->pSoftware;
298 __pImageMeta->pSoftware = null;
300 __pImageMeta->pSoftware = new (nothrow) String(*((rhs.__pImageMeta)->pSoftware));
302 else if (__pImageMeta->pSoftware != null)
304 delete __pImageMeta->pSoftware;
305 __pImageMeta->pSoftware = null;
307 else if ((rhs.__pImageMeta)->pSoftware != null)
309 __pImageMeta->pSoftware = new (nothrow) String(*((rhs.__pImageMeta)->pSoftware));
313 if (__pImageMeta->pWhiteBalance != null && (rhs.__pImageMeta)->pWhiteBalance != null)
315 // delete previous data
316 delete __pImageMeta->pWhiteBalance;
317 __pImageMeta->pWhiteBalance = null;
319 __pImageMeta->pWhiteBalance = new (nothrow) String(*((rhs.__pImageMeta)->pWhiteBalance));
321 else if (__pImageMeta->pWhiteBalance != null)
323 delete __pImageMeta->pWhiteBalance;
324 __pImageMeta->pWhiteBalance = null;
326 else if ((rhs.__pImageMeta)->pWhiteBalance != null)
328 __pImageMeta->pWhiteBalance = new (nothrow) String(*((rhs.__pImageMeta)->pWhiteBalance));
331 SysLog(NID_CNT, "_ImageMetadataImpl::operator =(const _ImageMetadataImpl& rhs) is called.");
336 _ImageMetadataImpl::Equals(const Tizen::Base::Object& rhs) const
338 const _ImageMetadataImpl* pRhs = dynamic_cast <const _ImageMetadataImpl*>(&rhs);
344 if (!((this->GetCameraManufacturer()).Equals(pRhs->GetCameraManufacturer())))
348 if (!((this->GetCameraModel()).Equals(pRhs->GetCameraModel())))
352 if (!((this->GetDateTime()).Equals(pRhs->GetDateTime())))
356 if (this->GetHeight() != pRhs->GetHeight())
360 if (Double::Compare(this->GetLatitude(), pRhs->GetLatitude()) != 0)
364 if (Double::Compare(this->GetLongitude(), pRhs->GetLongitude()) != 0)
368 if (this->GetOrientation() != pRhs->GetOrientation())
372 if (!((this->GetSoftware()).Equals(pRhs->GetSoftware())))
376 if (!((this->GetWhiteBalance()).Equals(pRhs->GetWhiteBalance())))
380 if (this->GetWidth() != pRhs->GetWidth())
389 _ImageMetadataImpl::GetHashCode(void) const
391 return (this->GetCameraManufacturer()).GetHashCode()
392 ^ (this->GetCameraModel()).GetHashCode()
393 ^ (this->GetDateTime()).GetHashCode()
394 ^ Integer::GetHashCode(this->GetHeight())
395 ^ Double::GetHashCode(this->GetLatitude())
396 ^ Double::GetHashCode(this->GetLongitude())
397 ^ Integer::GetHashCode(this->GetOrientation())
398 ^ (this->GetSoftware()).GetHashCode()
399 ^ (this->GetWhiteBalance()).GetHashCode()
400 ^ Integer::GetHashCode(this->GetWidth());
404 _ImageMetadataImpl::GetWidth(void) const
406 if (__pImageMeta == null)
408 SysLog(NID_CNT, "__pImageMeta is null.");
411 return __pImageMeta->width;
415 _ImageMetadataImpl::GetHeight(void) const
417 if (__pImageMeta == null)
419 SysLog(NID_CNT, "__pImageMeta is null.");
422 return __pImageMeta->height;
426 _ImageMetadataImpl::GetCameraManufacturer(void) const
428 if (__pImageMeta == null || __pImageMeta->pManufacturer == null)
430 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pManufacturer is null.");
433 return *(__pImageMeta->pManufacturer);
437 _ImageMetadataImpl::GetCameraModel(void) const
439 if (__pImageMeta == null || __pImageMeta->pModel == null)
441 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pModel is null.");
444 return *(__pImageMeta->pModel);
448 _ImageMetadataImpl::GetSoftware(void) const
450 if (__pImageMeta == null || __pImageMeta->pSoftware == null)
452 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pSoftware is null.");
455 return *(__pImageMeta->pSoftware);
459 _ImageMetadataImpl::GetDateTime(void) const
461 if (__pImageMeta == null || __pImageMeta->pDateTime == null)
463 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pDateTime is null.");
466 return *(__pImageMeta->pDateTime);
470 _ImageMetadataImpl::GetLatitude(void) const
472 if (__pImageMeta == null)
474 SysLog(NID_CNT, "__pImageMeta is null.");
475 return DEFAULT_COORDINATE;
477 return __pImageMeta->latitude;
481 _ImageMetadataImpl::GetLongitude(void) const
483 if (__pImageMeta == null)
485 SysLog(NID_CNT, "__pImageMeta is null.");
486 return DEFAULT_COORDINATE;
488 return __pImageMeta->longitude;
492 _ImageMetadataImpl::GetOrientation(void) const
494 if (__pImageMeta == null)
496 SysLog(NID_CNT, "__pImageMeta is null.");
497 return IMAGE_ORIENTATION_TYPE_UNKNOWN;
499 return __pImageMeta->orientation;
503 _ImageMetadataImpl::GetWhiteBalance(void) const
505 if (__pImageMeta == null || __pImageMeta->pWhiteBalance == null)
507 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pWhiteBalance is null.");
510 return *(__pImageMeta->pWhiteBalance);
519 _ImageMetadataImpl::GetThumbnailN(void) const
523 SysTryReturn(NID_CNT, __pImageMeta != null, null, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN failed.");
524 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(__pImageMeta->contentPath), null, E_DATA_NOT_FOUND,
525 "[E_DATA_NOT_FOUND] GetThumbnailN from contentPath failed.");
528 result r = image.Construct();
529 SysTryReturn(NID_CNT, !IsFailed(r), null, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN failed.");
531 Bitmap* pBitmap = image.DecodeN(__pImageMeta->contentPath, BITMAP_PIXEL_FORMAT_ARGB8888, THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT);
536 if (r == E_OUT_OF_MEMORY)
538 SysLogException(NID_CNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetThumbnailN failed.");
542 SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN failed.");