Add SelectablePalettePipeline for updating palette
This commit is contained in:
@@ -37,6 +37,10 @@ Bitmap::Bitmap(int width, int height, int depth, uchar *data, int data_size) {
|
||||
Create(width, height, depth, data, data_size);
|
||||
}
|
||||
|
||||
Bitmap::Bitmap(int width, int height, int depth, Bytes data) {
|
||||
Create(width, height, depth, data);
|
||||
}
|
||||
|
||||
// Pass raw pixel data directly to the surface
|
||||
void Bitmap::Create(int width, int height, int depth, uchar *data) {
|
||||
active_ = true;
|
||||
@@ -112,9 +116,18 @@ void Bitmap::CreateTexture(std::shared_ptr<SDL_Renderer> renderer) {
|
||||
SDL_Texture_Deleter{}};
|
||||
}
|
||||
|
||||
void Bitmap::UpdateTexture(std::shared_ptr<SDL_Renderer> renderer) {
|
||||
SDL_DestroyTexture(texture_.get());
|
||||
texture_ = nullptr;
|
||||
texture_ = std::shared_ptr<SDL_Texture>{
|
||||
SDL_CreateTextureFromSurface(renderer.get(), surface_.get()),
|
||||
SDL_Texture_Deleter{}};
|
||||
}
|
||||
|
||||
// Convert SNESPalette to SDL_Palette for surface.
|
||||
void Bitmap::ApplyPalette(const SNESPalette &palette) {
|
||||
palette_ = palette;
|
||||
SDL_UnlockSurface(surface_.get());
|
||||
for (int i = 0; i < palette.size_; ++i) {
|
||||
if (palette.GetColor(i).transparent) {
|
||||
surface_->format->palette->colors[i].r = 0;
|
||||
@@ -128,6 +141,7 @@ void Bitmap::ApplyPalette(const SNESPalette &palette) {
|
||||
surface_->format->palette->colors[i].a = palette.GetColor(i).rgb.w;
|
||||
}
|
||||
}
|
||||
SDL_LockSurface(surface_.get());
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -22,6 +22,7 @@ class Bitmap {
|
||||
Bitmap(int width, int height, int depth, uchar *data);
|
||||
Bitmap(int width, int height, int depth, int data_size);
|
||||
Bitmap(int width, int height, int depth, uchar *data, int data_size);
|
||||
Bitmap(int width, int height, int depth, Bytes data);
|
||||
|
||||
void Create(int width, int height, int depth, uchar *data);
|
||||
void Create(int width, int height, int depth, int data_size);
|
||||
@@ -31,6 +32,7 @@ class Bitmap {
|
||||
void Apply(Bytes data);
|
||||
|
||||
void CreateTexture(std::shared_ptr<SDL_Renderer> renderer);
|
||||
void UpdateTexture(std::shared_ptr<SDL_Renderer> renderer);
|
||||
|
||||
void ApplyPalette(const SNESPalette &palette);
|
||||
|
||||
|
||||
@@ -214,6 +214,20 @@ SDL_Palette* SNESPalette::GetSDL_Palette() {
|
||||
|
||||
PaletteGroup::PaletteGroup(uint8_t mSize) : size_(mSize) {}
|
||||
|
||||
PaletteGroup CreatePaletteGroupFromColFile(
|
||||
std::vector<SNESColor>& palette_rows) {
|
||||
PaletteGroup toret;
|
||||
|
||||
for (int i = 0; i < palette_rows.size(); i += 8) {
|
||||
SNESPalette palette;
|
||||
for (int j = 0; j < 8; j++) {
|
||||
palette.AddColor(palette_rows[i + j]);
|
||||
}
|
||||
toret.AddPalette(palette);
|
||||
}
|
||||
return toret;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
@@ -156,6 +156,8 @@ struct PaletteGroup {
|
||||
std::vector<SNESPalette> palettes;
|
||||
};
|
||||
|
||||
PaletteGroup CreatePaletteGroupFromColFile(std::vector<SNESColor>& colors);
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
|
||||
Reference in New Issue
Block a user