rename ApplyPalette with SetPalette

This commit is contained in:
scawful
2025-03-02 17:06:46 -05:00
parent a7d933eb14
commit c99a4b0bc4
11 changed files with 106 additions and 112 deletions

View File

@@ -61,7 +61,7 @@ class Renderer {
gfx::Bitmap &bitmap, gfx::Bitmap &bitmap,
gfx::SnesPalette &palette) { gfx::SnesPalette &palette) {
bitmap.Create(width, height, depth, data); bitmap.Create(width, height, depth, data);
RETURN_IF_ERROR(bitmap.ApplyPalette(palette)); RETURN_IF_ERROR(bitmap.SetPalette(palette));
RenderBitmap(&bitmap); RenderBitmap(&bitmap);
return absl::OkStatus(); return absl::OkStatus();
} }

View File

@@ -123,7 +123,7 @@ absl::Status DungeonEditor::RefreshGraphics() {
std::for_each_n( std::for_each_n(
rooms_[current_room_id_].blocks().begin(), 8, rooms_[current_room_id_].blocks().begin(), 8,
[this](int block) -> absl::Status { [this](int block) -> absl::Status {
RETURN_IF_ERROR(graphics_bin_[block].ApplyPaletteWithTransparent( RETURN_IF_ERROR(graphics_bin_[block].SetPaletteWithTransparent(
current_palette_group_[current_palette_id_], 0)); current_palette_group_[current_palette_id_], 0));
Renderer::GetInstance().UpdateBitmap(&graphics_bin_[block]); Renderer::GetInstance().UpdateBitmap(&graphics_bin_[block]);
return absl::OkStatus(); return absl::OkStatus();
@@ -133,7 +133,7 @@ absl::Status DungeonEditor::RefreshGraphics() {
std::for_each_n( std::for_each_n(
rooms_[current_room_id_].blocks().begin() + 8, 8, rooms_[current_room_id_].blocks().begin() + 8, 8,
[this, &sprites_aux1_pal_group](int block) -> absl::Status { [this, &sprites_aux1_pal_group](int block) -> absl::Status {
RETURN_IF_ERROR(graphics_bin_[block].ApplyPaletteWithTransparent( RETURN_IF_ERROR(graphics_bin_[block].SetPaletteWithTransparent(
sprites_aux1_pal_group[current_palette_id_], 0)); sprites_aux1_pal_group[current_palette_id_], 0));
Renderer::GetInstance().UpdateBitmap(&graphics_bin_[block]); Renderer::GetInstance().UpdateBitmap(&graphics_bin_[block]);
return absl::OkStatus(); return absl::OkStatus();

View File

@@ -45,7 +45,8 @@ absl::Status GraphicsEditor::Update() {
status_ = UpdateGfxEdit(); status_ = UpdateGfxEdit();
TAB_ITEM("Sheet Browser") TAB_ITEM("Sheet Browser")
if (asset_browser_.Initialized == false) { if (asset_browser_.Initialized == false) {
asset_browser_.Initialize(GraphicsSheetManager::GetInstance().gfx_sheets()); asset_browser_.Initialize(
GraphicsSheetManager::GetInstance().gfx_sheets());
} }
asset_browser_.Draw(GraphicsSheetManager::GetInstance().gfx_sheets()); asset_browser_.Draw(GraphicsSheetManager::GetInstance().gfx_sheets());
END_TAB_ITEM() END_TAB_ITEM()
@@ -115,8 +116,10 @@ void GraphicsEditor::DrawGfxEditToolset() {
TableNextColumn(); TableNextColumn();
if (Button(ICON_MD_CONTENT_COPY)) { if (Button(ICON_MD_CONTENT_COPY)) {
std::vector<uint8_t> png_data = std::vector<uint8_t> png_data = GraphicsSheetManager::GetInstance()
GraphicsSheetManager::GetInstance().gfx_sheets().at(current_sheet_).GetPngData(); .gfx_sheets()
.at(current_sheet_)
.GetPngData();
core::CopyImageToClipboard(png_data); core::CopyImageToClipboard(png_data);
} }
HOVER_HINT("Copy to Clipboard"); HOVER_HINT("Copy to Clipboard");
@@ -127,11 +130,13 @@ void GraphicsEditor::DrawGfxEditToolset() {
int width, height; int width, height;
core::GetImageFromClipboard(png_data, width, height); core::GetImageFromClipboard(png_data, width, height);
if (png_data.size() > 0) { if (png_data.size() > 0) {
GraphicsSheetManager::GetInstance().mutable_gfx_sheets() GraphicsSheetManager::GetInstance()
.mutable_gfx_sheets()
->at(current_sheet_) ->at(current_sheet_)
.Create(width, height, 8, png_data); .Create(width, height, 8, png_data);
Renderer::GetInstance().UpdateBitmap( Renderer::GetInstance().UpdateBitmap(
&GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->at(current_sheet_)); &GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->at(
current_sheet_));
} }
} }
HOVER_HINT("Paste from Clipboard"); HOVER_HINT("Paste from Clipboard");
@@ -151,7 +156,8 @@ void GraphicsEditor::DrawGfxEditToolset() {
} }
TableNextColumn(); TableNextColumn();
auto bitmap = GraphicsSheetManager::GetInstance().gfx_sheets()[current_sheet_]; auto bitmap =
GraphicsSheetManager::GetInstance().gfx_sheets()[current_sheet_];
auto palette = bitmap.palette(); auto palette = bitmap.palette();
for (int i = 0; i < palette.size(); i++) { for (int i = 0; i < palette.size(); i++) {
ImGui::SameLine(); ImGui::SameLine();
@@ -279,7 +285,9 @@ absl::Status GraphicsEditor::UpdateGfxTabView() {
ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysVerticalScrollbar |
ImGuiWindowFlags_AlwaysHorizontalScrollbar); ImGuiWindowFlags_AlwaysHorizontalScrollbar);
gfx::Bitmap& current_bitmap = GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->at(sheet_id); gfx::Bitmap& current_bitmap =
GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->at(
sheet_id);
auto draw_tile_event = [&]() { auto draw_tile_event = [&]() {
current_sheet_canvas_.DrawTileOnBitmap(tile_size_, &current_bitmap, current_sheet_canvas_.DrawTileOnBitmap(tile_size_, &current_bitmap,
@@ -288,8 +296,9 @@ absl::Status GraphicsEditor::UpdateGfxTabView() {
}; };
current_sheet_canvas_.UpdateColorPainter( current_sheet_canvas_.UpdateColorPainter(
GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->at(sheet_id), current_color_, GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->at(
draw_tile_event, tile_size_, current_scale_); sheet_id),
current_color_, draw_tile_event, tile_size_, current_scale_);
ImGui::EndChild(); ImGui::EndChild();
ImGui::EndTabItem(); ImGui::EndTabItem();
@@ -321,7 +330,8 @@ absl::Status GraphicsEditor::UpdateGfxTabView() {
current_sheet_ = id; current_sheet_ = id;
// ImVec2(0x100, 0x40), // ImVec2(0x100, 0x40),
current_sheet_canvas_.UpdateColorPainter( current_sheet_canvas_.UpdateColorPainter(
GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->at(id), current_color_, GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->at(id),
current_color_,
[&]() { [&]() {
}, },
@@ -358,11 +368,13 @@ absl::Status GraphicsEditor::UpdatePaletteColumn() {
if (refresh_graphics_ && !open_sheets_.empty()) { if (refresh_graphics_ && !open_sheets_.empty()) {
RETURN_IF_ERROR( RETURN_IF_ERROR(
GraphicsSheetManager::GetInstance().mutable_gfx_sheets() GraphicsSheetManager::GetInstance()
.mutable_gfx_sheets()
->data()[current_sheet_] ->data()[current_sheet_]
.ApplyPaletteWithTransparent(palette, edit_palette_sub_index_)); .SetPaletteWithTransparent(palette, edit_palette_sub_index_));
Renderer::GetInstance().UpdateBitmap( Renderer::GetInstance().UpdateBitmap(&GraphicsSheetManager::GetInstance()
&GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->data()[current_sheet_]); .mutable_gfx_sheets()
->data()[current_sheet_]);
refresh_graphics_ = false; refresh_graphics_ = false;
} }
} }
@@ -458,7 +470,7 @@ absl::Status GraphicsEditor::UpdateScadView() {
// TODO: Implement the Super Donkey 1 graphics decompression // TODO: Implement the Super Donkey 1 graphics decompression
// if (refresh_graphics_) { // if (refresh_graphics_) {
// for (int i = 0; i < kNumGfxSheets; i++) { // for (int i = 0; i < kNumGfxSheets; i++) {
// status_ = graphics_bin_[i].ApplyPalette( // status_ = graphics_bin_[i].SetPalette(
// col_file_palette_group_[current_palette_index_]); // col_file_palette_group_[current_palette_index_]);
// Renderer::GetInstance().UpdateBitmap(&graphics_bin_[i]); // Renderer::GetInstance().UpdateBitmap(&graphics_bin_[i]);
// } // }
@@ -534,7 +546,7 @@ absl::Status GraphicsEditor::DrawCgxImport() {
cgx_bitmap_.Create(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_.SetPalette(decoded_col_);
Renderer::GetInstance().RenderBitmap(&cgx_bitmap_); Renderer::GetInstance().RenderBitmap(&cgx_bitmap_);
} }
} }
@@ -556,16 +568,15 @@ absl::Status GraphicsEditor::DrawScrImport() {
InputInt("SCR Mod", &scr_mod_value_); InputInt("SCR Mod", &scr_mod_value_);
if (ImGui::Button("Load Scr Data")) { if (ImGui::Button("Load Scr Data")) {
status_ = status_ = gfx::LoadScr(scr_file_path_, scr_mod_value_, scr_data_);
gfx::LoadScr(scr_file_path_, scr_mod_value_, scr_data_);
decoded_scr_data_.resize(0x100 * 0x100); decoded_scr_data_.resize(0x100 * 0x100);
status_ = gfx::DrawScrWithCgx(current_bpp_, scr_data_, status_ = gfx::DrawScrWithCgx(current_bpp_, scr_data_, decoded_scr_data_,
decoded_scr_data_, decoded_cgx_); decoded_cgx_);
scr_bitmap_.Create(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_.SetPalette(decoded_col_);
Renderer::GetInstance().RenderBitmap(&scr_bitmap_); Renderer::GetInstance().RenderBitmap(&scr_bitmap_);
} }
} }
@@ -762,9 +773,9 @@ absl::Status GraphicsEditor::DecompressImportData(int size) {
auto palette_group = rom()->palette_group().overworld_animated; auto palette_group = rom()->palette_group().overworld_animated;
z3_rom_palette_ = palette_group[current_palette_]; z3_rom_palette_ = palette_group[current_palette_];
if (col_file_) { if (col_file_) {
status_ = bin_bitmap_.ApplyPalette(col_file_palette_); status_ = bin_bitmap_.SetPalette(col_file_palette_);
} else { } else {
status_ = bin_bitmap_.ApplyPalette(z3_rom_palette_); status_ = bin_bitmap_.SetPalette(z3_rom_palette_);
} }
} }
@@ -786,7 +797,7 @@ absl::Status GraphicsEditor::DecompressSuperDonkey() {
gfx_sheets_[i] = gfx::Bitmap(gfx::kTilesheetWidth, gfx::kTilesheetHeight, gfx_sheets_[i] = gfx::Bitmap(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
gfx::kTilesheetDepth, converted_sheet); gfx::kTilesheetDepth, converted_sheet);
if (col_file_) { if (col_file_) {
status_ = gfx_sheets_[i].ApplyPalette( status_ = gfx_sheets_[i].SetPalette(
col_file_palette_group_[current_palette_index_]); col_file_palette_group_[current_palette_index_]);
} else { } else {
// ROM palette // ROM palette
@@ -794,7 +805,7 @@ absl::Status GraphicsEditor::DecompressSuperDonkey() {
auto palette_group = rom()->palette_group().get_group( auto palette_group = rom()->palette_group().get_group(
kPaletteGroupAddressesKeys[current_palette_]); kPaletteGroupAddressesKeys[current_palette_]);
z3_rom_palette_ = *palette_group->mutable_palette(current_palette_index_); z3_rom_palette_ = *palette_group->mutable_palette(current_palette_index_);
status_ = gfx_sheets_[i].ApplyPalette(z3_rom_palette_); status_ = gfx_sheets_[i].SetPalette(z3_rom_palette_);
} }
Renderer::GetInstance().RenderBitmap(&gfx_sheets_[i]); Renderer::GetInstance().RenderBitmap(&gfx_sheets_[i]);
@@ -811,14 +822,14 @@ absl::Status GraphicsEditor::DecompressSuperDonkey() {
gfx_sheets_[i] = gfx::Bitmap(gfx::kTilesheetWidth, gfx::kTilesheetHeight, gfx_sheets_[i] = gfx::Bitmap(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
gfx::kTilesheetDepth, converted_sheet); gfx::kTilesheetDepth, converted_sheet);
if (col_file_) { if (col_file_) {
status_ = gfx_sheets_[i].ApplyPalette( status_ = gfx_sheets_[i].SetPalette(
col_file_palette_group_[current_palette_index_]); col_file_palette_group_[current_palette_index_]);
} else { } else {
// ROM palette // ROM palette
auto palette_group = rom()->palette_group().get_group( auto palette_group = rom()->palette_group().get_group(
kPaletteGroupAddressesKeys[current_palette_]); kPaletteGroupAddressesKeys[current_palette_]);
z3_rom_palette_ = *palette_group->mutable_palette(current_palette_index_); z3_rom_palette_ = *palette_group->mutable_palette(current_palette_index_);
status_ = gfx_sheets_[i].ApplyPalette(z3_rom_palette_); status_ = gfx_sheets_[i].SetPalette(z3_rom_palette_);
} }
Renderer::GetInstance().RenderBitmap(&gfx_sheets_[i]); Renderer::GetInstance().RenderBitmap(&gfx_sheets_[i]);

View File

@@ -126,8 +126,7 @@ absl::Status ScreenEditor::LoadDungeonMaps() {
ptr |= 0x0A0000; // Add bank to the short ptr ptr |= 0x0A0000; // Add bank to the short ptr
ptr_gfx |= 0x0A0000; // Add bank to the short ptr ptr_gfx |= 0x0A0000; // Add bank to the short ptr
int pc_ptr = SnesToPc(ptr); // Contains data for the next 25 rooms int pc_ptr = SnesToPc(ptr); // Contains data for the next 25 rooms
int pc_ptr_gfx = int pc_ptr_gfx = SnesToPc(ptr_gfx); // Contains data for the next 25 rooms
SnesToPc(ptr_gfx); // Contains data for the next 25 rooms
ASSIGN_OR_RETURN(uint16_t boss_room_d, ASSIGN_OR_RETURN(uint16_t boss_room_d,
rom()->ReadWord(zelda3::kDungeonMapBossRooms + (d * 2))); rom()->ReadWord(zelda3::kDungeonMapBossRooms + (d * 2)));
@@ -230,7 +229,7 @@ absl::Status ScreenEditor::LoadDungeonMapTile16(
tile16_sheet_.ComposeTile16(gfx_data, t1, t2, t3, t4, sheet_offset); tile16_sheet_.ComposeTile16(gfx_data, t1, t2, t3, t4, sheet_offset);
} }
RETURN_IF_ERROR(tile16_sheet_.mutable_bitmap()->ApplyPalette( RETURN_IF_ERROR(tile16_sheet_.mutable_bitmap()->SetPalette(
*rom()->mutable_dungeon_palette(3))); *rom()->mutable_dungeon_palette(3)));
Renderer::GetInstance().RenderBitmap(&*tile16_sheet_.mutable_bitmap().get()); Renderer::GetInstance().RenderBitmap(&*tile16_sheet_.mutable_bitmap().get());
@@ -238,7 +237,7 @@ absl::Status ScreenEditor::LoadDungeonMapTile16(
auto tile = tile16_sheet_.GetTile16(i); auto tile = tile16_sheet_.GetTile16(i);
tile16_individual_[i] = tile; tile16_individual_[i] = tile;
RETURN_IF_ERROR( RETURN_IF_ERROR(
tile16_individual_[i].ApplyPalette(*rom()->mutable_dungeon_palette(3))); tile16_individual_[i].SetPalette(*rom()->mutable_dungeon_palette(3)));
Renderer::GetInstance().RenderBitmap(&tile16_individual_[i]); Renderer::GetInstance().RenderBitmap(&tile16_individual_[i]);
} }
@@ -424,7 +423,7 @@ void ScreenEditor::DrawDungeonMapsRoomGfx() {
current_tile16_info.tiles[3], selected_tile16_, 212); current_tile16_info.tiles[3], selected_tile16_, 212);
tile16_individual_[selected_tile16_] = tile16_individual_[selected_tile16_] =
tile16_sheet_.GetTile16(selected_tile16_); tile16_sheet_.GetTile16(selected_tile16_);
RETURN_VOID_IF_ERROR(tile16_individual_[selected_tile16_].ApplyPalette( RETURN_VOID_IF_ERROR(tile16_individual_[selected_tile16_].SetPalette(
*rom()->mutable_dungeon_palette(3))); *rom()->mutable_dungeon_palette(3)));
Renderer::GetInstance().RenderBitmap( Renderer::GetInstance().RenderBitmap(
&tile16_individual_[selected_tile16_]); &tile16_individual_[selected_tile16_]);
@@ -455,7 +454,7 @@ void ScreenEditor::DrawDungeonMapsEditor() {
int y = (j / 8) * 8; int y = (j / 8) * 8;
sheets_[i].Get8x8Tile(tile_index, 0, 0, tile_data, tile_data_offset); sheets_[i].Get8x8Tile(tile_index, 0, 0, tile_data, tile_data_offset);
tile8_individual_.emplace_back(gfx::Bitmap(8, 8, 4, tile_data)); tile8_individual_.emplace_back(gfx::Bitmap(8, 8, 4, tile_data));
RETURN_VOID_IF_ERROR(tile8_individual_.back().ApplyPalette( RETURN_VOID_IF_ERROR(tile8_individual_.back().SetPalette(
*rom()->mutable_dungeon_palette(3))); *rom()->mutable_dungeon_palette(3)));
Renderer::GetInstance().RenderBitmap(&tile8_individual_.back()); Renderer::GetInstance().RenderBitmap(&tile8_individual_.back());
} }
@@ -556,7 +555,7 @@ void ScreenEditor::LoadBinaryGfx() {
gfx_sheets.emplace_back(converted_bin.begin() + (i * 0x1000), gfx_sheets.emplace_back(converted_bin.begin() + (i * 0x1000),
converted_bin.begin() + ((i + 1) * 0x1000)); converted_bin.begin() + ((i + 1) * 0x1000));
sheets_.emplace(i, gfx::Bitmap(128, 32, 8, gfx_sheets[i])); sheets_.emplace(i, gfx::Bitmap(128, 32, 8, gfx_sheets[i]));
status_ = sheets_[i].ApplyPalette(*rom()->mutable_dungeon_palette(3)); status_ = sheets_[i].SetPalette(*rom()->mutable_dungeon_palette(3));
if (status_.ok()) { if (status_.ok()) {
Renderer::GetInstance().RenderBitmap(&sheets_[i]); Renderer::GetInstance().RenderBitmap(&sheets_[i]);
} }

View File

@@ -63,7 +63,7 @@ absl::Status OverworldEditor::Update() {
status_ = absl::OkStatus(); status_ = absl::OkStatus();
if (rom_.is_loaded() && !all_gfx_loaded_) { if (rom_.is_loaded() && !all_gfx_loaded_) {
RETURN_IF_ERROR( RETURN_IF_ERROR(
tile16_editor_.InitBlockset(tile16_blockset_bmp_, current_gfx_bmp_, tile16_editor_.Initialize(tile16_blockset_bmp_, current_gfx_bmp_,
*overworld_.mutable_all_tiles_types())); *overworld_.mutable_all_tiles_types()));
ASSIGN_OR_RETURN(entrance_tiletypes_, zelda3::LoadEntranceTileTypes(rom_)); ASSIGN_OR_RETURN(entrance_tiletypes_, zelda3::LoadEntranceTileTypes(rom_));
all_gfx_loaded_ = true; all_gfx_loaded_ = true;
@@ -1059,7 +1059,7 @@ absl::Status OverworldEditor::LoadGraphics() {
} }
} }
RETURN_IF_ERROR(tile16_individual_[i].ApplyPalette(palette_)); RETURN_IF_ERROR(tile16_individual_[i].SetPalette(palette_));
Renderer::GetInstance().RenderBitmap(&tile16_individual_[i]); Renderer::GetInstance().RenderBitmap(&tile16_individual_[i]);
} }
@@ -1100,7 +1100,7 @@ absl::Status OverworldEditor::LoadSpriteGraphics() {
} }
sprite_previews_[sprite.id()].Create(width, height, depth, sprite_previews_[sprite.id()].Create(width, height, depth,
*sprite.preview_graphics()); *sprite.preview_graphics());
RETURN_IF_ERROR(sprite_previews_[sprite.id()].ApplyPalette(palette_)); RETURN_IF_ERROR(sprite_previews_[sprite.id()].SetPalette(palette_));
Renderer::GetInstance().RenderBitmap(&(sprite_previews_[sprite.id()])); Renderer::GetInstance().RenderBitmap(&(sprite_previews_[sprite.id()]));
} }
return absl::OkStatus(); return absl::OkStatus();
@@ -1169,12 +1169,11 @@ absl::Status OverworldEditor::RefreshMapPalette() {
if (i >= 2) sibling_index += 6; if (i >= 2) sibling_index += 6;
RETURN_IF_ERROR( RETURN_IF_ERROR(
overworld_.mutable_overworld_map(sibling_index)->LoadPalette()); overworld_.mutable_overworld_map(sibling_index)->LoadPalette());
RETURN_IF_ERROR( RETURN_IF_ERROR(maps_bmp_[sibling_index].SetPalette(current_map_palette));
maps_bmp_[sibling_index].ApplyPalette(current_map_palette));
} }
} }
RETURN_IF_ERROR(maps_bmp_[current_map_].ApplyPalette(current_map_palette)); RETURN_IF_ERROR(maps_bmp_[current_map_].SetPalette(current_map_palette));
return absl::OkStatus(); return absl::OkStatus();
} }
@@ -1210,7 +1209,7 @@ absl::Status OverworldEditor::RefreshTile16Blockset() {
palette_ = overworld_.current_area_palette(); palette_ = overworld_.current_area_palette();
// Create the tile16 blockset image // Create the tile16 blockset image
Renderer::GetInstance().UpdateBitmap(&tile16_blockset_bmp_); Renderer::GetInstance().UpdateBitmap(&tile16_blockset_bmp_);
RETURN_IF_ERROR(tile16_blockset_bmp_.ApplyPalette(palette_)); RETURN_IF_ERROR(tile16_blockset_bmp_.SetPalette(palette_));
// Copy the tile16 data into individual tiles. // Copy the tile16 data into individual tiles.
const auto tile16_data = overworld_.tile16_blockset_data(); const auto tile16_data = overworld_.tile16_blockset_data();
@@ -1232,7 +1231,7 @@ absl::Status OverworldEditor::RefreshTile16Blockset() {
} }
} }
tile16_individual_[index].set_data(tile_data); tile16_individual_[index].set_data(tile_data);
RETURN_IF_ERROR(tile16_individual_[index].ApplyPalette(palette_)); RETURN_IF_ERROR(tile16_individual_[index].SetPalette(palette_));
return absl::OkStatus(); return absl::OkStatus();
}, },
i)); i));

