Post by n00b on Feb 10, 2020 3:04:21 GMT -6
I tried it out. Its pretty smooth.
Also I modified the BMP export function to work with any size:
Also I modified the BMP export function to work with any size:
Function ExportBMP(bmp_file$, bmp_width, bmp_height, byref pdata, array_width)
'BMP FILE FORMAT
'-----------------------------------BMP Header----------------------------------------------------------
Dim BM_Header[14]
BM_Header[0] = Asc("B")
BM_Header[1] = Asc("M")
BM_Size = ((bmp_width * bmp_height) * 3) + 54 'Sprite_Width * Sprite_Height * Color_Depth + 54 (54 is size of BMP_Header + Info Header)
BM_Header[2] = AndBit( BM_Size, 255 )
BM_Header[3] = AndBit( BM_Size Shr 8, 255 )
BM_Header[4] = AndBit( BM_Size Shr 16, 255 )
BM_Header[5] = AndBit( BM_Size Shr 24, 255 )
'The next 4 bytes are not used for anything
BM_Header[6] = 0
BM_Header[7] = 0
BM_Header[8] = 0
BM_Header[9] = 0
'Offset Where pixel data starts (Its always going to be 54 for this routine)
BM_Header[10] = 54
BM_Header[11] = 0
BM_Header[12] = 0
BM_Header[13] = 0
'-----------------------------------End of BMP Header----------------------------------------------------------
'-----------------------------------DIB Header----------------------------------------------------------
Dim DIB_Header[40]
'Size of DIB Header (Its always going to be 40 bytes)
DIB_Header[0] = 40
DIB_Header[1] = 0
DIB_Header[2] = 0
DIB_Header[3] = 0
'BMP width in Pixels
DIB_Header[4] = AndBit( bmp_width, 255 )
DIB_Header[5] = 0'AndBit( bmp_width Shr 8, 255 )
DIB_Header[6] = 0'AndBit( bmp_width Shr 16, 255 )
DIB_Header[7] = 0'AndBit( bmp_width Shr 24, 255 )
'BMP height in Pixels
DIB_Header[8] = AndBit( bmp_height, 255 )
DIB_Header[9] = 0'AndBit( bmp_height Shr 8, 255 )
DIB_Header[10] = 0'AndBit( bmp_height Shr 16, 255 )
DIB_Header[11] = 0'AndBit( bmp_height Shr 24, 255 )
'Number of Color Planes (always 1)
DIB_Header[12] = 1
DIB_Header[13] = 0
'Color Depth (Bits per pixel)
DIB_Header[14] = 24
DIB_Header[15] = 0
'Compression Method used (always 0 for this routine)
DIB_Header[16] = 0
DIB_Header[17] = 0
DIB_Header[18] = 0
DIB_Header[19] = 0
'Image Size (Sprite_Width * Sprite_Height * Color_Depth_In_Bytes( it is 3 for 24-Bit ) )
Image_Size = bmp_width * bmp_height * 3
DIB_Header[20] = AndBit( Image_Size, 255 )
DIB_Header[21] = AndBit( Image_Size Shr 8, 255 )
DIB_Header[22] = AndBit( Image_Size Shr 16, 255 )
DIB_Header[23] = AndBit( Image_Size Shr 24, 255 )
'Pixels Per Meter - I am just setting it to 2834
DIB_PPM = 2834
'Horizontal Resolution (PPM)
DIB_Header[24] = AndBit( DIB_PPM, 255 )
DIB_Header[25] = AndBit( DIB_PPM Shr 8, 255 )
DIB_Header[26] = AndBit( DIB_PPM Shr 16, 255 )
DIB_Header[27] = AndBit( DIB_PPM Shr 24, 255 )
'Vertical Resolution (PPM)
DIB_Header[28] = AndBit( DIB_PPM, 255 )
DIB_Header[29] = AndBit( DIB_PPM Shr 8, 255 )
DIB_Header[30] = AndBit( DIB_PPM Shr 16, 255 )
DIB_Header[31] = AndBit( DIB_PPM Shr 24, 255 )
'Number of Colors in Color Palette - I am just setting this to default of 0 as well
DIB_Header[32] = 0
DIB_Header[33] = 0
DIB_Header[34] = 0
DIB_Header[35] = 0
'Number of Important colors - 0 sets every color to important ( I actually have no idea what this does )
DIB_Header[36] = 0
DIB_Header[37] = 0
DIB_Header[38] = 0
DIB_Header[39] = 0
f = FreeFile
FileOpen(f, bmp_file, BINARY_OUTPUT)
For i = 0 to 13
WriteByte(f, BM_Header[i])
Next
For i = 0 to 39
WriteByte(f, DIB_Header[i])
Next
padding = 4 - ( (bmp_width * 3) MOD 4 ): If padding = 4 Then: padding = 0: End If
For x = bmp_width-1 to 0 step -1
For y = 0 to bmp_height-1
WriteByte(f, AndBit(pdata[y*array_width+x], 255) )
WriteByte(f, AndBit(pdata[y*array_width+x] Shr 8, 255) )
WriteByte(f, AndBit(pdata[y*array_width+x] Shr 16, 255) )
Next
If padding > 0 Then
For i = 0 to padding-1
WriteByte(f, 0)
Next
End If
Next
FileClose(f)
End Function