JustAnotherDnDGame 0.1.0
Jeu de rôle tactique au d20, vue de dessus, en C++/Qt
Loading...
Searching...
No Matches
PixelPalette.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Valentin Eloy
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4#pragma once
5
6#include <cstdint>
7#include <filesystem>
8#include <string>
9#include <string_view>
10#include <vector>
11
13
23
24namespace hmi {
25
28 std::string name;
29 std::uint32_t color = 0xFF000000u;
30
31 [[nodiscard]] friend bool operator==(const PixelPaletteEntry&,
32 const PixelPaletteEntry&) noexcept = default;
33};
34
45public:
47 static constexpr int FORMAT_VERSION = 1;
48
50 [[nodiscard]] static PixelPalette loadFromString(std::string_view json);
51
54 [[nodiscard]] static PixelPalette loadFromFile(const std::filesystem::path& path);
55
57 [[nodiscard]] std::string toJsonString() const;
58
61 [[nodiscard]] bool saveToFile(const std::filesystem::path& path) const;
62
64 [[nodiscard]] const std::vector<PixelPaletteEntry>& entries() const noexcept {
65 return _entries;
66 }
67
69 void add(std::string name, std::uint32_t color);
71 bool removeAt(std::size_t index);
73 bool renameAt(std::size_t index, std::string newName);
76 bool moveEntry(std::size_t from, std::size_t to);
77
78private:
79 std::vector<PixelPaletteEntry> _entries;
80};
81
84 std::uint32_t color = 0;
85 int count = 0;
86};
87
98[[nodiscard]] std::vector<PixelPaletteExtractionEntry> extractPalette(const DecodedImage& image);
99
116[[nodiscard]] std::uint32_t nearestPaletteColor(std::uint32_t color,
117 const std::vector<std::uint32_t>& palette) noexcept;
118
119} // namespace hmi
Chargement de textures GPU depuis des fichiers image (EX-REN-041), au travers de QRhi.
Palette de couleurs nommées du projet, lue/écrite dans Assets/palettes.json.
Definition PixelPalette.h:44
static PixelPalette loadFromString(std::string_view json)
Definition PixelPalette.cpp:112
std::string toJsonString() const
Definition PixelPalette.cpp:148
std::vector< PixelPaletteEntry > _entries
Definition PixelPalette.h:79
const std::vector< PixelPaletteEntry > & entries() const noexcept
Definition PixelPalette.h:64
bool moveEntry(std::size_t from, std::size_t to)
Déplace l'entrée from à la position to (réordonnancement).
Definition PixelPalette.cpp:196
bool saveToFile(const std::filesystem::path &path) const
Écrit la palette dans un fichier, en créant les dossiers parents au besoin.
Definition PixelPalette.cpp:162
bool removeAt(std::size_t index)
Retire l'entrée index.
Definition PixelPalette.cpp:180
static PixelPalette loadFromFile(const std::filesystem::path &path)
Definition PixelPalette.cpp:136
void add(std::string name, std::uint32_t color)
Ajoute une entrée en fin de palette.
Definition PixelPalette.cpp:176
bool renameAt(std::size_t index, std::string newName)
Renomme l'entrée index.
Definition PixelPalette.cpp:188
static constexpr int FORMAT_VERSION
Version du format écrite dans le fichier.
Definition PixelPalette.h:47
Definition AudioEngine.cpp:15
std::vector< PixelPaletteExtractionEntry > extractPalette(const DecodedImage &image)
Couleurs effectivement présentes dans une image, dans un ordre déterministe.
Definition PixelPalette.cpp:209
std::uint32_t nearestPaletteColor(std::uint32_t color, const std::vector< std::uint32_t > &palette) noexcept
Couleur de palette la plus proche de color (mode « contraindre à la palette »).
Definition PixelPalette.cpp:227
Pixels RGBA décodés d'un fichier image, alpha non prémultiplié (cohérent avec le mélange du pipeline ...
Definition TextureLoader.h:27
Une entrée nommée de la palette de projet.
Definition PixelPalette.h:27
friend bool operator==(const PixelPaletteEntry &, const PixelPaletteEntry &) noexcept=default
std::string name
Definition PixelPalette.h:28
std::uint32_t color
R8G8B8A8_UNORM (LOT-54 TACHE-01).
Definition PixelPalette.h:29
Une couleur extraite, avec son nombre d'occurrences dans l'image.
Definition PixelPalette.h:83
std::uint32_t color
Definition PixelPalette.h:84
int count
Definition PixelPalette.h:85