1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-08-08 15:30:14 +00:00

Force skybox split palettes to always contain 128 colors (#2535)

* Force skybox split palettes to always contain 128 colors, padding with 0 if necessary

* Review
This commit is contained in:
Tharo 2025-05-25 20:50:34 +01:00 committed by GitHub
parent 385cf23064
commit faf2003d37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 48 additions and 3 deletions

View file

@ -245,6 +245,13 @@ class N64Palette(Structure):
_object_refcount.add_ref(pal)
return deref(pal)
def resize(self, new_count : int) -> Optional["N64Palette"]:
if new_count > 256:
raise ValueError("The largest possible palette size is 256")
pal = ln64texconv.n64texconv_palette_resize(byref(self), new_count)
_object_refcount.add_ref(pal)
return deref(pal)
@staticmethod
def from_png(path : str, fmt : int) -> Optional["N64Palette"]:
if fmt not in (G_IM_FMT_RGBA, G_IM_FMT_IA):
@ -306,6 +313,10 @@ ln64texconv.n64texconv_palette_copy.restype = POINTER(N64Palette)
ln64texconv.n64texconv_palette_reformat.argtypes = [POINTER(N64Palette), c_int]
ln64texconv.n64texconv_palette_reformat.restype = POINTER(N64Palette)
# struct n64_palette *n64texconv_palette_resize(struct n64_palette *pal, size_t new_count);
ln64texconv.n64texconv_palette_resize.argtypes = [POINTER(N64Palette), c_size_t]
ln64texconv.n64texconv_palette_resize.restype = POINTER(N64Palette)
# struct n64_palette *n64texconv_palette_from_png(const char *path, int fmt);
ln64texconv.n64texconv_palette_from_png.argtypes = [c_char_p, c_int]
ln64texconv.n64texconv_palette_from_png.restype = POINTER(N64Palette)

View file

@ -590,6 +590,24 @@ n64texconv_palette_reformat(struct n64_palette *pal, int fmt)
return new_pal;
}
struct n64_palette *
n64texconv_palette_resize(struct n64_palette *pal, size_t new_count)
{
assert(pal != NULL);
struct n64_palette *new_pal = n64texconv_palette_new(new_count, pal->fmt);
size_t min_count = (new_count < pal->count) ? new_count : pal->count;
size_t i;
for (i = 0; i < min_count; i++)
new_pal->texels[i] = pal->texels[i];
for (i = min_count; i < new_count; i++)
new_pal->texels[i] = (struct color){ .w = 0 };
return new_pal;
}
struct n64_palette *
n64texconv_palette_from_png(const char *path, int fmt)
{

View file

@ -55,6 +55,9 @@ n64texconv_palette_copy(struct n64_palette *pal);
struct n64_palette *
n64texconv_palette_reformat(struct n64_palette *pal, int fmt);
struct n64_palette *
n64texconv_palette_resize(struct n64_palette *pal, size_t new_count);
struct n64_palette *
n64texconv_palette_from_png(const char *path, int fmt);