View File

@@ -271,7 +271,7 @@ void Bitmap::Reformat(int format) {
SDL_Surface_Deleter()); SDL_Surface_Deleter());
surface_->pixels = pixel_data_; surface_->pixels = pixel_data_;
active_ = true; active_ = true;
auto apply_palette = ApplyPalette(palette_); auto apply_palette = SetPalette(palette_);
if (!apply_palette.ok()) { if (!apply_palette.ok()) {
SDL_Log("Failed to apply palette: %s\n", apply_palette.message().data()); SDL_Log("Failed to apply palette: %s\n", apply_palette.message().data());
active_ = false; active_ = false;
@@ -326,7 +326,7 @@ void Bitmap::UpdateTexture(SDL_Renderer *renderer) {
SDL_UnlockTexture(texture_.get()); SDL_UnlockTexture(texture_.get());
} }
absl::Status Bitmap::ApplyPalette(const SnesPalette &palette) { absl::Status Bitmap::SetPalette(const SnesPalette &palette) {
if (surface_ == nullptr) { if (surface_ == nullptr) {
return absl::FailedPreconditionError( return absl::FailedPreconditionError(
"Surface is null. Palette not applied"); "Surface is null. Palette not applied");
@@ -355,7 +355,7 @@ absl::Status Bitmap::ApplyPalette(const SnesPalette &palette) {
return absl::OkStatus(); return absl::OkStatus();
} }
absl::Status Bitmap::ApplyPaletteFromPaletteGroup(const SnesPalette &palette, absl::Status Bitmap::SetPaletteFromPaletteGroup(const SnesPalette &palette,
int palette_id) { int palette_id) {
auto start_index = palette_id * 8; auto start_index = palette_id * 8;
palette_ = palette.sub_palette(start_index, start_index + 8); palette_ = palette.sub_palette(start_index, start_index + 8);
@@ -379,7 +379,7 @@ absl::Status Bitmap::ApplyPaletteFromPaletteGroup(const SnesPalette &palette,
return absl::OkStatus(); return absl::OkStatus();
} }
absl::Status Bitmap::ApplyPaletteWithTransparent(const SnesPalette &palette, absl::Status Bitmap::SetPaletteWithTransparent(const SnesPalette &palette,
size_t index, int length) { size_t index, int length) {
if (index < 0 || index >= palette.size()) { if (index < 0 || index >= palette.size()) {
return absl::InvalidArgumentError("Invalid palette index"); return absl::InvalidArgumentError("Invalid palette index");
@@ -421,7 +421,7 @@ absl::Status Bitmap::ApplyPaletteWithTransparent(const SnesPalette &palette,
return absl::OkStatus(); return absl::OkStatus();
} }
void Bitmap::ApplyPalette(const std::vector<SDL_Color> &palette) { void Bitmap::SetPalette(const std::vector<SDL_Color> &palette) {
SDL_UnlockSurface(surface_.get()); SDL_UnlockSurface(surface_.get());
for (size_t i = 0; i < palette.size(); ++i) { for (size_t i = 0; i < palette.size(); ++i) {
surface_->format->palette->colors[i].r = palette[i].r; surface_->format->palette->colors[i].r = palette[i].r;

View File

@@ -3,9 +3,9 @@
#include <SDL.h> #include <SDL.h>
#include <span>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include <span>
#include "absl/status/status.h" #include "absl/status/status.h"
#include "app/core/platform/sdl_deleter.h" #include "app/core/platform/sdl_deleter.h"
@@ -81,7 +81,7 @@ class Bitmap {
data_(data), data_(data),
palette_(palette) { palette_(palette) {
Create(width, height, depth, data); Create(width, height, depth, data);
if (!ApplyPalette(palette).ok()) { if (!SetPalette(palette).ok()) {
std::cerr << "Error applying palette in bitmap constructor." << std::endl; std::cerr << "Error applying palette in bitmap constructor." << std::endl;
} }
} }
@@ -121,11 +121,11 @@ class Bitmap {
/** /**
* @brief Copy color data from the SnesPalette into the SDL_Palette * @brief Copy color data from the SnesPalette into the SDL_Palette
*/ */
absl::Status ApplyPalette(const SnesPalette &palette); absl::Status SetPalette(const SnesPalette &palette);
absl::Status ApplyPaletteWithTransparent(const SnesPalette &palette, absl::Status SetPaletteWithTransparent(const SnesPalette &palette,
size_t index, int length = 7); size_t index, int length = 7);
void ApplyPalette(const std::vector<SDL_Color> &palette); void SetPalette(const std::vector<SDL_Color> &palette);
absl::Status ApplyPaletteFromPaletteGroup(const SnesPalette &palette, absl::Status SetPaletteFromPaletteGroup(const SnesPalette &palette,
int palette_id); int palette_id);
void Get8x8Tile(int tile_index, int x, int y, std::vector<uint8_t> &tile_data, void Get8x8Tile(int tile_index, int x, int y, std::vector<uint8_t> &tile_data,

View File

@@ -41,38 +41,30 @@ snes_tile8 UnpackBppTile(const std::vector<uint8_t>& data,
bpp_pos[1] = offset + col * 2 + 1; bpp_pos[1] = offset + col * 2 + 1;
char mask = 1 << (7 - row); char mask = 1 << (7 - row);
tile.data[col * 8 + row] = (data[bpp_pos[0]] & mask) == mask; tile.data[col * 8 + row] = (data[bpp_pos[0]] & mask) == mask;
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[1]] & mask) == mask) tile.data[col * 8 + row] |= ((data[bpp_pos[1]] & mask) == mask) << 1;
<< 1;
if (bpp == 3) { if (bpp == 3) {
// When we have 3 bitplanes, the bytes for the third bitplane are after // When we have 3 bitplanes, the bytes for the third bitplane are after
// the 16 bytes of the 2 bitplanes. // the 16 bytes of the 2 bitplanes.
bpp_pos[2] = offset + 16 + col; bpp_pos[2] = offset + 16 + col;
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[2]] & mask) == mask) tile.data[col * 8 + row] |= ((data[bpp_pos[2]] & mask) == mask) << 2;
<< 2;
} }
if (bpp >= 4) { if (bpp >= 4) {
// For 4 bitplanes, the 2 added bitplanes are interlaced like the first // For 4 bitplanes, the 2 added bitplanes are interlaced like the first
// two. // two.
bpp_pos[2] = offset + 16 + col * 2; bpp_pos[2] = offset + 16 + col * 2;
bpp_pos[3] = offset + 16 + col * 2 + 1; bpp_pos[3] = offset + 16 + col * 2 + 1;
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[2]] & mask) == mask) tile.data[col * 8 + row] |= ((data[bpp_pos[2]] & mask) == mask) << 2;
<< 2; tile.data[col * 8 + row] |= ((data[bpp_pos[3]] & mask) == mask) << 3;
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[3]] & mask) == mask)
<< 3;
} }
if (bpp == 8) { if (bpp == 8) {
bpp_pos[4] = offset + 32 + col * 2; bpp_pos[4] = offset + 32 + col * 2;
bpp_pos[5] = offset + 32 + col * 2 + 1; bpp_pos[5] = offset + 32 + col * 2 + 1;
bpp_pos[6] = offset + 48 + col * 2; bpp_pos[6] = offset + 48 + col * 2;
bpp_pos[7] = offset + 48 + col * 2 + 1; bpp_pos[7] = offset + 48 + col * 2 + 1;
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[4]] & mask) == mask) tile.data[col * 8 + row] |= ((data[bpp_pos[4]] & mask) == mask) << 4;
<< 4; tile.data[col * 8 + row] |= ((data[bpp_pos[5]] & mask) == mask) << 5;
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[5]] & mask) == mask) tile.data[col * 8 + row] |= ((data[bpp_pos[6]] & mask) == mask) << 6;
<< 5; tile.data[col * 8 + row] |= ((data[bpp_pos[7]] & mask) == mask) << 7;
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[6]] & mask) == mask)
<< 6;
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[7]] & mask) == mask)
<< 7;
} }
} }
} }
@@ -97,29 +89,25 @@ std::vector<uint8_t> PackBppTile(const snes_tile8& tile, const uint32_t bpp) {
// 2bpp format // 2bpp format
if (bpp >= 2) { if (bpp >= 2) {
output[col * 2] += (uint8_t)((color & 1) << (7 - row)); output[col * 2] += ((color & 1) << (7 - row));
output[col * 2 + 1] += output[col * 2 + 1] += (((color & 2) == 2) << (7 - row));
(uint8_t)((uint8_t)((color & 2) == 2) << (7 - row));
} }
// 3bpp format // 3bpp format
if (bpp == 3) if (bpp == 3) output[16 + col] += (((color & 4) == 4) << (7 - row));
output[16 + col] += (uint8_t)(((color & 4) == 4) << (7 - row));
// 4bpp format // 4bpp format
if (bpp >= 4) { if (bpp >= 4) {
output[16 + col * 2] += (uint8_t)(((color & 4) == 4) << (7 - row)); output[16 + col * 2] += (((color & 4) == 4) << (7 - row));
output[16 + col * 2 + 1] += (uint8_t)(((color & 8) == 8) << (7 - row)); output[16 + col * 2 + 1] += (((color & 8) == 8) << (7 - row));
} }
// 8bpp format // 8bpp format
if (bpp == 8) { if (bpp == 8) {
output[32 + col * 2] += (uint8_t)(((color & 16) == 16) << (7 - row)); output[32 + col * 2] += (((color & 16) == 16) << (7 - row));
output[32 + col * 2 + 1] += output[32 + col * 2 + 1] += (((color & 32) == 32) << (7 - row));
(uint8_t)(((color & 32) == 32) << (7 - row)); output[48 + col * 2] += (((color & 64) == 64) << (7 - row));
output[48 + col * 2] += (uint8_t)(((color & 64) == 64) << (7 - row)); output[48 + col * 2 + 1] += (((color & 128) == 128) << (7 - row));
output[48 + col * 2 + 1] +=
(uint8_t)(((color & 128) == 128) << (7 - row));
} }
} }
} }
@@ -399,5 +387,4 @@ void CopyTile8bpp16(int x, int y, int tile, std::vector<uint8_t>& bitmap,
} }
} // namespace gfx } // namespace gfx
} // namespace yaze } // namespace yaze

