yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
snes_color.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GFX_SNES_COLOR_H_
2#define YAZE_APP_GFX_SNES_COLOR_H_
3
4#include <snes_color.h>
5
6#include <cstdint>
7#include <vector>
8
9#include "imgui/imgui.h"
10
11namespace yaze {
12namespace app {
13namespace gfx {
14
15constexpr int NumberOfColors = 3143;
16
18uint16_t ConvertRgbToSnes(const snes_color& color);
19uint16_t ConvertRgbToSnes(const ImVec4& color);
20
21std::vector<snes_color> Extract(const char* data, unsigned int offset,
22 unsigned int palette_size);
23
24std::vector<char> Convert(const std::vector<snes_color>& palette);
25
26constexpr uint8_t kColorByteMax = 255;
27constexpr float kColorByteMaxF = 255.f;
28
39class SnesColor {
40 public:
41 SnesColor() : rgb_(0.f, 0.f, 0.f, 0.f), snes_(0), rom_color_({0, 0, 0}) {}
42 explicit SnesColor(const ImVec4 val) : rgb_(val) {
43 snes_color color;
44 color.red = val.x / kColorByteMax;
45 color.green = val.y / kColorByteMax;
46 color.blue = val.z / kColorByteMax;
47 snes_ = ConvertRgbToSnes(color);
48 }
49 explicit SnesColor(const uint16_t val) : snes_(val) {
50 snes_color color = ConvertSnesToRgb(val);
51 rgb_ = ImVec4(color.red, color.green, color.blue, 0.f);
52 }
53 explicit SnesColor(const snes_color val)
54 : rgb_(val.red, val.green, val.blue, kColorByteMaxF),
55 snes_(ConvertRgbToSnes(val)),
56 rom_color_(val) {}
57
58 SnesColor(uint8_t r, uint8_t g, uint8_t b) {
59 rgb_ = ImVec4(r, g, b, kColorByteMaxF);
60 snes_color color;
61 color.red = r;
62 color.green = g;
63 color.blue = b;
64 snes_ = ConvertRgbToSnes(color);
65 rom_color_ = color;
66 }
67
68 ImVec4 rgb() const { return rgb_; }
69
70 void set_rgb(const ImVec4 val) {
71 rgb_.x = val.x / kColorByteMax;
72 rgb_.y = val.y / kColorByteMax;
73 rgb_.z = val.z / kColorByteMax;
74 snes_color color;
75 color.red = val.x;
76 color.green = val.y;
77 color.blue = val.z;
78 rom_color_ = color;
79 snes_ = ConvertRgbToSnes(color);
80 modified = true;
81 }
82
83 void set_snes(uint16_t val) {
84 snes_ = val;
86 rgb_ = ImVec4(col.red, col.green, col.blue, 0.f);
87 modified = true;
88 }
89
90 snes_color rom_color() const { return rom_color_; }
91 uint16_t snes() const { return snes_; }
92 bool is_modified() const { return modified; }
93 bool is_transparent() const { return transparent; }
94 void set_transparent(bool t) { transparent = t; }
95 void set_modified(bool m) { modified = m; }
96
97 private:
98 ImVec4 rgb_;
99 uint16_t snes_;
101 bool modified = false;
102 bool transparent = false;
103};
104
105SnesColor ReadColorFromRom(int offset, const uint8_t* rom);
106
107SnesColor GetCgxColor(uint16_t color);
108std::vector<SnesColor> GetColFileData(uint8_t* data);
109
110} // namespace gfx
111} // namespace app
112} // namespace yaze
113
114#endif // YAZE_APP_GFX_SNES_COLOR_H_
SNES Color container.
Definition snes_color.h:39
snes_color rom_color() const
Definition snes_color.h:90
SnesColor(const snes_color val)
Definition snes_color.h:53
void set_transparent(bool t)
Definition snes_color.h:94
SnesColor(const ImVec4 val)
Definition snes_color.h:42
void set_rgb(const ImVec4 val)
Definition snes_color.h:70
SnesColor(uint8_t r, uint8_t g, uint8_t b)
Definition snes_color.h:58
void set_modified(bool m)
Definition snes_color.h:95
SnesColor(const uint16_t val)
Definition snes_color.h:49
uint16_t snes() const
Definition snes_color.h:91
void set_snes(uint16_t val)
Definition snes_color.h:83
bool is_transparent() const
Definition snes_color.h:93
constexpr float kColorByteMaxF
Definition snes_color.h:27
SnesColor GetCgxColor(uint16_t color)
Definition snes_color.cc:80
SnesColor ReadColorFromRom(int offset, const uint8_t *rom)
Definition snes_color.cc:49
constexpr int NumberOfColors
Definition snes_color.h:15
std::vector< SnesColor > GetColFileData(uint8_t *data)
Definition snes_color.cc:90
snes_color ConvertSnesToRgb(uint16_t color_snes)
Definition snes_color.cc:20
std::vector< char > Convert(const std::vector< snes_color > &palette)
Definition snes_color.cc:70
uint16_t ConvertRgbToSnes(const snes_color &color)
Definition snes_color.cc:34
constexpr uint8_t kColorByteMax
Definition snes_color.h:26
std::vector< snes_color > Extract(const char *data, unsigned int offset, unsigned int palette_size)
Definition snes_color.cc:59
Definition common.cc:22
Primitive of 16-bit RGB SNES color.
Definition snes_color.h:13
uint16_t green
Definition snes_color.h:16
uint16_t red
Definition snes_color.h:14
uint16_t blue
Definition snes_color.h:15