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:
scawful
2025-09-23 22:01:06 -04:00
parent edaf6427c8
commit 223544fa01
2 changed files with 189 additions and 0 deletions

View File

@@ -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
*/