gfx housekeeping
This commit is contained in:
@@ -256,10 +256,12 @@ void Bitmap::Reformat(int format) {
|
|||||||
GetSnesPixelFormat(format)),
|
GetSnesPixelFormat(format)),
|
||||||
SDL_Surface_Deleter());
|
SDL_Surface_Deleter());
|
||||||
surface_->pixels = pixel_data_;
|
surface_->pixels = pixel_data_;
|
||||||
if (!ApplyPalette(palette_).ok()) {
|
|
||||||
// Some sort of error occurred, throw an exception?
|
|
||||||
}
|
|
||||||
active_ = true;
|
active_ = true;
|
||||||
|
auto apply_palette = ApplyPalette(palette_);
|
||||||
|
if (!apply_palette.ok()) {
|
||||||
|
SDL_Log("Failed to apply palette: %s\n", apply_palette.message().data());
|
||||||
|
active_ = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bitmap::CreateTexture(SDL_Renderer *renderer) {
|
void Bitmap::CreateTexture(SDL_Renderer *renderer) {
|
||||||
@@ -402,9 +404,7 @@ absl::Status Bitmap::ApplyPaletteWithTransparent(const SnesPalette &palette,
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
SDL_LockSurface(surface_.get());
|
SDL_LockSurface(surface_.get());
|
||||||
if (SDL_GetError() != nullptr) { // Check for SDL errors
|
SDL_RETURN_IF_ERROR()
|
||||||
return absl::InternalError(absl::StrCat("SDL Error: ", SDL_GetError()));
|
|
||||||
}
|
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ class Bitmap {
|
|||||||
height_ = 0;
|
height_ = 0;
|
||||||
depth_ = 0;
|
depth_ = 0;
|
||||||
data_size_ = 0;
|
data_size_ = 0;
|
||||||
palette_.Clear();
|
palette_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sdl_palette() {
|
auto sdl_palette() {
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ uint16_t ConvertRGBtoSNES(const snes_color& color) {
|
|||||||
|
|
||||||
uint16_t ConvertRGBtoSNES(const ImVec4& color) {
|
uint16_t ConvertRGBtoSNES(const ImVec4& color) {
|
||||||
snes_color new_color;
|
snes_color new_color;
|
||||||
new_color.red = color.x * 255;
|
new_color.red = color.x * kColorByteMax;
|
||||||
new_color.green = color.y * 255;
|
new_color.green = color.y * kColorByteMax;
|
||||||
new_color.blue = color.z * 255;
|
new_color.blue = color.z * kColorByteMax;
|
||||||
return ConvertRGBtoSNES(new_color);
|
return ConvertRGBtoSNES(new_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ std::vector<snes_color> Extract(const char* data, unsigned int offset,
|
|||||||
|
|
||||||
std::vector<char> Convert(const std::vector<snes_color>& palette);
|
std::vector<char> Convert(const std::vector<snes_color>& palette);
|
||||||
|
|
||||||
|
constexpr uint8_t kColorByteMax = 255;
|
||||||
|
constexpr float kColorByteMaxF = 255.f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SNES Color container
|
* @brief SNES Color container
|
||||||
*
|
*
|
||||||
@@ -35,9 +38,9 @@ class SnesColor {
|
|||||||
SnesColor() : rgb_(0.f, 0.f, 0.f, 0.f), snes_(0) {}
|
SnesColor() : rgb_(0.f, 0.f, 0.f, 0.f), snes_(0) {}
|
||||||
explicit SnesColor(const ImVec4 val) : rgb_(val) {
|
explicit SnesColor(const ImVec4 val) : rgb_(val) {
|
||||||
snes_color color;
|
snes_color color;
|
||||||
color.red = val.x / 255;
|
color.red = val.x / kColorByteMax;
|
||||||
color.green = val.y / 255;
|
color.green = val.y / kColorByteMax;
|
||||||
color.blue = val.z / 255;
|
color.blue = val.z / kColorByteMax;
|
||||||
snes_ = ConvertRGBtoSNES(color);
|
snes_ = ConvertRGBtoSNES(color);
|
||||||
}
|
}
|
||||||
explicit SnesColor(const uint16_t val) : snes_(val) {
|
explicit SnesColor(const uint16_t val) : snes_(val) {
|
||||||
@@ -45,12 +48,12 @@ class SnesColor {
|
|||||||
rgb_ = ImVec4(color.red, color.green, color.blue, 0.f);
|
rgb_ = ImVec4(color.red, color.green, color.blue, 0.f);
|
||||||
}
|
}
|
||||||
explicit SnesColor(const snes_color val)
|
explicit SnesColor(const snes_color val)
|
||||||
: rgb_(val.red, val.green, val.blue, 255.f),
|
: rgb_(val.red, val.green, val.blue, kColorByteMaxF),
|
||||||
snes_(ConvertRGBtoSNES(val)),
|
snes_(ConvertRGBtoSNES(val)),
|
||||||
rom_color_(val) {}
|
rom_color_(val) {}
|
||||||
|
|
||||||
SnesColor(uint8_t r, uint8_t g, uint8_t b) {
|
SnesColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||||
rgb_ = ImVec4(r, g, b, 255.f);
|
rgb_ = ImVec4(r, g, b, kColorByteMaxF);
|
||||||
snes_color color;
|
snes_color color;
|
||||||
color.red = r;
|
color.red = r;
|
||||||
color.green = g;
|
color.green = g;
|
||||||
@@ -62,9 +65,9 @@ class SnesColor {
|
|||||||
ImVec4 rgb() const { return rgb_; }
|
ImVec4 rgb() const { return rgb_; }
|
||||||
|
|
||||||
void set_rgb(const ImVec4 val) {
|
void set_rgb(const ImVec4 val) {
|
||||||
rgb_.x = val.x / 255;
|
rgb_.x = val.x / kColorByteMax;
|
||||||
rgb_.y = val.y / 255;
|
rgb_.y = val.y / kColorByteMax;
|
||||||
rgb_.z = val.z / 255;
|
rgb_.z = val.z / kColorByteMax;
|
||||||
snes_color color;
|
snes_color color;
|
||||||
color.red = val.x;
|
color.red = val.x;
|
||||||
color.green = val.y;
|
color.green = val.y;
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#ifndef YAZE_APP_GFX_PALETTE_H
|
#ifndef YAZE_APP_GFX_PALETTE_H
|
||||||
#define YAZE_APP_GFX_PALETTE_H
|
#define YAZE_APP_GFX_PALETTE_H
|
||||||
|
|
||||||
#include <SDL.h>
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -127,9 +125,7 @@ class SnesPalette {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AddColor(const SnesColor& color) { colors.emplace_back(color); }
|
void AddColor(const SnesColor& color) { colors.emplace_back(color); }
|
||||||
|
|
||||||
void AddColor(const snes_color& color) { colors.emplace_back(color); }
|
void AddColor(const snes_color& color) { colors.emplace_back(color); }
|
||||||
|
|
||||||
void AddColor(uint16_t color) { colors.emplace_back(color); }
|
void AddColor(uint16_t color) { colors.emplace_back(color); }
|
||||||
|
|
||||||
absl::StatusOr<SnesColor> GetColor(int i) const {
|
absl::StatusOr<SnesColor> GetColor(int i) const {
|
||||||
@@ -141,8 +137,7 @@ class SnesPalette {
|
|||||||
|
|
||||||
auto mutable_color(int i) { return &colors[i]; }
|
auto mutable_color(int i) { return &colors[i]; }
|
||||||
|
|
||||||
void Clear() { colors.clear(); }
|
void clear() { colors.clear(); }
|
||||||
|
|
||||||
auto size() const { return colors.size(); }
|
auto size() const { return colors.size(); }
|
||||||
auto empty() const { return colors.empty(); }
|
auto empty() const { return colors.empty(); }
|
||||||
|
|
||||||
@@ -156,14 +151,15 @@ class SnesPalette {
|
|||||||
|
|
||||||
void operator()(int i, const SnesColor& color) {
|
void operator()(int i, const SnesColor& color) {
|
||||||
if (i >= colors.size()) {
|
if (i >= colors.size()) {
|
||||||
throw std::out_of_range("SNESPalette: Index out of bounds");
|
std::cout << SNESPalette: Index out of bounds << std::endl;
|
||||||
}
|
}
|
||||||
colors[i] = color;
|
colors[i] = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(int i, const ImVec4& color) {
|
void operator()(int i, const ImVec4& color) {
|
||||||
if (i >= colors.size()) {
|
if (i >= colors.size()) {
|
||||||
throw std::out_of_range("SNESPalette: Index out of bounds");
|
std::cout << SNESPalette: Index out of bounds << std::endl;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
colors[i].set_rgb(color);
|
colors[i].set_rgb(color);
|
||||||
colors[i].set_modified(true);
|
colors[i].set_modified(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user