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 FMediaImageBuffer.h
20 * @brief This is the header file for the %ImageBuffer class.
22 * This header file contains the declarations of the %ImageBuffer class.
25 #ifndef _FMEDIA_IMAGEBUFFER_H_
26 #define _FMEDIA_IMAGEBUFFER_H_
28 #include <FMediaImage.h>
30 namespace Tizen { namespace Media
34 * @brief This class is used for handling decoded image data.
37 * @remarks The minimum dimension for JPEG encoding is 16x16 and for PNG encoding is 8x8.
39 * The %ImageBuffer class is used for handling decoded image data, including image decoding and encoding.
41 * The following example demonstrates how to use the %ImageBuffer class to decode and encode images.
47 using namespace Tizen::Base;
48 using namespace Tizen::Media;
56 // Constructs an image buffer instance with an image file
57 r = img.Construct(Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/test.bmp");
62 // Encodes the image buffer into compressed data
63 r = img.EncodeToFile(Tizen::App::App::GetInstance()->GetAppRootPath()+L"data/test.jpg", IMG_FORMAT_JPG, true, 70);
70 class _OSP_EXPORT_ ImageBuffer
71 : public Tizen::Base::Object
75 * This is the default constructor for this class. @n
76 * The object is not fully constructed after this constructor is called.
77 * For full construction, the Construct() method must be called right after
78 * calling this constructor.
87 * This is the destructor for this class. @n
88 * This destructor overrides Tizen::Base::Object::~Object().
94 virtual ~ImageBuffer(void);
97 * Initializes this instance of %ImageBuffer with the specified parameters.
101 * @return An error code
102 * @param[in] width The width of the image
103 * @param[in] height The height of the image
104 * @param[in] pixelFormat The pixel format of the image should be one of the values returned by the GetSupportedPixelFormatListN() method
105 * @param[in] pData The raw pixel data of the image @n
106 * If this value is not @c null, it is copied into the internal buffer of this instance, and the size of the data must be specified, @n
107 * else the default color data is filled.
108 * @param[in] length The size of the data @n
109 * This value must be set if @c pData is not @c null.
110 * @exception E_SUCCESS The method is successful.
111 * @exception E_INVALID_ARG A specified input parameter is invalid.
112 * @exception E_UNSUPPORTED_FORMAT The specified @c pixelFormat is not supported.
113 * @exception E_OUT_OF_MEMORY The memory is insufficient.
114 * @remarks There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is @c E_OUT_OF_MEMORY or not.
115 * For more information on how to handle the out-of-memory exception, refer <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
116 * @see GetSupportedPixelFormatListN()
118 result Construct(int width, int height, MediaPixelFormat pixelFormat, const byte* pData = null, int length = 0);
121 * Initializes this instance of %ImageBuffer with the decoded data of the given image path.
125 * @return An error code
126 * @param[in] srcImagePath The source image path
127 * @param[in] pDecodingRegion The region that is decoded @n
128 * If @c pDecodingRegion is @c null, then the whole image is decoded.
129 * @param[in] autoRotate If @c true then the image is rotated automatically before decoding based on the EXIF orientation tag @n
130 * If @c false then the image is decoded without rotation.
131 * @exception E_SUCCESS The method is successful.
132 * @exception E_INVALID_ARG A specified input parameter is invalid.
133 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
134 * @exception E_OVERFLOW The specified input instance exceeds the maximum supported file size or dimension.
135 * @exception E_OUT_OF_MEMORY The memory is insufficient.
136 * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed.
137 * @remarks There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is @c E_OUT_OF_MEMORY or not.
138 * For more information on how to handle the out-of-memory exception, refer <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
140 result Construct(const Tizen::Base::String &srcImagePath, const Tizen::Graphics::Rectangle *pDecodingRegion = null, bool autoRotate = true);
143 * Initializes this instance of %ImageBuffer with the decoded data of the given image buffer.
147 * @return An error code
148 * @param[in] srcImageBuf The buffer that contains the compressed image data
149 * @param[in] pDecodingRegion The region that is decoded @n
150 * If @c pDecodingRegion is @c null, then the whole image is decoded.
151 * @param[in] autoRotate If @c true then the image is rotated automatically before decoding based on the EXIF orientation tag @n
152 * If @c false the image is decoded without rotation.
153 * @exception E_SUCCESS The method is successful.
154 * @exception E_INVALID_ARG A specified input parameter is invalid.
155 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
156 * @exception E_OVERFLOW The specified input instance exceeds the maximum supported file size or dimension.
157 * @exception E_OUT_OF_MEMORY The memory is insufficient.
158 * @remarks There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is @c E_OUT_OF_MEMORY or not.
159 * For more information on how to handle the out-of-memory exception, refer <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
161 result Construct(const Tizen::Base::ByteBuffer &srcImageBuf, const Tizen::Graphics::Rectangle *pDecodingRegion = null, bool autoRotate = true);
164 * Initializes this instance of %ImageBuffer with the given bitmap data. @n
165 * The %Construct() method copies the raw RGB data from the @c srcBitmap,
166 * so the dimension of this instance can be different from that of @c srcBitmap, if @c srcBitmap is an auto-scaled bitmap.
170 * @return An error code
171 * @param[in] srcBitmap The source bitmap data
172 * @exception E_SUCCESS The method is successful.
173 * @exception E_INVALID_ARG The specified input parameter is invalid.
174 * @exception E_OVERFLOW The specified input instance exceeds the maximum supported file size or dimension.
175 * @exception E_OUT_OF_MEMORY The memory is insufficient.
177 result Construct(const Tizen::Graphics::Bitmap &srcBitmap);
180 * Initializes this instance of %ImageBuffer that is decoded using the given image path data, with the specified parameters.
184 * @return An error code
185 * @param[in] srcImagePath The source image path
186 * @param[in] destWidth The intended width of the image
187 * @param[in] destHeight The intended height of the image
188 * @param[in] scalingMethod The scaling method
189 * @exception E_SUCCESS The method is successful.
190 * @exception E_INVALID_ARG A specified input parameter is invalid.
191 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
192 * @exception E_OUT_OF_MEMORY The memory is insufficient.
193 * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed.
195 * - There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is @c E_OUT_OF_MEMORY or not.
196 * For more information on how to handle the out-of-memory exception, refer <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
197 * - This method does not retain the aspect ratio of the original image.
199 result Construct(const Tizen::Base::String &srcImagePath, int destWidth, int destHeight, ImageScalingMethod scalingMethod);
202 * Initializes this instance of %ImageBuffer that is decoded using the given image buffer data, with the specified parameters.
206 * @return An error code
207 * @param[in] srcImageBuf The buffer that contains the compressed image data
208 * @param[in] destWidth The intended width of the image
209 * @param[in] destHeight The intended height of the image
210 * @param[in] scalingMethod The scaling method
211 * @exception E_SUCCESS The method is successful.
212 * @exception E_INVALID_ARG A specified input parameter is invalid.
213 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
214 * @exception E_OUT_OF_MEMORY The memory is insufficient.
216 * - There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is @c E_OUT_OF_MEMORY or not.
217 * For more information on how to handle the out-of-memory exception, refer <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
218 * - This method does not retain the aspect ratio of the original image.
220 result Construct(const Tizen::Base::ByteBuffer &srcImageBuf, int destWidth, int destHeight, ImageScalingMethod scalingMethod);
223 * Gets the current exif orientation of the image data. @n
224 * If automatic rotation is enabled during the Construct() method then the orientation is reset to the default value.
228 * @return The orientation information of the current image data
230 ExifOrientation GetExifOrientation(void) const;
234 * Compares the specified Tizen::Base::Object instance with the current %ImageBuffer instance.
238 * @return @c true if the value of @c rhs matches the value of the current %ImageBuffer instance, @n
240 * @param[in] rhs A reference to the Tizen::Base::Object instance that is compared with the current %ImageBuffer instance
241 * @see Tizen::Base::Object::Equals()
243 virtual bool Equals(const Object& rhs) const;
246 * Gets the hash value of the current instance by overriding the %GetHashCode() method in the Tizen::Base::Object class.
250 * @return The hash value of the current instance
252 virtual int GetHashCode(void) const;
255 * Gets the height of the image buffer.
259 * @return The height of the image buffer
261 int GetHeight(void) const;
264 * Gets the width of the image buffer.
268 * @return The width of the image buffer
270 int GetWidth(void) const;
273 * Gets the current pixel format.
277 * @return The pixel format of the media
279 MediaPixelFormat GetPixelFormat(void) const;
282 * Encodes the data of this instance into the byte buffer. @n
283 * The supported encoding formats are JPEG, BMP, and PNG.
287 * @return A pointer to the Tizen::Base::ByteBuffer instance that contains the encoded image data
288 * @param[in] destImageFormat The intended image format
289 * @param[in] quality The encoding quality @n
290 * The valid range for this parameter is @c 1 to @c 100.
291 * @exception E_SUCCESS The method is successful.
292 * @exception E_OUT_OF_RANGE A specified input parameter is out of the valid range.
293 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
294 * @exception E_OUT_OF_MEMORY The memory is insufficient.
295 * @remarks The specific error code can be accessed using the GetLastResult() method.
297 Tizen::Base::ByteBuffer* EncodeToBufferN(ImageFormat destImageFormat, int quality = 90) const;
300 * Encodes the data of this instance into the file. @n
301 * The supported encoding formats are JPEG, BMP, and PNG.
305 * @return An error code
306 * @param[in] destImagePath The intended name of the encoded image file
307 * @param[in] destImageFormat The intended image format
308 * @param[in] overwrite Set to @c true to overwrite the file, @n
310 * @param[in] quality The encoding quality @n
311 * The valid range for this parameter is @c 1 to @c 100.
312 * @exception E_SUCCESS The method is successful.
313 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
314 * @exception E_OUT_OF_MEMORY The memory is insufficient.
315 * @exception E_ILLEGAL_ACCESS The specified file cannot be found or accessed.
316 * @exception E_FILE_ALREADY_EXIST The specified file already exists and the value of @c overwrite is @c false.
317 * @exception E_OUT_OF_RANGE A specified input parameter is out of the valid range.
318 * @remarks The application should use the Tizen::Content::ContentManager::CreateContent() method to register the created file into the Contents database.
320 result EncodeToFile(const Tizen::Base::String &destImagePath, ImageFormat destImageFormat, bool overwrite, int quality = 90) const;
323 * Gets an instance of Tizen::Graphics::Bitmap with the data of this instance.
327 * @return A pointer to the Tizen::Graphics::Bitmap instance
328 * @param[in] pixelFormat The bitmap pixel format
329 * @param[in] bufferScaling The buffer scaling type
330 * @exception E_SUCCESS The method is successful.
331 * @exception E_INVALID_ARG A specified input parameter is invalid.
332 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
333 * @exception E_OUT_OF_MEMORY The memory is insufficient.
334 * @remarks The specific error code can be accessed using the GetLastResult() method.
336 Tizen::Graphics::Bitmap* GetBitmapN(Tizen::Graphics::BitmapPixelFormat pixelFormat, Tizen::Graphics::BufferScaling bufferScaling) const;
339 * Gets an instance of Tizen::Graphics::Bitmap with the data of this instance after resizing it as per the specified width and height.
343 * @return A pointer to the Tizen::Graphics::Bitmap instance with the specified destination width and height
344 * @param[in] pixelFormat The bitmap pixel format
345 * @param[in] destWidth The intended width of the image
346 * @param[in] destHeight The intended height of the image
347 * @exception E_SUCCESS The method is successful.
348 * @exception E_INVALID_ARG A specified input parameter is invalid.
349 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
350 * @exception E_OUT_OF_MEMORY The memory is insufficient.
352 * - The specific error code can be accessed using the GetLastResult() method.
353 * - This method returns an auto-scaled bitmap to support the logical coordinate system,
354 * so the actual dimension of the returned bitmap can vary depending on the physical dimension of the target device.
356 Tizen::Graphics::Bitmap* GetBitmapN(Tizen::Graphics::BitmapPixelFormat pixelFormat, float destWidth, float destHeight) const;
359 * Gets an instance of Tizen::Base::ByteBuffer with the data of this instance.
363 * @return A pointer to the Tizen::Base::ByteBuffer instance
364 * @param[in] pixelFormat The pixel format
365 * @exception E_SUCCESS The method is successful.
366 * @exception E_INVALID_ARG The specified input parameter is invalid.
367 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
368 * @exception E_OUT_OF_MEMORY The memory is insufficient.
369 * @remarks The specific error code can be accessed using the GetLastResult() method.
370 * @see GetSupportedPixelFormatListN()
372 Tizen::Base::ByteBuffer* GetByteBufferN(MediaPixelFormat pixelFormat) const;
375 * Creates and returns a copy of the %ImageBuffer instance.
379 * @return A copy of the %ImageBuffer instance
380 * @exception E_SUCCESS The method is successful.
381 * @exception E_OUT_OF_MEMORY The memory is insufficient.
382 * @remarks The specific error code can be accessed using the GetLastResult() method.
384 virtual ImageBuffer* CloneN(void) const;
387 * Gets a new %ImageBuffer with the converted pixel format of the current image data.
391 * @return A pointer to the %ImageBuffer instance that contains the %ImageBuffer which is converted to the specified MediaPixelFormat
392 * @param[in] pixelFormat The pixel format for the returned %ImageBuffer
393 * @exception E_SUCCESS The method is successful.
394 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
395 * @exception E_INVALID_DATA The current data is invalid for this operation. @n
396 * This happens when the @c width or @c height is not an even value,
397 * and the requested pixel format is a sub-sampled pixel format like @c MEDIA_PIXEL_FORMAT_YUV420P.
399 * - The specific error code can be accessed using the GetLastResult() method.
400 * - There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is @c E_OUT_OF_MEMORY or not.
401 * For more information on how to handle the out-of-memory exception, refer <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
403 ImageBuffer* ConvertPixelFormatN(MediaPixelFormat pixelFormat) const;
406 * Gets the resized %ImageBuffer with the current image data. @n
407 * The aspect ratio of the data is not preserved.
411 * @return A pointer to the %ImageBuffer instance that contains the resized image data
412 * @param[in] width The width of the destination image
413 * @param[in] height The height of the destination image
414 * @exception E_SUCCESS The method is successful.
415 * @exception E_OUT_OF_RANGE A specified input parameter is out of the valid range.
416 * @exception E_OUT_OF_MEMORY The memory is insufficient.
417 * @exception E_INVALID_DATA The current data is invalid for this operation. @n
418 * This happens when the current pixel format is a sub-sampled pixel format like @c MEDIA_PIXEL_FORMAT_YUV420P,
419 * and the requested @c width or @c height is not an even value.
421 * - The specific error code can be accessed using the GetLastResult() method.
422 * - There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is @c E_OUT_OF_MEMORY or not.
423 * For more information on how to handle the out-of-memory exception, refer <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
425 ImageBuffer* ResizeN(int width, int height) const;
428 * Gets a horizontally or vertically flipped image from the current instance.
432 * @return A pointer to the %ImageBuffer instance that contains the flipped image data
433 * @param[in] flipType The flip type
434 * @exception E_SUCCESS The method is successful.
435 * @exception E_INVALID_ARG The specified input parameter is invalid.
436 * @exception E_OUT_OF_MEMORY The memory is insufficient.
438 * - The specific error code can be accessed using the GetLastResult() method.
439 * - There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is @c E_OUT_OF_MEMORY or not.
440 * For more information on how to handle the out-of-memory exception, refer <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
442 ImageBuffer* FlipN(ImageFlipType flipType) const;
445 * Rotates the image in the clockwise direction.
449 * @return A pointer to the %ImageBuffer instance that contains the rotated image data
450 * @param[in] rotateType The rotation type
451 * @exception E_SUCCESS The method is successful.
452 * @exception E_INVALID_ARG The specified input parameter is invalid.
453 * @exception E_INVALID_DATA The current data is invalid for this operation. @n
454 * This happens when the current pixel format is a sub-sampled pixel format like @c MEDIA_PIXEL_FORMAT_YUYV422,
455 * the height is an odd value, and the requested rotation type is @c IMAGE_ROTATION_90 or @c IMAGE_ROTATION_270.
456 * @exception E_OUT_OF_MEMORY The memory is insufficient.
458 * - The specific error code can be accessed using the GetLastResult() method.
459 * - There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is @c E_OUT_OF_MEMORY or not.
460 * For more information on how to handle the out-of-memory exception, refer <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
462 ImageBuffer* RotateN(ImageRotationType rotateType) const;
465 * Crops the region of the current %ImageBuffer instance.
469 * @return A pointer to the %ImageBuffer instance that contains the cropped image data
470 * @param[in] x The x position
471 * @param[in] y The y position
472 * @param[in] width The width of the destination image
473 * @param[in] height The height of the destination image
474 * @exception E_SUCCESS The method is successful.
475 * @exception E_OUT_OF_RANGE A specified input parameter is out of the valid range.
476 * @exception E_INVALID_DATA The current data is invalid for this operation. @n
477 * This happens when the current pixel format is a sub-sampled pixel format like @c MEDIA_PIXEL_FORMAT_YUV420P,
478 * and the requested @c x, @c y, @c width, or @c height is not an even value.
480 * - The specific error code can be accessed using the GetLastResult() method.
481 * - There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is @c E_OUT_OF_MEMORY or not.
482 * For more information on how to handle the out-of-memory exception, refer <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
484 ImageBuffer* CropN(int x, int y, int width, int height) const;
487 * Gets the image information.
491 * @return An error code
492 * @param[in] srcImagePath The source image path
493 * @param[out] imageFormat The format of the image
494 * @param[out] width The width of the image
495 * @param[out] height The height of the image
496 * @exception E_SUCCESS The method is successful.
497 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
498 * @exception E_OUT_OF_MEMORY The memory is insufficient.
499 * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed.
500 * @exception E_SYSTEM A system error has occurred.
502 static result GetImageInfo(const Tizen::Base::String& srcImagePath, ImageFormat &imageFormat, int &width, int &height);
505 * Gets the image information.
509 * @return An error code
510 * @param[in] srcImageBuf The buffer that contains the compressed image data
511 * @param[out] imageFormat The format of the image
512 * @param[out] width The width of the image
513 * @param[out] height The height of the image
514 * @exception E_SUCCESS The method is successful.
515 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
516 * @exception E_OUT_OF_MEMORY The memory is insufficient.
517 * @exception E_SYSTEM A system error has occurred.
519 static result GetImageInfo(const Tizen::Base::ByteBuffer& srcImageBuf, ImageFormat &imageFormat, int &width, int &height);
522 * Gets the list of supported pixel formats.
526 * @return The list of supported pixel formats, @n
527 * else @c null if an exception occurs
528 * @exception E_SUCCESS The method is successful.
529 * @exception E_OUT_OF_MEMORY The memory is insufficient.
530 * @exception E_SYSTEM A system error has occurred.
531 * @remarks The specific error code can be accessed using the GetLastResult() method.
533 * @see GetByteBufferN()
535 static Tizen::Base::Collection::IListT<MediaPixelFormat>* GetSupportedPixelFormatListN(void);
540 * The implementation of this copy constructor is intentionally blank
541 * and declared as private to prohibit copying of objects.
543 ImageBuffer(const ImageBuffer& rhs);
546 * The implementation of this copy assignment operator is intentionally blank
547 * and declared as private to prohibit copying of objects.
548 * Use CloneN() to get an exact copy of this instance.
549 * Use Equals() to compare contents of one instance with the other.
551 ImageBuffer& operator =(const ImageBuffer& rhs);
553 friend class _ImageBufferImpl;
554 class _ImageBufferImpl* __pImpl;
559 #endif // _FMEDIA_IMAGEBUFFER_H_