- [FIX] Els tiles necessiten un uint16_t

- [NEW] Pintat de una room
- [NEW] Càrrega de paletes en format JASC
This commit is contained in:
2025-11-01 10:31:05 +01:00
parent 76f4ae31c8
commit 008c9e7199
5 changed files with 80 additions and 9 deletions

View File

@@ -1,5 +1,9 @@
#include "images.h"
#include <map>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
namespace images
{
@@ -14,4 +18,42 @@ namespace images
images[filename] = image;
return image;
}
int loadPalette(std::string filename)
{
uint32_t palette[16];
FILE *file = fopen(filename.c_str(), "r");
if (!file) return -1;
char header[32];
int version, count;
// Read and validate header
if (!fgets(header, sizeof(header), file) || strncmp(header, "JASC-PAL", 8) != 0) {
fclose(file);
return -2;
}
if (fscanf(file, "%d\n%d\n", &version, &count) != 2 || count != 16) {
fclose(file);
return -3;
}
// Read 16 RGB triplets
for (int i = 0; i < 16; ++i) {
int r, g, b;
if (fscanf(file, "%d %d %d\n", &r, &g, &b) != 3) {
fclose(file);
return -4;
}
palette[i] = (r << 16) | (g << 8) | b;
}
fclose(file);
draw::setPalette(palette, 16);
return 0;
}
}