Treballant en la caché de les paletes
This commit is contained in:
@@ -11,6 +11,43 @@
|
||||
#include "screen.h"
|
||||
#include "gif.h" // for LoadGif, LoadPalette
|
||||
|
||||
// Carga una paleta desde un archivo
|
||||
Palette loadPalette(const std::string &file_path)
|
||||
{
|
||||
// Abrir el archivo en modo binario
|
||||
std::ifstream file(file_path, std::ios::binary | std::ios::ate);
|
||||
if (!file.is_open())
|
||||
{
|
||||
throw std::runtime_error("Error opening file: " + file_path);
|
||||
}
|
||||
|
||||
// Leer el contenido del archivo en un buffer
|
||||
std::streamsize size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
std::vector<Uint8> buffer(size);
|
||||
if (!file.read(reinterpret_cast<char *>(buffer.data()), size))
|
||||
{
|
||||
throw std::runtime_error("Error reading file: " + file_path);
|
||||
}
|
||||
|
||||
// Cargar la paleta usando los datos del buffer
|
||||
std::unique_ptr<Uint32[]> pal(LoadPalette(buffer.data()));
|
||||
if (pal == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Error loading palette from file: " + file_path);
|
||||
}
|
||||
|
||||
// Crear la paleta y copiar los datos
|
||||
Palette palette;
|
||||
std::copy(pal.get(), pal.get() + palette.size(), palette.begin());
|
||||
|
||||
// Mensaje de depuración
|
||||
printWithDots("Palette : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
|
||||
|
||||
return palette;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Surface::Surface(int w, int h)
|
||||
: surface_data_(std::make_shared<SurfaceData>(w, h)),
|
||||
@@ -60,33 +97,13 @@ SurfaceData Surface::loadSurface(const std::string &file_path)
|
||||
// Carga una paleta desde un archivo
|
||||
void Surface::loadPalette(const std::string &file_path)
|
||||
{
|
||||
// Abrir el archivo en modo binario
|
||||
std::ifstream file(file_path, std::ios::binary | std::ios::ate);
|
||||
if (!file.is_open())
|
||||
{
|
||||
throw std::runtime_error("Error opening file: " + file_path);
|
||||
}
|
||||
palette_ = ::loadPalette(file_path);
|
||||
}
|
||||
|
||||
// Leer el contenido del archivo en un buffer
|
||||
std::streamsize size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
std::vector<Uint8> buffer(size);
|
||||
if (!file.read(reinterpret_cast<char *>(buffer.data()), size))
|
||||
{
|
||||
throw std::runtime_error("Error reading file: " + file_path);
|
||||
}
|
||||
|
||||
// Cargar la paleta usando los datos del buffer
|
||||
std::unique_ptr<Uint32[]> pal(LoadPalette(buffer.data()));
|
||||
if (pal == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Error loading palette from file: " + file_path);
|
||||
}
|
||||
|
||||
// Copiar los datos de la paleta al std::array
|
||||
printWithDots("Palette : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
|
||||
std::copy(pal.get(), pal.get() + palette_.size(), palette_.begin());
|
||||
// Carga una paleta desde otra paleta
|
||||
void Surface::loadPalette(Palette palette)
|
||||
{
|
||||
palette_ = palette;
|
||||
}
|
||||
|
||||
// Establece un color en la paleta
|
||||
|
||||
Reference in New Issue
Block a user