Jump to content
Tuts 4 You

Convert bmp.bmp to bmp.pal bmp.bin


Recommended Posts

Does any body know what did comerade use to Convert bmp.bmp to bmp.pal bmp.bin in this example ?

I have tried so mamy converters and pallet creators but I can not get it ?

any body ?



Edited by wunder
Link to comment
Share on other sites

OK I found something called "gfx2gba.exe" but I t makes it into a damn c format ... I got that db tool that can ad db ...but I gut to know if there is a way to conver all from c to asm ...not # by #

Also the palet and the bin have to be combined by hand to male 1 file .....any other ideas on how to do this ...or at least easly convert the c to asm ?


Link to comment
Share on other sites

Well looking at the files, 2 are just stripped bytes from the bmp. The .pal is just the rgb section bytes 36h-75h The .bin is the image bitmaplines 76h-EOF The shakira bin has been rotated 180 degrees flipped vertical but its the same.


Meaning the bitmaplines are stored in opposite order.

32 x 32 image

B3 BB 33 33 33 DD DD 95 88 80 88 88 99 93 19 3D is line 00 in shakira.bmp

B3 BB 33 33 33 DD DD 95 88 80 88 88 99 93 19 3D is line 31 in shakira.bin

Edited by redblkjck
Link to comment
Share on other sites

this guy is using something to make those ...buy what? I found the files he uses to make the bin but waht does he use to get the bmp to Jasc Pal format (.pal) ?


Link to comment
Share on other sites

this guy is using something to make those ...buy what? I found the files he uses to make the bin but waht does he use to get the bmp to Jasc Pal format (.pal) ?

hex editor maybe, script file, custom tool... the pal file is just the color map for bin. all the bytes are taken directly from the bmp. you could copy and paste it with any hex editor. 010 editor has a plugin to help break down the bmp into a broken down structure. my guess is the bmp is saved to 32x32 size and then splits the bitmap lines and color map from the bmp. no 3rd party app used.

Link to comment
Share on other sites

how does he get the .pal ? it is obvious that he creats a bin and a pal than converts then to "db" and puts them into one inc file ...

I got the o10 editor from here http://www.woodmann....ory:Hex_Editors

and I can not follow what you are saying?

first 0x0F hex bytes from sov.pal

00 00 00 00 00 00 80 00 00 80 00 00 00 80 80 00

now the beginning of the sov.inc file, notice the db is just a csv of the hex values of the sov.pal in dec format. 0x80 = d 128

palette db 0,0,0,0,0,0,128,0,0,128,0,0,0,128,128,0 <-- same as above in dec

now the first set of bytes from the RGBQUAD color map in the sov.bmp starting at offset 0x36

00 00 00 00 00 00 80 00 00 80 00 00 00 80 80 00 <-- same as the sov.pal

now the first set of bytes from the sov.bin

91 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11

now the bitmaplines of the sov.bmp starting at offset 0x76

91 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 <-- same as sov.bin

Link to comment
Share on other sites

OK but what tools does he use to create those file ? the .bin and .pal will be different with my bitmap images ....

I tried all that ...but my pallets were off and my images were all a blure

Link to comment
Share on other sites

OK lets say that I have a bitmap now I want to creat the .inc ...so I have to create the bin and the pal ..... how do I create the .pal from the bitmap ?

and what does he use to convert to db ...all the db converters that I have don't do it right

Link to comment
Share on other sites

don't know what tool the person uses. my guess a script or a program they wrote to do it for them. it could be done manually but what fun would that be...

the .inc file is just a converted file of the .pal open the .inc with notepad+ or any other text editor. it's tab tab 'db' tab data, data, data, (total 16 data values of .pal converted to decimal...), CR, LF

maybe a program c2bin and mklogo does this, its used for firmware mods. i have no idea, never used it.

edit forgot to include the .bin is also in the .inc file. its the same pattern just added on to the stream of bytes.

Edited by redblkjck
Link to comment
Share on other sites

