cleanup bitmap class
This commit is contained in:
@@ -505,7 +505,7 @@ absl::Status GraphicsEditor::DrawCgxImport() {
|
|||||||
status_ = gfx::scad_format::LoadCgx(current_bpp_, cgx_file_path_, cgx_data_,
|
status_ = gfx::scad_format::LoadCgx(current_bpp_, cgx_file_path_, cgx_data_,
|
||||||
decoded_cgx_, extra_cgx_data_);
|
decoded_cgx_, extra_cgx_data_);
|
||||||
|
|
||||||
cgx_bitmap_.InitializeFromData(0x80, 0x200, 8, decoded_cgx_);
|
cgx_bitmap_.Create(0x80, 0x200, 8, decoded_cgx_);
|
||||||
if (col_file_) {
|
if (col_file_) {
|
||||||
cgx_bitmap_.ApplyPalette(decoded_col_);
|
cgx_bitmap_.ApplyPalette(decoded_col_);
|
||||||
rom()->RenderBitmap(&cgx_bitmap_);
|
rom()->RenderBitmap(&cgx_bitmap_);
|
||||||
@@ -540,7 +540,7 @@ absl::Status GraphicsEditor::DrawScrImport() {
|
|||||||
status_ = gfx::scad_format::DrawScrWithCgx(current_bpp_, scr_data_,
|
status_ = gfx::scad_format::DrawScrWithCgx(current_bpp_, scr_data_,
|
||||||
decoded_scr_data_, decoded_cgx_);
|
decoded_scr_data_, decoded_cgx_);
|
||||||
|
|
||||||
scr_bitmap_.InitializeFromData(0x100, 0x100, 8, decoded_scr_data_);
|
scr_bitmap_.Create(0x100, 0x100, 8, decoded_scr_data_);
|
||||||
if (scr_loaded_) {
|
if (scr_loaded_) {
|
||||||
scr_bitmap_.ApplyPalette(decoded_col_);
|
scr_bitmap_.ApplyPalette(decoded_col_);
|
||||||
rom()->RenderBitmap(&scr_bitmap_);
|
rom()->RenderBitmap(&scr_bitmap_);
|
||||||
|
|||||||
@@ -184,24 +184,7 @@ void ConvertPngToSurface(const std::vector<uint8_t> &png_data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bitmap::Bitmap(int width, int height, int depth, int data_size) {
|
Bitmap::Bitmap(int width, int height, int depth, int data_size) {
|
||||||
Create(width, height, depth, data_size);
|
Create(width, height, depth, Bytes(data_size, 0));
|
||||||
}
|
|
||||||
|
|
||||||
// Reserves data to later draw to surface via pointer
|
|
||||||
void Bitmap::Create(int width, int height, int depth, int size) {
|
|
||||||
active_ = true;
|
|
||||||
width_ = width;
|
|
||||||
height_ = height;
|
|
||||||
depth_ = depth;
|
|
||||||
data_size_ = size;
|
|
||||||
data_.reserve(size);
|
|
||||||
pixel_data_ = data_.data();
|
|
||||||
surface_ = std::unique_ptr<SDL_Surface, SDL_Surface_Deleter>(
|
|
||||||
SDL_CreateRGBSurfaceWithFormat(0, width, height, depth,
|
|
||||||
SDL_PIXELFORMAT_INDEX8),
|
|
||||||
SDL_Surface_Deleter());
|
|
||||||
surface_->pixels = pixel_data_;
|
|
||||||
GrayscalePalette(surface_->format->palette);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bitmap::Create(int width, int height, int depth, const Bytes &data) {
|
void Bitmap::Create(int width, int height, int depth, const Bytes &data) {
|
||||||
@@ -219,9 +202,7 @@ void Bitmap::Create(int width, int height, int depth, const Bytes &data) {
|
|||||||
GrayscalePalette(surface_->format->palette);
|
GrayscalePalette(surface_->format->palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates the texture that will be displayed to the screen.
|
|
||||||
void Bitmap::CreateTexture(SDL_Renderer *renderer) {
|
void Bitmap::CreateTexture(SDL_Renderer *renderer) {
|
||||||
// Ensure width and height are non-zero
|
|
||||||
if (width_ <= 0 || height_ <= 0) {
|
if (width_ <= 0 || height_ <= 0) {
|
||||||
SDL_Log("Invalid texture dimensions: width=%d, height=%d\n", width_,
|
SDL_Log("Invalid texture dimensions: width=%d, height=%d\n", width_,
|
||||||
height_);
|
height_);
|
||||||
@@ -239,11 +220,9 @@ void Bitmap::CreateTexture(SDL_Renderer *renderer) {
|
|||||||
SDL_Surface *converted_surface =
|
SDL_Surface *converted_surface =
|
||||||
SDL_ConvertSurfaceFormat(surface_.get(), SDL_PIXELFORMAT_ARGB8888, 0);
|
SDL_ConvertSurfaceFormat(surface_.get(), SDL_PIXELFORMAT_ARGB8888, 0);
|
||||||
if (converted_surface) {
|
if (converted_surface) {
|
||||||
// Create texture from the converted surface
|
|
||||||
converted_surface_ = std::unique_ptr<SDL_Surface, SDL_Surface_Deleter>(
|
converted_surface_ = std::unique_ptr<SDL_Surface, SDL_Surface_Deleter>(
|
||||||
converted_surface, SDL_Surface_Deleter());
|
converted_surface, SDL_Surface_Deleter());
|
||||||
} else {
|
} else {
|
||||||
// Handle the error
|
|
||||||
SDL_Log("SDL_ConvertSurfaceFormat failed: %s\n", SDL_GetError());
|
SDL_Log("SDL_ConvertSurfaceFormat failed: %s\n", SDL_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,11 +239,9 @@ void Bitmap::UpdateTexture(SDL_Renderer *renderer, bool use_sdl_update) {
|
|||||||
SDL_Surface *converted_surface =
|
SDL_Surface *converted_surface =
|
||||||
SDL_ConvertSurfaceFormat(surface_.get(), SDL_PIXELFORMAT_ARGB8888, 0);
|
SDL_ConvertSurfaceFormat(surface_.get(), SDL_PIXELFORMAT_ARGB8888, 0);
|
||||||
if (converted_surface) {
|
if (converted_surface) {
|
||||||
// Create texture from the converted surface
|
|
||||||
converted_surface_ = std::unique_ptr<SDL_Surface, SDL_Surface_Deleter>(
|
converted_surface_ = std::unique_ptr<SDL_Surface, SDL_Surface_Deleter>(
|
||||||
converted_surface, SDL_Surface_Deleter());
|
converted_surface, SDL_Surface_Deleter());
|
||||||
} else {
|
} else {
|
||||||
// Handle the error
|
|
||||||
SDL_Log("SDL_ConvertSurfaceFormat failed: %s\n", SDL_GetError());
|
SDL_Log("SDL_ConvertSurfaceFormat failed: %s\n", SDL_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +263,6 @@ void Bitmap::UpdateTexture(SDL_Renderer *renderer, bool use_sdl_update) {
|
|||||||
SDL_UnlockTexture(texture_.get());
|
SDL_UnlockTexture(texture_.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates the texture that will be displayed to the screen.
|
|
||||||
void Bitmap::CreateTexture(std::shared_ptr<SDL_Renderer> renderer) {
|
void Bitmap::CreateTexture(std::shared_ptr<SDL_Renderer> renderer) {
|
||||||
texture_ = std::shared_ptr<SDL_Texture>{
|
texture_ = std::shared_ptr<SDL_Texture>{
|
||||||
SDL_CreateTextureFromSurface(renderer.get(), surface_.get()),
|
SDL_CreateTextureFromSurface(renderer.get(), surface_.get()),
|
||||||
@@ -421,25 +397,6 @@ void Bitmap::ApplyPalette(const std::vector<SDL_Color> &palette) {
|
|||||||
SDL_LockSurface(surface_.get());
|
SDL_LockSurface(surface_.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bitmap::InitializeFromData(uint32_t width, uint32_t height, uint32_t depth,
|
|
||||||
const Bytes &data) {
|
|
||||||
active_ = true;
|
|
||||||
width_ = width;
|
|
||||||
height_ = height;
|
|
||||||
depth_ = depth;
|
|
||||||
data_ = data;
|
|
||||||
data_size_ = data.size();
|
|
||||||
pixel_data_ = data_.data();
|
|
||||||
|
|
||||||
surface_ = std::unique_ptr<SDL_Surface, SDL_Surface_Deleter>(
|
|
||||||
SDL_CreateRGBSurfaceWithFormat(0, width_, height_, depth_,
|
|
||||||
SDL_PIXELFORMAT_INDEX8),
|
|
||||||
SDL_Surface_Deleter());
|
|
||||||
|
|
||||||
surface_->pixels = pixel_data_;
|
|
||||||
GrayscalePalette(surface_->format->palette);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace gfx
|
} // namespace gfx
|
||||||
} // namespace app
|
} // namespace app
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class Bitmap {
|
|||||||
Bitmap(int width, int height, int depth, int data_size);
|
Bitmap(int width, int height, int depth, int data_size);
|
||||||
Bitmap(int width, int height, int depth, const Bytes &data)
|
Bitmap(int width, int height, int depth, const Bytes &data)
|
||||||
: width_(width), height_(height), depth_(depth), data_(data) {
|
: width_(width), height_(height), depth_(depth), data_(data) {
|
||||||
InitializeFromData(width, height, depth, data);
|
Create(width, height, depth, data);
|
||||||
}
|
}
|
||||||
Bitmap(int width, int height, int depth, const Bytes &data,
|
Bitmap(int width, int height, int depth, const Bytes &data,
|
||||||
const SnesPalette &palette)
|
const SnesPalette &palette)
|
||||||
@@ -57,24 +57,17 @@ class Bitmap {
|
|||||||
depth_(depth),
|
depth_(depth),
|
||||||
data_(data),
|
data_(data),
|
||||||
palette_(palette) {
|
palette_(palette) {
|
||||||
InitializeFromData(width, height, depth, data);
|
Create(width, height, depth, data);
|
||||||
if (!ApplyPalette(palette).ok()) {
|
if (!ApplyPalette(palette).ok()) {
|
||||||
std::cerr << "Error applying palette in bitmap constructor." << std::endl;
|
std::cerr << "Error applying palette in bitmap constructor." << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a bitmap object and reserves space for graphical data.
|
|
||||||
*/
|
|
||||||
void Create(int width, int height, int depth, int data_size);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Creates a bitmap object with the provided graphical data.
|
* @brief Creates a bitmap object with the provided graphical data.
|
||||||
*/
|
*/
|
||||||
void Create(int width, int height, int depth, const Bytes &data);
|
void Create(int width, int height, int depth, const Bytes &data);
|
||||||
|
|
||||||
void InitializeFromData(uint32_t width, uint32_t height, uint32_t depth,
|
|
||||||
const Bytes &data);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Creates the underlying SDL_Texture to be displayed.
|
* @brief Creates the underlying SDL_Texture to be displayed.
|
||||||
|
|||||||
@@ -13,13 +13,11 @@ namespace zelda3 {
|
|||||||
namespace screen {
|
namespace screen {
|
||||||
|
|
||||||
void TitleScreen::Create() {
|
void TitleScreen::Create() {
|
||||||
tiles8Bitmap.Create(128, 512, 8, 0x20000);
|
tiles8Bitmap.Create(128, 512, 8, Bytes(0, 0x20000));
|
||||||
tilesBG1Bitmap.Create(256, 256, 8, 0x80000);
|
tilesBG1Bitmap.Create(256, 256, 8, Bytes(0, 0x80000));
|
||||||
tilesBG2Bitmap.Create(256, 256, 8, 0x80000);
|
tilesBG2Bitmap.Create(256, 256, 8, Bytes(0, 0x80000));
|
||||||
oamBGBitmap.Create(256, 256, 8, 0x80000);
|
oamBGBitmap.Create(256, 256, 8, Bytes(0, 0x80000));
|
||||||
|
|
||||||
BuildTileset();
|
BuildTileset();
|
||||||
|
|
||||||
LoadTitleScreen();
|
LoadTitleScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user