Jump to content
Tuts 4 You

Convert bmp.bmp to bmp.pal bmp.bin


wunder

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 ?

cc_detective.gif

4kb-kg.zip

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 ?

gfx.zip

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.

edit

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) ?

tools.zip

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 ***
_Palette LABEL DWORD
db 004h, 002h, 004h, 000h, 044h, 07Ah, 0ACh, 000h, 084h, 0BEh, 0ECh, 000h, 054h, 096h, 0D4h, 000h
_Bmp LABEL DWORD
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,
0xB4,0xDA,0xF4,0x00,0x24,0x46,0x84,0x00,0x9C,0xCE,0xF4,0x00,0x74,0x9E,0xC4,0x00,
0x14,0x26,0x44,0x00,0x2C,0x62,0xA4,0x00,0xCC,0xE6,0xFC,0x00,0x6C,0xAA,0xE4,0x00,
0x94,0xBA,0xDC,0x00,0x44,0x82,0xC4,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x00,0x00};
unsigned char Bmp[512] = {0x19,0x9C,0xC7,0x1B,0x62,0x26,0xB2,0x62,0x22,0x22,0xBB,0x33,0xD1,0x76,0x66,0x66,
0x99,0x7C,0x77,0x64,0x66,0x66,0x32,0x66,0x26,0x62,0x2B,0xB3,0xD1,0x1B,0x64,0x67,
0x91,0xC7,0x74,0x66,0x26,0x64,0x26,0x44,0x44,0x46,0x22,0xB3,0x3D,0x13,0x64,0x47,
0x1C,0xC7,0x44,0x62,0xBB,0x64,0xB4,0x44,0xAA,0x44,0x66,0x2B,0xB3,0x13,0x64,0x44,
0x17,0x24,0x66,0x2B,0x2C,0xA6,0x26,0x44,0xAA,0xA4,0x46,0xC2,0xBB,0x33,0x64,0x4A,
0x1C,0x66,0x62,0xBB,0x2A,0x46,0x26,0x44,0xAA,0xAA,0x44,0x66,0x2B,0x33,0x4A,0xA4,
0x16,0x22,0x23,0x3B,0x66,0x66,0xB6,0x4A,0xAA,0xAA,0x44,0x66,0x2B,0x31,0x4A,0xA4,
0x7B,0x3B,0x33,0x3B,0x23,0x64,0xBB,0xB7,0xCA,0xAA,0x44,0x46,0x2B,0x39,0xCA,0xA4,
0x73,0xDD,0xD3,0x3B,0x23,0x6A,0x64,0xAA,0x71,0xB4,0x44,0x44,0x62,0x35,0x74,0x44,
0xC3,0x9D,0xDD,0x33,0x42,0xBA,0x47,0x77,0xC2,0x37,0x44,0x44,0x67,0x55,0xB6,0x44,
0xC2,0x91,0xDD,0x3D,0x64,0xBA,0xC0,0x08,0x87,0x44,0x44,0x67,0x31,0xD1,0xBB,0x64,
0x76,0xDD,0x3D,0xB3,0xB6,0xBC,0xC0,0x84,0x79,0x4A,0xA4,0x71,0x55,0xD3,0xB2,0xC4,
0x13,0x93,0x33,0x2B,0x33,0xB2,0x67,0x17,0x17,0x4A,0xA7,0x58,0x88,0x57,0x2B,0x26,
0x59,0xDB,0xB3,0x66,0xB3,0xB2,0x6A,0xAC,0xC6,0x44,0x61,0x58,0x18,0x83,0x2B,0x66,
0x51,0xB2,0x33,0x66,0x22,0x26,0x4C,0x44,0x44,0x66,0xC1,0xCC,0x15,0x5D,0x62,0x66,
0x33,0x22,0x33,0x6A,0x66,0x4A,0xA4,0x46,0x64,0x66,0x61,0x72,0x21,0x5D,0x66,0xCB,
0xB6,0x6B,0x9D,0x6A,0x66,0x4A,0xA4,0x44,0x44,0x66,0x61,0x17,0x31,0x5D,0x66,0xC4,
0x27,0x1D,0x9D,0x64,0x66,0x4A,0xAA,0x44,0x46,0x66,0x63,0x1B,0xB1,0x93,0xCB,0xB2,
0x35,0x13,0x93,0x46,0x26,0x4A,0xAA,0xA4,0x44,0x44,0x4B,0x3B,0x31,0x13,0xB3,0x1B,
0x11,0x2D,0xDB,0x42,0xB2,0xAA,0xAA,0xA4,0x44,0xAA,0xA4,0x2B,0x11,0xD3,0xB1,0x5B,
0x92,0x39,0xDB,0x22,0x22,0xAA,0xAA,0xA4,0x44,0xA4,0xC7,0x23,0x5D,0x33,0xB3,0x5D,
0x32,0x59,0xDB,0xBB,0x26,0xAA,0xAA,0xAA,0x44,0x46,0x31,0x79,0x53,0x3D,0x32,0x39,
0x31,0x99,0x33,0xD3,0xB6,0xAA,0xAA,0xAA,0xA4,0x2B,0x31,0x15,0x93,0x3D,0xD2,0x63,
0x99,0x93,0x1D,0x33,0xB6,0x4A,0xA4,0xBB,0xC2,0xB3,0xD1,0x58,0x93,0xBD,0x13,0xBB,
0x99,0x13,0x15,0x53,0x26,0x44,0x44,0xB9,0x11,0x95,0x91,0x85,0x51,0xBD,0x1D,0xDD,
0x9D,0x33,0x35,0x08,0x93,0x26,0x4A,0xA6,0xBD,0x99,0x95,0x05,0x59,0x3D,0x33,0xDD,
0x99,0x27,0xD9,0x88,0x88,0x53,0x26,0x44,0x62,0xB3,0x58,0x85,0x19,0x19,0x22,0x1D,
0x91,0x69,0x95,0x55,0x55,0x88,0x51,0x26,0x62,0x21,0x88,0x55,0x3C,0x91,0xC2,0xB1,
0x93,0xB5,0x58,0x59,0x95,0x55,0x88,0x57,0x22,0x38,0x08,0x51,0x3C,0x31,0xBD,0x3D,
0x12,0x19,0x9D,0xD9,0x99,0x95,0x58,0x85,0x13,0x98,0x88,0x51,0x31,0x33,0x19,0x91,
0x32,0x22,0x23,0xDD,0xDD,0xDD,0x99,0x58,0x85,0x88,0x88,0x85,0x99,0x13,0x99,0x11,
0xB3,0xBB,0x33,0x33,0x33,0xDD,0xDD,0x95,0x88,0x80,0x88,0x88,0x99,0x93,0x19,0x3D};
//*** End C declaration ***
Completed processing bitmap file content.

