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 converting the color space of the image, flipping, rotating, or resizing.
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 height of the source and destination images @n
130 * The value of the width and 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 The specified width and height are invalid, or the size of @c srcBuf or @c destBuf is insufficient.
134 * @exception E_INVALID_DATA A source image data in the buffer is invalid.
135 * @exception E_OUT_OF_MEMORY The memory is insufficient.
136 * @exception E_SYSTEM A system error has occurred.
137 * @remarks The supported pixel formats are @c MEDIA_PIXEL_FORMAT_RGB565LE, @c MEDIA_PIXEL_FORMAT_BGRA8888, and @c MEDIA_PIXEL_FORMAT_YUV420P. @n
138 * The conversion is possible between: @n
139 * - @c MEDIA_PIXEL_FORMAT_YUV420P and @c MEDIA_PIXEL_FORMAT_RGB565LE. @n
140 * - @c MEDIA_PIXEL_FORMAT_YUV420P and @c MEDIA_PIXEL_FORMAT_BGRA8888. @n
141 * The position and limit of @c destBuf are set along with the size of the converted data.
143 static result ConvertPixelFormat(const Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& destBuf, MediaPixelFormat srcPixelFormat, MediaPixelFormat destPixelFormat, const Tizen::Graphics::Dimension& dim);
150 * @return An error code
151 * @param[in] srcBuf The source buffer
152 * @param[out] destBuf The destination buffer
153 * @param[in] srcDim The width and height of the source image @n
154 * The value of the width and height must be greater than or equal to @c 1.
155 * @param[in] destDim The width and height of the destination image @n
156 * The value of the width and height must be greater than or equal to @c 1.
157 * @param[in] pixelFormat The source and destination pixel format
158 * @exception E_SUCCESS The method is successful.
159 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
160 * @exception E_INVALID_ARG The specified width and height are invalid, or the size of @c srcBuf or @c destBuf is insufficient.
161 * @exception E_INVALID_DATA A source image data in the buffer is invalid.
162 * @exception E_OUT_OF_MEMORY The memory is insufficient.
163 * @exception E_SYSTEM A system error has occurred.
164 * @remarks The supported pixel formats are @c MEDIA_PIXEL_FORMAT_RGB565LE, @c MEDIA_PIXEL_FORMAT_BGRA8888, and @c MEDIA_PIXEL_FORMAT_YUV420P. @n
165 * The position and limit of @c destBuf are set along with the size of the resized data. @n
166 * The minimum resolution is 16x16.
168 static result Resize(const Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& destBuf, const Tizen::Graphics::Dimension& srcDim, const Tizen::Graphics::Dimension& destDim, MediaPixelFormat pixelFormat);
175 * @return An error code
176 * @param[in] srcBuf The source buffer
177 * @param[out] destBuf The destination buffer
178 * @param[in] dim The width and height of the source image @n
179 * The value of the width and height must be equal to or greater than @c 1.
180 * @param[in] rotate The rotation type
181 * @param[in] pixelFormat The source and destination pixel formats
182 * @exception E_SUCCESS The method is successful.
183 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
184 * @exception E_INVALID_ARG The specified width and height are invalid, or the size of @c srcBuf or @c destBuf is insufficient.
185 * @exception E_INVALID_DATA A source image data in the buffer is invalid.
186 * @exception E_OUT_OF_MEMORY The memory is insufficient.
187 * @exception E_SYSTEM A system error has occurred.
188 * @remarks The supported pixel formats are @c MEDIA_PIXEL_FORMAT_RGB565LE, @c MEDIA_PIXEL_FORMAT_BGRA8888, and @c MEDIA_PIXEL_FORMAT_YUV420P. @n
189 * The position and limit of @c destBuf are set along with the size of the rotated data. @n
190 * The dimension of the destination buffer must be calculated by an application.
191 * @see ImageRotationType
193 static result Rotate(const Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& destBuf, const Tizen::Graphics::Dimension& dim, ImageRotationType rotate, MediaPixelFormat pixelFormat);
200 * @return An error code
201 * @param[in] srcBuf The source buffer
202 * @param[out] destBuf The destination buffer
203 * @param[in] dim The width and height of the source and destination images @n
204 * The value of the width and height must be equal to or greater than @c 1.
205 * @param[in] flip The flip type
206 * @param[in] pixelFormat The source and destination pixel formats
207 * @exception E_SUCCESS The method is successful.
208 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
209 * @exception E_INVALID_ARG The specified width and height are invalid, or the size of @c srcBuf or @c destBuf is insufficient.
210 * @exception E_INVALID_DATA A source image data in the buffer is invalid.
211 * @exception E_OUT_OF_MEMORY The memory is insufficient.
212 * @exception E_SYSTEM A system error has occurred.
213 * @remarks The supported pixel formats are @c MEDIA_PIXEL_FORMAT_RGB565LE, @c MEDIA_PIXEL_FORMAT_BGRA8888, and @c MEDIA_PIXEL_FORMAT_YUV420P. @n
214 * The position and limit of @c destBuf are set along with the size of the flipped data.
217 static result Flip(const Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& destBuf, const Tizen::Graphics::Dimension& dim, ImageFlipType flip, MediaPixelFormat pixelFormat);
222 * This default constructor is intentionally declared as private because
223 * this class cannot be constructed.
228 * This destructor is intentionally declared as private because this class
229 * cannot be constructed.
231 virtual ~ImageUtil(void);
234 * The implementation of this copy constructor is intentionally blank
235 * and declared as private to prohibit copying of objects.
237 ImageUtil(const ImageUtil& image);
240 * The implementation of this copy assignment operator is intentionally blank
241 * and declared as private to prohibit copying of objects.
243 ImageUtil& operator =(const ImageUtil& image);
245 }; // class ImageUtil
249 #endif // _FMEDIA_IMAGEUTIL_H_