mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-16 11:33:03 +01:00
Create GamePalette struct
This commit is contained in:
@@ -38,7 +38,7 @@ assert_struct_size(rct_sprite_file_header, 8);
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
static PaletteBGRA spriteFilePalette[256];
|
||||
static GamePalette spriteFilePalette;
|
||||
|
||||
static rct_sprite_file_header spriteFileHeader;
|
||||
static rct_g1_element* spriteFileEntries;
|
||||
@@ -215,19 +215,19 @@ static bool sprite_file_export(int32_t spriteIndex, const char* outPath)
|
||||
dpi.pitch = 0;
|
||||
dpi.zoom_level = 0;
|
||||
|
||||
std::memcpy(spriteFilePalette, StandardPalette, 256 * sizeof(PaletteBGRA));
|
||||
spriteFilePalette = StandardPalette;
|
||||
|
||||
if (spriteHeader->flags & G1_FLAG_RLE_COMPRESSION)
|
||||
{
|
||||
gfx_rle_sprite_to_buffer(
|
||||
spriteHeader->offset, pixels, reinterpret_cast<uint8_t*>(spriteFilePalette), &dpi, ImageId(), 0,
|
||||
spriteHeader->height, 0, spriteHeader->width);
|
||||
spriteHeader->offset, pixels, static_cast<uint8_t*>(spriteFilePalette), &dpi, ImageId(), 0, spriteHeader->height, 0,
|
||||
spriteHeader->width);
|
||||
}
|
||||
else
|
||||
{
|
||||
gfx_bmp_sprite_to_buffer(
|
||||
reinterpret_cast<uint8_t*>(spriteFilePalette), spriteHeader->offset, pixels, spriteHeader, &dpi,
|
||||
spriteHeader->height, spriteHeader->width, ImageId());
|
||||
static_cast<uint8_t*>(spriteFilePalette), spriteHeader->offset, pixels, spriteHeader, &dpi, spriteHeader->height,
|
||||
spriteHeader->width, ImageId());
|
||||
}
|
||||
|
||||
auto const pixels8 = dpi.bits;
|
||||
|
||||
@@ -29,6 +29,23 @@ struct PaletteBGRA
|
||||
uint8_t Alpha{};
|
||||
};
|
||||
|
||||
constexpr const auto PALETTE_SIZE = 256;
|
||||
|
||||
struct GamePalette
|
||||
{
|
||||
PaletteBGRA Colour[PALETTE_SIZE];
|
||||
|
||||
const PaletteBGRA& operator[](uint16_t idx) const
|
||||
{
|
||||
return Colour[idx];
|
||||
}
|
||||
|
||||
explicit operator uint8_t*()
|
||||
{
|
||||
return reinterpret_cast<uint8_t*>(Colour);
|
||||
}
|
||||
};
|
||||
|
||||
enum class IMAGE_FORMAT
|
||||
{
|
||||
UNKNOWN,
|
||||
|
||||
@@ -292,11 +292,11 @@ int32_t ImageImporter::CalculatePaletteIndex(
|
||||
return paletteIndex;
|
||||
}
|
||||
|
||||
int32_t ImageImporter::GetPaletteIndex(const PaletteBGRA* palette, int16_t* colour)
|
||||
int32_t ImageImporter::GetPaletteIndex(const GamePalette& palette, int16_t* colour)
|
||||
{
|
||||
if (!IsTransparentPixel(colour))
|
||||
{
|
||||
for (int32_t i = 0; i < 256; i++)
|
||||
for (int32_t i = 0; i < PALETTE_SIZE; i++)
|
||||
{
|
||||
if (static_cast<int16_t>(palette[i].Red) == colour[0] && static_cast<int16_t>(palette[i].Green) == colour[1]
|
||||
&& static_cast<int16_t>(palette[i].Blue) == colour[2])
|
||||
@@ -333,11 +333,11 @@ bool ImageImporter::IsChangablePixel(int32_t paletteIndex)
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t ImageImporter::GetClosestPaletteIndex(const PaletteBGRA* palette, const int16_t* colour)
|
||||
int32_t ImageImporter::GetClosestPaletteIndex(const GamePalette& palette, const int16_t* colour)
|
||||
{
|
||||
auto smallestError = static_cast<uint32_t>(-1);
|
||||
auto bestMatch = PALETTE_TRANSPARENT;
|
||||
for (int32_t x = 0; x < 256; x++)
|
||||
for (int32_t x = 0; x < PALETTE_SIZE; x++)
|
||||
{
|
||||
if (IsChangablePixel(x))
|
||||
{
|
||||
|
||||
@@ -58,14 +58,14 @@ namespace OpenRCT2::Drawing
|
||||
|
||||
static int32_t CalculatePaletteIndex(
|
||||
IMPORT_MODE mode, int16_t* rgbaSrc, int32_t x, int32_t y, int32_t width, int32_t height);
|
||||
static int32_t GetPaletteIndex(const PaletteBGRA* palette, int16_t* colour);
|
||||
static int32_t GetPaletteIndex(const GamePalette& palette, int16_t* colour);
|
||||
static bool IsTransparentPixel(const int16_t* colour);
|
||||
static bool IsChangablePixel(int32_t paletteIndex);
|
||||
static int32_t GetClosestPaletteIndex(const PaletteBGRA* palette, const int16_t* colour);
|
||||
static int32_t GetClosestPaletteIndex(const GamePalette& palette, const int16_t* colour);
|
||||
};
|
||||
} // namespace OpenRCT2::Drawing
|
||||
|
||||
constexpr const PaletteBGRA StandardPalette[256] = {
|
||||
constexpr const GamePalette StandardPalette = { {
|
||||
// 0 (unused)
|
||||
{ 0, 0, 0, 255 },
|
||||
|
||||
@@ -348,4 +348,4 @@ constexpr const PaletteBGRA StandardPalette[256] = {
|
||||
|
||||
// 255 (unused?)
|
||||
{ 0, 0, 0, 255 },
|
||||
};
|
||||
} };
|
||||
|
||||
Reference in New Issue
Block a user