Add copy and move constructors to Bitmap class for better resource management
- Implemented a copy constructor and copy assignment operator to enable deep copying of Bitmap objects. - Added move constructor and move assignment operator to optimize resource handling and prevent unnecessary data duplication. - Introduced SetPixel method for modifying individual pixels in the bitmap. - Added Resize method to adjust bitmap dimensions while preserving existing pixel data, enhancing flexibility in bitmap manipulation.
This commit is contained in:
@@ -71,6 +71,31 @@ class Bitmap {
|
||||
Bitmap(int width, int height, int depth, const std::vector<uint8_t> &data,
|
||||
const SnesPalette &palette);
|
||||
|
||||
/**
|
||||
* @brief Copy constructor - creates a deep copy
|
||||
*/
|
||||
Bitmap(const Bitmap& other);
|
||||
|
||||
/**
|
||||
* @brief Copy assignment operator
|
||||
*/
|
||||
Bitmap& operator=(const Bitmap& other);
|
||||
|
||||
/**
|
||||
* @brief Move constructor
|
||||
*/
|
||||
Bitmap(Bitmap&& other) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Move assignment operator
|
||||
*/
|
||||
Bitmap& operator=(Bitmap&& other) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~Bitmap() = default;
|
||||
|
||||
/**
|
||||
* @brief Create a bitmap with the given dimensions and data
|
||||
*/
|
||||
@@ -134,6 +159,16 @@ class Bitmap {
|
||||
*/
|
||||
void WriteColor(int position, const ImVec4 &color);
|
||||
|
||||
/**
|
||||
* @brief Set a pixel at the given x,y coordinates
|
||||
*/
|
||||
void SetPixel(int x, int y, const SnesColor& color);
|
||||
|
||||
/**
|
||||
* @brief Resize the bitmap to new dimensions
|
||||
*/
|
||||
void Resize(int new_width, int new_height);
|
||||
|
||||
/**
|
||||
* @brief Extract an 8x8 tile from the bitmap
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user