Fixed transparent issue of RGB565
[platform/framework/native/image.git] / src / FMediaImage.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file   FMediaImage.cpp
20  * @brief  This file contains the implementation of subsystem's Image.
21  */
22
23 #include <FIoFile.h>
24 #include <FMediaImage.h>
25 #include <FMediaImageUtil.h>
26 #include <FBaseInternalTypes.h>
27 #include <FBaseSysLog.h>
28 #include <FApp_AppInfo.h>
29 #include "FMedia_ImageImpl.h"
30 #include "FMedia_ImageUtilImpl.h"
31
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Base;
34 using namespace Tizen::Io;
35 using namespace Tizen::App;
36
37 namespace Tizen { namespace Media
38 {
39
40 static const int MIN_LIMIT_SIZE = 1024;
41
42 Image::Image(void)
43 {
44         __pImageImpl = null;
45 }
46
47 Image::~Image(void)
48 {
49         if (__pImageImpl != null)
50         {
51                 delete __pImageImpl;
52                 __pImageImpl = null;
53         }
54 }
55
56 result
57 Image::Construct(void)
58 {
59         result r = E_SUCCESS;
60
61         SysAssertf(__pImageImpl == null,
62                 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
63         _ImageImpl* pImageImpl = new (std::nothrow) _ImageImpl();
64         SysTryCatch(NID_MEDIA, pImageImpl != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
65                           "[E_OUT_OF_MEMORY] Construct Failed ");
66
67         r = pImageImpl->Construct();
68         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Create instance failed.", GetErrorMessage(r));
69
70         __pImageImpl = pImageImpl;
71         return E_SUCCESS;
72
73 CATCH:
74         if (pImageImpl)
75         {
76                 delete pImageImpl;
77                 pImageImpl = null;
78         }
79         return r;
80 }
81
82 Bitmap*
83 Image::DecodeN(const String& srcImagePath, BitmapPixelFormat pixelFormat) const
84 {
85         result r = E_SUCCESS;
86
87         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
88         SysTryCatch(NID_MEDIA, !srcImagePath.IsEmpty(), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] srcImagePath is empty");
89         SysSecureTryCatch(NID_MEDIA, File::IsFileExist(srcImagePath), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND,
90                           "[E_FILE_NOT_FOUND] srcImagePath:%ls", srcImagePath.GetPointer());
91         SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)),
92                           r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] pixelFormat:%d", pixelFormat);
93         return _ImageImpl::DecodeToBitmapN(srcImagePath, pixelFormat);
94
95 CATCH:
96         return null;
97 }
98
99
100 Bitmap*
101 Image::DecodeN(const String& srcImagePath, BitmapPixelFormat pixelFormat, int destWidth, int destHeight) const
102 {
103         result r = E_SUCCESS;
104
105         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
106         SysTryCatch(NID_MEDIA, !srcImagePath.IsEmpty(), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] srcImagePath is empty");
107         SysSecureTryCatch(NID_MEDIA, File::IsFileExist(srcImagePath), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND,
108                           "[E_FILE_NOT_FOUND] srcImagePath:%ls", srcImagePath.GetPointer());
109         SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)),
110                           r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] pixelFormat:%d", pixelFormat);
111         SysTryCatch(NID_MEDIA, destWidth > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destWidth:%d", destWidth);
112         SysTryCatch(NID_MEDIA, destHeight > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destHeight:%d", destHeight);
113
114         return _ImageImpl::DecodeToBitmapN(srcImagePath, pixelFormat, Dimension(destWidth, destHeight));
115
116 CATCH:
117         return null;
118 }
119
120 Bitmap*
121 Image::DecodeN(const ByteBuffer& srcImageBuf, ImageFormat srcImageFormat,
122                            BitmapPixelFormat pixelFormat) const
123 {
124         result r = E_SUCCESS;
125
126         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
127         SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImageBuf is null");
128         SysTryCatch(NID_MEDIA, ((srcImageFormat>IMG_FORMAT_NONE) && (srcImageFormat<=IMG_FORMAT_WBMP)), r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT,
129                           "[E_UNSUPPORTED_FORMAT] srcImageFormat:%d", srcImageFormat);
130         SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)),
131                           r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] %s=%d", "pixelFormat", pixelFormat);
132
133         return _ImageImpl::DecodeToBitmapN(srcImageBuf, pixelFormat);
134
135 CATCH:
136         return null;
137 }
138
139
140 Bitmap*
141 Image::DecodeN(const ByteBuffer& srcImageBuf, ImageFormat imgFormat, BitmapPixelFormat pixelFormat,
142                            int destWidth, int destHeight) const
143 {
144         result r = E_SUCCESS;
145
146         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
147         SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImageBuf is null");
148         SysTryCatch(NID_MEDIA, ((imgFormat>IMG_FORMAT_NONE) && (imgFormat<=IMG_FORMAT_WBMP)), r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT,
149                           "[E_UNSUPPORTED_FORMAT] imgFormat:%d", imgFormat);
150         SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)),
151                           r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] pixelFormat:%d", pixelFormat);
152         SysTryCatch(NID_MEDIA, destWidth > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destWidth:%d", destWidth);
153         SysTryCatch(NID_MEDIA, destHeight > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destHeight:%d", destHeight);
154
155         return _ImageImpl::DecodeToBitmapN(srcImageBuf, pixelFormat, Dimension(destWidth, destHeight), BUFFER_SCALING_AUTO);
156
157 CATCH:
158         return null;
159 }
160
161
162 Bitmap*
163 Image::DecodeN(const Tizen::Base::String& srcImagePath, Tizen::Graphics::BitmapPixelFormat pixelFormat,
164                            float destWidth, float destHeight) const
165 {
166         result r = E_SUCCESS;
167
168         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
169         SysTryCatch(NID_MEDIA, !srcImagePath.IsEmpty(), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] srcImagePath is empty");
170         SysSecureTryCatch(NID_MEDIA, File::IsFileExist(srcImagePath), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND,
171                           "[E_FILE_NOT_FOUND] srcImagePath:%ls", srcImagePath.GetPointer());
172         SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)),
173                           r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] pixelFormat:%d", pixelFormat);
174         SysTryCatch(NID_MEDIA, destWidth > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destWidth:%d", destWidth);
175         SysTryCatch(NID_MEDIA, destHeight > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destHeight:%d", destHeight);
176
177         return _ImageImpl::DecodeToBitmapN(srcImagePath, pixelFormat, FloatDimension(destWidth, destHeight));
178
179 CATCH:
180         return null;
181 }
182
183
184 Bitmap*
185 Image::DecodeN(const Tizen::Base::ByteBuffer& srcImageBuf, Tizen::Graphics::BitmapPixelFormat pixelFormat,
186                            float destWidth, float destHeight) const
187 {
188         result r = E_SUCCESS;
189
190         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
191         SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImageBuf is null");
192         SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)),
193                           r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] pixelFormat:%d", pixelFormat);
194         SysTryCatch(NID_MEDIA, destWidth > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destWidth:%d", destWidth);
195         SysTryCatch(NID_MEDIA, destHeight > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destHeight:%d", destHeight);
196
197         return _ImageImpl::DecodeToBitmapN(srcImageBuf, pixelFormat, FloatDimension(destWidth, destHeight));
198
199 CATCH:
200         return null;
201 }
202
203 ByteBuffer*
204 Image::EncodeToBufferN(const Bitmap& srcImageBuf, ImageFormat destImageFormat) const
205 {
206         result r = E_SUCCESS;
207
208         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
209         SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImageBuf is null");
210         SysTryCatch(NID_MEDIA, ((destImageFormat==IMG_FORMAT_BMP) || (destImageFormat==IMG_FORMAT_JPG) || (destImageFormat==IMG_FORMAT_PNG)),
211                           r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] destImageFormat:%d", destImageFormat);
212         SysTryCatch(NID_MEDIA, srcImageBuf.GetWidth() > 0 && srcImageBuf.GetHeight() > 0, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND,
213                           "[E_OBJ_NOT_FOUND] bmp.width=%d,height=%d", srcImageBuf.GetWidth(), srcImageBuf.GetHeight());
214
215
216         return _ImageImpl::EncodeToBufferN(srcImageBuf, destImageFormat);
217
218 CATCH:
219         return null;
220 }
221
222 result
223 Image::EncodeToFile(const Bitmap& srcImageBuf, ImageFormat destImageFormat,
224                                         const String& destImagePath, bool overwrite) const
225 {
226         result r = E_SUCCESS;
227
228         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
229         SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImageBuf is null");
230         SysTryCatch(NID_MEDIA, ((destImageFormat==IMG_FORMAT_BMP) || (destImageFormat==IMG_FORMAT_JPG) || (destImageFormat==IMG_FORMAT_PNG)),
231                           r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] destImageFormat:%d", destImageFormat);
232         SysTryCatch(NID_MEDIA, srcImageBuf.GetWidth() > 0 && srcImageBuf.GetHeight() > 0, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND,
233                           "[E_OBJ_NOT_FOUND] bmp.width=%d,height=%d", srcImageBuf.GetWidth(), srcImageBuf.GetHeight());
234
235         return _ImageImpl::EncodeToFile(srcImageBuf, destImageFormat, destImagePath, overwrite);
236
237 CATCH:
238         return r;
239 }
240
241 ByteBuffer*
242 Image::ConvertN(const String& srcImagePath, ImageFormat destImageFormat) const
243 {
244         result r = E_SUCCESS;
245
246         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
247         SysTryCatch(NID_MEDIA, !srcImagePath.IsEmpty(), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] path is empty");
248         SysSecureTryCatch(NID_MEDIA, File::IsFileExist(srcImagePath), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND,
249                           "[E_FILE_NOT_FOUND] srcImagePath:%ls", srcImagePath.GetPointer());
250         SysTryCatch(NID_MEDIA, ((destImageFormat>IMG_FORMAT_NONE) && (destImageFormat<=IMG_FORMAT_WBMP)), r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT,
251                           "[E_UNSUPPORTED_FORMAT] destImageFormat:%d", destImageFormat);
252
253         return _ImageImpl::ConvertToBufferN(srcImagePath, destImageFormat);
254
255 CATCH:
256         return null;
257 }
258
259
260 result
261 Image::CompressJpeg(const Tizen::Base::String& srcImagePath, const Tizen::Base::String& destImagePath, int limitSize) const
262 {
263         result r = E_SUCCESS;
264         ImageFormat imgFormat;
265
266         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
267         SysTryCatch(NID_MEDIA, !srcImagePath.IsEmpty(), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] srcImagePath is empty");
268         SysSecureTryCatch(NID_MEDIA, File::IsFileExist(srcImagePath), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND,
269                           "[E_FILE_NOT_FOUND] srcImagePath:%ls", srcImagePath.GetPointer());
270
271         // CompressJpeg should accept only jpeg encoded images.
272         imgFormat = _ImageUtilImpl::GetImageFormat(srcImagePath);
273         SysTryCatch(NID_MEDIA, imgFormat == IMG_FORMAT_JPG, r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT,
274                           "[E_UNSUPPORTED_FORMAT] image format(%d) != JPG", imgFormat);
275
276         SysTryCatch(NID_MEDIA, limitSize > MIN_LIMIT_SIZE, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE,
277                           "[E_OUT_OF_RANGE] limitSize:%d < %d", limitSize, MIN_LIMIT_SIZE);
278
279         return _ImageImpl::CompressJpeg(srcImagePath, destImagePath, limitSize);
280
281 CATCH:
282         return r;
283 }
284
285 Tizen::Base::ByteBuffer*
286 Image::CompressJpegN(const Tizen::Base::ByteBuffer& srcImageBuf, int limitSize) const
287 {
288         result r = E_SUCCESS;
289         ImageFormat imgFormat;
290
291         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
292         SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImageBuf is null");
293
294         SysTryCatch(NID_MEDIA, limitSize > MIN_LIMIT_SIZE, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE,
295                           "[E_OUT_OF_RANGE] limitSize:%d < %d", limitSize, MIN_LIMIT_SIZE);
296         SysTryCatch(NID_MEDIA, srcImageBuf.GetCapacity() > limitSize, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE,
297                           "[E_OUT_OF_RANGE] srcSize(%d) <= limitSize(%d)", srcImageBuf.GetCapacity(), limitSize);
298
299         imgFormat = _ImageUtilImpl::GetImageFormat(srcImageBuf);
300         SysTryCatch(NID_MEDIA, imgFormat == IMG_FORMAT_JPG, r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT,
301                           "[E_UNSUPPORTED_FORMAT] image format(%d) != JPG", imgFormat);
302
303         return _ImageImpl::CompressJpegN(srcImageBuf, limitSize);
304
305 CATCH:
306         return null;
307 }
308
309
310 Tizen::Base::ByteBuffer*
311 Image::DecodeToBufferN(const Tizen::Base::ByteBuffer& srcImageBuf, ImageFormat srcImageFormat,
312                                            Tizen::Graphics::BitmapPixelFormat pixelFormat,
313                                            int& imageWidth,  int& imageHeight) const
314 {
315         Dimension dim;
316         ByteBuffer* pBuf = null;
317         result r = E_SUCCESS;
318
319         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
320         SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImageBuf is null");
321         SysTryCatch(NID_MEDIA, ((srcImageFormat>IMG_FORMAT_NONE) && (srcImageFormat<=IMG_FORMAT_WBMP)), r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT,
322                           "[E_UNSUPPORTED_FORMAT] srcImageFormat:%d", srcImageFormat);
323         SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)),
324                           r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] pixelFormat:%d", pixelFormat);
325
326         pBuf = _ImageImpl::DecodeToBufferN(srcImageBuf, dim, Dimension(0,0), pixelFormat, srcImageFormat);
327         SysTryCatch(NID_MEDIA, pBuf != null, r = GetLastResult(), GetLastResult(),
328                           "[%s] Propagated.", GetErrorMessage(GetLastResult()));
329         imageWidth = dim.width;
330         imageHeight = dim.height;
331
332         return pBuf;
333
334 CATCH:
335
336         return null;
337 }
338
339 Tizen::Base::ByteBuffer*
340 Image::DecodeToBufferN(const Tizen::Base::String& srcImagePath,
341                                            Tizen::Graphics::BitmapPixelFormat pixelFormat,
342                                            int& imageWidth, int& imageHeight) const
343 {
344         Dimension dim;
345         ByteBuffer* pBuf = null;
346         result r = E_SUCCESS;
347
348         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
349         SysTryCatch(NID_MEDIA, !srcImagePath.IsEmpty(), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] srcImagePath is empty");
350         SysSecureTryCatch(NID_MEDIA, File::IsFileExist(srcImagePath), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND,
351                           "[E_FILE_NOT_FOUND] srcImagePath:%ls", srcImagePath.GetPointer());
352         SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)),
353                           r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] pixelFormat:%d", pixelFormat);
354
355         pBuf = _ImageImpl::DecodeToBufferN(srcImagePath, dim, Dimension(0,0), pixelFormat);
356         SysTryCatch(NID_MEDIA, pBuf != null, r = GetLastResult(), GetLastResult(),
357                           "[%s] Propagated.", GetErrorMessage(GetLastResult()));
358         imageWidth = dim.width;
359         imageHeight = dim.height;
360
361         return pBuf;
362
363 CATCH:
364
365         return null;
366 }
367
368 ImageFormat
369 Image::GetImageFormat(const Tizen::Base::String& srcImagePath) const
370 {
371         ImageFormat fmt;
372         result r = E_SUCCESS;
373
374         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
375         SysTryCatch(NID_MEDIA, !srcImagePath.IsEmpty(), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] srcImagePath is empty");
376         SysSecureTryCatch(NID_MEDIA, File::IsFileExist(srcImagePath), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND,
377                           "[E_FILE_NOT_FOUND] srcImagePath:%ls", srcImagePath.GetPointer());
378         fmt = _ImageUtilImpl::GetImageFormat(srcImagePath);
379         r = GetLastResult();
380
381         if (r == E_INVALID_DATA || r == E_INVALID_ARG)
382         {
383                 SetLastResult(E_UNSUPPORTED_FORMAT);
384         }
385
386         return fmt;
387
388 CATCH:
389         return IMG_FORMAT_NONE;
390 }
391
392
393 ImageFormat
394 Image::GetImageFormat(const Tizen::Base::ByteBuffer& srcImageBuf) const
395 {
396         ImageFormat fmt;
397         result r = E_SUCCESS;
398
399         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
400         SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImagePath is null");
401
402         fmt = _ImageUtilImpl::GetImageFormat(srcImageBuf);
403         r = GetLastResult();
404
405         if (r == E_INVALID_DATA || r == E_INVALID_ARG)
406         {
407                 SetLastResult(E_UNSUPPORTED_FORMAT);
408         }
409
410         return fmt;
411
412 CATCH:
413         return IMG_FORMAT_NONE;
414 }
415
416 bool
417 Image::HasAlphaChannels(const Tizen::Base::String& srcImagePath) const
418 {
419         result r = E_SUCCESS;
420
421         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
422         SysTryCatch(NID_MEDIA, !srcImagePath.IsEmpty(), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] srcImagePath is empty");
423         SysSecureTryCatch(NID_MEDIA, File::IsFileExist(srcImagePath), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND,
424                           "[E_FILE_NOT_FOUND] srcImagePath:%ls", srcImagePath.GetPointer());
425
426         return _ImageUtilImpl::HasAlphaChannel(srcImagePath);
427
428 CATCH:
429         return false;
430 }
431
432
433 bool
434 Image::HasAlphaChannels(const Tizen::Base::ByteBuffer& srcImageBuf) const
435 {
436         result r = E_SUCCESS;
437
438         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
439         SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImageBuf is null");
440
441         return _ImageUtilImpl::HasAlphaChannel(srcImageBuf);
442
443 CATCH:
444         return false;
445 }
446
447 result
448 Image::DecodeUrl(const Tizen::Base::Utility::Uri& srcImageUrl,
449                                  Tizen::Graphics::BitmapPixelFormat pixelFormat, int destWidth,
450                                  int destHeight, RequestId& reqId, const IImageDecodeUrlEventListener& listener,
451                                  long timeout) const
452 {
453         result r = E_SUCCESS;
454
455         SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use.");
456         SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)),
457                           r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] pixelFormat:%d", pixelFormat);
458         SysTryCatch(NID_MEDIA, destWidth > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destWidth:%d", destWidth);
459         SysTryCatch(NID_MEDIA, destHeight > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destHeight:%d", destHeight);
460
461         SysTryCatch(NID_MEDIA, timeout == TIMEOUT_INFINITE || timeout > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE,
462                           "[E_OUT_OF_RANGE] timeout:%d", timeout);
463
464         r = __pImageImpl->DecodeUrl(srcImageUrl, pixelFormat, destWidth,destHeight, reqId, listener, timeout);
465 SysTryCatch(NID_MEDIA, r == E_SUCCESS , , r, "[%s] Propagated.", GetErrorMessage(r));
466
467         return r;
468
469 CATCH:
470         return r;
471 }
472
473 }} // Tizen::Media