27dec86b96ca0fab061862bb02606e05c9e23a17
[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                                         ImgBuffer.Construct(pRequest->FilePath,width, height, IMAGE_SCALING_METHOD_FAST_BILINEAR );
256                                         imgOrientation = ImgBuffer.GetExifOrientation();
257
258                                         if (imgOrientation == EXIF_ORIENTATION_RIGHT_TOP ||
259                                                         imgOrientation == EXIF_ORIENTATION_TOP_RIGHT )
260                                         {
261                                                 pRotatedImgBuffer = ImgBuffer.RotateN(IMAGE_ROTATION_90);
262                                         }
263                                         else if (imgOrientation == EXIF_ORIENTATION_RIGHT_BOTTOM ||
264                                                         imgOrientation == EXIF_ORIENTATION_BOTTOM_RIGHT)
265                                         {
266                                                 pRotatedImgBuffer = ImgBuffer.RotateN(IMAGE_ROTATION_180);
267                                         }
268                                         else if (imgOrientation == EXIF_ORIENTATION_LEFT_BOTTOM ||
269                                                         imgOrientation  == EXIF_ORIENTATION_BOTTOM_LEFT)
270                                         {
271                                                 pRotatedImgBuffer = ImgBuffer.RotateN(IMAGE_ROTATION_270);
272                                         }
273
274                                         if ( pRotatedImgBuffer !=null )
275                                         {
276                                                 pRequest->pBitmap  = pRotatedImgBuffer->GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
277                                         }
278                                         else
279                                         {
280                                                 pRequest->pBitmap  = pTmpBmp;                   //ImgBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
281                                         }
282
283                                         if( pRequest->pBitmap == null )
284                                                 pRequest->pBitmap = pTmpBmp;
285
286                                         if ( pRotatedImgBuffer!=null )
287                                         {
288                                                 delete pRotatedImgBuffer;
289                                                 pRotatedImgBuffer = null;
290                                         }
291                                         AppLogDebug("Image Orientation [%d]", pImageMeta->GetOrientation() );
292
293                                 }
294                                 else
295                                 {
296                                         r = ImgBuffer.Construct(pRequest->FilePath,THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, IMAGE_SCALING_METHOD_FAST_BILINEAR );
297                                         pRequest->pBitmap = ImgBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
298
299                                 }
300
301                                 thumbMgrRes = THUMB_MGR_RES_SUCCESS;
302                         }
303                         else
304                         {
305                                 TryCatch(pTempBitmap != null, thumbMgrRes = THUMB_MGR_RES_FAILED, "Thumbnail generation failed");
306                                 thumbMgrRes = THUMB_MGR_RES_SUCCESS;
307                                 pRequest->pBitmap = pTempBitmap;
308                         }
309
310                         if ( pImageMeta != null )
311                                 delete pImageMeta;
312                 }
313         }
314         else
315         {
316                 TryCatch(pTempBitmap != null, thumbMgrRes = THUMB_MGR_RES_FAILED, "Thumbnail generation failed");
317                 thumbMgrRes = THUMB_MGR_RES_SUCCESS;
318                 pRequest->pBitmap = pTempBitmap;
319         }
320
321         if (pBitmapToMerge != null)
322         {
323                 delete pBitmapToMerge;
324                 pBitmapToMerge = null;
325         }
326
327         AppLogDebug("Exit [%s]:", GetErrorMessage(r));
328         return thumbMgrRes;
329
330 CATCH:
331
332         AppLogDebug("Exit Error Message[%s]:", GetErrorMessage(r));
333
334         if (pRequest != null)
335         {
336                 pRequest->pBitmap = null;
337         }
338
339         if (pTempBitmap != null)
340                 delete pTempBitmap;
341         
342         if (pMergedThumbnail)
343                 delete pMergedThumbnail;
344         
345         if ( pImageMeta != null )
346                 delete pImageMeta;
347
348         return thumbMgrRes;
349 }
350
351
352 Bitmap*
353 ThumbnailManager::GetThumbnailN(Tizen::Base::String& FilePath, Tizen::Graphics::Dimension& Dim)
354 {
355         bool GenerateThumbnail = false;
356         bool IsVideoFile = false;
357         result r = E_SUCCESS;
358
359         Bitmap* pTempBitmap = null;
360         Bitmap* pThumbBitmap = null;
361         Bitmap* pTmpBmp = null;
362
363         ImageMetadata* pImageMeta = null;
364
365         if (FilePath.IsEmpty() || FilePath.GetLength() == 0)
366         {
367                 return null;
368         }
369
370         pTempBitmap = MakeBitmapN(FilePath, GenerateThumbnail, IsVideoFile);
371         TryCatch(pTempBitmap != null, r = E_FAILURE, "Thumbnail Generation failed");
372
373         if (GenerateThumbnail)
374         {
375                 if (IsVideoFile)
376                 {
377                         VideoFrameExtractor extractor;
378                         result r = extractor.Construct(FilePath, MEDIA_PIXEL_FORMAT_BGRA8888);
379
380                         // Extracts video frames from the video file
381                         ImageBuffer* pImage = extractor.GetFrameN(0);
382                         if  ( pImage != null )
383                         {
384                                 pThumbBitmap = pImage->GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_AUTO);
385                                 TryCatch(pThumbBitmap != null, r = E_OUT_OF_MEMORY, "FRAMEEXTRACTOR : failed to allocate memory to pTempBitmap");
386                         }
387
388                 }
389                 else
390                 {
391                         pImageMeta = ContentManagerUtil::GetImageMetaN(FilePath);
392                         if (pImageMeta)
393                         {
394
395                                 pTmpBmp = pImageMeta->GetThumbnailN();
396                                 if (pTmpBmp)
397                                 {
398                                         pThumbBitmap = new (std::nothrow) Bitmap();
399                                         TryCatch(pThumbBitmap != null, r = E_OUT_OF_MEMORY, "failed to allocate memory to pTempBitmap");
400                                         pThumbBitmap->Construct(*pTmpBmp, Rectangle(0, 0, Dim.width, Dim.height));
401
402                                 }
403                                 else
404                                         pThumbBitmap = pTempBitmap;
405
406                                 delete pTmpBmp;
407                                 pTmpBmp = null;
408
409                                 delete pImageMeta;
410                                 pImageMeta = null;
411                         }
412                 }
413         }
414         else
415         {
416                 TryCatch(pTempBitmap != null, r = E_FAILURE, "Thumbnail Generation failed");
417                 pThumbBitmap = pTempBitmap;
418         }
419         return pThumbBitmap;
420
421 CATCH:
422
423         if (pImageMeta)
424                 delete pImageMeta;
425         if (pTempBitmap != null)
426         {
427                 delete pTempBitmap;
428                 pTempBitmap = null;
429         }
430         return null;
431
432 }
433
434 Bitmap*
435 ThumbnailManager::MakeBitmapN(const Tizen::Base::String& FilePath, bool& makeThumbnail, bool& bVideo)
436 {
437         result r = E_SUCCESS;
438
439         ImageBuffer* imageBuffer = null;
440         Bitmap* pTempBitmap = null;
441         AppResource* pAppResource = null;
442         ContentType contentType = CONTENT_TYPE_UNKNOWN;
443         BitmapPixelFormat pixelFormat = BITMAP_PIXEL_FORMAT_MIN;
444         ThumbMgrResultValues thumbMgrRes = THUMB_MGR_RES_SUCCESS;
445         String TempFilePath;
446
447
448         pAppResource = Application::GetInstance()->GetAppResource();
449         TryCatch(pAppResource != null, r = E_OUT_OF_MEMORY, "Could not locate app resource manager!");
450
451         contentType = MfUtility::GetContentType(FilePath);
452
453         switch(contentType)
454         {
455         case CONTENT_TYPE_IMAGE:
456         {
457                 if (FilePath.EndsWith(L"png") || FilePath.EndsWith(L"PNG"))
458                 {
459                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
460                         makeThumbnail = true;
461                         bVideo = false;
462                         return null;
463                 }
464                 else
465                 {
466                         pixelFormat = BITMAP_PIXEL_FORMAT_RGB565;
467                         makeThumbnail = true;
468                         bVideo = false;
469                         return null;
470                 }
471
472         }
473         break;
474         case CONTENT_TYPE_AUDIO:
475         {
476                 pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
477                 makeThumbnail = false;
478                 pTempBitmap = pAppResource->GetBitmapN(IDB_MUSIC, pixelFormat);
479                 return pTempBitmap;
480         }
481         break;
482         case CONTENT_TYPE_VIDEO:
483         {
484                 makeThumbnail = true;
485                 bVideo = true;
486                 return null;
487         }
488         break;
489         case CONTENT_TYPE_OTHER:
490         {
491                 makeThumbnail = false;
492                 bVideo = false;
493                 if (FilePath.EndsWith(L"pdf") || FilePath.EndsWith(L"PDF"))
494                 {
495                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
496                         pTempBitmap = pAppResource->GetBitmapN(IDB_PDF, pixelFormat);
497                         return pTempBitmap;
498                 }
499                 else if (FilePath.EndsWith(L"doc") || FilePath.EndsWith(L"DOC"))
500                 {
501                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
502                         pTempBitmap = pAppResource->GetBitmapN(IDB_MS_WORD, pixelFormat);
503                         return pTempBitmap;
504                 }
505                 else if (FilePath.EndsWith(L"docx") || FilePath.EndsWith(L"DOCX"))
506                 {
507                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
508                         pTempBitmap = pAppResource->GetBitmapN(IDB_MS_WORD, pixelFormat);
509                         return pTempBitmap;
510                 }
511                 else if (FilePath.EndsWith(L"xls") || FilePath.EndsWith(L"XLS"))
512                 {
513                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
514                         pTempBitmap = pAppResource->GetBitmapN(IDB_MS_EXCEL, pixelFormat);
515                         return pTempBitmap;
516                 }
517                 else if (FilePath.EndsWith(L"xlsx") || FilePath.EndsWith(L"XLSX"))
518                 {
519                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
520                         pTempBitmap = pAppResource->GetBitmapN(IDB_MS_EXCEL, pixelFormat);
521                         return pTempBitmap;
522                 }
523                 else if (FilePath.EndsWith(L"ppt") || FilePath.EndsWith(L"PPT"))
524                 {
525                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
526                         pTempBitmap = pAppResource->GetBitmapN(IDB_MS_PPT, pixelFormat);
527                         return pTempBitmap;
528                 }
529                 else if (FilePath.EndsWith(L"pptx") || FilePath.EndsWith(L"PPTX"))
530                 {
531                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
532                         pTempBitmap = pAppResource->GetBitmapN(IDB_MS_PPT, pixelFormat);
533                         return pTempBitmap;
534                 }
535                 else if (FilePath.EndsWith(L"html") || FilePath.EndsWith(L"HTML") || FilePath.EndsWith(L"htm") ||
536                                 FilePath.EndsWith(L"HTM") || FilePath.EndsWith(L"JS") || FilePath.EndsWith(L"js"))
537                 {
538                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
539                         pTempBitmap = pAppResource->GetBitmapN(IDB_HTML, pixelFormat);
540                         return pTempBitmap;
541                 }
542                 else if (FilePath.EndsWith(L"rss") || FilePath.EndsWith(L"RSS"))
543                 {
544                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
545                         pTempBitmap = pAppResource->GetBitmapN(IDB_RSS, pixelFormat);
546                         return pTempBitmap;
547                 }
548                 else if (FilePath.EndsWith(L"txt") || FilePath.EndsWith(L"TXT"))
549                 {
550                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
551                         pTempBitmap = pAppResource->GetBitmapN(IDB_TEXT, pixelFormat);
552                         return pTempBitmap;
553                 }
554                 else if (FilePath.EndsWith(L"SVF") || FilePath.EndsWith(L"svg"))
555                 {
556                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
557                         pTempBitmap = pAppResource->GetBitmapN(IDB_SVG, pixelFormat);
558                         return pTempBitmap;
559                 }
560                 else if (FilePath.EndsWith(L"swf") || FilePath.EndsWith(L"SWF"))
561                 {
562                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
563                         pTempBitmap = pAppResource->GetBitmapN(IDB_SWF, pixelFormat);
564                         return pTempBitmap;
565                 }
566                 else if (FilePath.EndsWith(L"tpk") || FilePath.EndsWith(L"TPK") || FilePath.EndsWith(L"wgt") || FilePath.EndsWith(L"WGT"))
567                 {
568                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
569                         pTempBitmap = pAppResource->GetBitmapN(IDB_TPK, pixelFormat);
570                         return pTempBitmap;
571                 }
572                 else if (FilePath.EndsWith(L"VCF") || FilePath.EndsWith(L"vcf"))
573                 {
574                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
575                         pTempBitmap = pAppResource->GetBitmapN(IDB_VCARD, pixelFormat);
576                         return pTempBitmap;
577                 }
578                 else if (FilePath.EndsWith(L"vcs") || FilePath.EndsWith(L"VCS"))
579                 {
580                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
581                         pTempBitmap = pAppResource->GetBitmapN(IDB_VCALENDAR, pixelFormat);
582                         return pTempBitmap;
583                 }
584                 else
585                 {
586                         pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
587                         pTempBitmap = pAppResource->GetBitmapN(IDB_UNKNOWN, pixelFormat);
588                         return pTempBitmap;
589                 }
590         }
591         break;
592         case CONTENT_TYPE_UNKNOWN:
593         {
594                 pixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
595                 makeThumbnail = false;
596                 pTempBitmap = pAppResource->GetBitmapN(IDB_UNKNOWN, pixelFormat);
597                 return pTempBitmap;
598         }
599         break;
600         case CONTENT_TYPE_ALL:
601         {
602                 //Empty Implementation
603         }
604         break;
605         }
606         //Generate thumbnail
607         imageBuffer = new (std::nothrow) ImageBuffer();
608         TryCatch(imageBuffer != null, thumbMgrRes = THUMB_MGR_RES_FAILED, "Failed to allocate memory to imageBuffer");
609
610         r = imageBuffer->Construct(FilePath, null, true);
611         TryCatch(r == E_SUCCESS, thumbMgrRes = THUMB_MGR_RES_FAILED, "Failed to construct to image decoder");
612
613         pTempBitmap = imageBuffer->GetBitmapN(pixelFormat, BUFFER_SCALING_AUTO);
614         TryCatch(pTempBitmap != null, thumbMgrRes = THUMB_MGR_RES_FAILED, "Failed to decode bitmap");
615
616         if (imageBuffer != null)
617         {
618                 delete imageBuffer;
619                 imageBuffer = null;
620         }
621         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
622         return pTempBitmap;
623
624 CATCH:
625         makeThumbnail = false;
626         bVideo = false;
627
628         if (imageBuffer != null)
629         {
630                 delete imageBuffer;
631                 imageBuffer = null;
632         }
633         AppLogDebug("EXIT: Error Message [%s]", GetErrorMessage(r));
634         return null;
635 }
636 result
637 ThumbnailManager::SetThumbnailSize(void /*Tizen::Graphics::Dimension& dim*/)
638 {
639         //__Dimention = dim;
640         return E_SUCCESS;
641 }
642
643 Tizen::Graphics::Dimension&
644 ThumbnailManager::GetDefaultThumbSize(void)
645 {
646         return __Dimension;
647 }
648
649 result
650 ThumbnailManager::ClearCurrentThumbRequest(void)
651 {
652         result r = E_SUCCESS;
653         if (__pCurrentThumbReq)
654         {
655                 __pCurrentThumbReq = null;
656         }
657         return r;
658 }
659 void
660 ThumbnailManager::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
661 {
662         ThumbRequest* pTempThumbReq = null;
663         ArrayList* pTempArrayList = null;
664         result r = E_SUCCESS;
665
666         switch (requestId)
667         {
668         case ThumbnailManager::THUMB_MGR_GET_THUMBNAIL:
669         {
670                 TryCatch(pArgs != null, r = E_FAILURE, "Argument list is null");
671                 pTempThumbReq = (ThumbRequest*) pArgs->GetAt(0);
672                 TryCatch(pTempThumbReq != null, r = E_FAILURE, "Request is null!");
673
674                 __pCurrentThumbReq = pTempThumbReq;
675                 TryCatch(__pCurrentThumbReq != null, , "E_FAILURE Current Request is null");
676
677                 if (GetThumbnail(__pCurrentThumbReq) == THUMB_MGR_RES_SUCCESS)
678                 {
679                         pTempArrayList = new (std::nothrow) ArrayList();
680                         pTempArrayList->Construct();
681                         pTempArrayList->Add(pTempThumbReq);
682                         Application::GetInstance()->SendUserEvent(THUMBNAIL_LAODED, pTempArrayList);
683                 }
684                 else
685                 {
686                         if (__pCurrentThumbReq != null)
687                         {
688                                 if (__pCurrentThumbReq->pBitmap != null)
689                                 {
690                                         delete __pCurrentThumbReq->pBitmap;
691                                         __pCurrentThumbReq->pBitmap = null;
692                                 }
693                         }
694                         Application::GetInstance()->SendUserEvent(THUMBNAIL_FAILED, null);
695                 }
696         }
697         break;
698
699         case ThumbnailManager::THUMB_MGR_STOP:
700         {
701                 ClearCurrentThumbRequest();
702         }
703         break;
704
705         default:
706         {
707                 AppLogDebug("Unsupported case reached!");
708                 Application::GetInstance()->SendUserEvent(THUMBNAIL_CANCELED, null);
709         }
710         break;
711         }
712         return;
713 CATCH:
714         ClearCurrentThumbRequest();
715         if (pArgs)
716         {
717                 pArgs->RemoveAll(true);
718                 delete pArgs;
719         }
720         Application::GetInstance()->SendUserEvent(THUMBNAIL_FAILED, null);
721         return;
722 }
723
724 result
725 ThumbnailManager::StopThumbnailManagerThread(void)
726 {
727         result r = E_SUCCESS;
728         r = Stop();
729         r = Join();
730         AppLogDebug("Exit : %s", GetErrorMessage(r));
731         return r;
732 }