Initial commit

This commit is contained in:
Gericom
2025-11-22 17:21:45 +01:00
commit 5d6f67c612
517 changed files with 63025 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
#include "common.h"
#include "DirectPalette.h"
u32 DirectPalette::GetHashCode() const
{
u32 hashcode = 1430287;
#pragma GCC unroll 8
for (int i = 0; i < 8; i++)
{
hashcode = hashcode * 7302013 + ((u32*)_colors)[i];
}
return hashcode;
}

View File

@@ -0,0 +1,23 @@
#pragma once
#include <string.h>
#include "IPalette.h"
/// @brief Palette of 16 specified colors.
class alignas(4) DirectPalette : public IPalette
{
public:
explicit DirectPalette(const u16* colors)
{
memcpy(_colors, colors, sizeof(_colors));
}
void GetColors(u16* dst) const override
{
memcpy(dst, _colors, sizeof(_colors));
}
u32 GetHashCode() const override;
private:
u16 _colors[16];
};

View File

@@ -0,0 +1,14 @@
#include "common.h"
#include "GradientPalette.h"
u32 GradientPalette::GetHashCode() const
{
u32 hashcode = 1430287;
hashcode = hashcode * 7302013 + _fromColor.r;
hashcode = hashcode * 7302013 + _fromColor.g;
hashcode = hashcode * 7302013 + _fromColor.b;
hashcode = hashcode * 7302013 + _toColor.r;
hashcode = hashcode * 7302013 + _toColor.g;
hashcode = hashcode * 7302013 + _toColor.b;
return hashcode;
}

View File

@@ -0,0 +1,23 @@
#pragma once
#include "core/math/Rgb.h"
#include "core/math/RgbMixer.h"
#include "IPalette.h"
/// @brief Gradient palette between two colors.
class GradientPalette : public IPalette
{
public:
GradientPalette(const Rgb<8, 8, 8>& from, const Rgb<8, 8, 8>& to)
: _fromColor(from), _toColor(to) { }
void GetColors(u16* dst) const override
{
RgbMixer::MakeGradientPalette(dst, _fromColor, _toColor);
}
u32 GetHashCode() const override;
private:
Rgb<8, 8, 8> _fromColor;
Rgb<8, 8, 8> _toColor;
};

View File

@@ -0,0 +1,18 @@
#pragma once
/// @brief Interface for a color palette.
class IPalette
{
public:
virtual ~IPalette() = 0;
/// @brief Gets the colors of the palette.
/// @param dst A pointer to an array the colors should be written to.
virtual void GetColors(u16* dst) const = 0;
/// @brief Gets a hash that represents this color palette.
/// @return The hash.
virtual u32 GetHashCode() const = 0;
};
inline IPalette::~IPalette() { }