Using the function LoadImage to load the bitmap file, you can then use GetObject to get information about the file. GetDIBColorTable will get you the palette and GetBitmapBits (or GetDIBBits) will return the actual bytes for the image. Using the return value from GetDIBColorTable you can determine the size of the palette and by multiplying the Width, Height and BitsPerPixel members of the BITMAP structure filled by GetObject and dividing by 8 you get the size in bytes of the bitmap data.

File: shakira.bmp
Loading bitmap.
Getting information about bitmap.
Bits Per Pixel: 4
Dimensions: 32 x 32
Size: 512
Entries in colour table: 16
;*** Begin MASM declaration ***
db 004h, 002h, 004h, 000h, 044h, 07Ah, 0ACh, 000h, 084h, 0BEh, 0ECh, 000h, 054h, 096h, 0D4h, 000h
db 019h, 09Ch, 0C7h, 01Bh, 062h, 026h, 0B2h, 062h, 022h, 022h, 0BBh, 033h, 0D1h, 076h, 066h, 066h
db 099h, 07Ch, 077h, 064h, 066h, 066h, 032h, 066h, 026h, 062h, 02Bh, 0B3h, 0D1h, 01Bh, 064h, 067h
db 091h, 0C7h, 074h, 066h, 026h, 064h, 026h, 044h, 044h, 046h, 022h, 0B3h, 03Dh, 013h, 064h, 047h
db 01Ch, 0C7h, 044h, 062h, 0BBh, 064h, 0B4h, 044h, 0AAh, 044h, 066h, 02Bh, 0B3h, 013h, 064h, 044h
db 017h, 024h, 066h, 02Bh, 02Ch, 0A6h, 026h, 044h, 0AAh, 0A4h, 046h, 0C2h, 0BBh, 033h, 064h, 04Ah
db 01Ch, 066h, 062h, 0BBh, 02Ah, 046h, 026h, 044h, 0AAh, 0AAh, 044h, 066h, 02Bh, 033h, 04Ah, 0A4h
db 016h, 022h, 023h, 03Bh, 066h, 066h, 0B6h, 04Ah, 0AAh, 0AAh, 044h, 066h, 02Bh, 031h, 04Ah, 0A4h
db 07Bh, 03Bh, 033h, 03Bh, 023h, 064h, 0BBh, 0B7h, 0CAh, 0AAh, 044h, 046h, 02Bh, 039h, 0CAh, 0A4h
db 073h, 0DDh, 0D3h, 03Bh, 023h, 06Ah, 064h, 0AAh, 071h, 0B4h, 044h, 044h, 062h, 035h, 074h, 044h
db 0C3h, 09Dh, 0DDh, 033h, 042h, 0BAh, 047h, 077h, 0C2h, 037h, 044h, 044h, 067h, 055h, 0B6h, 044h
db 0C2h, 091h, 0DDh, 03Dh, 064h, 0BAh, 0C0h, 008h, 087h, 044h, 044h, 067h, 031h, 0D1h, 0BBh, 064h
db 076h, 0DDh, 03Dh, 0B3h, 0B6h, 0BCh, 0C0h, 084h, 079h, 04Ah, 0A4h, 071h, 055h, 0D3h, 0B2h, 0C4h
db 013h, 093h, 033h, 02Bh, 033h, 0B2h, 067h, 017h, 017h, 04Ah, 0A7h, 058h, 088h, 057h, 02Bh, 026h
db 059h, 0DBh, 0B3h, 066h, 0B3h, 0B2h, 06Ah, 0ACh, 0C6h, 044h, 061h, 058h, 018h, 083h, 02Bh, 066h
db 051h, 0B2h, 033h, 066h, 022h, 026h, 04Ch, 044h, 044h, 066h, 0C1h, 0CCh, 015h, 05Dh, 062h, 066h
db 033h, 022h, 033h, 06Ah, 066h, 04Ah, 0A4h, 046h, 064h, 066h, 061h, 072h, 021h, 05Dh, 066h, 0CBh
db 0B6h, 06Bh, 09Dh, 06Ah, 066h, 04Ah, 0A4h, 044h, 044h, 066h, 061h, 017h, 031h, 05Dh, 066h, 0C4h
db 027h, 01Dh, 09Dh, 064h, 066h, 04Ah, 0AAh, 044h, 046h, 066h, 063h, 01Bh, 0B1h, 093h, 0CBh, 0B2h
db 035h, 013h, 093h, 046h, 026h, 04Ah, 0AAh, 0A4h, 044h, 044h, 04Bh, 03Bh, 031h, 013h, 0B3h, 01Bh
db 011h, 02Dh, 0DBh, 042h, 0B2h, 0AAh, 0AAh, 0A4h, 044h, 0AAh, 0A4h, 02Bh, 011h, 0D3h, 0B1h, 05Bh
db 092h, 039h, 0DBh, 022h, 022h, 0AAh, 0AAh, 0A4h, 044h, 0A4h, 0C7h, 023h, 05Dh, 033h, 0B3h, 05Dh
db 032h, 059h, 0DBh, 0BBh, 026h, 0AAh, 0AAh, 0AAh, 044h, 046h, 031h, 079h, 053h, 03Dh, 032h, 039h
db 031h, 099h, 033h, 0D3h, 0B6h, 0AAh, 0AAh, 0AAh, 0A4h, 02Bh, 031h, 015h, 093h, 03Dh, 0D2h, 063h
db 099h, 093h, 01Dh, 033h, 0B6h, 04Ah, 0A4h, 0BBh, 0C2h, 0B3h, 0D1h, 058h, 093h, 0BDh, 013h, 0BBh
db 099h, 013h, 015h, 053h, 026h, 044h, 044h, 0B9h, 011h, 095h, 091h, 085h, 051h, 0BDh, 01Dh, 0DDh
db 09Dh, 033h, 035h, 008h, 093h, 026h, 04Ah, 0A6h, 0BDh, 099h, 095h, 005h, 059h, 03Dh, 033h, 0DDh
db 099h, 027h, 0D9h, 088h, 088h, 053h, 026h, 044h, 062h, 0B3h, 058h, 085h, 019h, 019h, 022h, 01Dh
db 091h, 069h, 095h, 055h, 055h, 088h, 051h, 026h, 062h, 021h, 088h, 055h, 03Ch, 091h, 0C2h, 0B1h
db 093h, 0B5h, 058h, 059h, 095h, 055h, 088h, 057h, 022h, 038h, 008h, 051h, 03Ch, 031h, 0BDh, 03Dh
db 012h, 019h, 09Dh, 0D9h, 099h, 095h, 058h, 085h, 013h, 098h, 088h, 051h, 031h, 033h, 019h, 091h
db 032h, 022h, 023h, 0DDh, 0DDh, 0DDh, 099h, 058h, 085h, 088h, 088h, 085h, 099h, 013h, 099h, 011h
db 0B3h, 0BBh, 033h, 033h, 033h, 0DDh, 0DDh, 095h, 088h, 080h, 088h, 088h, 099h, 093h, 019h, 03Dh
;*** End MASM declaration ***
//*** Begin C declaration ***
unsigned char Palette[64] = {0x04,0x02,0x04,0x00,0x44,0x7A,0xAC,0x00,0x84,0xBE,0xEC,0x00,0x54,0x96,0xD4,0x00,
unsigned char Bmp[512] = {0x19,0x9C,0xC7,0x1B,0x62,0x26,0xB2,0x62,0x22,0x22,0xBB,0x33,0xD1,0x76,0x66,0x66,
//*** End C declaration ***
Completed processing bitmap file content.

VOID PrintCDeclaration(LPSTR lpszLabelName, BYTE *lpData, UINT uDataSize)
UINT i,j=0;
sprintf_s(szMsg, sizeof(szMsg), "unsigned char %s[%d] = {", lpszLabelName, uDataSize);
UpdateLog(szMsg);for(i=0; i<uDataSize; i++)
if(j==0 && i != 0)
UpdateLog(" ");
sprintf_s(szMsg, sizeof(szMsg), "0x%02X", lpData[i]);
UpdateLog(szMsg); j++;
if(j == 16 && i+1 != uDataSize)
else if (i+1 != uDataSize)
VOID PrintASMDeclaration(LPSTR lpszLabelName, BYTE *lpData, UINT uDataSize)
UINT i,j=0;
sprintf_s(szMsg, sizeof(szMsg), "_%s LABEL DWORD\r\n", lpszLabelName);
UpdateLog(szMsg);for(i=0; i<uDataSize; i++)
UpdateLog(" db ");
sprintf_s(szMsg, sizeof(szMsg), "0%02Xh", lpData[i]);
UpdateLog(szMsg); j++;
if(j == 16)
UpdateLog(", ");
VOID CreateHeaderFromBitmap(HWND hWnd)
CHAR CHMsg[MAX_PATH];if(GetBitmapName(hWnd))
ShowWindow(hLog, SW_HIDE);
// We have the file name, now lets see if we can do something with it...
UpdateLog("Loading bitmap.\r\n"); HINSTANCE hInst = GetModuleHandle(NULL);
UpdateLog("Failed to load file.\r\n");
UpdateLog("Getting information about bitmap.\r\n");
GetObject(hBmp, sizeof(BITMAP), &bm);
sprintf_s(CHMsg, sizeof(CHMsg), "Bits Per Pixel: %d\r\n", bm.bmBitsPixel);
sprintf_s(CHMsg, sizeof(CHMsg), "Dimensions: %d x %d\r\n", bm.bmHeight, bm.bmWidth);
if((bm.bmBitsPixel * bm.bmPlanes ) <= 8)
HBITMAP hOldBitmap;
RGBQUAD rgb[256]; // Create a memory DC and select the DIBSection into it
hMemDC = CreateCompatibleDC(NULL);
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBmp); // Get the DIBSection's color table & its size
INT SizeOfTable = GetDIBColorTable(hMemDC, 0, 256, rgb); // Calculate the size of required buffer.
INT BitmapImageSize = (bm.bmHeight *
bm.bmWidth *
bm.bmBitsPixel) / 8; // Allocate memory.
BYTE* pBitmapData = new BYTE[ BitmapImageSize ];
ZeroMemory( pBitmapData, BitmapImageSize ); // Get bitmap data.
GetBitmapBits( (HBITMAP) hBmp, BitmapImageSize, pBitmapData ); // Return our DC to its original state and delete it.
SelectObject(hMemDC, hOldBitmap);
DeleteDC(hMemDC); sprintf_s(CHMsg, sizeof(CHMsg), "Size: %d\r\n", BitmapImageSize);
UpdateLog(CHMsg); sprintf_s(CHMsg, sizeof(CHMsg), "Entries in colour table: %d\r\n\r\n", SizeOfTable);
UpdateLog(CHMsg); // Print ASM declaration
UpdateLog(";*** Begin MASM declaration ***\r\n\r\n");
PrintASMDeclaration("Palette", (BYTE*) &rgb, SizeOfTable * 4);
PrintASMDeclaration("Bmp", pBitmapData, BitmapImageSize);
UpdateLog(";*** End MASM declaration ***\r\n\r\n"); // Print C declaration
UpdateLog("//*** Begin C declaration ***\r\n\r\n");
PrintCDeclaration("Palette", (BYTE*) &rgb, SizeOfTable * 4);
PrintCDeclaration("Bmp", pBitmapData, BitmapImageSize);
UpdateLog("//*** End C declaration ***\r\n\r\n"); // Delete bitmap data after use.
delete pBitmapData;
pBitmapData = 0; UpdateLog("Completed processing bitmap file content.\r\n");
UpdateLog("Bitmap is greyscale, no colour table available.\r\n");
// Finally free the object resource for the loaded bitmap
ShowWindow(hLog, SW_SHOWNORMAL);}

