Ocean
wxwidgets/Bitmap.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_PLATFORM_WXWIDGETS_BITMAP_H
9 #define META_OCEAN_PLATFORM_WXWIDGETS_BITMAP_H
10 
12 
13 #include "ocean/base/Frame.h"
14 
15 namespace Ocean
16 {
17 
18 namespace Platform
19 {
20 
21 namespace WxWidgets
22 {
23 
24 /**
25  * This class implements a bitmap.
26  * @ingroup platformwxwidgets
27  */
28 class OCEAN_PLATFORM_WXWIDGETS_EXPORT Bitmap : public wxBitmap
29 {
30  public:
31 
32  /**
33  * Creates an empty bitmap object.
34  */
35  inline Bitmap();
36 
37  /**
38  * Creates bitmap object from a given image object.
39  * @param image The image with either RGB24 or RGBA32 pixel format and upper left pixel origin.
40  * @param scaleFactor The scale factor converting the number of pixels in the (virtual) display coordinate system to the number of pixels in the (native/pyhsical) screen coordinate system, with range (0, infinity)
41  */
42  explicit Bitmap(const wxImage& image, const double scaleFactor = 1.0);
43 
44  /**
45  * Creates a new bitmap object by a given frame.
46  * @param frame The frame from which the bitmap will be created
47  * @param convertIfNecessary True, to convert the given frame type if the frame's type cannot be represented by the bitmap; False, to create an empty bitmap if the type is not supported
48  * @param scaleFactor The scale factor converting the number of pixels in the (virtual) display coordinate system to the number of pixels in the (native/pyhsical) screen coordinate system, with range (0, infinity)
49  */
50  explicit Bitmap(const Frame& frame, const bool convertIfNecessary = true, const double scaleFactor = 1.0);
51 
52  /**
53  * Creates a new bitmap object by a given (optional transparent) frame while the new bitmap will be opaque.
54  * A transparent frame is blended with a specified background color, an opaque frame is simply copied.
55  * @param frame The frame from which the bitmap will be created
56  * @param backgroundColor The background color that is applied if the frame is transparent, ensure that the provided buffer is large enough
57  * @param convertIfNecessary True, to convert the given frame type if the frame's type cannot be represented by the bitmap; False, to create an empty bitmap if the type is not supported
58  * @param scaleFactor The scale factor converting the number of pixels in the (virtual) display coordinate system to the number of pixels in the (native/pyhsical) screen coordinate system, with range (0, infinity)
59  */
60  Bitmap(const Frame& frame, const unsigned char* backgroundColor, const bool convertIfNecessary, const double scaleFactor = 1.0);
61 
62  /**
63  * Replaces this bitmap by a given frame.
64  * @param frame The frame to set, may be invalid
65  * @param convertIfNecessary True, to convert the given frame type if the frame's type cannot be represented by the bitmap; False, to create an empty bitmap if the type is not supported
66  * @param scaleFactor The scale factor converting the number of pixels in the (virtual) display coordinate system to the number of pixels in the (native/pyhsical) screen coordinate system, with range (0, infinity)
67  * @return True, if succeeded
68  */
69  bool setFrame(const Frame& frame, const bool convertIfNecessary = true, const double scaleFactor = 1.0);
70 
71  /**
72  * Replaces this bitmap by a given (optional transparent) frame while the final bitmap is opaque.
73  * Transparent frames are blended with a specified background color, opaque frames are copied directly.
74  * @param frame The frame to set, may be invalid
75  * @param backgroundColor The background color that is applied if the frame is transparent, ensure that the provided buffer is large enough
76  * @param convertIfNecessary True, to convert the given frame type if the frame's type cannot be represented by the bitmap; False, to create an empty bitmap if the type is not supported
77  * @param scaleFactor The scale factor converting the number of pixels in the (virtual) display coordinate system to the number of pixels in the (native/pyhsical) screen coordinate system, with range (0, infinity)
78  * @return True, if succeeded
79  */
80  bool setFrame(const Frame& frame, const unsigned char* backgroundColor, const bool convertIfNecessary = true, const double scaleFactor = 1.0);
81 
82  protected:
83 
84  /**
85  * Replaces this bitmap by a given frame without alpha channel.
86  * @param frame The frame to set, must be valid
87  * @param convertIfNecessary True, to convert the given frame type if the frame's type cannot be represented by the bitmap; False, to create an empty bitmap if the type is not supported
88  * @param scaleFactor The scale factor converting the number of pixels in the (virtual) display coordinate system to the number of pixels in the (native/pyhsical) screen coordinate system, with range (0, infinity)
89  * @return True, if succeeded
90  */
91  bool setFrameWithoutAlpha(const Frame& frame, const bool convertIfNecessary, const double scaleFactor);
92 
93  /**
94  * Replaces this bitmap by a given frame with alpha channel.
95  * @param frame The frame to set, must be valid
96  * @param convertIfNecessary True, to convert the given frame type if the frame's type cannot be represented by the bitmap; False, to create an empty bitmap if the type is not supported
97  * @param scaleFactor The scale factor converting the number of pixels in the (virtual) display coordinate system to the number of pixels in the (native/pyhsical) screen coordinate system, with range (0, infinity)
98  * @return True, if succeeded
99  */
100  bool setFrameWithAlpha(const Frame& frame, const bool convertIfNecessary, const double scaleFactor);
101 };
102 
103 inline Bitmap::Bitmap() :
104  wxBitmap()
105 {
106  // nothing to do here
107 }
108 
109 }
110 
111 }
112 
113 }
114 
115 #endif // META_OCEAN_PLATFORM_WXWIDGETS_BITMAP_H
This class implements Ocean's image class.
Definition: Frame.h:1760
This class implements a bitmap.
Definition: wxwidgets/Bitmap.h:29
Bitmap()
Creates an empty bitmap object.
Definition: wxwidgets/Bitmap.h:103
Bitmap(const Frame &frame, const bool convertIfNecessary=true, const double scaleFactor=1.0)
Creates a new bitmap object by a given frame.
bool setFrameWithAlpha(const Frame &frame, const bool convertIfNecessary, const double scaleFactor)
Replaces this bitmap by a given frame with alpha channel.
Bitmap(const wxImage &image, const double scaleFactor=1.0)
Creates bitmap object from a given image object.
bool setFrame(const Frame &frame, const bool convertIfNecessary=true, const double scaleFactor=1.0)
Replaces this bitmap by a given frame.
Bitmap(const Frame &frame, const unsigned char *backgroundColor, const bool convertIfNecessary, const double scaleFactor=1.0)
Creates a new bitmap object by a given (optional transparent) frame while the new bitmap will be opaq...
bool setFrame(const Frame &frame, const unsigned char *backgroundColor, const bool convertIfNecessary=true, const double scaleFactor=1.0)
Replaces this bitmap by a given (optional transparent) frame while the final bitmap is opaque.
bool setFrameWithoutAlpha(const Frame &frame, const bool convertIfNecessary, const double scaleFactor)
Replaces this bitmap by a given frame without alpha channel.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15