Add Bitmap::Create overload

Makes use of sheet buffer, sheet buffer size, and custom palette
parameters.
This commit is contained in:
Justin Scofield
2022-07-12 07:41:14 -04:00
parent 48477d001c
commit 40fea79b0e
2 changed files with 14 additions and 0 deletions

View File

@@ -40,10 +40,12 @@ void Bitmap::Create(int width, int height, int depth, uchar *data) {
surface_->pixels = pixel_data_;
}
// Reserve data and draw to surface via pointer
void Bitmap::Create(int width, int height, int depth, int size) {
width_ = width;
height_ = height;
depth_ = depth;
data_size_ = size;
surface_ = SDL_CreateRGBSurfaceWithFormat(0, width, height, depth,
SDL_PIXELFORMAT_INDEX8);
// Default grayscale palette
@@ -57,6 +59,17 @@ void Bitmap::Create(int width, int height, int depth, int size) {
surface_->pixels = pixel_data_;
}
void Bitmap::Create(int width, int height, int depth, uchar *data, int size, const SNESPalette &palette) {
width_ = width;
height_ = height;
depth_ = depth;
pixel_data_ = data;
surface_ = SDL_CreateRGBSurfaceWithFormat(0, width, height, depth,
SDL_PIXELFORMAT_INDEX8);
surface_->format->palette = palette.GetSDL_Palette();
surface_->pixels = pixel_data_;
}
void Bitmap::CreateTexture(std::shared_ptr<SDL_Renderer> renderer) {
texture_ = SDL_CreateTextureFromSurface(renderer.get(), surface_);
}

View File

@@ -19,6 +19,7 @@ class Bitmap {
void Create(int width, int height, int depth, uchar *data);
void Create(int width, int height, int depth, int data_size);
void Create(int width, int height, int depth, uchar *data, int size, const SNESPalette &palette);
void CreateTexture(std::shared_ptr<SDL_Renderer> renderer);
void ApplyPalette(const SNESPalette &palette);