POC attached, no guarantees or promises, it was thrown together as a test only. Directly accessing the file bytes would be another method but i used Win32 API instead.




Edited by ghandi
  • Like 1
Link to comment
Share on other sites

Thank you so much for your Time....

I will try this when I get home tonight ......( I will try assembly with the file it creates)

Thank you again ..... clap2.gif

Link to comment
Share on other sites

Now it generates header files, MASM or C, radio button for selection. Once again, just POC so no guarantees offered for usability, etc.




Question. Does the resource .inc always invert the bitmaplines? I noticed in one of the examples the bmp was inverted to the .inc but the other was not. Your tool will invert the image to the .inc file. Is that the norm?

I was playing with a python script that will open the bmp and create the inc file but not inverted. The last line of .inc also includes CR LF if that affects the resource. The script is set for only 16 colors and 32x32 bmp. Could detect and correct it automaticly but this was just for experimenting. Ugly coding I know. It is what it is. usage: python bmp.py filename.bmp It will overwrite filename.inc in same folder

import os,struct,sys,reif len(sys.argv) != 2:
print 'Usage:python bmp.py bmpfile'
exit(1)filename = sys.argv[1]
filename_out = re.sub(r'.bmp', '.inc', filename)header_fmt = '=2sihhiiiihhiiiiii'
palette_fmt = 'BBBB'*16
bin_fmt = 'BBBBBBBBBBBBBBBB'*32 #change if height largerf = open(filename,'rb')
w = open(filename_out, 'wb')#read header
#Note header information is not always used or correct
print '----Header----'
s_header = f.read(54) # 0x36 BMP header
header_data = ['PE','Size','Res_1','Res_2','BtOffx','BitSz','Width','Height','Planes','BitCnt','Cmpres','SzImg','Pix_X','Pix_Y','ClrBit','ClrImp']
header = struct.unpack(header_fmt,s_header)
i = 0
while i < len(header):
print header_data[i], ' :', header[i] # 1x tab
i += 1#read palette
print '----palette----'
cleanPalette = 'palette'
s_palette = f.read(64) # colors bits * 4
palette = struct.unpack(palette_fmt,s_palette)
i = 0
while i < len(palette):
print repr(palette[i:i+16])
strPalette = repr(palette[i:i+16])
stripedPalette = re.sub(r'\s|\(|\)', '',strPalette)
cleanPalette += ' db ' + stripedPalette + '\r\n' # 2x tab db 1x tab no space
i += 16
#read bin
print '----BitMap----'
cleanBin = 'bmp'
s_bin = f.read(512) # size of bitmap 16 * height(lines)
bin = struct.unpack(bin_fmt,s_bin)
i = 0
while i < len(bin):
print repr(bin[i:i+16])
strBin = repr(bin[i:i+16])
stripedBin = re.sub(r'\s|\(|\)', '',strBin)
cleanBin += ' db ' + stripedBin + '\r\n' # 2x tab db 1x tab no space
i += 16
w.write(cleanPalette + cleanBin)

