Refactor color conversion logic for improved accuracy and consistency
- Updated color channel assignments in ConvertRgbToSnes and SnesColor constructor to remove unnecessary static_cast, enhancing clarity and ensuring correct value usage. - Simplified namespace declaration in snes_palette.cc for better readability. - Changed Paletteset constructor parameters to use const references, improving performance and consistency in object handling.
This commit is contained in:
@@ -39,9 +39,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 = static_cast<uint8_t>(color.x) * kColorByteMax;
|
new_color.red = color.x * kColorByteMax;
|
||||||
new_color.green = static_cast<uint8_t>(color.y) * kColorByteMax;
|
new_color.green = color.y * kColorByteMax;
|
||||||
new_color.blue = static_cast<uint8_t>(color.z) * kColorByteMax;
|
new_color.blue = color.z * kColorByteMax;
|
||||||
return ConvertRgbToSnes(new_color);
|
return ConvertRgbToSnes(new_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ class SnesColor {
|
|||||||
|
|
||||||
explicit SnesColor(const ImVec4 val) : rgb_(val) {
|
explicit SnesColor(const ImVec4 val) : rgb_(val) {
|
||||||
snes_color color;
|
snes_color color;
|
||||||
color.red = static_cast<uint8_t>(val.x) / kColorByteMax;
|
color.red = val.x / kColorByteMax;
|
||||||
color.green = static_cast<uint8_t>(val.y) / kColorByteMax;
|
color.green = val.y / kColorByteMax;
|
||||||
color.blue = static_cast<uint8_t>(val.z) / kColorByteMax;
|
color.blue = val.z / kColorByteMax;
|
||||||
snes_ = ConvertRgbToSnes(color);
|
snes_ = ConvertRgbToSnes(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,7 @@
|
|||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
#include "util/macro.h"
|
#include "util/macro.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze::gfx {
|
||||||
namespace gfx {
|
|
||||||
|
|
||||||
SnesPalette::SnesPalette(char *data) {
|
SnesPalette::SnesPalette(char *data) {
|
||||||
assert((sizeof(data) % 4 == 0) && (sizeof(data) <= 32));
|
assert((sizeof(data) % 4 == 0) && (sizeof(data) <= 32));
|
||||||
@@ -359,5 +358,4 @@ absl::Status LoadAllPalettes(const std::vector<uint8_t> &rom_data,
|
|||||||
|
|
||||||
std::unordered_map<uint8_t, gfx::Paletteset> GfxContext::palettesets_;
|
std::unordered_map<uint8_t, gfx::Paletteset> GfxContext::palettesets_;
|
||||||
|
|
||||||
} // namespace gfx
|
} // namespace yaze::gfx
|
||||||
} // namespace yaze
|
|
||||||
|
|||||||
@@ -395,10 +395,11 @@ struct Paletteset {
|
|||||||
* @param spr2 The second sprite palette.
|
* @param spr2 The second sprite palette.
|
||||||
* @param comp The composite palette.
|
* @param comp The composite palette.
|
||||||
*/
|
*/
|
||||||
Paletteset(gfx::SnesPalette main, gfx::SnesPalette animated,
|
Paletteset(const gfx::SnesPalette& main, const gfx::SnesPalette& animated,
|
||||||
gfx::SnesPalette aux1, gfx::SnesPalette aux2,
|
const gfx::SnesPalette& aux1, const gfx::SnesPalette& aux2,
|
||||||
gfx::SnesColor background, gfx::SnesPalette hud,
|
const gfx::SnesColor& background, const gfx::SnesPalette& hud,
|
||||||
gfx::SnesPalette spr, gfx::SnesPalette spr2, gfx::SnesPalette comp)
|
const gfx::SnesPalette& spr, const gfx::SnesPalette& spr2,
|
||||||
|
const gfx::SnesPalette& comp)
|
||||||
: main_(main),
|
: main_(main),
|
||||||
animated(animated),
|
animated(animated),
|
||||||
aux1(aux1),
|
aux1(aux1),
|
||||||
|
|||||||
Reference in New Issue
Block a user