Palette loading done.

This commit is contained in:
2025-08-27 19:59:55 -05:00
parent 7a90d2d38f
commit 6c11096fd2
11 changed files with 110 additions and 27 deletions

View File

@@ -1,6 +1,7 @@
import os
from args import args
from PIL import Image
import struct
def extractPaletteFromImage(image):
# goes through and finds all unique colors in the image
@@ -14,19 +15,14 @@ def extractPaletteFromImage(image):
return uniqueColors
def savePalette(pixels, outputFilePath):
# Pixels is a list of (R, G, B, A) tuples
data = "DPF" # Header for Dusk Palette Format
# Count of colors (int32_t)
colorCount = len(pixels)
data += colorCount.to_bytes(4, byteorder='little').decode('latin1')
for r, g, b, a in pixels:
data += bytes([r, g, b, a]).decode('latin1')
buf = bytearray(b"DPF")
buf += struct.pack("<i", colorCount) # little-endian int32_t
for r, g, b, a in pixels: # each channel 0..255
buf += struct.pack("BBBB", r, g, b, a) # raw bytes
os.makedirs(os.path.dirname(outputFilePath), exist_ok=True)
with open(outputFilePath, 'wb') as f:
f.write(data.encode('latin1'))
with open(outputFilePath, "wb") as f:
f.write(buf)
def processPalette(assetPath):
# Process the image file