edit note the code block is not keeping the tab char \t backslash t

Edited by redblkjck
Link to comment
Share on other sites

POC attached, no guarantees or promises, it was thrown together as a test only. Directly accessing the file bytes would be another method but i used Win32 API instead.



Thank you so much ...Last night I got some time around 4AM to try it ..... ( you first version...will try this one tonight )

and it works ! you should of made guarantees or promises...it works %100

I recommend that people use photo shop to make their images ....but If they do not have it ...I uploaded an example with explanation and your Tool Ghandi...so that is all in one package

Thank you Again Ghandi!

-----=======---- Solved -----=======---- clap2.gif

Bitmap.inc Example.zip

Bitmap.inc Example With Tools Needed.zip

Link to comment
Share on other sites

wunder: I never guarantee projects, let alone POC ones because they're only exploring possibilities and can come 'unstuck' so to speak. But if i offer them as they are, people can either use or learn from them hopefully.


Taken from Wikipedia's entry on BMP File Format:


Pixel array (bitmap data)

The pixel array is a block of 32-bit DWORDs, that describes the image pixel by pixel. Normally pixels are stored "upside-down" with respect to normal image raster scan order, starting in the lower left corner, going from left to right, and then row by row from the bottom to the top of the image.[1]

Uncompressed Windows bitmaps also can be stored from the top to bottom, when the Image Height value is negative.

My 'tool' does no inverting at all, it loads the bitmap using LoadImage then uses GDI functions to get the palette and image bytes raw, prints them to asm or C format and saves the result to a file. Any work done on bytes would be done by the API if at all, i used these functions because it meant i didn't have to learn the entire format of the file i could simply access the portions i wanted with a few calls and the output was identical to the original .bin and .pal files.



Edited by ghandi
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...