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 is 16x16 for JPEG encoding and 8x8 for PNG encoding.
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 image.
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 GetSupportedPixelFormatListN()
105 * @param[in] pData The raw pixel data of the image @n If @c pData is not @c null, then it is copied into the internal buffer of this instance.
106 * If @c null, then the default color data is filled.
107 * @param[in] length The size of the data
108 * @exception E_SUCCESS The method is successful.
109 * @exception E_INVALID_ARG A specified input parameter is invalid.
110 * @exception E_UNSUPPORTED_FORMAT The specified @c pixelFormat is not supported.
111 * @exception E_OUT_OF_MEMORY The memory is insufficient.
112 * @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.
113 * 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>.
114 * @see GetSupportedPixelFormatListN()
116 result Construct(int width, int height, MediaPixelFormat pixelFormat, const byte* pData = null, int length = 0);
119 * Initializes this instance of %ImageBuffer with the decoded data of the given image path.
123 * @return An error code
124 * @param[in] srcImagePath The source image path
125 * @param[in] pDecodingRegion The region that is decoded @n If this is @c null, then the whole image is decoded.
126 * @param[in] autoRotate If @c true the image is rotated automatically based on the EXIF orientation tag before decoding @n
127 * If @c false the image is decoded without rotation.
128 * @exception E_SUCCESS The method is successful.
129 * @exception E_INVALID_ARG A specified input parameter is invalid.
130 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
131 * @exception E_OVERFLOW The specified input instance exceeds the supported maximum file size or dimension.
132 * @exception E_OUT_OF_MEMORY The memory is insufficient.
133 * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed.
134 * @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.
135 * 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>.
137 result Construct(const Tizen::Base::String &srcImagePath, const Tizen::Graphics::Rectangle *pDecodingRegion = null, bool autoRotate = true);
140 * Initializes this instance of %ImageBuffer with the decoded data of the given image buffer.
144 * @return An error code
145 * @param[in] srcImageBuf The buffer that contains the compressed image data
146 * @param[in] pDecodingRegion The region that is decoded @n If this is @c null, then the whole image is decoded.
147 * @param[in] autoRotate If @c true the image is rotated automatically based on the EXIF orientation tag before decoding @n
148 * If @c false the image is decoded without rotation.
149 * @exception E_SUCCESS The method is successful.
150 * @exception E_INVALID_ARG A specified input parameter is invalid.
151 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
152 * @exception E_OVERFLOW The specified input instance exceeds the supported maximum file size or dimension.
153 * @exception E_OUT_OF_MEMORY The memory is insufficient.
154 * @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.
155 * 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>.
157 result Construct(const Tizen::Base::ByteBuffer &srcImageBuf, const Tizen::Graphics::Rectangle *pDecodingRegion = null, bool autoRotate = true);
160 * Initializes this instance of %ImageBuffer with the given bitmap data. @n
161 * The %Construct() method copies the raw RGB data from the @c srcBitmap,
162 * so the dimension of this instance can be different from that of @c srcBitmap if the @c srcBitmap is an auto-scaled bitmap.
166 * @return An error code
167 * @param[in] srcBitmap The source bitmap data
168 * @exception E_SUCCESS The method is successful.
169 * @exception E_INVALID_ARG The specified input parameter is invalid.
170 * @exception E_OVERFLOW The specified input instance exceeds the supported maximum file size or dimension.
171 * @exception E_OUT_OF_MEMORY The memory is insufficient.
173 result Construct(const Tizen::Graphics::Bitmap &srcBitmap);
176 * Initializes this instance of %ImageBuffer that is decoded with the data of the given image path with the specified parameters.
180 * @return An error code
181 * @param[in] srcImagePath The source image path
182 * @param[in] destWidth The intended width of the image
183 * @param[in] destHeight The intended height of the image
184 * @param[in] scalingMethod The scaling method
185 * @exception E_SUCCESS The method is successful.
186 * @exception E_INVALID_ARG A specified input parameter is invalid.
187 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
188 * @exception E_OUT_OF_MEMORY The memory is insufficient.
189 * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed.
191 * - There is a high probability for an occurrence of an out-of-memory exception.
192 * If possible, check whether the exception is E_OUT_OF_MEMORY or not. @n
193 * For more information on how to handle the out-of-memory exception, refer
194 * <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
195 * - This method does not retain the aspect ratio of the original image.
197 result Construct(const Tizen::Base::String &srcImagePath, int destWidth, int destHeight, ImageScalingMethod scalingMethod);
200 * Initializes this instance of %ImageBuffer that is decoded with the data of the given image buffer with the specified parameters.
204 * @return An error code
205 * @param[in] srcImageBuf The buffer that contains the compressed image data
206 * @param[in] destWidth The intended width of the image
207 * @param[in] destHeight The intended height of the image
208 * @param[in] scalingMethod The scaling method
209 * @exception E_SUCCESS The method is successful.
210 * @exception E_INVALID_ARG A specified input parameter is invalid.
211 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
212 * @exception E_OUT_OF_MEMORY The memory is insufficient.
214 * - There is a high probability for an occurrence of an out-of-memory exception.
215 * If possible, check whether the exception is E_OUT_OF_MEMORY or not. @n
216 * For more information on how to handle the out-of-memory exception, refer
217 * <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 Construct() 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 * Converts an instance of the Tizen::Base::Object class to an instance of %ImageBuffer and then
235 * compares it with the calling %ImageBuffer instance.
239 * @return @c true if the value of @c rhs matches the value of the calling %ImageBuffer instance, @n
241 * @param[in] rhs A reference to the Tizen::Base::Object instance that is to compare with the calling %ImageBuffer instance
242 * @see Tizen::Base::Object::Equals()
244 virtual bool Equals(const Object& rhs) const;
247 * Gets the hash value of the current instance by overriding the GetHashCode() method in the Tizen::Base::Object class.
251 * @return The hash value of the current instance
253 virtual int GetHashCode(void) const;
256 * Gets the height of the image buffer.
260 * @return The height of the image buffer
262 int GetHeight(void) const;
265 * Gets the width of the image buffer.
269 * @return The width of the image buffer
271 int GetWidth(void) const;
274 * Gets the current pixel format.
278 * @return The pixel format of the media
280 MediaPixelFormat GetPixelFormat(void) const;
283 * Encodes the data of this instance into a byte buffer. @n
284 * The supported encoding formats are JPEG, BMP, and PNG.
288 * @return A pointer to the Tizen::Base::ByteBuffer instance containing the encoded image data
289 * @param[in] destImageFormat The intended image format
290 * @param[in] quality The encoding quality @n
291 * Valid range of this parameter is @c 1 to @c 100.
292 * @exception E_SUCCESS The method is successful.
293 * @exception E_OUT_OF_RANGE A specified input parameter is out of range.
294 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
295 * @exception E_OUT_OF_MEMORY The memory is insufficient.
296 * @remarks The specific error code can be accessed using the GetLastResult() method.
298 Tizen::Base::ByteBuffer* EncodeToBufferN(ImageFormat destImageFormat, int quality = 90) const;
301 * Encodes the data of this instance to a file. @n
302 * The supported encoding formats are JPEG, BMP, and PNG.
306 * @return An error code
307 * @param[in] destImagePath The intended name of the encoded image file
308 * @param[in] destImageFormat The intended image format
309 * @param[in] overwrite Set to @c true to overwrite the file, @n
311 * @param[in] quality The encoding quality @n
312 * Valid range of this parameter is @c 1 to @c 100.
313 * @exception E_SUCCESS The method is successful.
314 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
315 * @exception E_OUT_OF_MEMORY The memory is insufficient.
316 * @exception E_ILLEGAL_ACCESS The specified file cannot be found or accessed.
317 * @exception E_FILE_ALREADY_EXIST The specified file already exists and the value of @c overwrite is @c false.
318 * @exception E_OUT_OF_RANGE A specified input parameter is out of range.
319 * @remarks The application should use Tizen::Content::ContentManager::CreateContent() to
320 * register the created file into the Contents database.
322 result EncodeToFile(const Tizen::Base::String &destImagePath, ImageFormat destImageFormat, bool overwrite, int quality = 90) const;
325 * Gets an instance of Tizen::Graphics::Bitmap with the data of this instance.
329 * @return A pointer to the Tizen::Graphics::Bitmap instance
330 * @param[in] pixelFormat The bitmap pixel format
331 * @param[in] bufferScaling The buffer scaling type
332 * @exception E_SUCCESS The method is successful.
333 * @exception E_INVALID_ARG A specified input parameter is invalid.
334 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
335 * @exception E_OUT_OF_MEMORY The memory is insufficient.
336 * @remarks The specific error code can be accessed using the GetLastResult() method.
338 Tizen::Graphics::Bitmap* GetBitmapN(Tizen::Graphics::BitmapPixelFormat pixelFormat, Tizen::Graphics::BufferScaling bufferScaling) const;
341 * Gets an instance of Tizen::Graphics::Bitmap with the data of this instance after resizing it as per the specified width and height
345 * @return A pointer to the Tizen::Graphics::Bitmap instance with the specified destination width and height.
346 * @param[in] pixelFormat The bitmap pixel format
347 * @param[in] destWidth The intended width of the image.
348 * @param[in] destHeight The intended height of the image.
349 * @exception E_SUCCESS The method is successful.
350 * @exception E_INVALID_ARG A specified input parameter is invalid.
351 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
352 * @exception E_OUT_OF_MEMORY The memory is insufficient.
354 * - The specific error code can be accessed using the GetLastResult() method.
355 * - This method returns auto scaled bitmap to support logical coordinate system,
356 * so the actual dimension of the returned bitmap can be vary depending on the physical dimension of target device.
358 Tizen::Graphics::Bitmap* GetBitmapN(Tizen::Graphics::BitmapPixelFormat pixelFormat, float destWidth, float destHeight) const;
361 * Gets an instance of Tizen::Base::ByteBuffer with the data of this instance.
365 * @return A pointer to the Tizen::Base::ByteBuffer instance
366 * @param[in] pixelFormat The pixel format
367 * @exception E_SUCCESS The method is successful.
368 * @exception E_INVALID_ARG The specified input parameter is invalid.
369 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
370 * @exception E_OUT_OF_MEMORY The memory is insufficient.
371 * @remarks The specific error code can be accessed using the GetLastResult() method.
372 * @see GetSupportedPixelFormatListN()
374 Tizen::Base::ByteBuffer* GetByteBufferN(MediaPixelFormat pixelFormat) const;
377 * Creates and returns a copy of this instance.
381 * @return A copy of this instance
382 * @exception E_SUCCESS The method is successful.
383 * @exception E_OUT_OF_MEMORY The memory is insufficient.
384 * @remarks The specific error code can be accessed using the GetLastResult() method.
386 virtual ImageBuffer* CloneN(void) const;
389 * Gets a new %ImageBuffer with the converted pixel format of the current image data.
393 * @return A pointer to the %ImageBuffer instance containing the converted %ImageBuffer by the specified MediaPixelFormat
394 * @param[in] pixelFormat The pixel format for returned %ImageBuffer
395 * @exception E_SUCCESS The method is successful.
396 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
397 * @exception E_INVALID_DATA The current data is invalid for this operation. @n
398 * This will happen when the width or height is not even value,
399 * and the requested pixel format is sub-sampled pixel format like @c MEDIA_PIXEL_FORMAT_YUV420P.
401 * - The specific error code can be accessed using the GetLastResult() method.
402 * - 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.
403 * 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>.
405 ImageBuffer* ConvertPixelFormatN(MediaPixelFormat pixelFormat) const;
408 * Gets a resized %ImageBuffer with the current image data. @n
409 * The aspect ratio of the data will not be preserved.
413 * @return A pointer to the %ImageBuffer instance containing the resized image data
414 * @param[in] width The width of the destination image
415 * @param[in] height The height of the destination image
416 * @exception E_SUCCESS The method is successful.
417 * @exception E_OUT_OF_RANGE A specified input parameter is out of range.
418 * @exception E_OUT_OF_MEMORY The memory is insufficient.
419 * @exception E_INVALID_DATA The current data is invalid for this operation. @n
420 * This will happen when the current pixel format is sub-sampled pixel format like @c MEDIA_PIXEL_FORMAT_YUV420P
421 * and the requested @c width or @c height is not even value.
423 * - The specific error code can be accessed using the GetLastResult() method.
424 * - 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.
425 * 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>.
427 ImageBuffer* ResizeN(int width, int height) const;
430 * Gets a horizontally or vertically flipped image from the current instance.
434 * @return A pointer to the %ImageBuffer instance containing the flipped image data
435 * @param[in] flipType The flip type
436 * @exception E_SUCCESS The method is successful.
437 * @exception E_INVALID_ARG The specified input parameter is invalid.
438 * @exception E_OUT_OF_MEMORY The memory is insufficient.
440 * - The specific error code can be accessed using the GetLastResult() method.
441 * - 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.
442 * 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>.
444 ImageBuffer* FlipN(ImageFlipType flipType) const;
447 * Gets a rotated image in clockwise direction from the current image.
451 * @return A pointer to the %ImageBuffer instance containing the rotated image data
452 * @param[in] rotateType The rotation type
453 * @exception E_SUCCESS The method is successful.
454 * @exception E_INVALID_ARG The specified input parameter is invalid.
455 * @exception E_INVALID_DATA The current data is invalid for this operation. @n
456 * This will happen when the current pixel format is sub-sampled pixel format like @c MEDIA_PIXEL_FORMAT_YUYV422
457 * and the height is odd value and the requested rotation type is @c IMAGE_ROTATION_90 or @c IMAGE_ROTATION_270.
458 * @exception E_OUT_OF_MEMORY The memory is insufficient.
460 * - The specific error code can be accessed using the GetLastResult() method.
461 * - 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.
462 * 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>.
464 ImageBuffer* RotateN(ImageRotationType rotateType) const;
467 * Crops the region of the current %ImageBuffer instance.
471 * @return A pointer to the %ImageBuffer instance containing the cropped image data
472 * @param[in] x The x position
473 * @param[in] y The y position
474 * @param[in] width The width of the destination image
475 * @param[in] height The height of the destination image
476 * @exception E_SUCCESS The method is successful.
477 * @exception E_OUT_OF_RANGE A specified input parameter is out of range.
478 * @exception E_INVALID_DATA The current data is invalid for this operation. @n
479 * This will happen when the current pixel format is sub-sampled pixel format like @c MEDIA_PIXEL_FORMAT_YUV420P
480 * and the requested @c x, @c y, @c width, or @c height is not even value.
482 * - The specific error code can be accessed using the GetLastResult() method.
483 * - 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.
484 * 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>.
486 ImageBuffer* CropN(int x, int y, int width, int height) const;
489 * Gets the image information.
493 * @return An error code
494 * @param[in] srcImagePath The source image path
495 * @param[out] imageFormat The format of the image
496 * @param[out] width The width of the image
497 * @param[out] height The height of the image
498 * @exception E_SUCCESS The method is successful.
499 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
500 * @exception E_OUT_OF_MEMORY The memory is insufficient.
501 * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed.
502 * @exception E_SYSTEM A system error has occurred.
504 static result GetImageInfo(const Tizen::Base::String& srcImagePath, ImageFormat &imageFormat, int &width, int &height);
507 * Gets the image information.
511 * @return An error code
512 * @param[in] srcImageBuf The buffer that contains the compressed image data
513 * @param[out] imageFormat The format of the image
514 * @param[out] width The width of the image
515 * @param[out] height The height of the image
516 * @exception E_SUCCESS The method is successful.
517 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
518 * @exception E_OUT_OF_MEMORY The memory is insufficient.
519 * @exception E_SYSTEM A system error has occurred.
521 static result GetImageInfo(const Tizen::Base::ByteBuffer& srcImageBuf, ImageFormat &imageFormat, int &width, int &height);
524 * Gets a list of the supported pixel formats.
528 * @return A list of the pixel formats supported by the %ImageBuffer class, @n
529 * else @c null if an exception occurs
530 * @exception E_SUCCESS The method is successful.
531 * @exception E_OUT_OF_MEMORY The memory is insufficient.
532 * @exception E_SYSTEM A system error has occurred.
533 * @remarks The specific error code can be accessed using the GetLastResult() method.
535 * @see GetByteBufferN()
537 static Tizen::Base::Collection::IListT<MediaPixelFormat>* GetSupportedPixelFormatListN(void);
542 * The implementation of this copy constructor is intentionally blank
543 * and declared as private to prohibit copying of objects.
545 ImageBuffer(const ImageBuffer& rhs);
548 * The implementation of this copy assignment operator is intentionally blank
549 * and declared as private to prohibit copying of objects.
550 * Use CloneN() to get an exact copy of this instance.
551 * Use Equals() to compare contents of one instance with the other.
553 ImageBuffer& operator =(const ImageBuffer& rhs);
555 friend class _ImageBufferImpl;
556 class _ImageBufferImpl* __pImpl;
561 #endif // _FMEDIA_IMAGEBUFFER_H_