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 FMediaImageUtil.h
20 * @brief This is the header file for the %ImageUtil class.
22 * This header file contains the declarations of the %ImageUtil class.
25 #ifndef _FMEDIA_IMAGE_UTIL_H_
26 #define _FMEDIA_IMAGE_UTIL_H_
29 #include <FGraphics.h>
31 #include <FMediaTypes.h>
32 #include <FMediaImageTypes.h>
34 namespace Tizen { namespace Media
41 * @brief This class provides methods for flipping, rotating, resizing, and converting the color space of an image.
45 * The %ImageUtil class provides methods for image pixel format conversion, and image scaling, such as resizing, rotating, and flipping.
47 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/media/viewing_processing_still_images.htm">Viewing and Processing Still Images</a>.
49 * The following example demonstrates how to use the %ImageUtil class.
56 #include <FGraphics.h>
59 using namespace Tizen::Base;
60 using namespace Tizen::Graphics;
61 using namespace Tizen::Media;
66 ByteBuffer yuvBuf, rgbBuf;
69 int width = 320, height = 240;
70 int yuvBufSize = width * height * 3 / 2;
71 int rgbBufSize = width * height * 4;
73 Dimension dim(width, height);
74 String filePath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/test.jpg";
76 pBuf = new byte[yuvBufSize];
78 // Fills source buffer with a 2x2 checkboard
79 for (int j = 0; j < height; j++)
81 for (int i = 0; i < width; i++)
83 pBuf[j * width + i] = (((i >= width / 2) + (j >= height / 2)) & 1) ? 255 : 0; // Y
86 memset(pBuf + width * height, 128, width * height / 4); // Cb
87 memset(pBuf + width * height * 5 / 4, 128, width * height / 4); // Cr
89 // Creates yuv and rgb buffers
90 yuvBuf.Construct(pBuf, 0, yuvBufSize, yuvBufSize);
91 yuvBuf.SetPosition(0);
92 yuvBuf.SetLimit(yuvBufSize);
94 rgbBuf.Construct(rgbBufSize);
95 rgbBuf.SetPosition(0);
96 rgbBuf.SetLimit(rgbBufSize);
100 // Converts pixel format
101 ImageUtil::ConvertPixelFormat(yuvBuf, rgbBuf, MEDIA_PIXEL_FORMAT_YUV420P, MEDIA_PIXEL_FORMAT_BGRA8888, dim);
103 // Makes a Bitmap with converted rgb data
104 bitmap.Construct(rgbBuf, dim, BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
105 image.EncodeToFile(bitmap, IMG_FORMAT_JPG, filePath, true);
115 class _OSP_EXPORT_ ImageUtil
120 * Converts the pixel format of the image.
124 * @return An error code
125 * @param[in] srcBuf The source buffer
126 * @param[out] destBuf The destination buffer
127 * @param[in] srcPixelFormat The source pixel format
128 * @param[in] destPixelFormat The destination pixel format
129 * @param[in] dim The width and the height of the source and the destination images @n
130 * The values of the width and the height must be greater than or equal to @c 1.
131 * @exception E_SUCCESS The method is successful.
132 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
133 * @exception E_INVALID_ARG Either of the following conditions has occurred:
134 * - The specified width and height are invalid.
135 * - The size of the specified @c srcBuf or the specified @c destBuf is insufficient.
136 * @exception E_INVALID_DATA The source image data in the buffer is invalid.
137 * @exception E_OUT_OF_MEMORY The memory is insufficient.
138 * @exception E_SYSTEM A system error has occurred.
140 * - The supported pixel formats are @c MEDIA_PIXEL_FORMAT_RGB565LE, @c MEDIA_PIXEL_FORMAT_BGRA8888, and @c MEDIA_PIXEL_FORMAT_YUV420P.
141 * - The conversion is possible between:
142 * - @c MEDIA_PIXEL_FORMAT_YUV420P and @c MEDIA_PIXEL_FORMAT_RGB565LE.
143 * - @c MEDIA_PIXEL_FORMAT_YUV420P and @c MEDIA_PIXEL_FORMAT_BGRA8888.
144 * - The position and the limit of @c destBuf are set along with the size of the converted data.
146 static result ConvertPixelFormat(const Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& destBuf, MediaPixelFormat srcPixelFormat, MediaPixelFormat destPixelFormat, const Tizen::Graphics::Dimension& dim);
153 * @return An error code
154 * @param[in] srcBuf The source buffer
155 * @param[out] destBuf The destination buffer
156 * @param[in] srcDim The width and the height of the source image @n
157 * The values of the width and the height must be greater than or equal to @c 1.
158 * @param[in] destDim The width and the height of the destination image @n
159 * The values of the width and the height must be greater than or equal to @c 1.
160 * @param[in] pixelFormat The source and the destination pixel format
161 * @exception E_SUCCESS The method is successful.
162 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
163 * @exception E_INVALID_ARG Either of the following conditions has occurred:
164 * - The specified width and height are invalid.
165 * - The size of the specified @c srcBuf or the specified @c destBuf is insufficient.
166 * @exception E_INVALID_DATA The source image data in the buffer is invalid.
167 * @exception E_OUT_OF_MEMORY The memory is insufficient.
168 * @exception E_SYSTEM A system error has occurred.
170 * - The supported pixel formats are @c MEDIA_PIXEL_FORMAT_RGB565LE, @c MEDIA_PIXEL_FORMAT_BGRA8888, and @c MEDIA_PIXEL_FORMAT_YUV420P.
171 * - The position and the limit of @c destBuf are set along with the size of the resized data.
172 * - The minimum resolution is 16x16.
174 static result Resize(const Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& destBuf, const Tizen::Graphics::Dimension& srcDim, const Tizen::Graphics::Dimension& destDim, MediaPixelFormat pixelFormat);
181 * @return An error code
182 * @param[in] srcBuf The source buffer
183 * @param[out] destBuf The destination buffer
184 * @param[in] dim The width and the height of the source image @n
185 * The values of the width and the height must be equal to or greater than @c 1.
186 * @param[in] rotate The rotation type
187 * @param[in] pixelFormat The source and the destination pixel formats
188 * @exception E_SUCCESS The method is successful.
189 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
190 * @exception E_INVALID_ARG Either of the following conditions has occurred:
191 * - The specified width and height are invalid.
192 * - The size of the specified @c srcBuf or the specified @c destBuf is insufficient.
193 * @exception E_INVALID_DATA The source image data in the buffer is invalid.
194 * @exception E_OUT_OF_MEMORY The memory is insufficient.
195 * @exception E_SYSTEM A system error has occurred.
197 * - The supported pixel formats are @c MEDIA_PIXEL_FORMAT_RGB565LE, @c MEDIA_PIXEL_FORMAT_BGRA8888, and @c MEDIA_PIXEL_FORMAT_YUV420P.
198 * - The position and the limit of @c destBuf are set along with the size of the rotated data.
199 * - The dimension of the destination buffer must be calculated by the application.
200 * @see ImageRotationType
202 static result Rotate(const Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& destBuf, const Tizen::Graphics::Dimension& dim, ImageRotationType rotate, MediaPixelFormat pixelFormat);
209 * @return An error code
210 * @param[in] srcBuf The source buffer
211 * @param[out] destBuf The destination buffer
212 * @param[in] dim The width and the height of the source and the destination images @n
213 * The values of the width and the height must be equal to or greater than @c 1.
214 * @param[in] flip The flip type
215 * @param[in] pixelFormat The source and the destination pixel formats
216 * @exception E_SUCCESS The method is successful.
217 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
218 * @exception E_INVALID_ARG Either of the following conditions has occurred:
219 * - The specified width and height are invalid.
220 * - The size of the specified @c srcBuf or the specified @c destBuf is insufficient.
221 * @exception E_INVALID_DATA The source image data in the buffer is invalid.
222 * @exception E_OUT_OF_MEMORY The memory is insufficient.
223 * @exception E_SYSTEM A system error has occurred.
225 * - The supported pixel formats are @c MEDIA_PIXEL_FORMAT_RGB565LE, @c MEDIA_PIXEL_FORMAT_BGRA8888, and @c MEDIA_PIXEL_FORMAT_YUV420P.
226 * - The position and the limit of @c destBuf are set along with the size of the flipped data.
229 static result Flip(const Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& destBuf, const Tizen::Graphics::Dimension& dim, ImageFlipType flip, MediaPixelFormat pixelFormat);
234 * This default constructor is intentionally declared as private because
235 * this class cannot be constructed.
240 * This destructor is intentionally declared as private because this class
241 * cannot be constructed.
243 virtual ~ImageUtil(void);
246 * The implementation of this copy constructor is intentionally blank
247 * and declared as private to prohibit copying of objects.
249 ImageUtil(const ImageUtil& image);
252 * The implementation of this copy assignment operator is intentionally blank
253 * and declared as private to prohibit copying of objects.
255 ImageUtil& operator =(const ImageUtil& image);
257 }; // class ImageUtil
261 #endif // _FMEDIA_IMAGEUTIL_H_