2 // Open Service Platform
3 // Copyright (c) 2012-2013 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.
20 * @brief This is the header file for the %Bitmap class.
22 * This header file contains the declarations of the %Bitmap class. @n
23 * The class encapsulates a bitmap, which consists of the pixel data
24 * for a graphics image and its attributes.
28 #ifndef _FGRP_BITMAP_H_
29 #define _FGRP_BITMAP_H_
33 #include <FBaseObject.h>
34 #include <FBaseByteBuffer.h>
35 #include <FGrpPoint.h>
36 #include <FGrpFloatPoint.h>
37 #include <FGrpDimension.h>
38 #include <FGrpFloatDimension.h>
39 #include <FGrpRectangle.h>
40 #include <FGrpFloatRectangle.h>
41 #include <FGrpColor.h>
42 #include <FGrpBufferInfo.h>
43 #include <FGrpBitmapCommon.h>
45 namespace Tizen { namespace Media
50 namespace Tizen { namespace Graphics
56 * @brief This class encapsulates a bitmap.
60 * @final This class is not intended for extension.
62 * The %Bitmap class encapsulates a bitmap, which consists of the pixel data
63 * for an image and its attributes.
65 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/graphics/bitmap.htm">Bitmaps</a>.
69 class _OSP_EXPORT_ Bitmap
70 : public Tizen::Base::Object
74 * This is the default constructor for this class.
77 * @remarks After creating an instance of this class, one of the
78 * Construct() methods must be called explicitly to initialize this instance.
84 * This is the destructor for this class.
88 virtual ~Bitmap(void);
91 * Initializes this instance of %Bitmap by copying a rectangular area of the Frame.
95 * @return An error code
96 * @param[in] rect The rectangular area of the Frame to copy into bitmap @n
97 * The width and height of the rectangle must be greater than @c 0. @n
98 * The area defined by @c rect is clipped to the edges of the Frame so that
99 * the rectangle does not fall outside the edges of the Frame. @n
100 * The rectangle must not fall outside the edges of the Frame entirely. @n
101 * If these conditions are not satisfied, an @c E_OUT_OF_RANGE exception is returned.
102 * @exception E_SUCCESS The method is successful.
103 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
104 * @exception E_INVALID_ARG A specified input parameter is invalid.
107 result Construct(const Rectangle& rect);
110 * Initializes this instance of %Bitmap with the specified dimensions and pixel format.
114 * @return An error code
115 * @param[in] dim The dimensions of the bitmap @n
116 * The width and height must be greater than @c 0.
117 * @param[in] format The pixel format
118 * @exception E_SUCCESS The method is successful.
119 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
120 * @exception E_INVALID_ARG A specified input parameter is invalid.
123 result Construct(const Dimension& dim, BitmapPixelFormat format);
126 * Initializes this instance of %Bitmap by copying the specified rectangular area of the specified canvas.
130 * @return An error code
131 * @param[in] canvas The canvas to copy @n
132 * The canvas must be constructed successfully before it is passed into this method. @n
133 * If not, an @c E_INVALID_ARG exception is returned.
134 * @param[in] rect The rectangular area of the canvas to copy into a bitmap @n
135 * The width and height of the rectangle must be greater than @c 0. @n
136 * The rectangle defined by @c rect is clipped to the edges of the canvas so that
137 * the rectangle does not fall outside the edges of the canvas. @n
138 * The rectangle must not fall outside the edges of the canvas entirely. @n
139 * If these conditions are not satisfied, an @c E_OUT_OF_RANGE exception is returned.
140 * @exception E_SUCCESS The method is successful.
141 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
142 * @exception E_INVALID_ARG A specified input parameter is invalid.
145 result Construct(const Canvas& canvas, const Tizen::Graphics::Rectangle& rect);
148 * Initializes this instance of %Bitmap by copying a rectangular area of the specified bitmap.
152 * @return An error code
153 * @param[in] bitmap The source bitmap @n
154 * The bitmap must be constructed successfully before it is passed into this method. @n
155 * If not, an @c E_INVALID_ARG exception is returned.
156 * @param[in] rect The rectangular area of the source bitmap to copy into this bitmap @n
157 * The width and height of the rectangle must be greater than @c 0. @n
158 * The rectangle defined by @c rect is clipped to the edges of the source bitmap so that
159 * the rectangle does not fall outside the edges of the source bitmap. @n
160 * The rectangle must not fall outside the edges of the source bitmap entirely. @n
161 * If these conditions are not satisfied, an @c E_OUT_OF_RANGE exception is returned.
162 * @exception E_SUCCESS The method is successful.
163 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
164 * @exception E_INVALID_ARG A specified input parameter is invalid.
167 result Construct(const Bitmap& bitmap, const Tizen::Graphics::Rectangle& rect);
170 * Initializes this instance of %Bitmap by using a buffer that contains raw data.
174 * @return An error code
175 * @param[in] buffer The buffer containing raw data
176 * @param[in] dim The dimensions of the bitmap @n
177 * The width and height must be greater than @c 0.
178 * @param[in] pixelFormat The pixel format of raw data
179 * @exception E_SUCCESS The method is successful.
180 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
181 * @exception E_INVALID_ARG A specified input parameter is invalid.
182 * @remarks The position property of ByteBuffer can be changed.
185 result Construct(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat);
188 * Initializes this instance of %Bitmap by using a buffer that contains raw data.
192 * @return An error code
193 * @param[in] buffer The buffer containing raw data
194 * @param[in] dim The dimensions of the bitmap @n
195 * The width and height must be greater than @c 0.
196 * @param[in] pixelFormat The pixel format of raw data
197 * @param[in] bufferScaling The buffer scaling type
198 * @exception E_SUCCESS The method is successful.
199 * @exception E_INVALID_ARG The specified input parameter is invalid.
200 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
201 * @remarks The position property of %ByteBuffer can be changed.
204 result Construct(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat, BufferScaling bufferScaling);
207 * Initializes this instance of %Bitmap by copying a rectangular area of the Frame.
211 * @return An error code
212 * @param[in] rect The rectangular area of the frame that is copied into bitmap @n
213 * The width and height of the rectangle must be greater than @c 0. @n
214 * The area defined by @c rect is clipped to the edges of the frame so that
215 * the rectangle does not fall outside the edges of the frame. @n
216 * The rectangle must not fall outside the edges of the frame entirely. @n
217 * If these conditions are not satisfied, an @c E_OUT_OF_RANGE exception is returned.
218 * @exception E_SUCCESS The method is successful.
219 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
220 * @exception E_INVALID_ARG A specified input parameter is invalid.
223 result Construct(const FloatRectangle& rect);
226 * Initializes this instance of %Bitmap with the specified dimensions and pixel format.
230 * @return An error code
231 * @param[in] dim The dimensions of the bitmap @n
232 * The width and height must be greater than @c 0.
233 * @param[in] format The pixel format
234 * @exception E_SUCCESS The method is successful.
235 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
236 * @exception E_INVALID_ARG A specified input parameter is invalid.
239 result Construct(const FloatDimension& dim, BitmapPixelFormat format);
242 * Initializes this instance of %Bitmap by copying a specified rectangular area of a specified canvas.
246 * @return An error code
247 * @param[in] canvas The canvas to copy @n
248 * The canvas must be constructed successfully before it is passed into this method. @n
249 * If not, an @c E_INVALID_ARG exception is returned.
250 * @param[in] rect The rectangular area of the canvas that is copied into a bitmap @n
251 * The width and height of the rectangle must be greater than @c 0. @n
252 * The rectangle defined by @c rect is clipped to the edges of the canvas so that
253 * the rectangle does not fall outside the edges of the canvas. @n
254 * The rectangle must not fall outside the edges of the canvas entirely. @n
255 * If these conditions are not satisfied, an @c E_OUT_OF_RANGE exception is returned.
256 * @exception E_SUCCESS The method is successful.
257 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
258 * @exception E_INVALID_ARG A specified input parameter is invalid.
261 result Construct(const Canvas& canvas, const FloatRectangle& rect);
264 * Initializes this instance of %Bitmap by copying a rectangular area of a specified bitmap.
268 * @return An error code
269 * @param[in] bitmap The source bitmap @n
270 * The bitmap must be constructed successfully before it is passed into this method. @n
271 * If not, an @c E_INVALID_ARG exception is returned.
272 * @param[in] rect The rectangular area of the source bitmap that is copied into this bitmap @n
273 * The width and height of the rectangle must be greater than @c 0. @n
274 * The rectangle defined by @c rect is clipped to the edges of the source bitmap so that
275 * the rectangle does not fall outside the edges of the source bitmap. @n
276 * The rectangle must not fall outside the edges of the source bitmap entirely. @n
277 * If these conditions are not satisfied, an @c E_OUT_OF_RANGE exception is returned.
278 * @exception E_SUCCESS The method is successful.
279 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
280 * @exception E_INVALID_ARG A specified input parameter is invalid.
283 result Construct(const Bitmap& bitmap, const FloatRectangle& rect);
287 * Scales the bitmap to the specified width and height.
291 * @return An error code
292 * @param[in] dim The dimensions of the specified rectangular area @n
293 * The width and height must be greater than @c 0.
294 * @exception E_SUCCESS The method is successful.
295 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
298 result Scale(const Dimension& dim);
301 * Scales the bitmap to a specified width and height.
305 * @return An error code
306 * @param[in] dim The dimensions of the specified rectangular area @n
307 * The width and height must be greater than @c 0.
308 * @exception E_SUCCESS The method is successful.
309 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
312 result Scale(const FloatDimension& dim);
315 * Merges the specified area of the source bitmap into the calling bitmap at the given Point.
319 * @return An error code
320 * @param[in] destPoint The X and Y coordinate of the top-left corner of the destination area in the calling bitmap instance
321 * @param[in] srcBitmap The source bitmap instance to copy from
322 * @param[in] srcRect The rectangular area to copy from the source bitmap @n
323 The width and height of the rectangle must be greater than or equal to @c 0.
324 * @exception E_SUCCESS The method is successful.
325 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred: @n
326 * - The value of the argument is outside the valid range defined by the method. @n
327 * - The destX, destY, srcX, or srcY has a negative value. @n
328 * @exception E_INVALID_ARG A specified input parameter is invalid.
331 result Merge(const Point& destPoint, const Bitmap& srcBitmap, const Rectangle& srcRect);
334 * Merges a specified area of the source bitmap into the calling bitmap at a given point.
338 * @return An error code
339 * @param[in] destPoint The X and Y coordinate of the top-left corner of the destination area in the calling bitmap instance
340 * @param[in] srcBitmap The source bitmap instance to copy from
341 * @param[in] srcRect The rectangular area to copy from the source bitmap @n
342 * The width and height of the rectangle must be greater than or equal to @c 0.
343 * @exception E_SUCCESS The method is successful.
344 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred: @n
345 * - The value of the argument is outside the valid range defined by the method. @n
346 * - The destX, destY, srcX, or srcY has a negative value. @n
347 * @exception E_INVALID_ARG A specified input parameter is invalid.
350 result Merge(const FloatPoint& destPoint, const Bitmap& srcBitmap, const FloatRectangle& srcRect);
353 * Gets the height of the bitmap.
357 * @return The height of the bitmap, @n
358 * else @c -1 if the method fails
361 int GetHeight(void) const;
364 * Gets the height of the bitmap.
368 * @return The height of the bitmap, @n
369 * else @c -1 if the method fails
372 float GetHeightF(void) const;
375 * Gets the actual height of the bitmap.
379 * @return The actual height of the bitmap, @n
380 * else @c -1.0f if the method fails
383 float GetActualHeight(void) const;
386 * Gets the width of the bitmap.
390 * @return The width of the bitmap, @n
391 * else @c -1 if the method fails
394 int GetWidth(void) const;
397 * Gets the width of the bitmap.
401 * @return The width of the bitmap, @n
402 * else @c -1 if the method fails
405 float GetWidthF(void) const;
408 * Gets the actual width of the bitmap.
412 * @return The actual width of the bitmap, @n
413 * else @c -1.0f if the method fails
416 float GetActualWidth(void) const;
419 * Gets the number of bits per pixel of the bitmap.
423 * @return The bits per pixel, @n
424 * else @c -1 if the method fails
427 int GetBitsPerPixel(void) const;
430 * Gets the pixel color format of the bitmap.
434 * @return The pixel color format
437 BitmapPixelFormat GetPixelColorFormat(void) const;
440 * Sets the scaling quality to be used for bitmap scaling.
444 * @return An error code
445 * @param[in] quality The scaling quality to use for bitmap scaling.
446 * @exception E_SUCCESS The method is successful.
447 * @exception E_INVALID_ARG A specified input parameter is invalid.
450 result SetScalingQuality(BitmapScalingQuality quality);
453 * Gets the current scaling quality.
457 * @return The scaling quality
458 * @remarks The default value is @c BITMAP_SCALING_QUALITY_LOW.
461 BitmapScalingQuality GetScalingQuality(void) const;
464 * Sets the specified color as masking color. @n
465 * All pixels with this color are treated as transparent.
469 * @return An error code
470 * @param[in] pColor The color that is treated as transparent @n
471 * If the parameter is set to @c null, the masking color is removed from this bitmap. @n
472 * Only ::BITMAP_PIXEL_FORMAT_RGB565 is supported.
473 * @exception E_SUCCESS The method is successful.
474 * @exception E_INVALID_ARG A specified input parameter is invalid.
477 result SetMaskingColor(const Color* pColor);
480 * Gets a masking color.
484 * @return An error code
485 * @param[out] color The color that is treated as transparent
486 * @exception E_SUCCESS The method is successful.
487 * @exception E_INVALID_DATA The masking color is not defined.
490 result GetMaskingColor(Color& color) const;
493 * Sets the alpha constant.
496 * @param[in] opacity The opacity of the bitmap @n
497 * This value ranges from @c 0 to @c 255.
498 * @remarks The alpha constant is used for the Canvas::DrawBitmap() method.
500 void SetAlphaConstant(int opacity);
503 * Gets the alpha constant.
507 * @return The alpha constant, @n
508 * else @c -1 if the method fails
510 int GetAlphaConstant(void) const;
513 * Checks whether the instance is nine patched bitmap.
517 * @return @c true if the instance is nine patched bitmap, @n
520 bool IsNinePatchedBitmap(void) const;
523 * Locks a bitmap for direct pixel access. @n
524 * It sets up a bitmap for accessing the pixels directly. Between the calls to Bitmap::Lock() and Bitmap::Unlock(),
525 * you can write to and read from the bitmap's pixels. After you are done accessing the bitmap's pixels,
526 * you must call %Bitmap::Unlock() to release the lock.
530 * @return An error code
531 * @param[out] info The extra information of the bitmap
532 * @param[in] timeout The time in milliseconds @n
533 * This value determines the time the caller waits for the lock to be obtained. @n
534 * If the lock attempt fails, @c E_TIMEOUT is returned. @n
535 * The default value is @c INFINITE, which means that the method does not return a value until the lock is acquired.
536 * @exception E_SUCCESS The method is successful.
537 * @exception E_TIMEOUT The operation is not completed within the specified time period.
538 * @exception E_SYSTEM An unknown operating system error has occurred.
541 result Lock(BufferInfo& info, long timeout = INFINITE);
544 * Unlocks a bitmap. @n
545 * A bitmap that is locked using Bitmap::Lock() must be unlocked using Bitmap::Unlock().
546 * The bitmap buffer can be modified when the bitmap is locked, but is applied only when the bitmap is unlocked.
547 * Therefore, all locked bitmap operations can only be used after the bitmap is unlocked using %Bitmap::Unlock().
551 * @return An error code
552 * @exception E_SUCCESS The method is successful.
553 * @exception E_SYSTEM An unknown operating system error has occurred.
559 * Gets a non scaled bitmap.
563 * @return The non scaled bitmap, @n
564 * else @c null if an exception occurs
565 * @param[in] buffer The buffer containing raw data
566 * @param[in] dim The dimensions of the bitmap @n
567 * The width and height must be greater than @c 0.
568 * @param[in] pixelFormat The pixel format of raw data
569 * @exception E_SUCCESS The method is successful.
570 * @exception E_INVALID_ARG The specified input parameter is invalid.
571 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
573 * @remarks The specific error code can be accessed using the GetLastResult() method.
575 static Bitmap* GetNonScaledBitmapN(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat);
579 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
581 Bitmap(const Bitmap& rhs);
584 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
586 Bitmap& operator =(const Bitmap& rhs);
589 // This method is for internal use only.
590 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
592 // Initializes this instance of %Bitmap by using a buffer that contains raw data.
596 // @return An error code
597 // @param[in] buffer The buffer containing raw bitmap data
598 // @param[in] dim The dimensions of the bitmap @n
599 // The width and height must be greater than @c 0.
600 // @param[in] pixelFormat The pixel format of the raw bitmap buffer
601 // @param[in] autoScaling Set to @c true to automatically scale the bitmap, @n
603 // @exception E_SUCCESS The method is successful.
604 // @exception E_INVALID_ARG A specified input parameter is invalid.
605 // @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
607 result Construct(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat, bool autoScaling);
610 // This method is for internal use only.
611 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
613 // Initializes this instance of %Bitmap by using a buffer that contains raw data.
617 // @return An error code
618 // @param[in] pBuffer A pointer to the raw bitmap buffer
619 // @param[in] bufferSize The size of the raw bitmap buffer
620 // @param[in] dim The dimensions of the bitmap @n
621 // The width and height must be greater than @c 0.
622 // @param[in] pixelFormat The pixel format of the raw bitmap buffer
623 // @param[in] autoScaling Set to @c true to automatically scale the bitmap, @n
625 // @exception E_SUCCESS The method is successful.
626 // @exception E_INVALID_ARG A specified input parameter is invalid.
627 // @exception E_UNSUPPORTED_FORMAT The specified format is not supported
629 result Construct(const byte* pBuffer, int bufferSize, const Dimension& dim, BitmapPixelFormat pixelFormat, bool autoScaling);
632 friend class Tizen::Media::Image;
635 friend class _BitmapImpl;
638 // This variable is for internal use only.
639 // Using this variable can cause behavioral, security-related, and consistency-related issues in the application.
643 class _BitmapImpl* __pImpl;
647 }} // Tizen::Graphics
649 #endif //_FGRP_BITMAP_H_