clang-tidy

This commit is contained in:
2026-04-03 09:31:41 +02:00
parent 8dcc1d282a
commit 46dc81124f
25 changed files with 320 additions and 314 deletions
+34 -34
View File
@@ -15,9 +15,9 @@
// ── Conversión string ↔ PaletteSortMode ──────────────────────────────────────
auto sortModeFromString(const std::string& str) -> PaletteSortMode {
const std::string lower = toLower(str);
if (lower == "luminance") { return PaletteSortMode::LUMINANCE; }
if (lower == "spectrum") { return PaletteSortMode::SPECTRUM; }
const std::string LOWER = toLower(str);
if (LOWER == "luminance") { return PaletteSortMode::LUMINANCE; }
if (LOWER == "spectrum") { return PaletteSortMode::SPECTRUM; }
return PaletteSortMode::ORIGINAL;
}
@@ -66,15 +66,15 @@ namespace {
// Luminancia percibida (ITU-R BT.709)
auto luminance(Uint32 color) -> double {
return 0.2126 * redOf(color) + 0.7152 * greenOf(color) + 0.0722 * blueOf(color);
return (0.2126 * redOf(color)) + (0.7152 * greenOf(color)) + (0.0722 * blueOf(color));
}
// Distancia euclídea al cuadrado en espacio RGB (no necesita sqrt para comparar)
auto rgbDistanceSq(Uint32 a, Uint32 b) -> int {
const int dr = redOf(a) - redOf(b);
const int dg = greenOf(a) - greenOf(b);
const int db = blueOf(a) - blueOf(b);
return dr * dr + dg * dg + db * db;
const int DR = redOf(a) - redOf(b);
const int DG = greenOf(a) - greenOf(b);
const int DB = blueOf(a) - blueOf(b);
return (DR * DR) + (DG * DG) + (DB * DB);
}
// Cuenta los colores activos en la paleta (los que tienen alpha != 0)
@@ -89,31 +89,31 @@ namespace {
// Ordenar por luminancia
auto sortByLuminance(const Palette& palette) -> Palette {
const size_t n = countActiveColors(palette);
std::vector<Uint32> colors(palette.begin(), palette.begin() + static_cast<ptrdiff_t>(n));
std::sort(colors.begin(), colors.end(), [](Uint32 a, Uint32 b) {
const size_t N = countActiveColors(palette);
std::vector<Uint32> colors(palette.begin(), palette.begin() + static_cast<ptrdiff_t>(N));
std::ranges::sort(colors, [](Uint32 a, Uint32 b) {
return luminance(a) < luminance(b);
});
Palette result{};
result.fill(0);
std::copy(colors.begin(), colors.end(), result.begin());
std::ranges::copy(colors, result.begin());
return result;
}
// Ordenar por similitud con la paleta ZX Spectrum (greedy matching)
auto sortBySpectrum(const Palette& palette) -> Palette {
const size_t n = countActiveColors(palette);
std::vector<Uint32> available(palette.begin(), palette.begin() + static_cast<ptrdiff_t>(n));
const size_t N = countActiveColors(palette);
std::vector<Uint32> available(palette.begin(), palette.begin() + static_cast<ptrdiff_t>(N));
std::vector<Uint32> result;
result.reserve(n);
result.reserve(N);
// Para cada color de referencia del Spectrum, buscar el más cercano disponible
const size_t refs = std::min(n, SPECTRUM_REFERENCE.size());
for (size_t i = 0; i < refs && !available.empty(); ++i) {
const Uint32 ref = SPECTRUM_REFERENCE[i];
auto best = std::min_element(available.begin(), available.end(), [ref](Uint32 a, Uint32 b) {
return rgbDistanceSq(a, ref) < rgbDistanceSq(b, ref);
const size_t REFS = std::min(N, SPECTRUM_REFERENCE.size());
for (size_t i = 0; i < REFS && !available.empty(); ++i) {
const Uint32 REF = SPECTRUM_REFERENCE[i];
auto best = std::ranges::min_element(available, [REF](Uint32 a, Uint32 b) {
return rgbDistanceSq(a, REF) < rgbDistanceSq(b, REF);
});
result.push_back(*best);
available.erase(best);
@@ -126,7 +126,7 @@ namespace {
Palette out{};
out.fill(0);
std::copy(result.begin(), result.end(), out.begin());
std::ranges::copy(result, out.begin());
return out;
}
} // namespace
@@ -149,9 +149,9 @@ PaletteManager::PaletteManager(
// Leer y aplicar paleta inicial directamente desde el archivo
// (Resource::Cache aún no está disponible en este punto del ciclo de vida)
const auto initial_palette = sortPalette(readPalFile(palettes_.at(current_)), sort_mode_);
game_surface_->setPalette(initial_palette);
border_surface_->setPalette(initial_palette);
const auto INITIAL_PALETTE = sortPalette(readPalFile(palettes_.at(current_)), sort_mode_);
game_surface_->setPalette(INITIAL_PALETTE);
border_surface_->setPalette(INITIAL_PALETTE);
// Procesar la lista: conservar solo los nombres de archivo (sin ruta)
processPathList();
@@ -170,9 +170,9 @@ void PaletteManager::previous() {
}
auto PaletteManager::setByName(const std::string& name) -> bool {
const std::string lower_name = toLower(name + ".pal");
const std::string LOWER_NAME = toLower(name + ".pal");
for (size_t i = 0; i < palettes_.size(); ++i) {
if (toLower(palettes_[i]) == lower_name) {
if (toLower(palettes_[i]) == LOWER_NAME) {
current_ = i;
apply();
return true;
@@ -186,8 +186,8 @@ auto PaletteManager::getNames() const -> std::vector<std::string> {
names.reserve(palettes_.size());
for (const auto& p : palettes_) {
std::string name = p;
const size_t pos = name.find(".pal");
if (pos != std::string::npos) { name.erase(pos, 4); }
const size_t POS = name.find(".pal");
if (POS != std::string::npos) { name.erase(POS, 4); }
std::ranges::transform(name, name.begin(), ::tolower);
names.push_back(std::move(name));
}
@@ -196,8 +196,8 @@ auto PaletteManager::getNames() const -> std::vector<std::string> {
auto PaletteManager::getCurrentName() const -> std::string {
std::string name = palettes_.at(current_);
const size_t pos = name.find(".pal");
if (pos != std::string::npos) { name.erase(pos, 4); }
const size_t POS = name.find(".pal");
if (POS != std::string::npos) { name.erase(POS, 4); }
std::ranges::transform(name, name.begin(), ::tolower);
return name;
}
@@ -242,16 +242,16 @@ void PaletteManager::apply() {
}
auto PaletteManager::findIndex(const std::string& name) const -> size_t {
const std::string lower_name = toLower(name + ".pal");
const std::string LOWER_NAME = toLower(name + ".pal");
for (size_t i = 0; i < palettes_.size(); ++i) {
if (toLower(getFileName(palettes_[i])) == lower_name) {
if (toLower(getFileName(palettes_[i])) == LOWER_NAME) {
return i;
}
}
// Fallback: buscar la paleta por defecto
const std::string default_name = toLower(std::string(Defaults::Video::PALETTE_NAME) + ".pal");
const std::string DEFAULT_NAME = toLower(std::string(Defaults::Video::PALETTE_NAME) + ".pal");
for (size_t i = 0; i < palettes_.size(); ++i) {
if (toLower(getFileName(palettes_[i])) == default_name) {
if (toLower(getFileName(palettes_[i])) == DEFAULT_NAME) {
return i;
}
}