Remove unecessary comments

This commit is contained in:
scawful
2023-11-10 23:22:24 -05:00
parent 6b5e100371
commit e4b23b9b26
2 changed files with 14 additions and 311 deletions

View File

@@ -151,7 +151,7 @@ void Bitmap::ApplyPalette(const SNESPalette &palette) {
palette_ = palette; palette_ = palette;
SDL_UnlockSurface(surface_.get()); SDL_UnlockSurface(surface_.get());
for (int i = 0; i < palette.size(); ++i) { for (int i = 0; i < palette.size(); ++i) {
if (palette.GetColor(i).isTransparent()) { if (palette.GetColor(i).IsTransparent()) {
surface_->format->palette->colors[i].r = 0; surface_->format->palette->colors[i].r = 0;
surface_->format->palette->colors[i].g = 0; surface_->format->palette->colors[i].g = 0;
surface_->format->palette->colors[i].b = 0; surface_->format->palette->colors[i].b = 0;

View File

@@ -19,9 +19,6 @@ namespace yaze {
namespace app { namespace app {
namespace gfx { namespace gfx {
/**
* @brief Struct representing an SNES color.
*/
struct snes_color { struct snes_color {
uint16_t red; /**< Red component of the color. */ uint16_t red; /**< Red component of the color. */
uint16_t blue; /**< Blue component of the color. */ uint16_t blue; /**< Blue component of the color. */
@@ -29,9 +26,6 @@ struct snes_color {
}; };
using snes_color = struct snes_color; using snes_color = struct snes_color;
/**
* @brief Struct representing an SNES palette.
*/
struct snes_palette { struct snes_palette {
uint id; /**< ID of the palette. */ uint id; /**< ID of the palette. */
uint size; /**< Size of the palette. */ uint size; /**< Size of the palette. */
@@ -39,20 +33,7 @@ struct snes_palette {
}; };
using snes_palette = struct snes_palette; using snes_palette = struct snes_palette;
/**
* @brief Converts an RGB color to an SNES color.
*
* @param color The RGB color to convert.
* @return The converted SNES color.
*/
uint16_t ConvertRGBtoSNES(const snes_color& color); uint16_t ConvertRGBtoSNES(const snes_color& color);
/**
* @brief Converts an SNES color to an RGB color.
*
* @param snes_color The SNES color to convert.
* @return The converted RGB color.
*/
snes_color ConvertSNEStoRGB(uint16_t snes_color); snes_color ConvertSNEStoRGB(uint16_t snes_color);
/** /**
@@ -74,21 +55,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);
/**
* @brief Struct representing an SNES color with additional functionality.
*/
struct SNESColor { struct SNESColor {
/**
* @brief Default constructor.
*/
SNESColor() : rgb(0.f, 0.f, 0.f, 0.f), snes(0) {} SNESColor() : rgb(0.f, 0.f, 0.f, 0.f), snes(0) {}
/**
* @brief Constructor that takes an ImVec4 value and converts it to an SNES
* color.
*
* @param val The ImVec4 value to convert.
*/
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 / 255;
@@ -97,29 +66,12 @@ struct SNESColor {
snes = ConvertRGBtoSNES(color); snes = ConvertRGBtoSNES(color);
} }
/**
* @brief Constructor that takes an SNES color and initializes the object with
* it.
*
* @param val The SNES color to initialize with.
*/
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, 255.f),
snes(ConvertRGBtoSNES(val)), snes(ConvertRGBtoSNES(val)),
rom_color(val) {} rom_color(val) {}
/**
* @brief Gets the RGB value of the color.
*
* @return The RGB value of the color.
*/
ImVec4 GetRGB() const { return rgb; } ImVec4 GetRGB() const { return rgb; }
/**
* @brief Sets the RGB value of the color.
*
* @param val The RGB value to set.
*/
void SetRGB(const ImVec4 val) { void SetRGB(const ImVec4 val) {
rgb.x = val.x / 255; rgb.x = val.x / 255;
rgb.y = val.y / 255; rgb.y = val.y / 255;
@@ -133,25 +85,9 @@ struct SNESColor {
modified = true; modified = true;
} }
/**
* @brief Gets the RGB value of the color as it appears in the ROM.
*
* @return The RGB value of the color as it appears in the ROM.
*/
snes_color GetRomRGB() const { return rom_color; } snes_color GetRomRGB() const { return rom_color; }
/**
* @brief Gets the SNES value of the color.
*
* @return The SNES value of the color.
*/
uint16_t GetSNES() const { return snes; } uint16_t GetSNES() const { return snes; }
/**
* @brief Sets the SNES value of the color.
*
* @param val The SNES value to set.
*/
void SetSNES(uint16_t val) { void SetSNES(uint16_t val) {
snes = val; snes = val;
snes_color col = ConvertSNEStoRGB(val); snes_color col = ConvertSNEStoRGB(val);
@@ -159,79 +95,26 @@ struct SNESColor {
modified = true; modified = true;
} }
/** bool IsModified() const { return modified; }
* @brief Checks if the color has been modified. bool IsTransparent() const { return transparent; }
* void SetTransparent(bool t) { transparent = t; }
* @return True if the color has been modified, false otherwise. void SetModified(bool m) { modified = m; }
*/
bool isModified() const { return modified; }
/**
* @brief Checks if the color is transparent.
*
* @return True if the color is transparent, false otherwise.
*/
bool isTransparent() const { return transparent; }
/**
* @brief Sets whether the color is transparent or not.
*
* @param t True to set the color as transparent, false otherwise.
*/
void setTransparent(bool t) { transparent = t; }
/**
* @brief Sets whether the color has been modified or not.
*
* @param m True to set the color as modified, false otherwise.
*/
void setModified(bool m) { modified = m; }
private: private:
ImVec4 rgb; /**< The RGB value of the color. */ ImVec4 rgb;
uint16_t snes; /**< The SNES value of the color. */ uint16_t snes;
snes_color snes_color rom_color;
rom_color; /**< The RGB value of the color as it appears in the ROM. */ bool modified = false;
bool modified = false; /**< Whether the color has been modified or not. */ bool transparent = false;
bool transparent = false; /**< Whether the color is transparent or not. */
}; };
/**
* @brief Reads an SNES color from a ROM.
*
* @param offset The offset in the ROM to read from.
* @param rom The ROM to read from.
*/
gfx::SNESColor ReadColorFromROM(int offset, const uchar* rom); gfx::SNESColor ReadColorFromROM(int offset, const uchar* rom);
/**
* @brief Gets an SNES color from a CGX color.
*
* @param color The CGX color to get the SNES color from.
* @return The SNES color.
*/
SNESColor GetCgxColor(uint16_t color); SNESColor GetCgxColor(uint16_t color);
/**
* @brief Gets a vector of SNES colors from a data buffer.
*
* @param data The data buffer to extract from.
* @return A vector of SNES colors extracted from the buffer.
*/
std::vector<SNESColor> GetColFileData(uchar* data); std::vector<SNESColor> GetColFileData(uchar* data);
/**
* @brief Class representing an SNES palette with additional functionality.
*/
class SNESPalette { class SNESPalette {
public: public:
/**
* @brief Constructor that takes a vector of data and initializes the palette
* with it.
*
* @tparam T The type of data in the vector.
* @param data The vector of data to initialize the palette with.
*/
template <typename T> template <typename T>
explicit SNESPalette(const std::vector<T>& data) { explicit SNESPalette(const std::vector<T>& data) {
for (const auto& item : data) { for (const auto& item : data) {
@@ -239,72 +122,17 @@ class SNESPalette {
} }
} }
/**
* @brief Default constructor.
*/
SNESPalette() = default; SNESPalette() = default;
/**
* @brief Constructor that takes a size and initializes the palette with it.
*
* @param mSize The size to initialize the palette with.
*/
explicit SNESPalette(uint8_t mSize); explicit SNESPalette(uint8_t mSize);
/**
* @brief Constructor that takes a character array and initializes the palette
* with it.
*
* @param snesPal The character array to initialize the palette with.
*/
explicit SNESPalette(char* snesPal); explicit SNESPalette(char* snesPal);
/**
* @brief Constructor that takes an unsigned character array and initializes
* the palette with it.
*
* @param snes_pal The unsigned character array to initialize the palette
* with.
*/
explicit SNESPalette(const unsigned char* snes_pal); explicit SNESPalette(const unsigned char* snes_pal);
/**
* @brief Constructor that takes a vector of ImVec4 values and initializes the
* palette with it.
*
* @param The vector of ImVec4 values to initialize the palette with.
*/
explicit SNESPalette(const std::vector<ImVec4>&); explicit SNESPalette(const std::vector<ImVec4>&);
/**
* @brief Constructor that takes a vector of SNES colors and initializes the
* palette with it.
*
* @param The vector of SNES colors to initialize the palette with.
*/
explicit SNESPalette(const std::vector<snes_color>&); explicit SNESPalette(const std::vector<snes_color>&);
/**
* @brief Constructor that takes a vector of SNES colors with additional
* functionality and initializes the palette with it.
*
* @param The vector of SNES colors with additional functionality to
* initialize the palette with.
*/
explicit SNESPalette(const std::vector<SNESColor>&); explicit SNESPalette(const std::vector<SNESColor>&);
/**
* @brief Gets the SDL palette associated with the SNES palette.
*
* @return The SDL palette.
*/
SDL_Palette* GetSDL_Palette(); SDL_Palette* GetSDL_Palette();
/**
* @brief Creates the palette with a vector of SNES colors.
*
* @param cols The vector of SNES colors to create the palette with.
*/
void Create(const std::vector<SNESColor>& cols) { void Create(const std::vector<SNESColor>& cols) {
for (const auto& each : cols) { for (const auto& each : cols) {
colors.push_back(each); colors.push_back(each);
@@ -312,32 +140,16 @@ class SNESPalette {
size_ = cols.size(); size_ = cols.size();
} }
/**
* @brief Adds an SNES color to the palette.
*
* @param color The SNES color to add.
*/
void AddColor(SNESColor color) { void AddColor(SNESColor color) {
colors.push_back(color); colors.push_back(color);
size_++; size_++;
} }
/**
* @brief Adds an SNES color to the palette.
*
* @param color The SNES color to add.
*/
void AddColor(snes_color color) { void AddColor(snes_color color) {
colors.emplace_back(color); colors.emplace_back(color);
size_++; size_++;
} }
/**
* @brief Gets the color at the specified index.
*
* @param i The index of the color to get.
* @return The color at the specified index.
*/
auto GetColor(int i) const { auto GetColor(int i) const {
if (i > size_) { if (i > size_) {
throw std::out_of_range("SNESPalette: Index out of bounds"); throw std::out_of_range("SNESPalette: Index out of bounds");
@@ -345,40 +157,20 @@ class SNESPalette {
return colors[i]; return colors[i];
} }
/**
* @brief Clears the palette.
*/
void Clear() { void Clear() {
colors.clear(); colors.clear();
size_ = 0; size_ = 0;
} }
/**
* @brief Gets the size of the palette.
*
* @return The size of the palette.
*/
auto size() const { return colors.size(); } auto size() const { return colors.size(); }
/** SNESColor& operator[](int i) {
* @brief Gets the color at the specified index.
*
* @param i The index of the color to get.
* @return The color at the specified index.
*/
SNESColor operator[](int i) {
if (i > size_) { if (i > size_) {
throw std::out_of_range("SNESPalette: Index out of bounds"); throw std::out_of_range("SNESPalette: Index out of bounds");
} }
return colors[i]; return colors[i];
} }
/**
* @brief Sets the color at the specified index.
*
* @param i The index of the color to set.
* @param color The color to set.
*/
void operator()(int i, const SNESColor& color) { void operator()(int i, const SNESColor& color) {
if (i >= size_) { if (i >= size_) {
throw std::out_of_range("SNESPalette: Index out of bounds"); throw std::out_of_range("SNESPalette: Index out of bounds");
@@ -386,18 +178,12 @@ class SNESPalette {
colors[i] = color; colors[i] = color;
} }
/**
* @brief Sets the color at the specified index.
*
* @param i The index of the color to set.
* @param color The color to set.
*/
void operator()(int i, const ImVec4& color) { void operator()(int i, const ImVec4& color) {
if (i >= size_) { if (i >= size_) {
throw std::out_of_range("SNESPalette: Index out of bounds"); throw std::out_of_range("SNESPalette: Index out of bounds");
} }
colors[i].SetRGB(color); colors[i].SetRGB(color);
colors[i].setModified(true); colors[i].SetModified(true);
} }
private: private:
@@ -406,62 +192,21 @@ class SNESPalette {
}; };
SNESPalette ReadPaletteFromROM(int offset, int num_colors, const uchar* rom); SNESPalette ReadPaletteFromROM(int offset, int num_colors, const uchar* rom);
/**
* @brief Gets the address of a palette in a group.
*
* @param group_name The name of the group.
* @param palette_index The index of the palette.
* @param color_index The index of the color.
* @return The address of the palette.
*/
uint32_t GetPaletteAddress(const std::string& group_name, size_t palette_index, uint32_t GetPaletteAddress(const std::string& group_name, size_t palette_index,
size_t color_index); size_t color_index);
/**
* @brief Converts an SNES color to a float array.
*
* @param color The SNES color to convert.
* @return The float array representing the SNES color.
*/
std::array<float, 4> ToFloatArray(const SNESColor& color); std::array<float, 4> ToFloatArray(const SNESColor& color);
/**
* @brief Struct representing a group of SNES palettes.
*/
struct PaletteGroup { struct PaletteGroup {
/**
* @brief Default constructor.
*/
PaletteGroup() = default; PaletteGroup() = default;
/**
* @brief Constructor that takes a size and initializes the group with it.
*
* @param mSize The size to initialize the group with.
*/
explicit PaletteGroup(uint8_t mSize); explicit PaletteGroup(uint8_t mSize);
/**
* @brief Adds a palette to the group.
*
* @param pal The palette to add.
* @return An absl::Status indicating whether the operation was successful or
* not.
*/
absl::Status AddPalette(SNESPalette pal) { absl::Status AddPalette(SNESPalette pal) {
palettes.emplace_back(pal); palettes.emplace_back(pal);
size_ = palettes.size(); size_ = palettes.size();
return absl::OkStatus(); return absl::OkStatus();
} }
/**
* @brief Adds a color to the group.
*
* @param color The color to add.
* @return An absl::Status indicating whether the operation was successful or
* not.
*/
absl::Status AddColor(SNESColor color) { absl::Status AddColor(SNESColor color) {
if (size_ == 0) { if (size_ == 0) {
palettes.emplace_back(); palettes.emplace_back();
@@ -470,27 +215,13 @@ struct PaletteGroup {
return absl::OkStatus(); return absl::OkStatus();
} }
/**
* @brief Clears the group.
*/
void Clear() { void Clear() {
palettes.clear(); palettes.clear();
size_ = 0; size_ = 0;
} }
/**
* @brief Gets the size of the group.
*
* @return The size of the group.
*/
auto size() const { return palettes.size(); } auto size() const { return palettes.size(); }
/**
* @brief Gets the palette at the specified index.
*
* @param i The index of the palette to get.
* @return The palette at the specified index.
*/
SNESPalette operator[](int i) { SNESPalette operator[](int i) {
if (i > size_) { if (i > size_) {
std::cout << "PaletteGroup: Index out of bounds" << std::endl; std::cout << "PaletteGroup: Index out of bounds" << std::endl;
@@ -499,12 +230,6 @@ struct PaletteGroup {
return palettes[i]; return palettes[i];
} }
/**
* @brief Gets the palette at the specified index.
*
* @param i The index of the palette to get.
* @return The palette at the specified index.
*/
const SNESPalette& operator[](int i) const { const SNESPalette& operator[](int i) const {
if (i > size_) { if (i > size_) {
std::cout << "PaletteGroup: Index out of bounds" << std::endl; std::cout << "PaletteGroup: Index out of bounds" << std::endl;
@@ -513,14 +238,6 @@ struct PaletteGroup {
return palettes[i]; return palettes[i];
} }
/**
* @brief Sets the color at the specified index.
*
* @param i The index of the color to set.
* @param color The color to set.
* @return An absl::Status indicating whether the operation was successful or
* not.
*/
absl::Status operator()(int i, const SNESColor& color) { absl::Status operator()(int i, const SNESColor& color) {
if (i >= size_) { if (i >= size_) {
return absl::InvalidArgumentError("PaletteGroup: Index out of bounds"); return absl::InvalidArgumentError("PaletteGroup: Index out of bounds");
@@ -529,14 +246,6 @@ struct PaletteGroup {
return absl::OkStatus(); return absl::OkStatus();
} }
/**
* @brief Sets the color at the specified index.
*
* @param i The index of the color to set.
* @param color The color to set.
* @return An absl::Status indicating whether the operation was successful or
* not.
*/
absl::Status operator()(int i, const ImVec4& color) { absl::Status operator()(int i, const ImVec4& color) {
if (i >= size_) { if (i >= size_) {
return absl::InvalidArgumentError("PaletteGroup: Index out of bounds"); return absl::InvalidArgumentError("PaletteGroup: Index out of bounds");
@@ -546,16 +255,10 @@ struct PaletteGroup {
} }
private: private:
int size_ = 0; /**< The size of the group. */ int size_ = 0;
std::vector<SNESPalette> palettes; /**< The palettes in the group. */ std::vector<SNESPalette> palettes;
}; };
/**
* @brief Creates a palette group from a vector of SNES colors.
*
* @param colors The vector of SNES colors to create the group from.
* @return The created palette group.
*/
PaletteGroup CreatePaletteGroupFromColFile(std::vector<SNESColor>& colors); PaletteGroup CreatePaletteGroupFromColFile(std::vector<SNESColor>& colors);
} // namespace gfx } // namespace gfx