12#include "absl/container/flat_hash_map.h"
13#include "absl/status/status.h"
14#include "absl/status/statusor.h"
17#include "imgui/imgui.h"
27namespace palette_group_internal {
30 auto data = rom_data.data();
31 for (
int i = 0; i < 6; i++) {
36 return absl::OkStatus();
40 const std::vector<uint8_t> &rom_data,
42 auto data = rom_data.data();
43 for (
int i = 0; i < 20; i++) {
48 return absl::OkStatus();
52 const std::vector<uint8_t> &rom_data,
54 auto data = rom_data.data();
55 for (
int i = 0; i < 14; i++) {
59 return absl::OkStatus();
64 auto data = rom_data.data();
65 for (
int i = 0; i < 2; i++) {
69 return absl::OkStatus();
74 auto data = rom_data.data();
79 return absl::OkStatus();
84 auto data = rom_data.data();
85 for (
int i = 0; i < 5; i++) {
89 return absl::OkStatus();
94 auto data = rom_data.data();
95 for (
int i = 0; i < 4; i++) {
99 return absl::OkStatus();
104 auto data = rom_data.data();
105 for (
int i = 0; i < 3; i++) {
109 return absl::OkStatus();
114 auto data = rom_data.data();
115 for (
int i = 0; i < 12; i++) {
119 return absl::OkStatus();
124 auto data = rom_data.data();
125 for (
int i = 0; i < 11; i++) {
129 return absl::OkStatus();
134 auto data = rom_data.data();
135 for (
int i = 0; i < 24; i++) {
139 return absl::OkStatus();
144 auto data = rom_data.data();
145 for (
int i = 0; i < 20; i++) {
149 return absl::OkStatus();
160 return absl::OkStatus();
165 auto data = rom_data.data();
170 return absl::OkStatus();
174 const std::vector<uint8_t> &rom_data,
176 auto data = rom_data.data();
177 for (
int i = 0; i < 2; i++) {
181 return absl::OkStatus();
204 {
"ow_main", 35}, {
"ow_aux", 21}, {
"ow_animated", 7},
205 {
"hud", 32}, {
"global_sprites", 60}, {
"armors", 15},
206 {
"swords", 3}, {
"shields", 4}, {
"sprites_aux1", 7},
207 {
"sprites_aux2", 7}, {
"sprites_aux3", 7}, {
"dungeon_main", 90},
208 {
"grass", 1}, {
"3d_object", 8}, {
"ow_mini_map", 128},
212 size_t color_index) {
220 uint32_t address = base_address + (palette_index * colors_per_palette * 2) +
227 assert((
sizeof(data) % 4 == 0) && (
sizeof(data) <= 32));
228 for (
unsigned i = 0; i <
sizeof(data); i += 2) {
239 assert((
sizeof(snes_pal) % 4 == 0) && (
sizeof(snes_pal) <= 32));
240 for (
unsigned i = 0; i <
sizeof(snes_pal); i += 2) {
242 col.
set_snes(snes_pal[i + 1] << (uint16_t)8);
251 for (
const auto &each : cols) {
259 for (
const auto &each : cols) {
267 for (
const auto &each : cols) {
273 int color_offset = 0;
274 std::vector<gfx::SnesColor> colors(num_colors);
276 while (color_offset < num_colors) {
277 short color = (
ushort)((rom[offset + 1]) << 8) | rom[offset];
279 new_color.
red = (color & 0x1F) * 8;
280 new_color.
green = ((color >> 5) & 0x1F) * 8;
281 new_color.
blue = ((color >> 10) & 0x1F) * 8;
283 if (color_offset == 0) {
284 colors[color_offset].set_transparent(
true);
294 std::array<float, 4> colorArray;
295 colorArray[0] = color.
rgb().x / 255.0f;
296 colorArray[1] = color.
rgb().y / 255.0f;
297 colorArray[2] = color.
rgb().z / 255.0f;
298 colorArray[3] = color.
rgb().w;
303 std::vector<SnesColor> &palette_rows) {
305 for (
int i = 0; i < palette_rows.size(); i += 8) {
307 for (
int j = 0; j < 8; j++) {
308 palette.
AddColor(palette_rows[i + j].rom_color());
312 return palette_group;
318 for (
int i = 0; i < palette.
size(); i += num_colors) {
320 if (i + num_colors < palette.
size()) {
321 for (
int j = 0; j < num_colors; j++) {
322 new_palette.
AddColor(palette[i + j]);
327 return palette_group;
330using namespace palette_group_internal;
350 return absl::OkStatus();
static std::unordered_map< uint8_t, gfx::Paletteset > palettesets_
void set_rgb(const ImVec4 val)
void set_snes(uint16_t val)
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
void AddColor(const SnesColor &color)
std::vector< SnesColor > colors
#define RETURN_IF_ERROR(expression)
absl::Status Load3DObjectPalettes(const std::vector< uint8_t > &rom_data, gfx::PaletteGroupMap &palette_groups)
absl::Status LoadShieldPalettes(const std::vector< uint8_t > &rom_data, gfx::PaletteGroupMap &palette_groups)
absl::Status LoadGlobalSpritePalettes(const std::vector< uint8_t > &rom_data, gfx::PaletteGroupMap &palette_groups)
absl::Status LoadHUDPalettes(const std::vector< uint8_t > &rom_data, gfx::PaletteGroupMap &palette_groups)
absl::Status LoadOverworldMiniMapPalettes(const std::vector< uint8_t > &rom_data, gfx::PaletteGroupMap &palette_groups)
absl::Status LoadOverworldAuxiliaryPalettes(const std::vector< uint8_t > &rom_data, gfx::PaletteGroupMap &palette_groups)
absl::Status LoadOverworldMainPalettes(const std::vector< uint8_t > &rom_data, gfx::PaletteGroupMap &palette_groups)
absl::Status LoadGrassColors(const std::vector< uint8_t > &rom_data, gfx::PaletteGroupMap &palette_groups)
absl::Status LoadDungeonMainPalettes(const std::vector< uint8_t > &rom_data, gfx::PaletteGroupMap &palette_groups)
absl::Status LoadSpriteAux1Palettes(const std::vector< uint8_t > &rom_data, gfx::PaletteGroupMap &palette_groups)
absl::Status LoadSpriteAux2Palettes(const std::vector< uint8_t > &rom_data, gfx::PaletteGroupMap &palette_groups)
absl::Status LoadSpriteAux3Palettes(const std::vector< uint8_t > &rom_data, gfx::PaletteGroupMap &palette_groups)
absl::Status LoadOverworldAnimatedPalettes(const std::vector< uint8_t > &rom_data, gfx::PaletteGroupMap &palette_groups)
absl::Status LoadArmorPalettes(const std::vector< uint8_t > &rom_data, gfx::PaletteGroupMap &palette_groups)
absl::Status LoadSwordPalettes(const std::vector< uint8_t > &rom_data, gfx::PaletteGroupMap &palette_groups)
uint32_t GetPaletteAddress(const std::string &group_name, size_t palette_index, size_t color_index)
const absl::flat_hash_map< std::string, uint32_t > kPaletteGroupAddressMap
constexpr int kSwordPalettes
constexpr int kOverworldMiniMapPalettes
SnesColor ReadColorFromRom(int offset, const uint8_t *rom)
constexpr int kShieldPalettes
constexpr int kHudPalettes
constexpr int kSpritesPalettesAux3
const absl::flat_hash_map< std::string, uint32_t > kPaletteGroupColorCounts
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 kTriforcePalette
absl::StatusOr< PaletteGroup > CreatePaletteGroupFromColFile(std::vector< SnesColor > &palette_rows)
constexpr int kHardcodedGrassLW
constexpr int kOverworldPaletteMain
constexpr int kOverworldPaletteAux
snes_color ConvertSnesToRgb(uint16_t color_snes)
constexpr int kSpritesPalettesAux2
uint16_t ConvertRgbToSnes(const snes_color &color)
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
PaletteGroup overworld_main
PaletteGroup sprites_aux1
PaletteGroup sprites_aux3
PaletteGroup sprites_aux2
PaletteGroup global_sprites
PaletteGroup overworld_animated
PaletteGroup dungeon_main
PaletteGroup overworld_mini_map
Represents a group of palettes.
void AddPalette(SnesPalette pal)
void AddColor(SnesColor color)