diff --git a/src/app/editor/graphics_editor.cc b/src/app/editor/graphics_editor.cc index 1370471e..974b4831 100644 --- a/src/app/editor/graphics_editor.cc +++ b/src/app/editor/graphics_editor.cc @@ -505,7 +505,7 @@ absl::Status GraphicsEditor::DrawCgxImport() { status_ = gfx::scad_format::LoadCgx(current_bpp_, cgx_file_path_, 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_) { cgx_bitmap_.ApplyPalette(decoded_col_); rom()->RenderBitmap(&cgx_bitmap_); @@ -540,7 +540,7 @@ absl::Status GraphicsEditor::DrawScrImport() { status_ = gfx::scad_format::DrawScrWithCgx(current_bpp_, scr_data_, 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_) { scr_bitmap_.ApplyPalette(decoded_col_); rom()->RenderBitmap(&scr_bitmap_); diff --git a/src/app/gfx/bitmap.cc b/src/app/gfx/bitmap.cc index e61d97b9..3dfcbf0e 100644 --- a/src/app/gfx/bitmap.cc +++ b/src/app/gfx/bitmap.cc @@ -184,24 +184,7 @@ void ConvertPngToSurface(const std::vector &png_data, } Bitmap::Bitmap(int width, int height, int depth, int data_size) { - Create(width, height, depth, data_size); -} - -// 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_CreateRGBSurfaceWithFormat(0, width, height, depth, - SDL_PIXELFORMAT_INDEX8), - SDL_Surface_Deleter()); - surface_->pixels = pixel_data_; - GrayscalePalette(surface_->format->palette); + Create(width, height, depth, Bytes(data_size, 0)); } 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); } -// Creates the texture that will be displayed to the screen. void Bitmap::CreateTexture(SDL_Renderer *renderer) { - // Ensure width and height are non-zero if (width_ <= 0 || height_ <= 0) { SDL_Log("Invalid texture dimensions: width=%d, height=%d\n", width_, height_); @@ -239,11 +220,9 @@ void Bitmap::CreateTexture(SDL_Renderer *renderer) { SDL_Surface *converted_surface = SDL_ConvertSurfaceFormat(surface_.get(), SDL_PIXELFORMAT_ARGB8888, 0); if (converted_surface) { - // Create texture from the converted surface converted_surface_ = std::unique_ptr( converted_surface, SDL_Surface_Deleter()); } else { - // Handle the error 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_ConvertSurfaceFormat(surface_.get(), SDL_PIXELFORMAT_ARGB8888, 0); if (converted_surface) { - // Create texture from the converted surface converted_surface_ = std::unique_ptr( converted_surface, SDL_Surface_Deleter()); } else { - // Handle the error 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()); } -// Creates the texture that will be displayed to the screen. void Bitmap::CreateTexture(std::shared_ptr renderer) { texture_ = std::shared_ptr{ SDL_CreateTextureFromSurface(renderer.get(), surface_.get()), @@ -421,25 +397,6 @@ void Bitmap::ApplyPalette(const std::vector &palette) { 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_CreateRGBSurfaceWithFormat(0, width_, height_, depth_, - SDL_PIXELFORMAT_INDEX8), - SDL_Surface_Deleter()); - - surface_->pixels = pixel_data_; - GrayscalePalette(surface_->format->palette); -} - } // namespace gfx } // namespace app } // namespace yaze diff --git a/src/app/gfx/bitmap.h b/src/app/gfx/bitmap.h index 85206e21..9eab5080 100644 --- a/src/app/gfx/bitmap.h +++ b/src/app/gfx/bitmap.h @@ -48,7 +48,7 @@ class Bitmap { Bitmap(int width, int height, int depth, int data_size); Bitmap(int width, int height, int depth, const Bytes &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, const SnesPalette &palette) @@ -57,24 +57,17 @@ class Bitmap { depth_(depth), data_(data), palette_(palette) { - InitializeFromData(width, height, depth, data); + Create(width, height, depth, data); if (!ApplyPalette(palette).ok()) { 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. */ 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. diff --git a/src/app/zelda3/screen/title_screen.cc b/src/app/zelda3/screen/title_screen.cc index 3ef63361..075e72f6 100644 --- a/src/app/zelda3/screen/title_screen.cc +++ b/src/app/zelda3/screen/title_screen.cc @@ -13,13 +13,11 @@ namespace zelda3 { namespace screen { void TitleScreen::Create() { - tiles8Bitmap.Create(128, 512, 8, 0x20000); - tilesBG1Bitmap.Create(256, 256, 8, 0x80000); - tilesBG2Bitmap.Create(256, 256, 8, 0x80000); - oamBGBitmap.Create(256, 256, 8, 0x80000); - + tiles8Bitmap.Create(128, 512, 8, Bytes(0, 0x20000)); + tilesBG1Bitmap.Create(256, 256, 8, Bytes(0, 0x80000)); + tilesBG2Bitmap.Create(256, 256, 8, Bytes(0, 0x80000)); + oamBGBitmap.Create(256, 256, 8, Bytes(0, 0x80000)); BuildTileset(); - LoadTitleScreen(); }