gfx2gba doesn't convert image properly

85 views Asked by At

I am making a GBA game using the devkitARM toolchain, and I would like to start using sprites. I am using a very simple tutorial, and it tells me to use gfx2gba to convert my bitmaps to C arrays. Here is my bitmap:

bitmap

In case anything went wrong, I then process the array and convert it back into an image, but something corrupts the image or something like that:

wrong

By the way, I may have changed the color palette while converting it back, but that isn't the main thing.

What am I doing wrong? My gfx2gba command is gfx2gba -fsrc -c16 -t8 bitmap.bmp. Here is the generated C file:

//
// 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
};

And here's the palette:

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

EDIT: If anyone wanted to see the code, here is my Python script for converting back into an image:

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")
0

There are 0 answers