Refactor color conversion functions for consistent naming and improved readability
This commit is contained in:
@@ -433,7 +433,7 @@ absl::Status PaletteEditor::HandleColorPopup(gfx::SnesPalette& palette, int i,
|
||||
|
||||
// SNES Format
|
||||
CustomFormatString(buf, IM_ARRAYSIZE(buf), "$%04X",
|
||||
ConvertRGBtoSNES(ImVec4(col[0], col[1], col[2], 1.0f)));
|
||||
ConvertRgbToSnes(ImVec4(col[0], col[1], col[2], 1.0f)));
|
||||
if (Selectable(buf)) SetClipboardText(buf);
|
||||
|
||||
EndPopup();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
|
||||
#include "app/gfx/snes_color.h"
|
||||
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace gfx {
|
||||
@@ -17,7 +17,7 @@ constexpr uint16_t SNES_BLUE_MASK = 32;
|
||||
constexpr uint16_t SNES_GREEN_SHIFT = 32;
|
||||
constexpr uint16_t SNES_BLUE_SHIFT = 1024;
|
||||
|
||||
snes_color ConvertSNEStoRGB(uint16_t color_snes) {
|
||||
snes_color ConvertSnesToRgb(uint16_t color_snes) {
|
||||
snes_color result;
|
||||
|
||||
result.red = (color_snes % SNES_RED_MASK) * 8;
|
||||
@@ -31,19 +31,19 @@ snes_color ConvertSNEStoRGB(uint16_t color_snes) {
|
||||
return result;
|
||||
}
|
||||
|
||||
uint16_t ConvertRGBtoSNES(const snes_color& color) {
|
||||
uint16_t ConvertRgbToSnes(const snes_color& color) {
|
||||
uint16_t red = color.red / 8;
|
||||
uint16_t green = color.green / 8;
|
||||
uint16_t blue = color.blue / 8;
|
||||
return (blue * SNES_BLUE_SHIFT) + (green * SNES_GREEN_SHIFT) + red;
|
||||
}
|
||||
|
||||
uint16_t ConvertRGBtoSNES(const ImVec4& color) {
|
||||
uint16_t ConvertRgbToSnes(const ImVec4& color) {
|
||||
snes_color new_color;
|
||||
new_color.red = color.x * kColorByteMax;
|
||||
new_color.green = color.y * kColorByteMax;
|
||||
new_color.blue = color.z * kColorByteMax;
|
||||
return ConvertRGBtoSNES(new_color);
|
||||
return ConvertRgbToSnes(new_color);
|
||||
}
|
||||
|
||||
SnesColor ReadColorFromRom(int offset, const uint8_t* rom) {
|
||||
@@ -62,7 +62,7 @@ std::vector<snes_color> Extract(const char* data, unsigned int offset,
|
||||
for (unsigned int i = 0; i < palette_size * 2; i += 2) {
|
||||
uint16_t snes_color = (static_cast<uint8_t>(data[offset + i + 1]) << 8) |
|
||||
static_cast<uint8_t>(data[offset + i]);
|
||||
palette[i / 2] = ConvertSNEStoRGB(snes_color);
|
||||
palette[i / 2] = ConvertSnesToRgb(snes_color);
|
||||
}
|
||||
return palette;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ std::vector<snes_color> Extract(const char* data, unsigned int offset,
|
||||
std::vector<char> Convert(const std::vector<snes_color>& palette) {
|
||||
std::vector<char> data(palette.size() * 2);
|
||||
for (unsigned int i = 0; i < palette.size(); i++) {
|
||||
uint16_t snes_data = ConvertRGBtoSNES(palette[i]);
|
||||
uint16_t snes_data = ConvertRgbToSnes(palette[i]);
|
||||
data[i * 2] = snes_data & 0xFF;
|
||||
data[i * 2 + 1] = snes_data >> 8;
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ namespace gfx {
|
||||
|
||||
constexpr int NumberOfColors = 3143;
|
||||
|
||||
snes_color ConvertSNEStoRGB(uint16_t snes_color);
|
||||
uint16_t ConvertRGBtoSNES(const snes_color& color);
|
||||
uint16_t ConvertRGBtoSNES(const ImVec4& color);
|
||||
snes_color ConvertSnesToRgb(uint16_t snes_color);
|
||||
uint16_t ConvertRgbToSnes(const snes_color& color);
|
||||
uint16_t ConvertRgbToSnes(const ImVec4& color);
|
||||
|
||||
std::vector<snes_color> Extract(const char* data, unsigned int offset,
|
||||
unsigned int palette_size);
|
||||
@@ -44,15 +44,15 @@ class SnesColor {
|
||||
color.red = val.x / kColorByteMax;
|
||||
color.green = val.y / kColorByteMax;
|
||||
color.blue = val.z / kColorByteMax;
|
||||
snes_ = ConvertRGBtoSNES(color);
|
||||
snes_ = ConvertRgbToSnes(color);
|
||||
}
|
||||
explicit SnesColor(const uint16_t val) : snes_(val) {
|
||||
snes_color color = ConvertSNEStoRGB(val);
|
||||
snes_color color = ConvertSnesToRgb(val);
|
||||
rgb_ = ImVec4(color.red, color.green, color.blue, 0.f);
|
||||
}
|
||||
explicit SnesColor(const snes_color val)
|
||||
: rgb_(val.red, val.green, val.blue, kColorByteMaxF),
|
||||
snes_(ConvertRGBtoSNES(val)),
|
||||
snes_(ConvertRgbToSnes(val)),
|
||||
rom_color_(val) {}
|
||||
|
||||
SnesColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
@@ -61,7 +61,7 @@ class SnesColor {
|
||||
color.red = r;
|
||||
color.green = g;
|
||||
color.blue = b;
|
||||
snes_ = ConvertRGBtoSNES(color);
|
||||
snes_ = ConvertRgbToSnes(color);
|
||||
rom_color_ = color;
|
||||
}
|
||||
|
||||
@@ -76,13 +76,13 @@ class SnesColor {
|
||||
color.green = val.y;
|
||||
color.blue = val.z;
|
||||
rom_color_ = color;
|
||||
snes_ = ConvertRGBtoSNES(color);
|
||||
snes_ = ConvertRgbToSnes(color);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
void set_snes(uint16_t val) {
|
||||
snes_ = val;
|
||||
snes_color col = ConvertSNEStoRGB(val);
|
||||
snes_color col = ConvertSnesToRgb(val);
|
||||
rgb_ = ImVec4(col.red, col.green, col.blue, 0.f);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ SnesPalette::SnesPalette(char *data) {
|
||||
SnesColor col;
|
||||
col.set_snes(static_cast<uchar>(data[i + 1]) << 8);
|
||||
col.set_snes(col.snes() | static_cast<uchar>(data[i]));
|
||||
snes_color mColor = ConvertSNEStoRGB(col.snes());
|
||||
snes_color mColor = ConvertSnesToRgb(col.snes());
|
||||
col.set_rgb(ImVec4(mColor.red, mColor.green, mColor.blue, 1.f));
|
||||
colors.push_back(col);
|
||||
}
|
||||
@@ -241,7 +241,7 @@ SnesPalette::SnesPalette(const unsigned char *snes_pal) {
|
||||
SnesColor col;
|
||||
col.set_snes(snes_pal[i + 1] << (uint16_t)8);
|
||||
col.set_snes(col.snes() | snes_pal[i]);
|
||||
snes_color mColor = ConvertSNEStoRGB(col.snes());
|
||||
snes_color mColor = ConvertSnesToRgb(col.snes());
|
||||
col.set_rgb(ImVec4(mColor.red, mColor.green, mColor.blue, 1.f));
|
||||
colors.push_back(col);
|
||||
}
|
||||
@@ -258,7 +258,7 @@ SnesPalette::SnesPalette(const std::vector<ImVec4> &cols) {
|
||||
SnesPalette::SnesPalette(const std::vector<snes_color> &cols) {
|
||||
for (const auto &each : cols) {
|
||||
SnesColor scol;
|
||||
scol.set_snes(ConvertRGBtoSNES(each));
|
||||
scol.set_snes(ConvertRgbToSnes(each));
|
||||
colors.push_back(scol);
|
||||
}
|
||||
}
|
||||
@@ -279,7 +279,7 @@ SnesPalette ReadPaletteFromRom(int offset, int num_colors, const uint8_t *rom) {
|
||||
new_color.red = (color & 0x1F) * 8;
|
||||
new_color.green = ((color >> 5) & 0x1F) * 8;
|
||||
new_color.blue = ((color >> 10) & 0x1F) * 8;
|
||||
colors[color_offset].set_snes(ConvertRGBtoSNES(new_color));
|
||||
colors[color_offset].set_snes(ConvertRgbToSnes(new_color));
|
||||
if (color_offset == 0) {
|
||||
colors[color_offset].set_transparent(true);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ IMGUI_API bool SnesColorEdit4(absl::string_view label, SnesColor* color,
|
||||
ImGui::ColorEdit4(label.data(), (float*)&displayColor.x, flags);
|
||||
|
||||
color->set_rgb(displayColor);
|
||||
color->set_snes(gfx::ConvertRGBtoSNES(displayColor));
|
||||
color->set_snes(gfx::ConvertRgbToSnes(displayColor));
|
||||
|
||||
return pressed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user