2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 <FGrpDimension.h>
37 #include <FGrpRectangle.h>
38 #include <FGrpColor.h>
39 #include <FGrpBufferInfo.h>
40 #include <FGrpBitmapCommon.h>
42 namespace Tizen { namespace Media
47 namespace Tizen { namespace Graphics
53 * @brief This class encapsulates a bitmap.
57 * @final This class is not intended for extension.
59 * The %Bitmap class encapsulates a bitmap, which consists of the pixel data
60 * for an image and its attributes.
62 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/graphics/bitmap.htm">Bitmaps</a>.
66 class _OSP_EXPORT_ Bitmap
67 : public Tizen::Base::Object
71 * This is the default constructor for this class.
74 * @remarks After creating an instance of this class, one of the
75 * Construct() methods must be called explicitly to initialize this instance.
81 * This is the destructor for this class.
85 virtual ~Bitmap(void);
88 * Initializes this instance of %Bitmap by copying a rectangular area of the Frame.
92 * @return An error code
93 * @param[in] rect The rectangular area of the Frame to be copied into bitmap @n
94 * The width and height of the rectangle must be greater than @c 0. @n
95 * The area defined by @c rect is clipped to the edges of the Frame so that
96 * the rectangle does not fall outside the edges of the Frame. @n
97 * The rectangle must not fall outside the edges of the Frame entirely. @n
98 * If these conditions are not satisfied, an E_OUT_OF_RANGE exception is returned.
99 * @exception E_SUCCESS The method is successful.
100 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
101 * @exception E_INVALID_ARG A specified input parameter is invalid.
104 result Construct(const Rectangle& rect);
107 * Initializes this instance of %Bitmap with the specified dimensions and pixel format.
111 * @return An error code
112 * @param[in] dim The dimensions of the bitmap @n
113 * The width and height must be greater than @c 0.
114 * @param[in] format The pixel format
115 * @exception E_SUCCESS The method is successful.
116 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
117 * @exception E_INVALID_ARG A specified input parameter is invalid.
120 result Construct(const Dimension& dim, BitmapPixelFormat format);
123 * Initializes this instance of %Bitmap by copying the specified rectangular area of the specified canvas.
127 * @return An error code
128 * @param[in] canvas The canvas to copy @n
129 * The canvas must be constructed successfully before it is passed into this method. @n
130 * If not, an E_INVALID_ARG exception is returned.
131 * @param[in] rect The rectangular area of the canvas to be copied into a bitmap @n
132 * The width and height of the rectangle must be greater than @c 0. @n
133 * The rectangle defined by @c rect is clipped to the edges of the canvas so that
134 * the rectangle does not fall outside the edges of the canvas. @n
135 * The rectangle must not fall outside the edges of the canvas entirely. @n
136 * If these conditions are not satisfied, an E_OUT_OF_RANGE exception is returned.
137 * @exception E_SUCCESS The method is successful.
138 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
139 * @exception E_INVALID_ARG A specified input parameter is invalid.
142 result Construct(const Canvas& canvas, const Tizen::Graphics::Rectangle& rect);
145 * Initializes this instance of %Bitmap by copying a rectangular area of the specified bitmap.
149 * @return An error code
150 * @param[in] bitmap The source bitmap @n
151 * The bitmap must be constructed successfully before it is passed into this method. @n
152 * If not, an E_INVALID_ARG exception is returned.
153 * @param[in] rect The rectangular area of the source bitmap to be copied into this bitmap @n
154 * The width and height of the rectangle must be greater than @c 0. @n
155 * The rectangle defined by @c rect is clipped to the edges of the source bitmap so that
156 * the rectangle does not fall outside the edges of the source bitmap. @n
157 * The rectangle must not fall outside the edges of the source bitmap entirely. @n
158 * If these conditions are not satisfied, an E_OUT_OF_RANGE exception is returned.
159 * @exception E_SUCCESS The method is successful.
160 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
161 * @exception E_INVALID_ARG A specified input parameter is invalid.
164 result Construct(const Bitmap& bitmap, const Tizen::Graphics::Rectangle& rect);
167 * Initializes this instance of %Bitmap by using a buffer that contains raw data.
171 * @return An error code
172 * @param[in] buffer The buffer containing raw data
173 * @param[in] dim The dimensions of the bitmap @n
174 * The width and height must be greater than @c 0.
175 * @param[in] pixelFormat The pixel format of raw data
176 * @exception E_SUCCESS The method is successful.
177 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
178 * @exception E_INVALID_ARG A specified input parameter is invalid.
179 * @remarks The position property of ByteBuffer can be changed.
182 result Construct(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat);
185 * Initializes this instance of %Bitmap by using a buffer that contains raw data.
189 * @return An error code
190 * @param[in] buffer The buffer containing raw data
191 * @param[in] dim The dimensions of the bitmap @n
192 * The width and height must be greater than @c 0.
193 * @param[in] pixelFormat The pixel format of raw data
194 * @param[in] bufferScaling The buffer scaling type
195 * @exception E_SUCCESS The method is successful.
196 * @exception E_INVALID_ARG The specified input parameter is invalid.
197 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
198 * @remarks The position property of %ByteBuffer can be changed.
201 result Construct(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat, BufferScaling bufferScaling);
205 * Scales the bitmap to the specified width and height.
209 * @return An error code
210 * @param[in] dim The dimensions of the specified rectangular area @n
211 * The width and height must be greater than @c 0.
212 * @exception E_SUCCESS The method is successful.
213 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
216 result Scale(const Dimension& dim);
219 * Merges the specified area of the source bitmap into the calling bitmap at the given Point.
223 * @return An error code
224 * @param[in] destPoint The X and Y coordinate of the top-left corner of the destination area in the calling bitmap instance
225 * @param[in] srcBitmap The source bitmap instance to copy from
226 * @param[in] srcRect The rectangular area to copy from the source bitmap @n
227 The width and height of the rectangle must be greater than or equal to @c 0.
228 * @exception E_SUCCESS The method is successful.
229 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred: @n
230 * - The value of the argument is outside the valid range defined by the method. @n
231 * - The destX, destY, srcX, or srcY has a negative value. @n
232 * - The specified @c srcWidth or @c srcHeight is less than @c 0.
233 * @exception E_INVALID_ARG A specified input parameter is invalid.
236 result Merge(const Point& destPoint, const Bitmap& srcBitmap, const Rectangle& srcRect);
239 * Gets the height of the bitmap.
243 * @return The height of the bitmap, @n
244 * else @c -1 if the method fails
247 int GetHeight(void) const;
250 * Gets the width of the bitmap.
254 * @return The width of the bitmap, @n
255 * else @c -1 if the method fails
258 int GetWidth(void) const;
261 * Gets the number of bits per pixel of the bitmap.
265 * @return The bits per pixel, @n
266 * else @c -1 if the method fails
269 int GetBitsPerPixel(void) const;
272 * Gets the pixel color format of the bitmap.
276 * @return The pixel color format
279 BitmapPixelFormat GetPixelColorFormat(void) const;
282 * Sets the scaling quality to be used for bitmap scaling.
286 * @return An error code
287 * @param[in] quality The scaling quality to use for bitmap scaling.
288 * @exception E_SUCCESS The method is successful.
289 * @exception E_INVALID_ARG A specified input parameter is invalid.
292 result SetScalingQuality(BitmapScalingQuality quality);
295 * Gets the current scaling quality.
299 * @return The scaling quality
300 * @remarks The default value is BITMAP_SCALING_QUALITY_LOW.
303 BitmapScalingQuality GetScalingQuality(void) const;
306 * Sets the specified color as masking color. @n
307 * All pixels with this color are treated as transparent.
311 * @return An error code
312 * @param[in] pColor The color that is treated as transparent @n
313 * If the parameter is set to @c null, the masking color is removed from this bitmap. @n
314 * Only BitmapPixelFormat::BITMAP_PIXEL_FORMAT_RGB565 is supported.
315 * @exception E_SUCCESS The method is successful.
316 * @exception E_INVALID_ARG A specified input parameter is invalid.
319 result SetMaskingColor(const Color* pColor);
322 * Gets a masking color.
326 * @return An error code
327 * @param[out] color The color that is treated as transparent
328 * @exception E_SUCCESS The method is successful.
329 * @exception E_INVALID_DATA The masking color is not defined.
332 result GetMaskingColor(Color& color) const;
335 * Sets the alpha constant.
338 * @param[in] opacity The opacity of the bitmap @n
339 * This value ranges from @c 0 to @c 255.
340 * @remarks The alpha constant is used for the Canvas::DrawBitmap() method.
342 void SetAlphaConstant(int opacity);
345 * Gets the alpha constant.
349 * @return The alpha constant, @n
350 * else @c -1 if the method fails
352 int GetAlphaConstant(void) const;
355 * Checks whether the instance is nine patched bitmap.
359 * @return @c true if the instance is nine patched bitmap, @n
362 bool IsNinePatchedBitmap(void) const;
365 * Locks a bitmap for direct pixel access. @n
366 * It sets up a bitmap for accessing the pixels directly. Between the calls to Bitmap::Lock and Bitmap::Unlock,
367 * you can write to and read from the bitmap's pixels. After you are done accessing the bitmap's pixels,
368 * you must call Bitmap::Unlock to release the lock.
372 * @return An error code
373 * @param[out] info The extra information of the bitmap
374 * @param[in] timeout The time in milliseconds @n
375 * This value determines the time the caller waits for the lock to be obtained. @n
376 * If the lock attempt fails, E_TIMEOUT is returned. @n
377 * The default value is @c INFINITE, which means that the method does not return a value until the lock is acquired.
378 * @exception E_SUCCESS The method is successful.
379 * @exception E_TIMEOUT The operation is not completed within the specified time period.
380 * @exception E_SYSTEM An unknown operating system error has occurred.
383 result Lock(BufferInfo& info, long timeout = INFINITE);
386 * Unlocks a bitmap. @n
387 * A bitmap that is locked using Bitmap::Lock() must be unlocked using Bitmap::Unlock().
388 * The bitmap buffer can be modified when the bitmap is locked, but is applied only when the bitmap is unlocked.
389 * Therefore, all locked bitmap operations can only be used after the bitmap is unlocked using Bitmap::Unlock().
393 * @return An error code
394 * @exception E_SUCCESS The method is successful.
395 * @exception E_SYSTEM An unknown operating system error has occurred.
401 * Gets a non scaled bitmap.
405 * @return The non scaled bitmap, @n
406 * else @c null if an exception occurs
407 * @param[in] buffer The buffer containing raw data
408 * @param[in] dim The dimensions of the bitmap @n
409 * The width and height must be greater than @c 0.
410 * @param[in] pixelFormat The pixel format of raw data
411 * @exception E_SUCCESS The method is successful.
412 * @exception E_INVALID_ARG The specified input parameter is invalid.
413 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
415 * @remarks The specific error code can be accessed using the GetLastResult() method.
417 static Bitmap* GetNonScaledBitmapN(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat);
421 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
423 Bitmap(const Bitmap& rhs);
426 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
428 Bitmap& operator =(const Bitmap& rhs);
431 // This method is for internal use only.
432 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
434 // Initializes this instance of %Bitmap by using a buffer that contains raw data.
438 // @return An error code
439 // @param[in] buffer The buffer containing raw bitmap data
440 // @param[in] dim The dimensions of the bitmap @n
441 // The width and height must be greater than @c 0.
442 // @param[in] pixelFormat The pixel format of the raw bitmap buffer
443 // @param[in] autoScaling Set to @c true to automatically scale the bitmap, @n
445 // @exception E_SUCCESS The method is successful.
446 // @exception E_INVALID_ARG A specified input parameter is invalid.
447 // @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
449 result Construct(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat, bool autoScaling);
452 // This method is for internal use only.
453 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
455 // Initializes this instance of %Bitmap by using a buffer that contains raw data.
459 // @return An error code
460 // @param[in] pBuffer A pointer to the raw bitmap buffer
461 // @param[in] bufferSize The size of the raw bitmap buffer
462 // @param[in] dim The dimensions of the bitmap @n
463 // The width and height must be greater than @c 0.
464 // @param[in] pixelFormat The pixel format of the raw bitmap buffer
465 // @param[in] autoScaling Set to @c true to automatically scale the bitmap, @n
467 // @exception E_SUCCESS The method is successful.
468 // @exception E_INVALID_ARG A specified input parameter is invalid.
469 // @exception E_UNSUPPORTED_FORMAT The specified format is not supported
471 result Construct(const byte* pBuffer, int bufferSize, const Dimension& dim, BitmapPixelFormat pixelFormat, bool autoScaling);
474 friend class Tizen::Media::Image;
477 friend class _BitmapImpl;
480 // This variable is for internal use only.
481 // Using this variable can cause behavioral, security-related, and consistency-related issues in the application.
485 class _BitmapImpl* __pImpl;
489 }} // Tizen::Graphics
491 #endif //_FGRP_BITMAP_H_