snes_palette improvements

This commit is contained in:
Justin Scofield
2022-09-10 09:06:31 -05:00
parent 50b944851c
commit 51fdb0603f
2 changed files with 15 additions and 5 deletions

View File

@@ -81,6 +81,10 @@ void SNESColor::setRgb(ImVec4 val) {
snes = ConvertRGBtoSNES(col);
}
void SNESColor::setRgb(snes_color val) {
snes = ConvertRGBtoSNES(val);
}
void SNESColor::setSNES(uint16_t val) {
snes = val;
snes_color col = ConvertSNEStoRGB(val);
@@ -130,6 +134,15 @@ SNESPalette::SNESPalette(const std::vector<ImVec4>& cols) {
size_ = cols.size();
}
SNESPalette::SNESPalette(const std::vector<snes_color>& cols) {
for (const auto& each : cols) {
SNESColor scol;
scol.setRgb(each);
colors.push_back(scol);
}
size_ = cols.size();
}
char* SNESPalette::encode() {
auto data = new char[size_ * 2];
for (unsigned int i = 0; i < size_; i++) {
@@ -141,7 +154,6 @@ char* SNESPalette::encode() {
}
SDL_Palette* SNESPalette::GetSDL_Palette() {
std::cout << "Converting SNESPalette to SDL_Palette" << std::endl;
auto sdl_palette = std::make_shared<SDL_Palette>();
sdl_palette->ncolors = size_;
@@ -154,8 +166,6 @@ SDL_Palette* SNESPalette::GetSDL_Palette() {
<< " G:" << color[i].g << " B:" << color[i].b << ")" << std::endl;
}
sdl_palette->colors = color.data();
colors_.push_back(color);
return sdl_palette.get();
}

View File

@@ -43,6 +43,7 @@ struct SNESColor {
uint16_t snes = 0;
ImVec4 rgb;
void setRgb(ImVec4);
void setRgb(snes_color);
void setSNES(uint16_t);
};
@@ -53,14 +54,13 @@ class SNESPalette {
explicit SNESPalette(char* snesPal);
explicit SNESPalette(const unsigned char* snes_pal);
explicit SNESPalette(const std::vector<ImVec4>&);
explicit SNESPalette(const std::vector<snes_color>&);
char* encode();
SDL_Palette* GetSDL_Palette();
int size_ = 0;
std::vector<SNESColor> colors;
std::vector<SDL_Color*> colors_arrays_;
std::vector<std::vector<SDL_Color>> colors_;
};
} // namespace gfx