1#ifndef YAZE_APP_GFX_PALETTE_H
2#define YAZE_APP_GFX_PALETTE_H
10#include "absl/status/status.h"
11#include "absl/status/statusor.h"
14#include "imgui/imgui.h"
40static constexpr absl::string_view kPaletteCategoryNames[] = {
41 "Sword",
"Shield",
"Clothes",
"World Colors",
42 "Area Colors",
"Global Sprites",
"Sprites Aux1",
"Sprites Aux2",
43 "Sprites Aux3",
"Dungeons",
"World Map",
"Dungeon Map",
44 "Triforce",
"Crystal"};
46static constexpr absl::string_view kPaletteGroupNames[] = {
47 "swords",
"shields",
"armors",
"ow_main",
48 "ow_aux",
"global_sprites",
"sprites_aux1",
"sprites_aux2",
49 "sprites_aux3",
"dungeon_main",
"ow_mini_map",
"ow_mini_map",
50 "3d_object",
"3d_object"};
52constexpr const char *kPaletteGroupAddressesKeys[] = {
53 "ow_main",
"ow_aux",
"ow_animated",
"hud",
54 "global_sprites",
"armors",
"swords",
"shields",
55 "sprites_aux1",
"sprites_aux2",
"sprites_aux3",
"dungeon_main",
56 "grass",
"3d_object",
"ow_mini_map",
109 template <
typename T>
111 for (
const auto &item : data) {
118 explicit SnesPalette(
const unsigned char *snes_pal);
120 explicit SnesPalette(
const std::vector<snes_color> &);
121 explicit SnesPalette(
const std::vector<SnesColor> &);
123 void Create(
const std::vector<SnesColor> &cols) {
124 for (
const auto &each : cols) {
125 colors.emplace_back(each);
135 return absl::InvalidArgumentError(
"SnesPalette: Index out of bounds");
148 std::cout <<
"SNESPalette: Index out of bounds" << std::endl;
156 std::cout <<
"SNESPalette: Index out of bounds" << std::endl;
163 std::cout <<
"SNESPalette: Index out of bounds" << std::endl;
167 colors[i].set_modified(
true);
172 for (
int i = start; i < end; i++) {
213 std::cout <<
"PaletteGroup: Index out of bounds" << std::endl;
221 std::cout <<
"PaletteGroup: Index out of bounds" << std::endl;
257 if (group_name ==
"ow_main") {
259 }
else if (group_name ==
"ow_aux") {
261 }
else if (group_name ==
"ow_animated") {
263 }
else if (group_name ==
"hud") {
265 }
else if (group_name ==
"global_sprites") {
267 }
else if (group_name ==
"armors") {
269 }
else if (group_name ==
"swords") {
271 }
else if (group_name ==
"shields") {
273 }
else if (group_name ==
"sprites_aux1") {
275 }
else if (group_name ==
"sprites_aux2") {
277 }
else if (group_name ==
"sprites_aux3") {
279 }
else if (group_name ==
"dungeon_main") {
281 }
else if (group_name ==
"grass") {
283 }
else if (group_name ==
"3d_object") {
285 }
else if (group_name ==
"ow_mini_map") {
288 throw std::out_of_range(
"PaletteGroupMap: Group not found");
292 template <
typename Func>
308 return absl::OkStatus();
342 std::vector<SnesColor> &colors);
348 SnesPalette &palette,
int num_colors = 8);
360 PaletteGroupMap &groups);
Shared graphical context across editors.
static std::unordered_map< uint8_t, gfx::Paletteset > palettesets_
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