View File

@@ -68,8 +68,7 @@ absl::StatusOr<std::array<gfx::Bitmap, kNumLinkSheets>> LoadLinkGraphics(
auto link_sheet_8bpp = gfx::SnesTo8bppSheet(link_sheet_data, /*bpp=*/4); auto link_sheet_8bpp = gfx::SnesTo8bppSheet(link_sheet_data, /*bpp=*/4);
link_graphics[i].Create(gfx::kTilesheetWidth, gfx::kTilesheetHeight, link_graphics[i].Create(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
gfx::kTilesheetDepth, link_sheet_8bpp); gfx::kTilesheetDepth, link_sheet_8bpp);
RETURN_IF_ERROR( RETURN_IF_ERROR(link_graphics[i].SetPalette(rom.palette_group().armors[0]);)
link_graphics[i].ApplyPalette(rom.palette_group().armors[0]);)
Renderer::GetInstance().RenderBitmap(&link_graphics[i]); Renderer::GetInstance().RenderBitmap(&link_graphics[i]);
} }
return link_graphics; return link_graphics;
@@ -109,10 +108,10 @@ absl::StatusOr<std::array<gfx::Bitmap, kNumGfxSheets>> LoadAllGraphicsData(
if (graphics_sheets[i].is_active()) { if (graphics_sheets[i].is_active()) {
if (i > 115) { if (i > 115) {
// Apply sprites palette // Apply sprites palette
RETURN_IF_ERROR(graphics_sheets[i].ApplyPaletteWithTransparent( RETURN_IF_ERROR(graphics_sheets[i].SetPaletteWithTransparent(
rom.palette_group().global_sprites[0], 0)); rom.palette_group().global_sprites[0], 0));
} else { } else {
RETURN_IF_ERROR(graphics_sheets[i].ApplyPaletteWithTransparent( RETURN_IF_ERROR(graphics_sheets[i].SetPaletteWithTransparent(
rom.palette_group().dungeon_main[0], 0)); rom.palette_group().dungeon_main[0], 0));
} }
} }

View File

@@ -34,8 +34,7 @@ absl::Status LoadDungeonMapGfxFromBinary(Rom &rom,
gfx_sheets.emplace_back(converted_bin.begin() + (i * 0x1000), gfx_sheets.emplace_back(converted_bin.begin() + (i * 0x1000),
converted_bin.begin() + ((i + 1) * 0x1000)); converted_bin.begin() + ((i + 1) * 0x1000));
sheets[i] = gfx::Bitmap(128, 32, 8, gfx_sheets[i]); sheets[i] = gfx::Bitmap(128, 32, 8, gfx_sheets[i]);
RETURN_IF_ERROR( RETURN_IF_ERROR(sheets[i].SetPalette(*rom.mutable_dungeon_palette(3)));
sheets[i].ApplyPalette(*rom.mutable_dungeon_palette(3)));
core::Renderer::GetInstance().RenderBitmap(&sheets[i]); core::Renderer::GetInstance().RenderBitmap(&sheets[i]);
} }
} else { } else {

View File

@@ -68,7 +68,7 @@ absl::Status Inventory::Create() {
} }
bitmap_.Create(256, 256, 8, data_); bitmap_.Create(256, 256, 8, data_);
RETURN_IF_ERROR(bitmap_.ApplyPalette(palette_)); RETURN_IF_ERROR(bitmap_.SetPalette(palette_));
Renderer::GetInstance().RenderBitmap(&bitmap_); Renderer::GetInstance().RenderBitmap(&bitmap_);
return absl::OkStatus(); return absl::OkStatus();
} }
@@ -87,7 +87,7 @@ absl::Status Inventory::BuildTileset() {
tilesheets_bmp_.Create(128, 0x130, 64, test_); tilesheets_bmp_.Create(128, 0x130, 64, test_);
auto hud_pal_group = rom()->palette_group().hud; auto hud_pal_group = rom()->palette_group().hud;
palette_ = hud_pal_group[0]; palette_ = hud_pal_group[0];
RETURN_IF_ERROR(tilesheets_bmp_.ApplyPalette(palette_)) RETURN_IF_ERROR(tilesheets_bmp_.SetPalette(palette_))
Renderer::GetInstance().RenderBitmap(&tilesheets_bmp_); Renderer::GetInstance().RenderBitmap(&tilesheets_bmp_);
return absl::OkStatus(); return absl::OkStatus();
} }