79 lines
1.7 KiB
C++
79 lines
1.7 KiB
C++
#include "Bitmap.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
|
|
Bitmap::~Bitmap() {
|
|
clear();
|
|
}
|
|
|
|
Bitmap::Bitmap(const Bitmap &other) {
|
|
copyFrom(other);
|
|
}
|
|
|
|
Bitmap & Bitmap::operator=(const Bitmap &other) {
|
|
if (this != &other) {
|
|
clear();
|
|
copyFrom(other);
|
|
}
|
|
|
|
return *this;
|
|
}
|
|
|
|
Bitmap::Bitmap(Bitmap &&other) noexcept {
|
|
moveFrom(std::move(other));
|
|
}
|
|
|
|
Bitmap & Bitmap::operator=(Bitmap &&other) noexcept {
|
|
moveFrom(std::move(other));
|
|
|
|
return *this;
|
|
}
|
|
|
|
Bitmap::Bitmap(uint16_t width, uint16_t height)
|
|
: _width(width), _height(height), _data(new uint8_t[width * height]) {
|
|
}
|
|
|
|
Bitmap::Bitmap(uint16_t width, uint16_t height, uint8_t *data) : Bitmap(width, height) {
|
|
memcpy(_data, data, width * height);
|
|
}
|
|
|
|
void Bitmap::SetPaletteEntry(uint8_t index, Video::PaletteEntry entry) {
|
|
_pal[index] = entry;
|
|
}
|
|
|
|
Video::PaletteEntry Bitmap::GetPaletteEntry(uint8_t index) const {
|
|
return _pal[index];
|
|
}
|
|
|
|
void Bitmap::clear() {
|
|
delete[] _data;
|
|
_data = nullptr;
|
|
_width = _height = 0;
|
|
}
|
|
|
|
void Bitmap::copyFrom(const Bitmap &other) {
|
|
_width = other._width;
|
|
_height = other._height;
|
|
_data = new uint8_t[_width * _height];
|
|
for (auto i = 0; i < 256; i++) _pal[i] = other._pal[i];
|
|
|
|
memcpy(_data, other._data, _width * _height);
|
|
}
|
|
|
|
void Bitmap::moveFrom(Bitmap &&other) noexcept {
|
|
// Clear existing data
|
|
clear();
|
|
|
|
// Copy data from other
|
|
_data = other._data;
|
|
_width = other._width;
|
|
_height = other._height;
|
|
for (auto i = 0; i < 256; i++) _pal[i] = other._pal[i];
|
|
|
|
// Clear other
|
|
other._data = nullptr;
|
|
other._width = other._height = 0;
|
|
}
|