palette stuff
This commit is contained in:
@@ -103,8 +103,9 @@ void Bitmap::CreateTexture(std::shared_ptr<SDL_Renderer> renderer) {
|
||||
}
|
||||
|
||||
// Convert SNESPalette to SDL_Palette for surface.
|
||||
void Bitmap::ApplyPalette(SNESPalette &palette) {
|
||||
surface_->format->palette = palette.GetSDL_Palette();
|
||||
void Bitmap::ApplyPalette(SNESPalette palette) {
|
||||
palette_ = palette;
|
||||
surface_->format->palette = palette_.GetSDL_Palette();
|
||||
}
|
||||
|
||||
void Bitmap::SetPaletteColor(int id, gfx::snes_color color) {
|
||||
|
||||
@@ -30,7 +30,7 @@ class Bitmap {
|
||||
|
||||
void CreateTexture(std::shared_ptr<SDL_Renderer> renderer);
|
||||
|
||||
void ApplyPalette(SNESPalette &palette);
|
||||
void ApplyPalette(SNESPalette palette);
|
||||
void SetPaletteColor(int id, gfx::snes_color color);
|
||||
|
||||
absl::StatusOr<std::vector<Bitmap>> CreateTiles();
|
||||
@@ -72,6 +72,7 @@ class Bitmap {
|
||||
bool freed_ = false;
|
||||
uchar *pixel_data_;
|
||||
Bytes data_;
|
||||
gfx::SNESPalette palette_;
|
||||
std::shared_ptr<SDL_Texture> texture_ = nullptr;
|
||||
std::shared_ptr<SDL_Surface> surface_ = nullptr;
|
||||
};
|
||||
|
||||
@@ -64,6 +64,8 @@ char* Convert(const snes_palette pal) {
|
||||
|
||||
SNESColor::SNESColor() : rgb(ImVec4(0.f, 0.f, 0.f, 0.f)) {}
|
||||
|
||||
SNESColor::SNESColor(snes_color val) { snes = ConvertRGBtoSNES(val); }
|
||||
|
||||
SNESColor::SNESColor(ImVec4 val) : rgb(val) {
|
||||
snes_color col;
|
||||
col.red = (uchar)val.x;
|
||||
@@ -81,9 +83,7 @@ void SNESColor::setRgb(ImVec4 val) {
|
||||
snes = ConvertRGBtoSNES(col);
|
||||
}
|
||||
|
||||
void SNESColor::setRgb(snes_color val) {
|
||||
snes = ConvertRGBtoSNES(val);
|
||||
}
|
||||
void SNESColor::setRgb(snes_color val) { snes = ConvertRGBtoSNES(val); }
|
||||
|
||||
void SNESColor::setSNES(uint16_t val) {
|
||||
snes = val;
|
||||
@@ -143,6 +143,20 @@ SNESPalette::SNESPalette(const std::vector<snes_color>& cols) {
|
||||
size_ = cols.size();
|
||||
}
|
||||
|
||||
SNESPalette::SNESPalette(const std::vector<SNESColor>& cols) {
|
||||
for (const auto& each : cols) {
|
||||
colors.push_back(each);
|
||||
}
|
||||
size_ = cols.size();
|
||||
}
|
||||
|
||||
void SNESPalette::Create(const std::vector<SNESColor>& cols) {
|
||||
for (const auto& each : cols) {
|
||||
colors.push_back(each);
|
||||
}
|
||||
size_ = cols.size();
|
||||
}
|
||||
|
||||
char* SNESPalette::encode() {
|
||||
auto data = new char[size_ * 2];
|
||||
for (unsigned int i = 0; i < size_; i++) {
|
||||
@@ -169,6 +183,11 @@ SDL_Palette* SNESPalette::GetSDL_Palette() {
|
||||
return sdl_palette.get();
|
||||
}
|
||||
|
||||
PaletteGroup::PaletteGroup(uint8_t mSize) {
|
||||
size = mSize;
|
||||
palettes.reserve(size);
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
@@ -40,6 +40,7 @@ char* Convert(const snes_palette pal);
|
||||
struct SNESColor {
|
||||
SNESColor();
|
||||
explicit SNESColor(ImVec4);
|
||||
explicit SNESColor(snes_color);
|
||||
uint16_t snes = 0;
|
||||
ImVec4 rgb;
|
||||
void setRgb(ImVec4);
|
||||
@@ -55,6 +56,19 @@ class SNESPalette {
|
||||
explicit SNESPalette(const unsigned char* snes_pal);
|
||||
explicit SNESPalette(const std::vector<ImVec4>&);
|
||||
explicit SNESPalette(const std::vector<snes_color>&);
|
||||
explicit SNESPalette(const std::vector<SNESColor>&);
|
||||
|
||||
void Create(const std::vector<SNESColor>&);
|
||||
|
||||
auto GetColor(int i) const { return colors[i]; }
|
||||
|
||||
SNESColor operator[](int i) {
|
||||
if (i > size_) {
|
||||
std::cout << "SNESPalette: Index out of bounds" << std::endl;
|
||||
return colors[0];
|
||||
}
|
||||
return colors[i];
|
||||
}
|
||||
|
||||
char* encode();
|
||||
SDL_Palette* GetSDL_Palette();
|
||||
@@ -63,6 +77,20 @@ class SNESPalette {
|
||||
std::vector<SNESColor> colors;
|
||||
};
|
||||
|
||||
struct PaletteGroup {
|
||||
PaletteGroup() = default;
|
||||
explicit PaletteGroup(uint8_t mSize);
|
||||
SNESPalette operator[](int i) {
|
||||
if (i > size) {
|
||||
std::cout << "PaletteGroup: Index out of bounds" << std::endl;
|
||||
return palettes[0];
|
||||
}
|
||||
return palettes[i];
|
||||
}
|
||||
int size = 0;
|
||||
std::vector<SNESPalette> palettes;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
|
||||
Reference in New Issue
Block a user