Palette loading done.
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user