[content] Remove Open Service Platform words
[platform/framework/native/content.git] / src / FCnt_ImageMetadataImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16 /**
17  * @file                FCnt_ImageMetadataImpl.cpp
18  * @brief               This is the implementation file for the %_ImageMetadataImpl class.
19  *
20  * This file contains implementation of the %_ImageMetadataImpl class.
21  */
22
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>
30
31 using namespace std;
32 using namespace Tizen::Base;
33 using namespace Tizen::Io;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Media;
36
37 namespace Tizen { namespace Content
38 {
39
40 static const int THUMBNAIL_IMAGE_WIDTH = 320;
41 static const int THUMBNAIL_IMAGE_HEIGHT = 240;
42 static const double DEFAULT_COORDINATE = -200.0;
43
44 _ImageMetadataImpl::_ImageMetadataImpl(void)
45         : Object()
46 {
47         unique_ptr<ImageMeta, ImageMetaDeleter> pNewImageMeta(new (nothrow) ImageMeta());
48         if (pNewImageMeta != null)
49         {
50                 __pImageMeta = move(pNewImageMeta);
51         }
52         else
53         {
54                 __pImageMeta = null;
55                 SysLog(NID_CNT, "The memory is insufficient.");
56         }
57 }
58
59 _ImageMetadataImpl::~_ImageMetadataImpl(void)
60 {
61
62 }
63
64 _ImageMetadataImpl*
65 _ImageMetadataImpl::GetInstance(ImageMetadata& imageMetadata)
66 {
67         return imageMetadata.__pImpl;
68 }
69
70 const _ImageMetadataImpl*
71 _ImageMetadataImpl::GetInstance(const ImageMetadata& imageMetadata)
72 {
73         return imageMetadata.__pImpl;
74 }
75
76 result
77 _ImageMetadataImpl::SetImageMetadata(const ImageMeta* pImageMeta)
78 {
79         ClearLastResult();
80
81         SysTryReturnResult(NID_CNT, pImageMeta != null, E_INVALID_ARG, "pImageMeta is null.");
82
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;
89
90         if (pImageMeta->pManufacturer != null)
91         {
92                 __pImageMeta->pManufacturer = new (nothrow) String(*(pImageMeta->pManufacturer));
93                 SysTryReturnResult(NID_CNT, __pImageMeta->pManufacturer != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
94         }
95         if (pImageMeta->pModel != null)
96         {
97                 __pImageMeta->pModel = new (nothrow) String(*(pImageMeta->pModel));
98                 SysTryReturnResult(NID_CNT, __pImageMeta->pModel != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
99         }
100         if (pImageMeta->pDateTime != null)
101         {
102                 __pImageMeta->pDateTime = new (nothrow) String(*(pImageMeta->pDateTime));
103                 SysTryReturnResult(NID_CNT, __pImageMeta->pDateTime != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
104         }
105         if (pImageMeta->pSoftware != null)
106         {
107                 __pImageMeta->pSoftware = new (nothrow) String(*(pImageMeta->pSoftware));
108                 SysTryReturnResult(NID_CNT, __pImageMeta->pSoftware != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
109         }
110         if (pImageMeta->pWhiteBalance != null)
111         {
112                 __pImageMeta->pWhiteBalance = new (nothrow) String(*(pImageMeta->pWhiteBalance));
113                 SysTryReturnResult(NID_CNT, __pImageMeta->pWhiteBalance != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
114         }
115
116         return E_SUCCESS;
117 }
118
119 ImageMeta*
120 _ImageMetadataImpl::GetImageMetadata(void) const
121 {
122         return __pImageMeta.get();
123 }
124
125 _ImageMetadataImpl::_ImageMetadataImpl(const _ImageMetadataImpl& rhs)
126         : Object()
127 {
128         unique_ptr<ImageMeta, ImageMetaDeleter> pNewImageMeta(new (nothrow) ImageMeta());
129         if (pNewImageMeta != null)
130         {
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;
137
138                 if ((rhs.__pImageMeta)->pManufacturer != null)
139                 {
140                         pNewImageMeta->pManufacturer = new (nothrow) String(*((rhs.__pImageMeta)->pManufacturer));
141                         if (pNewImageMeta->pManufacturer == null)
142                         {
143                                 SysLog(NID_CNT, "The memory is insufficient.");
144                                 return;
145                         }
146                 }
147                 if ((rhs.__pImageMeta)->pModel != null)
148                 {
149                         pNewImageMeta->pModel = new (nothrow) String(*((rhs.__pImageMeta)->pModel));
150                         if (pNewImageMeta->pModel == null)
151                         {
152                                 SysLog(NID_CNT, "The memory is insufficient.");
153                                 return;
154                         }
155                 }
156                 if ((rhs.__pImageMeta)->pDateTime != null)
157                 {
158                         pNewImageMeta->pDateTime = new (nothrow) String(*((rhs.__pImageMeta)->pDateTime));
159                         if (pNewImageMeta->pDateTime == null)
160                         {
161                                 SysLog(NID_CNT, "The memory is insufficient.");
162                                 return;
163                         }
164                 }
165                 if ((rhs.__pImageMeta)->pSoftware != null)
166                 {
167                         pNewImageMeta->pSoftware = new (nothrow) String(*((rhs.__pImageMeta)->pSoftware));
168                         if (pNewImageMeta->pSoftware == null)
169                         {
170                                 SysLog(NID_CNT, "The memory is insufficient.");
171                                 return;
172                         }
173                 }
174                 if ((rhs.__pImageMeta)->pWhiteBalance != null)
175                 {
176                         pNewImageMeta->pWhiteBalance = new (nothrow) String(*((rhs.__pImageMeta)->pWhiteBalance));
177                         if (pNewImageMeta->pWhiteBalance == null)
178                         {
179                                 SysLog(NID_CNT, "The memory is insufficient.");
180                                 return;
181                         }
182                 }
183
184                 __pImageMeta = move(pNewImageMeta);
185         }
186         else
187         {
188                 __pImageMeta = null;
189                 SysLog(NID_CNT, "The memory is insufficient.");
190         }
191 }
192
193 _ImageMetadataImpl&
194 _ImageMetadataImpl::operator =(const _ImageMetadataImpl& rhs)
195 {
196         // check for self-assignment
197         if (this == &rhs)
198         {
199                 return *this;
200         }
201
202         // __pImageMeta
203         if (__pImageMeta != null && (rhs.__pImageMeta) != null)
204         {
205                 // DeleteMetadata(__pImageMeta);
206                 // __pImageMeta = new (nothrow) ImageMeta;
207
208                 __pImageMeta.reset(new (nothrow) ImageMeta);
209         }
210         else if (__pImageMeta != null)
211         {
212                 //DeleteMetadata(__pImageMeta);
213
214                 __pImageMeta.reset(null);
215                 return *this;
216         }
217         else if ((rhs.__pImageMeta) != null)
218         {
219                 //__pImageMeta = new (nothrow) ImageMeta;
220
221                 __pImageMeta.reset(new (nothrow) ImageMeta);
222         }
223         else
224         {
225                 // __pImageMeta and rhs.__pImageMeta are null.
226                 return *this;
227         }
228
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;
235
236         // pManufacturer
237         if (__pImageMeta->pManufacturer != null && (rhs.__pImageMeta)->pManufacturer != null)
238         {
239                 // delete previous data
240                 delete __pImageMeta->pManufacturer;
241                 __pImageMeta->pManufacturer = null;
242
243                 __pImageMeta->pManufacturer = new (nothrow) String(*((rhs.__pImageMeta)->pManufacturer));
244         }
245         else if (__pImageMeta->pManufacturer != null)
246         {
247                 delete __pImageMeta->pManufacturer;
248                 __pImageMeta->pManufacturer = null;
249         }
250         else if ((rhs.__pImageMeta)->pManufacturer != null)
251         {
252                 __pImageMeta->pManufacturer = new (nothrow) String(*((rhs.__pImageMeta)->pManufacturer));
253         }
254
255         // pModel
256         if (__pImageMeta->pModel != null && (rhs.__pImageMeta)->pModel != null)
257         {
258                 // delete previous data
259                 delete __pImageMeta->pModel;
260                 __pImageMeta->pModel = null;
261
262                 __pImageMeta->pModel = new (nothrow) String(*((rhs.__pImageMeta)->pModel));
263         }
264         else if (__pImageMeta->pModel != null)
265         {
266                 delete __pImageMeta->pModel;
267                 __pImageMeta->pModel = null;
268         }
269         else if ((rhs.__pImageMeta)->pModel != null)
270         {
271                 __pImageMeta->pModel = new (nothrow) String(*((rhs.__pImageMeta)->pModel));
272         }
273
274         // pDateTime
275         if (__pImageMeta->pDateTime != null && (rhs.__pImageMeta)->pDateTime != null)
276         {
277                 // delete previous data
278                 delete __pImageMeta->pDateTime;
279                 __pImageMeta->pDateTime = null;
280
281                 __pImageMeta->pDateTime = new (nothrow) String(*((rhs.__pImageMeta)->pDateTime));
282         }
283         else if (__pImageMeta->pDateTime != null)
284         {
285                 delete __pImageMeta->pDateTime;
286                 __pImageMeta->pDateTime = null;
287         }
288         else if ((rhs.__pImageMeta)->pDateTime != null)
289         {
290                 __pImageMeta->pDateTime = new (nothrow) String(*((rhs.__pImageMeta)->pDateTime));
291         }
292
293         // pSoftware
294         if (__pImageMeta->pSoftware != null && (rhs.__pImageMeta)->pSoftware != null)
295         {
296                 // delete previous data
297                 delete __pImageMeta->pSoftware;
298                 __pImageMeta->pSoftware = null;
299
300                 __pImageMeta->pSoftware = new (nothrow) String(*((rhs.__pImageMeta)->pSoftware));
301         }
302         else if (__pImageMeta->pSoftware != null)
303         {
304                 delete __pImageMeta->pSoftware;
305                 __pImageMeta->pSoftware = null;
306         }
307         else if ((rhs.__pImageMeta)->pSoftware != null)
308         {
309                 __pImageMeta->pSoftware = new (nothrow) String(*((rhs.__pImageMeta)->pSoftware));
310         }
311
312         // pWhiteBalance
313         if (__pImageMeta->pWhiteBalance != null && (rhs.__pImageMeta)->pWhiteBalance != null)
314         {
315                 // delete previous data
316                 delete __pImageMeta->pWhiteBalance;
317                 __pImageMeta->pWhiteBalance = null;
318
319                 __pImageMeta->pWhiteBalance = new (nothrow) String(*((rhs.__pImageMeta)->pWhiteBalance));
320         }
321         else if (__pImageMeta->pWhiteBalance != null)
322         {
323                 delete __pImageMeta->pWhiteBalance;
324                 __pImageMeta->pWhiteBalance = null;
325         }
326         else if ((rhs.__pImageMeta)->pWhiteBalance != null)
327         {
328                 __pImageMeta->pWhiteBalance = new (nothrow) String(*((rhs.__pImageMeta)->pWhiteBalance));
329         }
330
331         SysLog(NID_CNT, "_ImageMetadataImpl::operator =(const _ImageMetadataImpl& rhs) is called.");
332         return *this;
333 }
334
335 bool
336 _ImageMetadataImpl::Equals(const Tizen::Base::Object& rhs) const
337 {
338         const _ImageMetadataImpl* pRhs = dynamic_cast <const _ImageMetadataImpl*>(&rhs);
339         if (pRhs == null)
340         {
341                 return false;
342         }
343
344         if (!((this->GetCameraManufacturer()).Equals(pRhs->GetCameraManufacturer())))
345         {
346                 return false;
347         }
348         if (!((this->GetCameraModel()).Equals(pRhs->GetCameraModel())))
349         {
350                 return false;
351         }
352         if (!((this->GetDateTime()).Equals(pRhs->GetDateTime())))
353         {
354                 return false;
355         }
356         if (this->GetHeight() != pRhs->GetHeight())
357         {
358                 return false;
359         }
360         if (Double::Compare(this->GetLatitude(), pRhs->GetLatitude()) != 0)
361         {
362                 return false;
363         }
364         if (Double::Compare(this->GetLongitude(), pRhs->GetLongitude()) != 0)
365         {
366                 return false;
367         }
368         if (this->GetOrientation() != pRhs->GetOrientation())
369         {
370                 return false;
371         }
372         if (!((this->GetSoftware()).Equals(pRhs->GetSoftware())))
373         {
374                 return false;
375         }
376         if (!((this->GetWhiteBalance()).Equals(pRhs->GetWhiteBalance())))
377         {
378                 return false;
379         }
380         if (this->GetWidth() != pRhs->GetWidth())
381         {
382                 return false;
383         }
384
385         return true;
386 }
387
388 int
389 _ImageMetadataImpl::GetHashCode(void) const
390 {
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());
401 }
402
403 int
404 _ImageMetadataImpl::GetWidth(void) const
405 {
406         if (__pImageMeta == null)
407         {
408                 SysLog(NID_CNT, "__pImageMeta is null.");
409                 return 0;
410         }
411         return __pImageMeta->width;
412 }
413
414 int
415 _ImageMetadataImpl::GetHeight(void) const
416 {
417         if (__pImageMeta == null)
418         {
419                 SysLog(NID_CNT, "__pImageMeta is null.");
420                 return 0;
421         }
422         return __pImageMeta->height;
423 }
424
425 String
426 _ImageMetadataImpl::GetCameraManufacturer(void) const
427 {
428         if (__pImageMeta == null || __pImageMeta->pManufacturer == null)
429         {
430                 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pManufacturer is null.");
431                 return String();
432         }
433         return *(__pImageMeta->pManufacturer);
434 }
435
436 String
437 _ImageMetadataImpl::GetCameraModel(void) const
438 {
439         if (__pImageMeta == null || __pImageMeta->pModel == null)
440         {
441                 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pModel is null.");
442                 return String();
443         }
444         return *(__pImageMeta->pModel);
445 }
446
447 String
448 _ImageMetadataImpl::GetSoftware(void) const
449 {
450         if (__pImageMeta == null || __pImageMeta->pSoftware == null)
451         {
452                 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pSoftware is null.");
453                 return String();
454         }
455         return *(__pImageMeta->pSoftware);
456 }
457
458 String
459 _ImageMetadataImpl::GetDateTime(void) const
460 {
461         if (__pImageMeta == null || __pImageMeta->pDateTime == null)
462         {
463                 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pDateTime is null.");
464                 return String();
465         }
466         return *(__pImageMeta->pDateTime);
467 }
468
469 double
470 _ImageMetadataImpl::GetLatitude(void) const
471 {
472         if (__pImageMeta == null)
473         {
474                 SysLog(NID_CNT, "__pImageMeta is null.");
475                 return DEFAULT_COORDINATE;
476         }
477         return __pImageMeta->latitude;
478 }
479
480 double
481 _ImageMetadataImpl::GetLongitude(void) const
482 {
483         if (__pImageMeta == null)
484         {
485                 SysLog(NID_CNT, "__pImageMeta is null.");
486                 return DEFAULT_COORDINATE;
487         }
488         return __pImageMeta->longitude;
489 }
490
491 ImageOrientationType
492 _ImageMetadataImpl::GetOrientation(void) const
493 {
494         if (__pImageMeta == null)
495         {
496                 SysLog(NID_CNT, "__pImageMeta is null.");
497                 return IMAGE_ORIENTATION_TYPE_UNKNOWN;
498         }
499         return __pImageMeta->orientation;
500 }
501
502 String
503 _ImageMetadataImpl::GetWhiteBalance(void) const
504 {
505         if (__pImageMeta == null || __pImageMeta->pWhiteBalance == null)
506         {
507                 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pWhiteBalance is null.");
508                 return String();
509         }
510         return *(__pImageMeta->pWhiteBalance);
511 }
512
513 //
514 // E_SUCCESS
515 // E_DATA_NOT_FOUND
516 // E_OUT_OF_MEMORY
517 //
518 Bitmap*
519 _ImageMetadataImpl::GetThumbnailN(void) const
520 {
521         ClearLastResult();
522
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.");
526
527         Image image;
528         result r = image.Construct();
529         SysTryReturn(NID_CNT, !IsFailed(r), null, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN failed.");
530
531         Bitmap* pBitmap = image.DecodeN(__pImageMeta->contentPath, BITMAP_PIXEL_FORMAT_ARGB8888, THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT);
532         if (pBitmap == null)
533         {
534                 r = GetLastResult();
535
536                 if (r == E_OUT_OF_MEMORY)
537                 {
538                         SysLogException(NID_CNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetThumbnailN failed.");
539                 }
540                 else
541                 {
542                         SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN failed.");
543                 }
544
545                 return null;
546         }
547
548         return pBitmap;
549 }
550 }}