NABI_Se issue fixes
[apps/osp/MyFiles.git] / src / MfThumbnailManager.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 /**
18  * @file: ThumbnailManager.cpp
19  * @brief: This file contains the implementation of ThumbnailManager class,
20  * which manages creation of Thumbnails for each folder entry.
21  */
22
23 #include <FApp.h>
24 #include <FBase.h>
25 #include <FContent.h>
26 #include <FGraphics.h>
27 #include <FMedia.h>
28
29 #include "MfThumbnailManager.h"
30 #include "MfUtility.h"
31 #include "MfMyFilesApp.h"
32
33 using namespace Tizen::App;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Graphics;
36
37 static ThumbnailManager* thumbnailManager = null;
38
39 #if 0
40 static const wchar_t* IDB_VIDEO_PLAY_THUMB_BIG = L"U01_thumbnail_icon_video.png";
41 #endif
42
43 using namespace     Tizen::App;
44 using namespace     Tizen::Base;
45 using namespace     Tizen::Base::Collection;
46 using namespace     Tizen::Base::Runtime;
47 using namespace     Tizen::Content;
48 using namespace     Tizen::Graphics;
49 using namespace     Tizen::Media;
50
51 ThumbnailManager*
52 ThumbnailManager::GetInstance(void)
53 {
54         if (thumbnailManager == null)
55         {
56                 CreateInstance();
57         }
58         return thumbnailManager;
59 }
60
61 void
62 ThumbnailManager::CreateInstance(void)
63 {
64         result r = E_SUCCESS;
65
66         thumbnailManager = new (std::nothrow) ThumbnailManager();
67         r = thumbnailManager->Construct();
68
69
70         if (r != E_SUCCESS)
71         {
72                 DeleteInstance();
73                 return;
74         }
75
76         std::atexit(DeleteInstance);
77 }
78
79 void
80 ThumbnailManager::DeleteInstance(void)
81 {
82         if (thumbnailManager != null)
83         {
84                 /*thumbnailManager->Stop();
85                 thumbnailManager->Join();*/
86
87                 delete thumbnailManager;
88                 thumbnailManager = null;
89         }
90 }
91 result
92 ThumbnailManager::Construct(void)
93 {
94         result r = E_FAILURE;
95         r = Thread::Construct(THREAD_TYPE_EVENT_DRIVEN);
96
97         AppResource* pAppResource = null;
98         pAppResource = Application::GetInstance()->GetAppResource();
99
100         __pDummyImage = pAppResource->GetBitmapN(IDB_DUMMY_IMG, BITMAP_PIXEL_FORMAT_ARGB8888);
101
102         r = Start();
103         return r;
104 }
105
106 ThumbnailManager::ThumbnailManager(void)
107         : __pCurrentThumbReq(null)
108         , __pDummyImage(null)
109 {
110         //Empty Implementation.
111 }
112
113 ThumbnailManager::~ThumbnailManager(void)
114 {
115         ClearCurrentThumbRequest();
116         delete __pDummyImage;
117 }
118
119 ThumbnailManager::ThumbnailManager(const ThumbnailManager& thumbnailManager)
120 {
121         __pCurrentThumbReq = null;
122 }
123
124 ThumbnailManager&
125 ThumbnailManager::operator =(const ThumbnailManager& thumbnailManager)
126 {
127         if (this != &thumbnailManager)
128         {
129                 __pCurrentThumbReq = thumbnailManager.__pCurrentThumbReq;
130         }
131         return *this;
132
133 }
134
135 ThumbMgrResultValues
136 ThumbnailManager::GetThumbnail(ThumbRequest* pRequest)
137 {
138         result r = E_SUCCESS;
139         ThumbMgrResultValues thumbMgrRes = THUMB_MGR_RES_SUCCESS;
140
141         AppResource* pAppResource = null;
142
143         Bitmap* pTempBitmap = null;
144         Bitmap* pBitmapToMerge = null;
145         Bitmap* pMergedThumbnail = null;
146
147         ImageBuffer* pVideoFrameBuff = null;
148         ImageBuffer*            pRotatedImgBuff = null;
149
150         Tizen::Content::ImageMetadata*          pImageMeta = null;
151         VideoFrameExtractor extractor;
152         RecordingRotation videoRecordingRotation;
153         Bitmap*         pTmpBmp = null;
154
155         ImageBuffer* pRotatedImgBuffer = null;
156
157         ImageBuffer ImgBuffer;
158         int height, width;
159         ImageFormat imgFormat;
160         ExifOrientation imgOrientation;
161
162
163         bool GenerateThumbnail = false;
164         bool IsVideoFile = false;
165
166
167         TryCatch((pRequest != null) && (pRequest->iRquestId > -1) && (pRequest->FilePath.IsEmpty() == false), thumbMgrRes = THUMB_MGR_RES_FAILED, "ThumbRequest is NULL, Thumbnail genrataion failed!");
168
169         pAppResource = Application::GetInstance()->GetAppResource();
170         pBitmapToMerge = pAppResource->GetBitmapN(IDB_VIDEO_PLAY_SMALL, BITMAP_PIXEL_FORMAT_ARGB8888);
171         if (pBitmapToMerge != null)
172         {
173                 pBitmapToMerge->Scale(Dimension(ID_THUMBNAIL_WIDH, ID_THUMBNAIL_HEIGHT));
174         }
175
176         //Generate thumbnail
177         pTempBitmap = MakeBitmapN(pRequest->FilePath, GenerateThumbnail, IsVideoFile);
178         if (GenerateThumbnail)
179         {
180                 if (IsVideoFile)
181                 {
182                         r = extractor.Construct(pRequest->FilePath, MEDIA_PIXEL_FORMAT_BGRA8888);
183
184                         // Extracts video frames from the video file
185                         if (!IsFailed(r))
186                         {
187                                 pVideoFrameBuff = extractor.GetFrameN(0);
188                                 if  ( pVideoFrameBuff !=null)
189                                 {
190                                         videoRecordingRotation = extractor.GetRecordingRotation();
191                                         if ( videoRecordingRotation == RECORDING_ROTATION_90 )
192                                                 pRotatedImgBuff = pVideoFrameBuff->RotateN(IMAGE_ROTATION_90);
193                                         else if ( videoRecordingRotation == RECORDING_ROTATION_180 )
194                                                 pRotatedImgBuff = pVideoFrameBuff->RotateN(IMAGE_ROTATION_180);
195                                         else if ( videoRecordingRotation == RECORDING_ROTATION_270 )
196                                                 pRotatedImgBuff = pVideoFrameBuff->RotateN(IMAGE_ROTATION_270);
197                                         else
198                                                 pRotatedImgBuff = extractor.GetFrameN(0);
199
200                                         if ( pRotatedImgBuff !=null )
201                                                 pRequest->pBitmap = pRotatedImgBuff->GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
202                                         else
203                                                 pRequest->pBitmap = pVideoFrameBuff->GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
204
205                                         TryCatch(pRequest->pBitmap != null, r = E_OUT_OF_MEMORY, "FRAMEEXTRACTOR : failed to allocate memory to pTempBitmap");
206
207                                         if (pVideoFrameBuff)
208                                         {
209                                                 delete pVideoFrameBuff;
210                                                 pVideoFrameBuff = null;
211                                         }
212
213                                         if (pRotatedImgBuff != null)
214                                         {
215                                                 delete pRotatedImgBuff;
216                                                 pRotatedImgBuff = null;
217                                         }
218                                 }
219                         }
220                         if( pRequest->pBitmap==null)
221                         {
222                                 pRequest->pBitmap = new (std::nothrow) Bitmap();
223                                 if (__pDummyImage)
224                                         r = pRequest->pBitmap->Construct(*__pDummyImage, Rectangle(0, 0, __pDummyImage->GetWidth(), __pDummyImage->GetHeight()));
225                         }
226
227                         if (pBitmapToMerge)
228                         {
229                                 pMergedThumbnail = MfUtility::MergeBitmapN(pRequest->pBitmap, pBitmapToMerge, ID_THUMBNAIL_WIDH, ID_THUMBNAIL_HEIGHT);
230                                 if (pMergedThumbnail != null)
231                                 {
232                                         pRequest->pBitmap = pMergedThumbnail;
233                                         AppLogDebug("Bitmap Merging Completed Successfully: [%s]", GetErrorMessage(GetLastResult()));
234                                 }
235                                 pBitmapToMerge = null;
236                         }
237                         if (pTempBitmap)
238                         {
239                                 delete pTempBitmap;
240                                 pTempBitmap = null;
241                         }
242
243                         AppLogDebug("VideoThumbnail:STOP");
244                         thumbMgrRes = THUMB_MGR_RES_SUCCESS;
245                 }
246                 else
247                 {
248                         pImageMeta = ContentManagerUtil::GetImageMetaN(pRequest->FilePath);
249                         if (pImageMeta)
250                         {
251                                 pTmpBmp = pImageMeta->GetThumbnailN();
252                                 if (pTmpBmp)
253                                 {
254                                         ImageBuffer::GetImageInfo(pRequest->FilePath, imgFormat, width, height);
255                                         r = ImgBuffer.Construct(pRequest->FilePath,width, height, IMAGE_SCALING_METHOD_FAST_BILINEAR );
256                                         TryCatch(r == E_SUCCESS, , "ImageBuffer::Construct failed");
257
258                                         imgOrientation = ImgBuffer.GetExifOrientation();
259                                         TryCatch(GetLastResult() == E_SUCCESS, , "ImageBuffer::GetExifOrientation failed");
260
261                                         if (imgOrientation == EXIF_ORIENTATION_RIGHT_TOP ||
262                                                         imgOrientation == EXIF_ORIENTATION_TOP_RIGHT )
263                                         {
264                                                 pRotatedImgBuffer = ImgBuffer.RotateN(IMAGE_ROTATION_90);
265                                         }
266                                         else if (imgOrientation == EXIF_ORIENTATION_RIGHT_BOTTOM ||
267                                                         imgOrientation == EXIF_ORIENTATION_BOTTOM_RIGHT)
268                                         {
269                                                 pRotatedImgBuffer = ImgBuffer.RotateN(IMAGE_ROTATION_180);
270                                         }
271                                         else if (imgOrientation == EXIF_ORIENTATION_LEFT_BOTTOM ||
272                                                         imgOrientation  == EXIF_ORIENTATION_BOTTOM_LEFT)
273                                         {
274                                                 pRotatedImgBuffer = ImgBuffer.RotateN(IMAGE_ROTATION_270);
275                                         }
276
277                                         if ( pRotatedImgBuffer !=null )
278                                         {
279                                                 pRequest->pBitmap  = pRotatedImgBuffer->GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
280                                         }
281                                         else
282                                         {
283                                                 pRequest->pBitmap  = pTmpBmp;                   //ImgBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
284                                         }
285
286                                         if( pRequest->pBitmap == null )
287                                                 pRequest->pBitmap = pTmpBmp;
288
289                                         if ( pRotatedImgBuffer!=null )
290                                         {
291                                                 delete pRotatedImgBuffer;
292                                                 pRotatedImgBuffer = null;
293                                         }
294                                         AppLogDebug("Image Orientation [%d]", pImageMeta->GetOrientation() );
295
296                                 }
297                                 else
298                                 {
299                                         r = ImgBuffer.Construct(pRequest->FilePath,THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, IMAGE_SCALING_METHOD_FAST_BILINEAR );
300                                         TryCatch(r == E_SUCCESS, , "ImageBuffer::Construct failed");
301                                         pRequest->pBitmap = ImgBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
302
303                                 }
304
305                                 thumbMgrRes = THUMB_MGR_RES_SUCCESS;
306                         }
307                         else
308                         {
309                                 TryCatch(pTempBitmap != null, thumbMgrRes = THUMB_MGR_RES_FAILED, "Thumbnail generation failed");
310                                 thumbMgrRes = THUMB_MGR_RES_SUCCESS;
311                                 pRequest->pBitmap = pTempBitmap;
312                         }
313
314                         if ( pImageMeta != null )
315                                 delete pImageMeta;
316                 }
317         }
318         else
319         {
320                 TryCatch(pTempBitmap != null, thumbMgrRes = THUMB_MGR_RES_FAILED, "Thumbnail generation failed");
321                 thumbMgrRes = THUMB_MGR_RES_SUCCESS;
322                 pRequest->pBitmap = pTempBitmap;
323         }
324
325         if (pBitmapToMerge != null)
326         {
327                 delete pBitmapToMerge;
328                 pBitmapToMerge = null;
329         }
330
331         AppLogDebug("Exit [%s]:", GetErrorMessage(r));
332         return thumbMgrRes;
333
334 CATCH:
335
336         AppLogDebug("Exit Error Message[%s]:", GetErrorMessage(r));
337
338         if (pRequest != null)
339         {
340                 pRequest->pBitmap = null;
341         }
342
343         if (pTempBitmap != null)
344                 delete pTempBitmap;
345         
346         if (pMergedThumbnail)
347                 delete pMergedThumbnail;
348         
349         if ( pImageMeta != null )
350                 delete pImageMeta;
351
352         return thumbMgrRes;
353 }
354
355
356 Bitmap*
357 ThumbnailManager::GetThumbnailN(Tizen::Base::String& FilePath, Tizen::Graphics::Dimension& Dim)
358 {
359         bool GenerateThumbnail = false;
360         bool IsVideoFile = false;
361         result r = E_SUCCESS;
362
363         Bitmap* pTempBitmap = null;
364         Bitmap* pThumbBitmap = null;
365         Bitmap* pTmpBmp = null;
366
367         ImageMetadata* pImageMeta = null;
368
369         if (FilePath.IsEmpty() || FilePath.GetLength() == 0)
370         {
371                 return null;
372         }
373
374         pTempBitmap = MakeBitmapN(FilePath, GenerateThumbnail, IsVideoFile);
375         TryCatch(pTempBitmap != null, r = E_FAILURE, "Thumbnail Generation failed");
376
377         if (GenerateThumbnail)
378         {
379                 if (IsVideoFile)
380                 {
381                         VideoFrameExtractor extractor;
382                         result r = extractor.Construct(FilePath, MEDIA_PIXEL_FORMAT_BGRA8888);
383
384                         // Extracts video frames from the video file
385                         ImageBuffer* pImage = extractor.GetFrameN(0);
386                         if  ( pImage != null )
387                         {
388                                 pThumbBitmap = pImage->GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_AUTO);
389                                 TryCatch(pThumbBitmap != null, r = E_OUT_OF_MEMORY, "FRAMEEXTRACTOR : failed to allocate memory to pTempBitmap");
390                         }
391
392                 }
393                 else
394                 {
395                         pImageMeta = ContentManagerUtil::GetImageMetaN(FilePath);
396                         if (pImageMeta)
397                         {
398
399                                 pTmpBmp = pImageMeta->GetThumbnailN();
400                                 if (pTmpBmp)
401                                 {
402                                         pThumbBitmap = new (std::nothrow) Bitmap();
403                                         TryCatch(pThumbBitmap != null, r = E_OUT_OF_MEMORY, "failed to allocate memory to pTempBitmap");
404                                         pThumbBitmap->Construct(*pTmpBmp, Rectangle(0, 0, Dim.width, Dim.height));
405
406                                 }
407                                 else
408                                         pThumbBitmap = pTempBitmap;
409
410                                 delete pTmpBmp;
411                                 pTmpBmp = null;
412
413                                 delete pImageMeta;
414                                 pImageMeta = null;
415                         }
416                 }
417         }
418         else
419         {
420                 TryCatch(pTempBitmap != null, r = E_FAILURE, "Thumbnail Generation failed");
421                 pThumbBitmap = pTempBitmap;
422         }
423         return pThumbBitmap;
424
425 CATCH:
426
427         if (pImageMeta)
428                 delete pImageMeta;
429         if (pTempBitmap != null)
430         {
431                 delete pTempBitmap;
432                 pTempBitmap = null;
433         }
434         return null;
435
436 }
437
438 Bitmap*
439 ThumbnailManager::MakeBitmapN(const Tizen::Base::String& FilePath, bool& makeThumbnail, bool& bVideo)
440 {
441         result r = E_SUCCESS;
442
443         ImageBuffer* imageBuffer = null;
444         Bitmap* pTempBitmap = null;
445         AppResource* pAppResource = null;
446         ContentType contentType = CONTENT_TYPE_UNKNOWN;
447         BitmapPixelFormat pixelFormat = BITMAP_PIXEL_FORMAT_MIN;
448         ThumbMgrResultValues thumbMgrRes = THUMB_MGR_RES_SUCCESS;
449         String TempFilePath;
450
451
452         pAppResource = Application::GetInstance()->GetAppResource();
453         TryCatch(pAppResource != null, r = E_OUT_OF_MEMORY, "Could not locate app resource manager!");
454
455         contentType = MfUtility::GetContentType(FilePath);
456
457         switch(contentType)
458         {
459         case CONTENT_TYPE_IMAGE:
460         {
461                 if (FilePath.EndsWith(L"png") || FilePath.EndsWith(L"PNG"))
462                 {
463                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
464                         makeThumbnail = true;
465                         bVideo = false;
466                         return null;
467                 }
468                 else
469                 {
470                         pixelFormat = BITMAP_PIXEL_FORMAT_RGB565;
471                         makeThumbnail = true;
472                         bVideo = false;
473                         return null;
474                 }
475
476         }
477         break;
478         case CONTENT_TYPE_AUDIO:
479         {
480                 pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
481                 makeThumbnail = false;
482                 pTempBitmap = pAppResource->GetBitmapN(IDB_MUSIC, pixelFormat);
483                 return pTempBitmap;
484         }
485         break;
486         case CONTENT_TYPE_VIDEO:
487         {
488                 makeThumbnail = true;
489                 bVideo = true;
490                 return null;
491         }
492         break;
493         case CONTENT_TYPE_OTHER:
494         {
495                 makeThumbnail = false;
496                 bVideo = false;
497                 if (FilePath.EndsWith(L"pdf") || FilePath.EndsWith(L"PDF"))
498                 {
499                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
500                         pTempBitmap = pAppResource->GetBitmapN(IDB_PDF, pixelFormat);
501                         return pTempBitmap;
502                 }
503                 else if (FilePath.EndsWith(L"doc") || FilePath.EndsWith(L"DOC"))
504                 {
505                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
506                         pTempBitmap = pAppResource->GetBitmapN(IDB_MS_WORD, pixelFormat);
507                         return pTempBitmap;
508                 }
509                 else if (FilePath.EndsWith(L"docx") || FilePath.EndsWith(L"DOCX"))
510                 {
511                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
512                         pTempBitmap = pAppResource->GetBitmapN(IDB_MS_WORD, pixelFormat);
513                         return pTempBitmap;
514                 }
515                 else if (FilePath.EndsWith(L"xls") || FilePath.EndsWith(L"XLS"))
516                 {
517                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
518                         pTempBitmap = pAppResource->GetBitmapN(IDB_MS_EXCEL, pixelFormat);
519                         return pTempBitmap;
520                 }
521                 else if (FilePath.EndsWith(L"xlsx") || FilePath.EndsWith(L"XLSX"))
522                 {
523                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
524                         pTempBitmap = pAppResource->GetBitmapN(IDB_MS_EXCEL, pixelFormat);
525                         return pTempBitmap;
526                 }
527                 else if (FilePath.EndsWith(L"ppt") || FilePath.EndsWith(L"PPT"))
528                 {
529                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
530                         pTempBitmap = pAppResource->GetBitmapN(IDB_MS_PPT, pixelFormat);
531                         return pTempBitmap;
532                 }
533                 else if (FilePath.EndsWith(L"pptx") || FilePath.EndsWith(L"PPTX"))
534                 {
535                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
536                         pTempBitmap = pAppResource->GetBitmapN(IDB_MS_PPT, pixelFormat);
537                         return pTempBitmap;
538                 }
539                 else if (FilePath.EndsWith(L"html") || FilePath.EndsWith(L"HTML") || FilePath.EndsWith(L"htm") ||
540                                 FilePath.EndsWith(L"HTM") || FilePath.EndsWith(L"JS") || FilePath.EndsWith(L"js"))
541                 {
542                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
543                         pTempBitmap = pAppResource->GetBitmapN(IDB_HTML, pixelFormat);
544                         return pTempBitmap;
545                 }
546                 else if (FilePath.EndsWith(L"rss") || FilePath.EndsWith(L"RSS"))
547                 {
548                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
549                         pTempBitmap = pAppResource->GetBitmapN(IDB_RSS, pixelFormat);
550                         return pTempBitmap;
551                 }
552                 else if (FilePath.EndsWith(L"txt") || FilePath.EndsWith(L"TXT"))
553                 {
554                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
555                         pTempBitmap = pAppResource->GetBitmapN(IDB_TEXT, pixelFormat);
556                         return pTempBitmap;
557                 }
558                 else if (FilePath.EndsWith(L"SVF") || FilePath.EndsWith(L"svg"))
559                 {
560                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
561                         pTempBitmap = pAppResource->GetBitmapN(IDB_SVG, pixelFormat);
562                         return pTempBitmap;
563                 }
564                 else if (FilePath.EndsWith(L"swf") || FilePath.EndsWith(L"SWF"))
565                 {
566                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
567                         pTempBitmap = pAppResource->GetBitmapN(IDB_SWF, pixelFormat);
568                         return pTempBitmap;
569                 }
570                 else if (FilePath.EndsWith(L"tpk") || FilePath.EndsWith(L"TPK") || FilePath.EndsWith(L"wgt") || FilePath.EndsWith(L"WGT"))
571                 {
572                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
573                         pTempBitmap = pAppResource->GetBitmapN(IDB_TPK, pixelFormat);
574                         return pTempBitmap;
575                 }
576                 else if (FilePath.EndsWith(L"VCF") || FilePath.EndsWith(L"vcf"))
577                 {
578                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
579                         pTempBitmap = pAppResource->GetBitmapN(IDB_VCARD, pixelFormat);
580                         return pTempBitmap;
581                 }
582                 else if (FilePath.EndsWith(L"vcs") || FilePath.EndsWith(L"VCS"))
583                 {
584                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
585                         pTempBitmap = pAppResource->GetBitmapN(IDB_VCALENDAR, pixelFormat);
586                         return pTempBitmap;
587                 }
588                 else
589                 {
590                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
591                         pTempBitmap = pAppResource->GetBitmapN(IDB_UNKNOWN, pixelFormat);
592                         return pTempBitmap;
593                 }
594         }
595         break;
596         case CONTENT_TYPE_UNKNOWN:
597         {
598                 pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
599                 makeThumbnail = false;
600                 pTempBitmap = pAppResource->GetBitmapN(IDB_UNKNOWN, pixelFormat);
601                 return pTempBitmap;
602         }
603         break;
604         case CONTENT_TYPE_ALL:
605         {
606                 //Empty Implementation
607         }
608         break;
609         }
610         //Generate thumbnail
611         imageBuffer = new (std::nothrow) ImageBuffer();
612         TryCatch(imageBuffer != null, thumbMgrRes = THUMB_MGR_RES_FAILED, "Failed to allocate memory to imageBuffer");
613
614         r = imageBuffer->Construct(FilePath, null, true);
615         TryCatch(r == E_SUCCESS, thumbMgrRes = THUMB_MGR_RES_FAILED, "Failed to construct to image decoder");
616
617         pTempBitmap = imageBuffer->GetBitmapN(pixelFormat, BUFFER_SCALING_AUTO);
618         TryCatch(pTempBitmap != null, thumbMgrRes = THUMB_MGR_RES_FAILED, "Failed to decode bitmap");
619
620         if (imageBuffer != null)
621         {
622                 delete imageBuffer;
623                 imageBuffer = null;
624         }
625         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
626         return pTempBitmap;
627
628 CATCH:
629         makeThumbnail = false;
630         bVideo = false;
631
632         if (imageBuffer != null)
633         {
634                 delete imageBuffer;
635                 imageBuffer = null;
636         }
637         AppLogDebug("EXIT: Error Message [%s]", GetErrorMessage(r));
638         return null;
639 }
640 result
641 ThumbnailManager::SetThumbnailSize(void /*Tizen::Graphics::Dimension& dim*/)
642 {
643         //__Dimention = dim;
644         return E_SUCCESS;
645 }
646
647 Tizen::Graphics::Dimension&
648 ThumbnailManager::GetDefaultThumbSize(void)
649 {
650         return __Dimension;
651 }
652
653 result
654 ThumbnailManager::ClearCurrentThumbRequest(void)
655 {
656         result r = E_SUCCESS;
657         if (__pCurrentThumbReq)
658         {
659                 __pCurrentThumbReq = null;
660         }
661         return r;
662 }
663 void
664 ThumbnailManager::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
665 {
666         ThumbRequest* pTempThumbReq = null;
667         ArrayList* pTempArrayList = null;
668         result r = E_SUCCESS;
669
670         switch (requestId)
671         {
672         case ThumbnailManager::THUMB_MGR_GET_THUMBNAIL:
673         {
674                 TryCatch(pArgs != null, r = E_FAILURE, "Argument list is null");
675                 pTempThumbReq = (ThumbRequest*) pArgs->GetAt(0);
676                 TryCatch(pTempThumbReq != null, r = E_FAILURE, "Request is null!");
677
678                 __pCurrentThumbReq = pTempThumbReq;
679                 TryCatch(__pCurrentThumbReq != null, , "E_FAILURE Current Request is null");
680
681                 if (GetThumbnail(__pCurrentThumbReq) == THUMB_MGR_RES_SUCCESS)
682                 {
683                         pTempArrayList = new (std::nothrow) ArrayList();
684                         pTempArrayList->Construct();
685                         pTempArrayList->Add(pTempThumbReq);
686                         Application::GetInstance()->SendUserEvent(THUMBNAIL_LAODED, pTempArrayList);
687                 }
688                 else
689                 {
690                         if (__pCurrentThumbReq != null)
691                         {
692                                 if (__pCurrentThumbReq->pBitmap != null)
693                                 {
694                                         delete __pCurrentThumbReq->pBitmap;
695                                         __pCurrentThumbReq->pBitmap = null;
696                                 }
697                         }
698                         Application::GetInstance()->SendUserEvent(THUMBNAIL_FAILED, null);
699                 }
700         }
701         break;
702
703         case ThumbnailManager::THUMB_MGR_STOP:
704         {
705                 ClearCurrentThumbRequest();
706         }
707         break;
708
709         default:
710         {
711                 AppLogDebug("Unsupported case reached!");
712                 Application::GetInstance()->SendUserEvent(THUMBNAIL_CANCELED, null);
713         }
714         break;
715         }
716         return;
717 CATCH:
718         ClearCurrentThumbRequest();
719         if (pArgs)
720         {
721                 pArgs->RemoveAll(true);
722                 delete pArgs;
723         }
724         Application::GetInstance()->SendUserEvent(THUMBNAIL_FAILED, null);
725         return;
726 }
727
728 result
729 ThumbnailManager::StopThumbnailManagerThread(void)
730 {
731         result r = E_SUCCESS;
732         r = Stop();
733         r = Join();
734         AppLogDebug("Exit : %s", GetErrorMessage(r));
735         return r;
736 }