主题:Quickbasic真彩显示全代码
DECLARE SUB pset15or16bit (x%, y%, c&)
DECLARE FUNCTION rgb2color& (rgbcolor&)
DEFINT A-Z
TYPE REGTYPE
ax AS INTEGER
bx AS INTEGER
cx AS INTEGER
dx AS INTEGER
bp AS INTEGER
si AS INTEGER
di AS INTEGER
flags AS INTEGER
ds AS INTEGER
es AS INTEGER
END TYPE
DIM SHARED reg AS REGTYPE
TYPE BMPINFOSTRUCT
'"BITMAPFILEHEADER" structure begins here:
bm AS STRING * 2 'a 2 byte string always set to "BM" to identify the bitmap file
filesize AS LONG 'the size of the entire file in bytes
reserved AS LONG
bitmapdataoffset AS LONG 'the offset within the file where the raw data for the bitmap begins
sizeofbitmapinfoheader AS LONG'usually set to 40
'"BITMAPINFOHEADER" structure begins here:
x AS LONG 'width
y AS LONG 'height
planes AS INTEGER 'always 1
bitsperpixel AS INTEGER
compressiontype AS LONG 'usually 0
imagesize AS LONG 'set to 0 if it is an uncompressed bitmap
xpelspermeter AS LONG 'usually 0
ypelspermeter AS LONG 'usually 0
colorsused AS LONG 'specifies the number of colors used in the bitmap, if set to 0 the number of colors is calculated using the bitsperpixel member
importantcolors AS LONG 'specifies the number of colors that are "important" for the bitmap, if set to zero, all colors are important.
END TYPE
DIM bmpinfo AS BMPINFOSTRUCT
DIM SHARED currentvesapage AS INTEGER
DIM SHARED screenx AS INTEGER
DIM SHARED screeny AS INTEGER
DIM SHARED bitsperpixel AS INTEGER
'set vesa screen mode
reg.ax = &H4F02
reg.bx = &H111'640x480x16
CALL interrupt(&H10, reg, reg)
screenx = 640
screeny = 480
bitsperpixel = 16
'draw some random dots
FOR i& = 0 TO 100000
pset15or16bit RND * screenx, RND * screeny, RND * 65536
NEXT
'load a real color bmp file and display it
OPEN "1.bmp" FOR BINARY AS #1
GET #1, , bmpinfo
bmprowsizeinbytes = bmpinfo.x * 3
'force row size in bytes to be an even multiple of 4
IF bmprowsizeinbytes AND &H3 THEN
bmprowsizeinbytes = bmprowsizeinbytes \ 4 * 4 + 4
END IF
'create a string to load a row of data into
bmprowdata$ = SPACE$(bmprowsizeinbytes)
'draw the bmp onscreen
FOR y = 0 TO bmpinfo.y - 1
fileoffset& = bmpinfo.bitmapdataoffset + 1& + (bmpinfo.y - y - 1) * bmprowsizeinbytes
GET #1, fileoffset&, bmprowdata$
FOR x = 0 TO bmpinfo.x - 1
pset15or16bit x, y, rgb2color(CVL(MID$(bmprowdata$, x * 3 + 1, 3) + CHR$(0)))
NEXT
NEXT
CLOSE #1
SUB pset15or16bit (x%, y%, c&)
IF x% < 0 THEN EXIT SUB
IF y% < 0 THEN EXIT SUB
IF x% >= screenx THEN EXIT SUB
IF y% >= screeny THEN EXIT SUB
offset& = 2& * screenx * y% + 2& * x%
requiredvesapage% = offset& \ 65536
byteoffsetwithinpage& = offset& MOD 65536
IF requiredvesapage% <> currentvesapage THEN
reg.ax = &H4F05
reg.bx = 0
reg.dx = requiredvesapage%
CALL interrupt(&H10, reg, reg)
currentvesapage = requiredvesapage%
END IF
DEF SEG = &HA000
POKE byteoffsetwithinpage&, c& AND &HFF&
POKE byteoffsetwithinpage& + 1, (c& \ 256&) AND &HFF&
END SUB
FUNCTION rgb2color& (rgbcolor&)
'This converts a 24/32bit color value into a 15 or 16 bit color value
IF bitsperpixel = 16 THEN
rgb2color& = (rgbcolor& AND 255&) \ 8& + (rgbcolor& AND 64512) \ 32& + (rgbcolor& AND 16252928) \ 256&
EXIT FUNCTION
END IF
IF bitsperpixel = 15 THEN
rgb2color& = (rgbcolor& AND 255&) \ 8& + (rgbcolor& AND 63488) \ 64& + (rgbcolor& AND 16252928) \ 512&
EXIT FUNCTION
END IF
END FUNCTION
已经调试过了,一定可以,先做一张真彩色的BMP,JPG的因为有压缩算法,比较麻烦,就用BMP的了,一定要真彩,256色的都不可以,然后取个1.bmp名就可以了。因为显示真彩色是调用中断的,而显示没有调用中断,感觉比较慢。
DECLARE FUNCTION rgb2color& (rgbcolor&)
DEFINT A-Z
TYPE REGTYPE
ax AS INTEGER
bx AS INTEGER
cx AS INTEGER
dx AS INTEGER
bp AS INTEGER
si AS INTEGER
di AS INTEGER
flags AS INTEGER
ds AS INTEGER
es AS INTEGER
END TYPE
DIM SHARED reg AS REGTYPE
TYPE BMPINFOSTRUCT
'"BITMAPFILEHEADER" structure begins here:
bm AS STRING * 2 'a 2 byte string always set to "BM" to identify the bitmap file
filesize AS LONG 'the size of the entire file in bytes
reserved AS LONG
bitmapdataoffset AS LONG 'the offset within the file where the raw data for the bitmap begins
sizeofbitmapinfoheader AS LONG'usually set to 40
'"BITMAPINFOHEADER" structure begins here:
x AS LONG 'width
y AS LONG 'height
planes AS INTEGER 'always 1
bitsperpixel AS INTEGER
compressiontype AS LONG 'usually 0
imagesize AS LONG 'set to 0 if it is an uncompressed bitmap
xpelspermeter AS LONG 'usually 0
ypelspermeter AS LONG 'usually 0
colorsused AS LONG 'specifies the number of colors used in the bitmap, if set to 0 the number of colors is calculated using the bitsperpixel member
importantcolors AS LONG 'specifies the number of colors that are "important" for the bitmap, if set to zero, all colors are important.
END TYPE
DIM bmpinfo AS BMPINFOSTRUCT
DIM SHARED currentvesapage AS INTEGER
DIM SHARED screenx AS INTEGER
DIM SHARED screeny AS INTEGER
DIM SHARED bitsperpixel AS INTEGER
'set vesa screen mode
reg.ax = &H4F02
reg.bx = &H111'640x480x16
CALL interrupt(&H10, reg, reg)
screenx = 640
screeny = 480
bitsperpixel = 16
'draw some random dots
FOR i& = 0 TO 100000
pset15or16bit RND * screenx, RND * screeny, RND * 65536
NEXT
'load a real color bmp file and display it
OPEN "1.bmp" FOR BINARY AS #1
GET #1, , bmpinfo
bmprowsizeinbytes = bmpinfo.x * 3
'force row size in bytes to be an even multiple of 4
IF bmprowsizeinbytes AND &H3 THEN
bmprowsizeinbytes = bmprowsizeinbytes \ 4 * 4 + 4
END IF
'create a string to load a row of data into
bmprowdata$ = SPACE$(bmprowsizeinbytes)
'draw the bmp onscreen
FOR y = 0 TO bmpinfo.y - 1
fileoffset& = bmpinfo.bitmapdataoffset + 1& + (bmpinfo.y - y - 1) * bmprowsizeinbytes
GET #1, fileoffset&, bmprowdata$
FOR x = 0 TO bmpinfo.x - 1
pset15or16bit x, y, rgb2color(CVL(MID$(bmprowdata$, x * 3 + 1, 3) + CHR$(0)))
NEXT
NEXT
CLOSE #1
SUB pset15or16bit (x%, y%, c&)
IF x% < 0 THEN EXIT SUB
IF y% < 0 THEN EXIT SUB
IF x% >= screenx THEN EXIT SUB
IF y% >= screeny THEN EXIT SUB
offset& = 2& * screenx * y% + 2& * x%
requiredvesapage% = offset& \ 65536
byteoffsetwithinpage& = offset& MOD 65536
IF requiredvesapage% <> currentvesapage THEN
reg.ax = &H4F05
reg.bx = 0
reg.dx = requiredvesapage%
CALL interrupt(&H10, reg, reg)
currentvesapage = requiredvesapage%
END IF
DEF SEG = &HA000
POKE byteoffsetwithinpage&, c& AND &HFF&
POKE byteoffsetwithinpage& + 1, (c& \ 256&) AND &HFF&
END SUB
FUNCTION rgb2color& (rgbcolor&)
'This converts a 24/32bit color value into a 15 or 16 bit color value
IF bitsperpixel = 16 THEN
rgb2color& = (rgbcolor& AND 255&) \ 8& + (rgbcolor& AND 64512) \ 32& + (rgbcolor& AND 16252928) \ 256&
EXIT FUNCTION
END IF
IF bitsperpixel = 15 THEN
rgb2color& = (rgbcolor& AND 255&) \ 8& + (rgbcolor& AND 63488) \ 64& + (rgbcolor& AND 16252928) \ 512&
EXIT FUNCTION
END IF
END FUNCTION
已经调试过了,一定可以,先做一张真彩色的BMP,JPG的因为有压缩算法,比较麻烦,就用BMP的了,一定要真彩,256色的都不可以,然后取个1.bmp名就可以了。因为显示真彩色是调用中断的,而显示没有调用中断,感觉比较慢。