2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FMedia_ImageDecoder.h
20 * @brief This is the header file for the _ImageDecoder.
23 #ifndef _FMEDIA_INTERNAL_IMAGE_DECODER_H_
24 #define _FMEDIA_INTERNAL_IMAGE_DECODER_H_
26 #include <unique_ptr.h>
27 #include <FBaseObject.h>
28 #include <FMediaImageTypes.h>
30 namespace Tizen { namespace Base {
35 namespace Tizen { namespace Media
41 * @class _ImageDecoder
42 * @brief This class provides internal APIs for image decoding.
44 * This class provides internal methods for image decoding.
46 class _OSP_EXPORT_ _ImageDecoder
47 : virtual public Tizen::Base::Object
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.
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.
71 static Tizen::Base::ByteBuffer*
72 DecodeToBufferN(const Tizen::Base::String& filePath, MediaPixelFormat pixelFormat,
73 int &width, int &height, bool autoRotate = false);
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.
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.
98 static Tizen::Base::ByteBuffer*
99 DecodeRegionToBufferN(const Tizen::Base::String& filePath, MediaPixelFormat pixelFormat,
100 int x, int y, int width, int height);
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.
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.
124 static Tizen::Base::ByteBuffer*
125 DecodeRegionToBufferN(const Tizen::Base::ByteBuffer& srcBuf, MediaPixelFormat pixelFormat,
126 int x, int y, int width, int height);
129 * Gets image informations
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.
142 static result GetImageInfo(const Tizen::Base::String& filePath, ImageFormat &imgFormat,
143 int &width, int &height);
145 // DO NOT USE these APIs outside of Tizen::Media
148 virtual ~_ImageDecoder(void);
151 * Initializes this instance of ImageDecode.
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.
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);
166 * Initializes this instance of ImageDecode.
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.
175 result Construct(const Tizen::Base::ByteBuffer& srcBuffer,
176 MediaPixelFormat pixelFormat = MEDIA_PIXEL_FORMAT_BGRA8888,
177 ImageFormat imgFormat = IMG_FORMAT_NONE);
180 * Decodes image buffer.
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.
187 byte* DecodeN(int& outLength, ImageScalingMethod scalingMethod = IMAGE_SCALING_METHOD_FAST_BILINEAR);
190 * Decodes image buffer.
192 * @return A ByteBuffer pointer that contains decoded image data.
193 * @exception E_SUCCESS The method is successful.
196 Tizen::Base::ByteBuffer* DecodeN(void);
201 * return Image format
202 * @exception E_SUCCESS The method is successful.
205 ImageFormat GetImageFormat(void) const;
208 * Sets region of decoding
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.
218 result SetDecodingRegion(int x, int y, int width, int height);
221 * Get the demension of decoded image
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.
229 result GetDimension(int &width, int &height) const;
234 * return image pixel format
235 * @exception E_SUCCESS The method is successful.
238 MediaPixelFormat GetPixelFormat(void) const;
244 * @exception E_SUCCESS The method is successful.
245 * @remark Used to get decoder specific values, such as duration,
246 * transparency etc for gif decoder.
248 result GetValue(const Tizen::Base::String& key, Tizen::Base::Object &value);
251 * Set demension of output
253 * return An error code
254 * param[in] width The width of output image
255 * param[in] height The height of output image
256 * @exception E_SUCCESS The method is successful.
259 result SetOutputDimension(int width, int height, bool keepAspectRatio);
262 _ImageDecoder(const _ImageDecoder& dec);
263 _ImageDecoder& operator =(const _ImageDecoder& dec);
265 static _IImageDecoder* CreateDecoderN(ImageFormat srcFormat);
267 //_IImageDecoder* __pDec;
268 std::unique_ptr<_IImageDecoder> __pDec;
269 ImageFormat __imgFormat;
281 int __orientationInfo;
282 MediaPixelFormat __pixelFormat;
283 std::unique_ptr<Tizen::Base::ByteBuffer> __pSrcBuf;
285 }; // class _ImageDecoder