Merge from master branch
[platform/framework/native/image.git] / src / FMediaGifDecoder.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   FMediaGifDecoder.cpp
20  * @brief  This file contains the implementation of GifDecoder.
21  */
22
23 #include <FMediaTypes.h>
24 #include <FBaseSysLog.h>
25 #include "FMediaGifDecoder.h"
26 #include "FMedia_GifDecoderImpl.h"
27
28 namespace Tizen { namespace Media
29 {
30
31 GifDecoder::GifDecoder(void)
32 {
33         __pDecImpl = null;
34 }
35
36 GifDecoder::~GifDecoder(void)
37 {
38         if (__pDecImpl)
39         {
40                 delete __pDecImpl;
41         }
42 }
43
44 result
45 GifDecoder::Construct(const Tizen::Base::String& filePath, MediaPixelFormat pixelFormat)
46 {
47         result r = E_SUCCESS;
48         ClearLastResult();
49         // Check pre-construct
50         SysAssertf(__pDecImpl == null,
51                 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
52         // Create _GifDecoderImpl_ instance
53         _GifDecoderImpl* pGifDecoderImpl = new (std::nothrow) _GifDecoderImpl();
54         SysTryCatch(NID_MEDIA, pGifDecoderImpl, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed Propagated.");
55         r = pGifDecoderImpl->Construct(filePath,pixelFormat);
56         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagated", GetErrorMessage(r));
57         __pDecImpl = pGifDecoderImpl;
58         return r;
59 CATCH:
60         if (pGifDecoderImpl)
61         {
62                 delete pGifDecoderImpl;
63                 pGifDecoderImpl = null;
64         }
65         return r;
66 }
67
68 result
69 GifDecoder::Construct(const Tizen::Base::ByteBuffer& srcBuf, MediaPixelFormat pixelFormat)
70 {
71         result r = E_SUCCESS;
72         ClearLastResult();
73         // Check pre-construct
74         SysAssertf(__pDecImpl == null,
75                 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
76         // Create _GifDecoderImpl_ instance
77         _GifDecoderImpl* pGifDecoderImpl = new (std::nothrow) _GifDecoderImpl();
78         SysTryCatch(NID_MEDIA, pGifDecoderImpl, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed Propagated.");
79         r = pGifDecoderImpl->Construct(srcBuf,pixelFormat);
80         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagated", GetErrorMessage(r));
81         __pDecImpl = pGifDecoderImpl;
82         return r;
83 CATCH:
84         if (pGifDecoderImpl)
85         {
86                 delete pGifDecoderImpl;
87                 pGifDecoderImpl = null;
88         }
89         return r;
90 }
91
92
93 int
94 GifDecoder::GetWidth(void) const
95 {
96         ClearLastResult();
97         SysAssertf(__pDecImpl != null, "Not yet constructed. Construct() should be called before use.");
98         return __pDecImpl->GetWidth();
99
100 }
101
102 int
103 GifDecoder::GetHeight(void) const
104 {
105         ClearLastResult();
106         SysAssertf(__pDecImpl != null, "Not yet constructed. Construct() should be called before use.");
107         return __pDecImpl->GetHeight();
108 }
109
110 Tizen::Base::ByteBuffer*
111 GifDecoder::GetNextFrameN(long& duration)
112 {
113         ClearLastResult();
114         SysAssertf(__pDecImpl != null, "Not yet constructed. Construct() should be called before use.");
115
116         return __pDecImpl->GetNextFrameN(duration);
117 }
118
119 Tizen::Graphics::Bitmap*
120 GifDecoder::GetNextBitmapN(long& duration, Tizen::Graphics::BufferScaling bufferScaling)
121 {
122         ClearLastResult();
123         SysAssertf(__pDecImpl != null, "Not yet constructed. Construct() should be called before use.");
124
125         return __pDecImpl->GetNextBitmapN(duration, bufferScaling);
126 }
127
128 }} //Tizen::Media