1#ifndef YAZE_APP_GFX_PALETTE_H
2#define YAZE_APP_GFX_PALETTE_H
11#include "absl/base/casts.h"
12#include "absl/status/status.h"
13#include "absl/status/statusor.h"
17#include "imgui/imgui.h"
42static constexpr absl::string_view kPaletteCategoryNames[] = {
43 "Sword",
"Shield",
"Clothes",
"World Colors",
44 "Area Colors",
"Global Sprites",
"Sprites Aux1",
"Sprites Aux2",
45 "Sprites Aux3",
"Dungeons",
"World Map",
"Dungeon Map",
46 "Triforce",
"Crystal"};
48static constexpr absl::string_view kPaletteGroupNames[] = {
49 "swords",
"shields",
"armors",
"ow_main",
50 "ow_aux",
"global_sprites",
"sprites_aux1",
"sprites_aux2",
51 "sprites_aux3",
"dungeon_main",
"ow_mini_map",
"ow_mini_map",
52 "3d_object",
"3d_object"};
54constexpr const char* kPaletteGroupAddressesKeys[] = {
55 "ow_main",
"ow_aux",
"ow_animated",
"hud",
56 "global_sprites",
"armors",
"swords",
"shields",
57 "sprites_aux1",
"sprites_aux2",
"sprites_aux3",
"dungeon_main",
58 "grass",
"3d_object",
"ow_mini_map",
111 template <
typename T>
113 for (
const auto& item : data) {
120 explicit SnesPalette(
const unsigned char* snes_pal);
122 explicit SnesPalette(
const std::vector<snes_color>&);
123 explicit SnesPalette(
const std::vector<SnesColor>&);
125 void Create(
const std::vector<SnesColor>& cols) {
126 for (
const auto& each : cols) {
127 colors.emplace_back(each);
137 return absl::InvalidArgumentError(
"SnesPalette: Index out of bounds");
150 std::cout <<
"SNESPalette: Index out of bounds" << std::endl;
158 std::cout <<
"SNESPalette: Index out of bounds" << std::endl;
165 std::cout <<
"SNESPalette: Index out of bounds" << std::endl;
169 colors[i].set_modified(
true);
174 for (
int i = start; i < end; i++) {
215 std::cout <<
"PaletteGroup: Index out of bounds" << std::endl;
223 std::cout <<
"PaletteGroup: Index out of bounds" << std::endl;
259 if (group_name ==
"ow_main") {
261 }
else if (group_name ==
"ow_aux") {
263 }
else if (group_name ==
"ow_animated") {
265 }
else if (group_name ==
"hud") {
267 }
else if (group_name ==
"global_sprites") {
269 }
else if (group_name ==
"armors") {
271 }
else if (group_name ==
"swords") {
273 }
else if (group_name ==
"shields") {
275 }
else if (group_name ==
"sprites_aux1") {
277 }
else if (group_name ==
"sprites_aux2") {
279 }
else if (group_name ==
"sprites_aux3") {
281 }
else if (group_name ==
"dungeon_main") {
283 }
else if (group_name ==
"grass") {
285 }
else if (group_name ==
"3d_object") {
287 }
else if (group_name ==
"ow_mini_map") {
290 throw std::out_of_range(
"PaletteGroupMap: Group not found");
294 template <
typename Func>
310 return absl::OkStatus();
344 std::vector<SnesColor>& colors);
350 SnesPalette& palette,
int num_colors = 8);
362 PaletteGroupMap& groups);
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
SnesPalette sub_palette(int start, int end) const
void AddColor(uint16_t color)
void AddColor(const SnesColor &color)
auto mutable_color(int i)
void operator()(int i, const ImVec4 &color)
void AddColor(const snes_color &color)
SnesColor & operator[](int i)
std::vector< SnesColor > colors
absl::StatusOr< SnesColor > GetColor(int i) const
SnesPalette(const std::vector< T > &data)
void Create(const std::vector< SnesColor > &cols)
void operator()(int i, const SnesColor &color)
#define RETURN_IF_ERROR(expression)
uint32_t GetPaletteAddress(const std::string &group_name, size_t palette_index, size_t color_index)
constexpr int CustomAreaSpecificBGASM
constexpr int kSwordPalettes
constexpr int kDungeonMapPalettes
constexpr int kOverworldMiniMapPalettes
constexpr int CustomAreaSpecificBGPalette
constexpr int kShieldPalettes
constexpr int kDungeonMapBgPalettes
constexpr int kHudPalettes
constexpr int kSpritesPalettesAux3
std::array< float, 4 > ToFloatArray(const SnesColor &color)
SnesPalette ReadPaletteFromRom(int offset, int num_colors, const uint8_t *rom)
constexpr int kArmorPalettes
constexpr int kOverworldPaletteAnimated
absl::Status LoadAllPalettes(const std::vector< uint8_t > &rom_data, PaletteGroupMap &groups)
Loads all the palettes for the game.
constexpr int kHardcodedGrassDW
constexpr int kSpritesPalettesAux1
constexpr int kGlobalSpritePalettesDW
constexpr int kCrystalPalette
constexpr int kNumPalettes
constexpr int kTriforcePalette
absl::StatusOr< PaletteGroup > CreatePaletteGroupFromColFile(std::vector< SnesColor > &palette_rows)
constexpr int kHardcodedGrassLW
constexpr int kOverworldPaletteMain
constexpr int kCustomAreaSpecificBGEnabled
constexpr int kOverworldPaletteAux
constexpr int kSpritesPalettesAux2
constexpr int kHardcodedGrassSpecial
absl::StatusOr< PaletteGroup > CreatePaletteGroupFromLargePalette(SnesPalette &palette, int num_colors)
Take a SNESPalette, divide it into palettes of 8 colors.
constexpr int kGlobalSpritesLW
constexpr int kDungeonMainPalettes
Primitive of 16-bit RGB SNES color.
Represents a mapping of palette groups.
PaletteGroup overworld_aux
auto get_group(const std::string &group_name)
PaletteGroup overworld_main
PaletteGroup sprites_aux1
PaletteGroup sprites_aux3
PaletteGroup sprites_aux2
PaletteGroup global_sprites
PaletteGroup overworld_animated
PaletteGroup dungeon_main
absl::Status for_each(Func &&func)
PaletteGroup overworld_mini_map
Represents a group of palettes.
std::vector< SnesPalette > palettes
const SnesPalette & operator[](int i) const
void AddPalette(SnesPalette pal)
void AddColor(SnesColor color)
void SetName(const std::string &name)
auto palette(int i) const
SnesPalette operator[](int i)
auto mutable_palette(int i)
Represents a set of palettes used in a SNES graphics system.
Paletteset()=default
Default constructor for Paletteset.
gfx::SnesColor background
gfx::SnesPalette animated
Paletteset(gfx::SnesPalette main, gfx::SnesPalette animated, gfx::SnesPalette aux1, gfx::SnesPalette aux2, gfx::SnesColor background, gfx::SnesPalette hud, gfx::SnesPalette spr, gfx::SnesPalette spr2, gfx::SnesPalette comp)
Constructor for Paletteset.
gfx::SnesPalette composite