Bitmap class additions

This commit is contained in:
Justin Scofield
2022-08-27 22:07:18 -05:00
parent b2030be95f
commit b65c7893a3
2 changed files with 36 additions and 3 deletions

View File

@@ -33,6 +33,10 @@ Bitmap::Bitmap(int width, int height, int depth, int data_size) {
Create(width, height, depth, data_size);
}
Bitmap::Bitmap(int width, int height, int depth, uchar *data, int data_size) {
Create(width, height, depth, data, data_size);
}
// Pass raw pixel data directly to the surface
void Bitmap::Create(int width, int height, int depth, uchar *data) {
width_ = width;
@@ -62,6 +66,21 @@ void Bitmap::Create(int width, int height, int depth, int size) {
surface_->pixels = pixel_data_;
}
// Pass raw pixel data directly to the surface
void Bitmap::Create(int width, int height, int depth, uchar *data, int size) {
width_ = width;
height_ = height;
depth_ = depth;
pixel_data_ = data;
data_size_ = size;
surface_ = std::unique_ptr<SDL_Surface, sdl_deleter>(
SDL_CreateRGBSurfaceWithFormat(0, width_, height_, depth_,
SDL_PIXELFORMAT_INDEX8),
sdl_deleter());
GrayscalePalette(surface_->format->palette);
surface_->pixels = pixel_data_;
}
// Creates the texture that will be displayed to the screen.
void Bitmap::CreateTexture(std::shared_ptr<SDL_Renderer> renderer) {
texture_ = std::unique_ptr<SDL_Texture, sdl_deleter>(