1

我正在使用 devkitARM 工具链制作 GBA 游戏,我想开始使用精灵。我正在使用一个非常简单的教程,它告诉我使用 gfx2gba 将我的位图转换为 C 数组。这是我的位图:

位图

万一出现任何问题,我会处理数组并将其转换回图像,但是某些东西会破坏图像或类似的东西:

错误的

顺便说一句,我可能在将其转换回来时更改了调色板,但这不是主要的。

我究竟做错了什么?我的 gfx2gba 命令是gfx2gba -fsrc -c16 -t8 bitmap.bmp. 这是生成的C文件:

//
// numbers (288 uncompressed bytes)
//
extern const unsigned char numbers_Bitmap[288] = {
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x20, 0x22, 0x22, 0x02, 0x20, 0x22, 0x22, 0x22, 0x20, 0x22, 
0x22, 0x22, 0x20, 0x22, 0x22, 0x22, 0x20, 0x22, 0x22, 0x02, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 
0x33, 0x33, 0x33, 0x33, 0x33, 0x03, 0x30, 0x33, 0x33, 0x30, 0x03, 0x33, 0x33, 0x33, 0x03, 0x33, 
0x33, 0x03, 0x30, 0x33, 0x33, 0x30, 0x33, 0x33, 0x33, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 
0x99, 0x99, 0x99, 0x99, 0x99, 0x09, 0x90, 0x99, 0x99, 0x90, 0x09, 0x99, 0x99, 0x99, 0x09, 0x99, 
0x99, 0x09, 0x90, 0x99, 0x99, 0x99, 0x09, 0x99, 0x99, 0x90, 0x09, 0x99, 0x99, 0x09, 0x90, 0x99, 
0x11, 0x11, 0x11, 0x11, 0x11, 0x01, 0x10, 0x11, 0x11, 0x10, 0x10, 0x11, 0x01, 0x11, 0x10, 0x11, 
0x01, 0x00, 0x00, 0x10, 0x11, 0x11, 0x10, 0x11, 0x11, 0x11, 0x10, 0x11, 0x11, 0x11, 0x11, 0x11, 
0x44, 0x44, 0x44, 0x44, 0x44, 0x00, 0x00, 0x44, 0x44, 0x40, 0x44, 0x44, 0x44, 0x00, 0x40, 0x44, 
0x44, 0x44, 0x04, 0x44, 0x44, 0x44, 0x04, 0x44, 0x44, 0x00, 0x40, 0x44, 0x44, 0x44, 0x44, 0x44, 
0x77, 0x77, 0x77, 0x77, 0x77, 0x07, 0x70, 0x77, 0x77, 0x70, 0x77, 0x77, 0x77, 0x00, 0x70, 0x77, 
0x77, 0x70, 0x07, 0x77, 0x77, 0x70, 0x07, 0x77, 0x77, 0x07, 0x70, 0x77, 0x77, 0x77, 0x77, 0x77, 
0x55, 0x55, 0x55, 0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x55, 0x05, 0x55, 0x55, 0x55, 0x50, 0x55, 
0x55, 0x55, 0x50, 0x55, 0x55, 0x05, 0x55, 0x55, 0x55, 0x05, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 
0x66, 0x66, 0x66, 0x66, 0x66, 0x06, 0x60, 0x66, 0x66, 0x60, 0x06, 0x66, 0x66, 0x60, 0x06, 0x66, 
0x66, 0x06, 0x60, 0x66, 0x66, 0x60, 0x06, 0x66, 0x66, 0x60, 0x06, 0x66, 0x66, 0x06, 0x60, 0x66, 
0x88, 0x88, 0x88, 0x88, 0x88, 0x08, 0x80, 0x88, 0x88, 0x80, 0x08, 0x88, 0x88, 0x80, 0x08, 0x88, 
0x88, 0x08, 0x00, 0x88, 0x88, 0x88, 0x08, 0x88, 0x88, 0x08, 0x80, 0x88, 0x88, 0x88, 0x88, 0x88
};

这是调色板:

extern const unsigned short master_Palette[16] = {
0x0000, 0x0390, 0x209c, 0x221c, 0x2304, 0x6108, 0x6114, 0x6280, 
0x629c, 0x03ff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
};

编辑:如果有人想查看代码,这是我用于转换回图像的 Python 脚本:

a = [
2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,2,0,2,2,0,2,2,2,2,2,2,2,0,2,2,
2,2,2,2,2,0,2,2,2,2,2,2,2,0,2,2,2,2,0,2,0,0,2,2,2,2,2,2,2,2,2,2,
3,3,3,3,3,3,3,3,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]

def x(y):
    if y == 0:
        return 0, 0, 0
    elif y == 2:
        return 255, 0, 0
    elif y == 3:
        return 255, 128, 0
    elif y == 9:
        return 255, 255, 0
    elif y == 1:
        return 128, 255, 0
    elif y == 4:
        return 0, 128, 0
    elif y == 7:
        return 0, 128, 255
    elif y == 5:
        return 0, 0, 255
    elif y == 6:
        return 128, 0, 255
    elif y == 8:
        return 255, 0, 255
    elif y == 10:
        return 255, 255, 255

import numpy as np
from PIL import Image

b = np.array(list(map(x, a)))
c = b.astype(np.uint8).reshape((72, 8, 3))
Image.fromarray(c).save("numbers.png")
4

0 回答 0