merge with master
[framework/osp/image-core.git] / src / inc / FMedia_ImageDecoder.h
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   FMedia_ImageDecoder.h
20  * @brief  This is the header file for the _ImageDecoder.
21  */
22
23 #ifndef _FMEDIA_INTERNAL_IMAGE_DECODER_H_
24 #define _FMEDIA_INTERNAL_IMAGE_DECODER_H_
25
26 #include <unique_ptr.h>
27 #include <FBaseObject.h>
28 #include <FMediaImageTypes.h>
29
30 namespace Tizen { namespace Base {
31 class ByteBuffer;
32 class String;
33 } }
34
35 namespace Tizen { namespace Media
36 {
37
38 class _IImageDecoder;
39
40 /**
41  * @class  _ImageDecoder
42  * @brief  This class provides internal APIs for image decoding.
43  *
44  * This class provides internal methods for image decoding.
45  */
46 class _OSP_EXPORT_ _ImageDecoder
47         : virtual public Tizen::Base::Object
48 {
49 public:
50         /**
51          * Decodes an image data into the decoded byte buffer container without resizing. @n
52          * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP.
53          *
54          * @return         A decoded byte data that is not resized, @n
55          *                 else @c null if an exception occurs
56          * @param[in]  filePath           The image file path to decode.
57          * @param[in]  pixelFormat                The output pixel format. @c
58          * @param[out] width                  The width of image. @n
59          * @param[out] height                 The height of image.
60          * @exception  E_SUCCESS              The method is successful.
61          * @exception  E_INVALID_ARG          A specified color format is not supported.
62          * @exception  E_OVERFLOW             The source image exceeds max size or length.
63          * @exception  E_UNSUPPORTED_FORMAT   The specified format is not supported.
64          * @exception  E_OUT_OF_MEMORY        The memory is insufficient.
65          * @exception  E_FILE_NOT_FOUND       The specified image file cannot be found.
66          * @exception  E_SYSTEM               A system error has occurred.
67          * @remarks        The specific error code can be accessed using the GetLastResult() method.
68          * @remarks    Supported pixel formats are MEDIA_PIXEL_FORMAT_RGB565LE,
69          *              MEDIA_PIXEL_FORMAT_BGRA8888, and MEDIA_PIXEL_FORMAT_RGBA8888.
70          */
71         static Tizen::Base::ByteBuffer*
72                 DecodeToBufferN(const Tizen::Base::String& filePath, MediaPixelFormat pixelFormat,
73                                                 int &width, int &height, bool autoRotate = false);
74
75         /**
76          * Decodes a region of image data into the decoded byte buffer container without resizing. @n
77          * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP.
78          *
79          * @return         A decoded byte data that is not resized, @n
80          *             else @c null if an exception occurs
81          * @param[in]  filePath              The image file path to decode.
82          * @param[in]  pixelFormat           The output pixel format. @c
83          * @param[in]  x                     The x position of decoding region
84          * @param[in]  y                     The y position of decoding region
85          * @param[in]  width                 The width of decoding region.
86          * @param[in]  height                The height of decoding region.
87          * @exception  E_SUCCESS             The method is successful.
88          * @exception  E_INVALID_ARG         A specified color format is not supported.
89          * @exception  E_OVERFLOW            The source image exceeds max size or length.
90          * @exception  E_UNSUPPORTED_FORMAT  The specified format is not supported.
91          * @exception  E_OUT_OF_MEMORY       The memory is insufficient.
92          * @exception  E_FILE_NOT_FOUND      The specified image file cannot be found.
93          * @exception  E_SYSTEM              A system error has occurred.
94          * @remarks        The specific error code can be accessed using the GetLastResult() method.
95          * @remarks    Supported pixel formats are MEDIA_PIXEL_FORMAT_RGB565LE,
96          *             MEDIA_PIXEL_FORMAT_BGRA8888, and MEDIA_PIXEL_FORMAT_RGBA8888.
97          */
98         static Tizen::Base::ByteBuffer*
99                 DecodeRegionToBufferN(const Tizen::Base::String& filePath, MediaPixelFormat pixelFormat,
100                                                           int x, int y, int width, int height);
101
102         /**
103          * Decodes a region of image data into the decoded byte buffer container without resizing. @n
104          * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP.
105          *
106          * @return         A decoded byte data that is not resized, @n
107          *             else @c null if an exception occurs
108          * @param[in]  srcBuf                The buffer that contains source data.
109          * @param[in]  pixelFormat           The output pixel format. @c
110          * @param[in]  x                     The x position of decoding region
111          * @param[in]  y                     The y position of decoding region
112          * @param[in]  width                 The width of decoding region.
113          * @param[in]  height                The height of decoding region.
114          * @exception  E_SUCCESS             The method is successful.
115          * @exception  E_INVALID_ARG         A specified color format is not supported.
116          * @exception  E_OVERFLOW            The source image exceeds max size or length.
117          * @exception  E_UNSUPPORTED_FORMAT  The specified format is not supported.
118          * @exception  E_OUT_OF_MEMORY       The memory is insufficient.
119          * @exception  E_SYSTEM              A system error has occurred.
120          * @remarks        The specific error code can be accessed using the GetLastResult() method.
121          * @remarks    Supported pixel formats are MEDIA_PIXEL_FORMAT_RGB565LE,
122          *             MEDIA_PIXEL_FORMAT_BGRA8888, and MEDIA_PIXEL_FORMAT_RGBA8888.
123          */
124         static Tizen::Base::ByteBuffer*
125                 DecodeRegionToBufferN(const Tizen::Base::ByteBuffer& srcBuf, MediaPixelFormat pixelFormat,
126                                                           int x, int y, int width, int height);
127
128         /**
129          * Gets image informations
130          *
131          * @return  An error code
132          * @param[in]  filePath              The path of image file
133          * @param[out] imFormat              The format of image
134          * @param[out] width                 The width of image
135          * @param[out] height                The height of image
136          * @exception  E_SUCCESS             The method is successful.
137          * @exception  E_UNSUPPORTED_FORMAT  The specified format is not supported.
138          * @exception  E_OUT_OF_MEMORY       The memory is insufficient.
139          * @exception  E_FILE_NOT_FOUND      The specified file cannot be found or accessed.
140          * @exception  E_SYSTEM              A system error has occurred.
141          */
142         static result GetImageInfo(const Tizen::Base::String& filePath, ImageFormat &imgFormat,
143                                                            int &width, int &height);
144
145 // DO NOT USE these APIs outside of Tizen::Media
146         _ImageDecoder(void);
147
148         virtual ~_ImageDecoder(void);
149
150         /**
151          * Initializes this instance of ImageDecode.
152          *
153          * param[in]   srcPath      Source image file path.
154          * param[in]   pixelFormat  Output pixel format.
155          * param[in]   imgFormat    Input image format.
156          * @return      An error code
157          * @exception  E_SUCCESS        The method is successful.
158          * @exception  E_SYSTEM A system error has occurred.
159          */
160         result Construct(const Tizen::Base::String& srcPath,
161                                          MediaPixelFormat pixelFormat = MEDIA_PIXEL_FORMAT_BGRA8888,
162                                          ImageFormat imgFormat = IMG_FORMAT_NONE,
163                                          bool autoRotate = false);
164
165         /**
166          * Initializes this instance of ImageDecode.
167          *
168          * param[in]   srcBuffer                Source image buffer.
169          * param[in]   pixelFormat  Output pixel format.
170          * param[in]   imgFormat    Input image format.
171          * @return         An error code
172          * @exception  E_SUCCESS                The method is successful.
173          * @exception  E_SYSTEM         A system error has occurred.
174          */
175         result Construct(const Tizen::Base::ByteBuffer& srcBuffer,
176                                          MediaPixelFormat pixelFormat = MEDIA_PIXEL_FORMAT_BGRA8888,
177                                          ImageFormat imgFormat = IMG_FORMAT_NONE);
178
179         /**
180          * Decodes image buffer.
181          *
182          * param[out]   outLength       Output buffer length
183          * @return          A byte pointer that contains decoded image data.
184          * @exception   E_SUCCESS       The method is successful.
185          * @remark
186          */
187         byte* DecodeN(int& outLength, ImageScalingMethod scalingMethod = IMAGE_SCALING_METHOD_FAST_BILINEAR);
188
189         /**
190          * Decodes image buffer.
191          *
192          * @return         A ByteBuffer pointer that contains decoded image data.
193          * @exception   E_SUCCESS       The method is successful.
194          * @remark
195          */
196         Tizen::Base::ByteBuffer* DecodeN(void);
197
198         /**
199          * Gets image format
200          *
201          * return    Image format
202          * @exception    E_SUCCESS      The method is successful.
203          * @remark
204          */
205         ImageFormat GetImageFormat(void) const;
206
207         /**
208          * Sets region of decoding
209          *
210          * return     An error code
211          * param[in]   x                x position
212          * param[in]   y            y position
213          * param[in]   width        width of decoding region
214          * param[in]   height       height of decoding region
215          * @exception  E_SUCCESS        The method is successful.
216          * @remark
217          */
218         result SetDecodingRegion(int x, int y, int width, int height);
219
220         /**
221          * Get the demension of decoded image
222          *
223          * return           An error code
224          * param[out]   width       The width of image
225          * param[out]   height      The height of image
226          * @exception   E_SUCCESS       The method is successful.
227          * @remark
228          */
229         result GetDimension(int &width, int &height) const;
230
231         /**
232          * Get pixel format
233          *
234          * return        image pixel format
235          * @exception    E_SUCCESS      The method is successful.
236          * @remark
237          */
238         MediaPixelFormat GetPixelFormat(void) const;
239
240         /**
241          * Set demension of output
242          *
243          * return        An error code
244          * param[in]     width      The width of output image
245          * param[in]     height     The height of output image
246          * @exception    E_SUCCESS      The method is successful.
247          * @remark
248          */
249         result SetOutputDimension(int width, int height, bool keepAspectRatio);
250
251 private:
252         _ImageDecoder(const _ImageDecoder& dec);
253         _ImageDecoder& operator =(const _ImageDecoder& dec);
254
255         static _IImageDecoder* CreateDecoderN(ImageFormat srcFormat);
256
257         //_IImageDecoder* __pDec;
258         std::unique_ptr<_IImageDecoder> __pDec;
259         ImageFormat __imgFormat;
260         struct
261         {
262                 int width;
263                 int height;
264         } __orgDim;
265         struct
266         {
267                 int width;
268                 int height;
269         } __outDim;
270         bool __autoRotate;
271         int __orientationInfo;
272         MediaPixelFormat __pixelFormat;
273         std::unique_ptr<Tizen::Base::ByteBuffer> __pSrcBuf;
274
275 }; // class _ImageDecoder
276
277 }}
278
279 #endif