我不确定“louie”文件的用途,但这个 python 脚本应该有助于重建图像:
import png
# simple scale from [0,0x1f] to [0,0xff]
def scale_up(n):
return (n<<3)|n
def make_pal(n):
val = (n[1]<<8)|n[0]
return [scale_up((val>>0)&0x1f), scale_up((val>>5)&0x1f), scale_up((val>>10)&0x1f)]
w=256
h=192
image_base='img_159_9_0'
pixel_data_file=f'{image_base}_dewey.bin'
palette_file=f'{image_base}_huey.bin'
with open(palette_file, 'rb') as f:
pal_bytes = f.read()
real_pal=[]
for i in range(0,256):
m = make_pal(pal_bytes[i*2:i*2+2])
real_pal.append(m)
with open(pixel_data_file, 'rb') as f:
pixel_bytes = f.read()
tile_w = 8
tile_h = 8
image_tile_h = h/tile_h
image_tile_w = w/tile_w
# if any pixel/channel is not written, the png writer will complain about -1
rows_dat = [[-1 for n in range(w*3)] for m in range(h)]
for i in range(w*h):
tile_i = int(i / (tile_w*tile_h))
tile_x = int(tile_i % image_tile_w)
tile_y = int(tile_i / image_tile_w)
small_i = int(i % (tile_w*tile_h))
small_x = int(small_i % tile_w)
small_y = int(small_i / tile_w)
rows_dat[tile_y*tile_h + small_y][3*(tile_x*tile_w + small_x)] = real_pal[pixel_bytes[i]][0]
rows_dat[tile_y*tile_h + small_y][3*(tile_x*tile_w + small_x)+1] = real_pal[pixel_bytes[i]][1]
rows_dat[tile_y*tile_h + small_y][3*(tile_x*tile_w + small_x)+2] = real_pal[pixel_bytes[i]][2]
with open(f'{image_base}.png', 'wb') as of:
writer = png.Writer(width=w, height=h, greyscale=False)
writer.write(of, rows_dat)
在您的示例数据中,它看起来像是img_159_9_0_dewey.bin在开头填充了 64 个字节的0x00's。我不确定这是否是转储时的错误,但删除它会有所帮助。
您提供的所有图像似乎都是 256x192(我让它们旋转,平铺逻辑更清晰而不旋转 - 您可以在之后执行此操作),由 8x8 像素平铺组成。像素数据(存储在 中dewey)索引到存储为 u16le(存储在 中huey)的 RGB555 值调色板中。您没有提供任何内容,但我猜 32 字节huey文件只是 16 种颜色的调色板 - 相应的像素数据可能由紧密打包的 4 位索引组成。