I'm porting some BMP stuff - this info is useful for loading BMP textures directly or creating BMP files directly without going through GDI.
Charles
'===============
'bmp file loader
'===============
type BmpMapHeader
short bfType
long bfSize
short bfReserved1
short bfReserved2
long bfOffBits
long biSize
long biWidth
long biHeight
short biPlanes
short biBitCount
long biCompression
long biSizeImage
long biXPelsPerMeter
long biYPelsPerMeter
long biClrUsed
long biClrImportant
end type
string bmpfile="t.bmp" 'choose your file
string bmpdata=""
getfile bmpfile,bmpdata
sys le=len bmpdata
if le=0 then print "no data" : jmp fwd done
'
BmpMapHeader *d : @d = *bmpdata
'---------------------
'DISPLAY HEADER VALUES
'=====================
'
#if 1 '0/1 excl/incl
'
'capture signature to string
'---------------------------
'
string n=" "
**n=?d
n=left n,2
'
string cr=chr(13)+chr(10)
string tab=chr(9)
string pr="BMP HEADER DATA FOR " bmpfile cr cr
def p pr=pr+ %1 tab %2 cr
'
'------------------------------------------
p "Signature: " n
p "File Size: " d.bfSize
p "Bit data offset : " d.bfOffBits
p "Header size: " d.bisize
p "Image Width: " d.biWidth
p "Image Height: " d.biHeight
p "Bit planes: " d.biPlanes
p "Bits per pixel: " d.biBitCount
p "Compression: " d.biCompression
p "Size of Image: " d.biSizeImage
p "Xpixels per metre:" d.biXPelsPerMeter
p "Ypixels per metre:" d.biYPelsPerMeter
p "Colours used: " d.biClrUsed
p "Colours important:" d.biClrImportant
'------------------------------------------
print pr
'
#endif 'display header values
'----------------
'ACCESS TO PIXELS
'================
type pixel byte r,g,b
pixel *pix : @pix = *BmpData + d.bfOffBits
'print pix[1].r
'-------------
'SAVE BMP FILE
'=============
'putfile "s.bmp",BmpData
'====
done:
'====
BmpData=""
'=====
'NOTES
'=====
'----------------------------------------------------------------------------------------------------------
' BMP file formats
'
' The BITMAPFILEHEADER:
'----------------------------------------------------------------------------------------------------------
'start size name stdvalue purpose
'----------------------------------------------------------------------------------------------------------
'1 2 bfType 19778 must always be set to 'BM' to declare that this is a .bmp-file.
'3 4 bfSize ?? the size of the file in bytes.
'7 2 bfReserved1 0 must always be set to zero.
'9 2 bfReserved2 0 must always be set to zero.
'11 4 bfOffBits 1078 specifies the offset from the beginning of the file to the bitmap data.
'----------------------------------------------------------------------------------------------------------
'
'
' The BITMAPINFOHEADER:
'----------------------------------------------------------------------------------------------------------
'start size name stdvalue purpose
'----------------------------------------------------------------------------------------------------------
'15 4 biSize 40 size of the BITMAPINFOHEADER structure, in bytes.
'19 4 biWidth 100 width of the image, in pixels.
'23 4 biHeight 100 height of the image, in pixels.
'27 2 biPlanes 0 number of planes of the target device, must be set to zero.
'29 2 biBitCount 8 number of bits per pixel.
'31 4 biCompression 0 type of compression, usually set to zero (no compression).
'35 4 biSizeImage 0 size of the image data, in bytes. If there is no compression, it is valid to set this member to zero.
'39 4 biXPelsPerMeter 0 horizontal pixels per meter on the designated targer device, usually set to zero.
'43 4 biYPelsPerMeter 0 vertical pixels per meter on the designated targer device, usually set to zero.
'47 4 biClrUsed 0 number of colors used in the bitmap, if set to zero the number of colors is calculated using the biBitCount member.
'51 4 biClrImportant 0 number of color that are 'important' for the bitmap, if set to zero, all colors are important.
'----------------------------------------------------------------------------------------------------------