VOID PrintCDeclaration(LPSTR lpszLabelName, BYTE *lpData, UINT uDataSize)
{
CHAR szMsg[MAX_PATH];
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)
{
UpdateLog(",\r\n");
j=0;
}
else if (i+1 != uDataSize)
{
UpdateLog(",");
}
}UpdateLog("};\r\n");
}
VOID PrintASMDeclaration(LPSTR lpszLabelName, BYTE *lpData, UINT uDataSize)
{
CHAR szMsg[MAX_PATH];
UINT i,j=0;
sprintf_s(szMsg, sizeof(szMsg), "_%s LABEL DWORD\r\n", lpszLabelName);
UpdateLog(szMsg);for(i=0; i<uDataSize; i++)
{
if(j==0)
{
UpdateLog(" db ");
}
sprintf_s(szMsg, sizeof(szMsg), "0%02Xh", lpData[i]);
UpdateLog(szMsg); j++;
if(j == 16)
{
UpdateLog("\r\n");
j=0;
}
else
{
UpdateLog(", ");
}
}UpdateLog("\r\n");
}
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);
HANDLE hBmp = LoadImage(hInst, szFileName, IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if(!hBmp)
{
UpdateLog("Failed to load file.\r\n");
}
else
{
UpdateLog("Getting information about bitmap.\r\n");
BITMAP bm;
GetObject(hBmp, sizeof(BITMAP), &bm);
sprintf_s(CHMsg, sizeof(CHMsg), "Bits Per Pixel: %d\r\n", bm.bmBitsPixel);
UpdateLog(CHMsg);
sprintf_s(CHMsg, sizeof(CHMsg), "Dimensions: %d x %d\r\n", bm.bmHeight, bm.bmWidth);
UpdateLog(CHMsg);
if((bm.bmBitsPixel * bm.bmPlanes ) <= 8)
{
HDC hMemDC;
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");
}
else
{
UpdateLog("Bitmap is greyscale, no colour table available.\r\n");
}
// Finally free the object resource for the loaded bitmap
DeleteObject(hBmp);
}
}
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.

HR,

Ghandi

Bmp2Header.rar

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.

HR,

Ghandi

Nice.

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)
f.close
w.close

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.

HR,

Ghandi

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.

redblkjck:

Taken from Wikipedia's entry on BMP File Format:

http://en.wikipedia....8bitmap_data.29

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.

HR,

Ghandi

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...