OutFile ReadBitmap.exe Section /* ReadBitmap function needs the function bin2dec attached to work with 1 and 4 BITS bitmaps, and Hex2Bin for 4 BITS bitmaps. For any other type, these functions aren't needed.*/ #----------------------------------------------------------------------- Push "CreateBitmapExample.bmp" #----------------------------------------------------------------------- /* Bitmap file to read */ #----------------------------------------------------------------------- Call ReadBitmap #----------------------------------------------------------------------- /* Function call. */ #----------------------------------------------------------------------- Pop $R0 #----------------------------------------------------------------------- /* Output -> Palette colors*/ /* 1, 4 and 8 BITS: Colors in the format RRGGBB separated by vertical bars "|", each one is identified by the colors order, from left to right.*/ /* 24 BITS: It's null. */ #----------------------------------------------------------------------- Pop $R1 #----------------------------------------------------------------------- /* Output -> number of bits (1,4,8,24 BITS) */ #----------------------------------------------------------------------- Pop $R2 #----------------------------------------------------------------------- /* Output -> height */ #----------------------------------------------------------------------- Pop $R3 #----------------------------------------------------------------------- /* Output -> width */ #----------------------------------------------------------------------- Pop $R4 #----------------------------------------------------------------------- /* Output */ /* 1, 4 and 8 BITS: Index numbers of colors indicated by the palette colors, starting at 0. 1 BIT bitmaps have 2 colors, 4 BITS bitmaps have 16, and 8 BITS bitmaps have 256 colors. 24 BITS: Colors in the format RRGGBB (in hexadecimal) separated by vertical bars "|". */ SectionEnd Function ReadBitmap Exch $R0 Push $R1 Push $R2 Push $R3 Push $R4 Push $R5 Push $R6 Push $R7 Push $R8 Push $R9 Push $0 Push $1 StrCpy $1 "" # Open requested file (just to write) FileOpen $R0 '$R0' r # Write default structure for C-Evo maps FileReadByte $R0 $R1 ;Required Startup (BM) FileReadByte $R0 $R1 FileReadByte $R0 $R1 ;File Size (Not important) FileReadByte $R0 $R1 FileReadByte $R0 $R1 FileReadByte $R0 $R1 FileReadByte $R0 $R1 ;Reserved FileReadByte $R0 $R1 FileReadByte $R0 $R1 FileReadByte $R0 $R1 FileReadByte $R0 $R1 ;Header Size (Not Important) FileReadByte $R0 $R1 FileReadByte $R0 $R1 FileReadByte $R0 $R1 FileReadByte $R0 $R1 ;Length of the Bitmap Info Header (bitmap = 40) FileReadByte $R0 $R1 FileReadByte $R0 $R1 FileReadByte $R0 $R1 # Width FileReadByte $R0 $R1 # Size level 1 - Small FileReadByte $R0 $R2 # Size level 2 - Medium FileReadByte $R0 $R3 # Size level 3 - Big FileReadByte $R0 $R4 # Size level 4 - Gigantic IntOp $R4 $R4 * 16777215 IntOp $R3 $R3 * 65535 IntOp $R2 $R2 * 255 IntOp $R1 $R1 + $R2 IntOp $R1 $R1 + $R3 IntOp $R1 $R1 + $R4 # Height FileReadByte $R0 $R2 # Size level 1 - Small FileReadByte $R0 $R3 # Size level 2 - Medium FileReadByte $R0 $R4 # Size level 3 - Big FileReadByte $R0 $R5 # Size level 4 - Gigantic IntOp $R5 $R5 * 16777215 IntOp $R4 $R4 * 65535 IntOp $R3 $R3 * 255 IntOp $R2 $R2 + $R3 IntOp $R2 $R2 + $R4 IntOp $R2 $R2 + $R5 FileReadByte $R0 $R3 ;Planes (Bitmap = 1) FileReadByte $R0 $R3 FileReadByte $R0 $R3 ;Bits per Pixel FileReadByte $R0 $R4 FileReadByte $R0 $R4 ;Compression (No Compression -> Bitmap = 0) FileReadByte $R0 $R4 FileReadByte $R0 $R4 FileReadByte $R0 $R4 FileReadByte $R0 $R4 ;Bitmap Data Size (Not Important) FileReadByte $R0 $R4 FileReadByte $R0 $R4 FileReadByte $R0 $R4 FileReadByte $R0 $R4 ;Hresolution (Not Important) FileReadByte $R0 $R4 FileReadByte $R0 $R4 FileReadByte $R0 $R4 FileReadByte $R0 $R4 ;Vresolution (Not Important) FileReadByte $R0 $R4 FileReadByte $R0 $R4 FileReadByte $R0 $R4 FileReadByte $R0 $R4 ;Number of Colors (Not Important) FileReadByte $R0 $R4 FileReadByte $R0 $R4 FileReadByte $R0 $R4 FileReadByte $R0 $R4 ;Number of Important Colors (Not Important) FileReadByte $R0 $R4 FileReadByte $R0 $R4 FileReadByte $R0 $R4 /* Just a note how to read bitmaps: Every bitmap except those with 24 bits pixels have a palette, including monochrome bitmaps.*/ StrCpy $R4 "" StrCmp $R3 24 EndReadPallete StrCpy $R4 "" StrCpy $R5 0 ReadPallete: IntOp $R5 $R5 + 1 FileReadByte $R0 $R6 ;Color Blue FileReadByte $R0 $R7 ;Color Green FileReadByte $R0 $R8 ;Color Red FileReadByte $R0 $R9 IntFmt $R6 "%02x" $R6 IntFmt $R7 "%02x" $R7 IntFmt $R8 "%02x" $R8 StrCpy $R4 "$R4$R8$R7$R6|" StrCmp $R3 1 0 +2 StrCmp $R5 2 EndReadPallete StrCmp $R3 4 0 +2 StrCmp $R5 16 EndReadPallete StrCmp $R3 8 0 +2 StrCmp $R5 256 EndReadPallete Goto ReadPallete EndReadPallete: /* End of palette code */ # Initialize variables StrCpy $R5 "" StrCpy $R6 0 StrCpy $R7 0 StrCpy $R9 0 # Next Line NextLine: IntOp $R7 $R7 + 1 #Line Number StrCpy $R6 0 # Next Color of the Line NextColor: IntOp $R6 $R6 + 1 #Color Number of the Line # 1 bit bitmap StrCmp $R3 1 0 Bit1 IntOp $R6 $R6 - 1 Bit1NextColor: StrCpy $0 0 FileReadByte $R0 $R8 IntFmt $R8 "%02x" $R8 StrCpy $R9 $R8 "" 1 StrCpy $R8 $R8 1 Push $R8 Call Hex2Bin Pop $R8 Push $R9 Call Hex2Bin Pop $R9 StrCpy $R8 $R8$R9 Bit1Start: IntOp $0 $0 + 1 IntOp $R6 $R6 + 1 StrCmp $0 1 0 +2 StrCpy $R9 $R8 1 StrCmp $0 2 0 +3 StrCpy $R9 $R8 "" 1 StrCpy $R9 $R9 1 StrCmp $0 3 0 +3 StrCpy $R9 $R8 "" 2 StrCpy $R9 $R9 1 StrCmp $0 4 0 +3 StrCpy $R9 $R8 "" 3 StrCpy $R9 $R9 1 StrCmp $0 5 0 +3 StrCpy $R9 $R8 "" 4 StrCpy $R9 $R9 1 StrCmp $0 6 0 +3 StrCpy $R9 $R8 "" 5 StrCpy $R9 $R9 1 StrCmp $0 7 0 +3 StrCpy $R9 $R8 "" 6 StrCpy $R9 $R9 1 StrCmp $0 8 0 +2 StrCpy $R9 $R8 "" 7 StrCpy $1 $1$R9| StrCmp $R6 $R1 Bit1EndingLine StrCmp $0 8 Bit1NextColor Bit1Start Bit1EndingLine: StrCpy $R5 $1$R5 StrCpy $1 "" StrCpy $R8 "" /* Just a note how to create bitmaps: Each line has to be divisible by 4, so add null characters.*/ IntOp $R9 $R6 / 8 IntOp $R9 $R9 % 4 IntOp $R9 4 - $R9 IntOp $R9 $R9 - 1 IntCmp $R9 0 +4 +4 FileReadByte $R0 $R8 IntOp $R9 $R9 - 1 Goto -3 /* End of extra null characters code */ StrCmp $R7 $R2 End NextLine Bit1: # 4 bit bitmap StrCmp $R3 4 0 Bit4 IntOp $R6 $R6 - 1 Bit4NextColor: StrCpy $0 0 FileReadByte $R0 $R8 IntFmt $R8 "%02x" $R8 StrCpy $R9 $R8 "" 1 StrCpy $R8 $R8 1 Push $R8 Call Hex2Bin Pop $R8 Push $R9 Call Hex2Bin Pop $R9 Bit4Start: IntOp $0 $0 + 1 IntOp $R6 $R6 + 1 StrCmp $0 1 0 +2 Push $R8 StrCmp $0 2 0 +2 Push $R9 Call Bin2Dec Pop $R8 StrCpy $1 $1$R8| StrCmp $R6 $R1 Bit4EndingLine StrCmp $0 2 Bit4NextColor Bit4Start Bit4EndingLine: StrCpy $R5 $1$R5 StrCpy $1 "" StrCpy $R8 "" /* Just a note how to create bitmaps: Each line has to be divisible by 4, so add null characters.*/ IntOp $R9 $R6 / 2 IntOp $R9 $R9 % 4 StrCmp $R9 0 +2 IntOp $R9 4 - $R9 IntCmp $R9 0 +4 +4 FileReadByte $R0 $R8 IntOp $R9 $R9 - 1 Goto -3 /* End of extra null characters code */ StrCmp $R7 $R2 End NextLine Bit4: # 8 bit bitmap StrCmp $R3 8 0 Bit8 FileReadByte $R0 $R8 StrCpy $R5 $R5$R8| StrCmp $R6 $R1 0 NextColor /* Just a note how to create bitmaps: Each line has to be divisible by 4, so add null characters.*/ IntOp $R9 $R6 % 4 StrCmp $R9 0 +2 IntOp $R9 4 - $R9 IntCmp $R9 0 +4 +4 FileReadByte $R0 $R8 IntOp $R9 $R9 - 1 Goto -3 /* End of extra null characters code */ StrCmp $R7 $R2 End NextLine Bit8: # 24 bit bitmap StrCmp $R3 24 0 Bit24 FileReadByte $R0 $R8 ;Color Blue IntFmt $R8 "%02x" $R8 StrCpy $R5 $R5$R8 FileReadByte $R0 $R8 ;Color Green IntFmt $R8 "%02x" $R8 StrCpy $R5 $R5$R8 FileReadByte $R0 $R8 ;Color Red IntFmt $R8 "%02x" $R8 StrCpy $R5 $R5$R8| StrCmp $R6 $R1 0 NextColor /* Just a note how to create bitmaps: Each line has to be divisible by 4, so add null characters.*/ IntOp $R9 $R9 * 3 IntOp $R9 $R9 % 4 IntOp $R9 4 - $R9 IntCmp $R9 0 +4 +4 FileReadByte $R0 $R8 IntOp $R9 $R9 - 1 Goto -3 /* End of extra null characters code */ StrCmp $R7 $R2 End NextLine Bit24: # End of bitmap reading End: StrCpy $R4 $R4 -1 StrCpy $R5 $R5 -1 FileClose $R0 # Return variables to user Pop $1 Pop $0 Pop $R9 Pop $R8 Pop $R7 Pop $R6 Exch $R5 Exch Exch $R4 Exch Exch 2 Exch $R3 Exch 2 Exch 3 Exch $R2 Exch 3 Exch 4 Exch $R1 Exch 4 Exch 5 Pop $R0 FunctionEnd Function bin2dec Exch $R9 ; binary input string (max 16 bits) Push $R8 Push $R7 ; 4 character hex output string (empty if error detected) Exch 2 StrLen $R8 $R9 IntCmp $R8 16 start start too_long start: StrCpy $R7 0 loop: StrCpy $R8 $R9 1 StrCmp $R8 "" done StrCpy $R9 $R9 "" 1 StrCmp $R8 "0" good_digit StrCmp $R8 "1" good_digit bad_digit good_digit: IntOp $R7 $R7 * 2 IntOp $R7 $R7 + $R8 Goto loop too_long: StrCpy $R7 "" Goto exit bad_digit: StrCpy $R7 "" Goto exit done: exit: Pop $R9 Pop $R8 Exch $R7 FunctionEnd Function Hex2Bin Push $0 Exch Exch $1 Exch Push $2 Push $3 Push $4 Push $5 Push $6 Push $7 ; Set/Get Source Hex Number StrLen $0 $1 StrCpy $3 $0 ; loop - Get 1 Letter per loop from right for process NextLetter: StrCpy $4 '$5 $4' StrCpy $5 '' StrCmp $3 '0' End IntOP $3 $3 - 1 StrCpy $2 $1 1 $3 StrCpy $6 '256' IntOP $6 $6 / 2 IntOP $7 0x$2 & $6 IntCmp $7 '0' +2 StrCpy $7 '1' StrCpy $5 '$5$7' StrCmp $6 '1' NextLetter -5 End: StrCpy $1 $4 "" 4 StrCpy $1 $1 4 Pop $7 Pop $6 Pop $5 Pop $4 Pop $3 Pop $2 Pop $0 Exch $1 FunctionEnd