' ================================================================= ' Program Name : BMPREAD.BAS ' Programmer : B. Kahl ' Date : February 28, 1996 ' Description : This program will load a Windows 3 bitmap graphics ' file and display it. generally written for 16color 480x640 screen ' 12 modes. This is a primative version with slow disk read. (reading ' each pixel line 320 bytes per disk access) Future versions will ' load larger amounts of pixel data during a single disk access. ' ' Written w/PowerBASIC assisted by Dave Navarro, Jr., Gary J. Sibio, ' and John Pearson ' ================================================================= cls f1% = freefile ' filename$ = "C:\WINDOWS\BOXES.BMP" filename$ = "C:\WINDOWS\CHESS.BMP" Open filename$ for binary as f1% FiLen& = lof(f1%) Map BMPFileHdr$$ * 14,_ 'Standrd BMP File Header Record=14Bytes 2 as FType$$,_ 'File Type BM or 0xD42 4 as FSize$$,_ 'File Size 2 as Resrv1$$,_ 'Not Used 2 as Resrv2$$,_ 'Not Used 4 as OffSet$$ 'Offset to Beginning of Data seek #f1%,0 'start of BMP get$ #f1%,14,BMPFileHdr$$ 'Read stndrd MBP File Header 14 bytes if FType$$ <> "BM" then print Ftype$$;"File Not BMP Format Cannot Display":end FSize&=cvl(FSize$$) OffSet& = cvl(OffSet$$) '3E = Mono, 76=16 Clr, 436=256 Clr, 36=16.7mil ' 62dec , 118dec , 1078 , 54dec Map BMPInfoHdr$$ * 40,_ 'Standrd BMP Info Header Record=40Bytes 4 as Size$$,_ 'Len of the header in bytes 4 as Wid$$,_ 'Width of the image in Pixels 4 as Height$$,_ 'height of the image in Pixels 2 as Planes$$,_ 'Num of Planes (min =1) 2 as BitCnt$$,_ 'Bits per Pixel 1,4,8,24 4 as Comprsn$$,_ 'comprsn Scheme 0=none,RGB,RLE8,RLE4 4 as SizeImage$$,_ 'size (bytes) of the bits in image 4 as XpelsPerMeter$$,_ 'horz Res in Pixels per Meter 4 as YpelsPerMeter$$,_ 'Ver Res in Pixels per Meter 4 as ClrUsed$$,_ 'Num of Colrs Used 0=max 4 as ClrImprtnt$$ 'Num of Colr Indexes considrd imptnt 0=all get$ #f1%,40,BMPInfoHdr$$ 'Read stndrd MBP Info Header 40 bytes size& =cvl(size$$) wid% =cvl(wid$$) height%=cvl(height$$) Planes%=cvi(Planes$$) BitCnt%=cvi(BitCnt$$) print "File Name$ = ";FileName$ print "FileSize =";FSize& print "Offset to Data =";OffSet& print "Header Size =";size& print "Image Width =";wid% print "Image Height =";height% print "Planes =";Planes% print "Bits Per Pixel =";BitCnt% Print "Press any Key to Continue" input a$ Map RGB$$*4,_ 'Color Values 1 as Blue$$,_ '0-255 1 as Green$$,_ '0-255 1 as red$$,_ '0-255 1 as rsrvd$$ screen 12 'VGA screen mode 12 16 colors 640x480 'this line has to be prior to setting palette cls for i%=0 to 15 get$ #f1%,4,RGB$$ 'Read RGB Values start at 54 bytes from start 0-255 Blue?= cvbyt(Blue$$)\4 '1 byte containing Blue Value from file convert to 0-63 Green?=cvbyt(Green$$)\4 'ditto Green Red? =cvbyt(red$$)\4 'ditto red reg 1, &h1010 'AX set individual DAC register 5-21 PC Interrupts reg 2, i%'p%\256 'BX Register Number from BH reg 3, Green?*256+Blue? 'CH=Green, CL=Blue 0-63 reg 4, Red?*256 'DH=Red 0-63 call interrupt &h10 next i% seek #f1%,offset& 'offset pnt read from BMP File header for y% = height%-1 to 0 step -1 'bottom screen line first in file get$ f1%,wid%\2,buf$ 'read 1 line data from file @ a time for x%=0 TO wid%-1 step 4 'build array from string pix??= cvwrd(mid$(buf$,(x%\2)+1,2)) 'convert 2bytes string to array val ms? = pix??\256 'most significant 8 bits ls? = pix?? mod 256 'least significant 8 bits pset (x%+2,y%),ms?\16 'most significant 4 bits pset (x%+3,y%),ms? mod 16 pset (x% ,y%),ls?\16 pset (x%+1,y%),ls? mod 16 'least signif if instat then exit,exit 'exit loop when any key pressed next x% sound 50,.001 next y% close #f1% end