How to Save Color Registers After BSAVE of (PICEM) Graphics (78888)
This article was previously published under Q78888
SUMMARY
QuickBasic cannot use .PCX, .GIF, or .PIC graphics files directly. The
utility PICEM210.EXE can be used to display the graphics on the screen
so that QuickBasic can BSAVE and later BLOAD the image. However, BSAVE
saves only the bit planes, not the color registers. If the graphics
image changes the color registers, then these changes will be lost,
resulting in a gray-scale image when loaded with the BLOAD statement.
This is a limitation of the BSAVE statement, not PICEM210.EXE.
In order to retain the picture's original colors, use the CALL
INTERRUPTX &H10 with function &H17 to place the color registers into
an array, then BSAVE the array. To restore the picture's colors, BLOAD
the color register array that was saved with BSAVE and use CALL
INTERRUPTX &H10 with function &H12.
Of the four sample programs provided below, examples 1 and 3 BSAVE the
picture and its color registers, and examples 2 and 4 BLOAD the
picture and its color registers. These programs apply to QuickBasic
versions 4.0, 4.0b, and 4.5, to Microsoft Basic Compiler versions 6.0
and 6.0b, and to Microsoft Basic Professional Development System (PDS)
versions 7.0 and 7.1 for MS-DOS. Because Basic BSAVEs SCREENs 7, 8, 9,
and 12 differently then SCREEN 13, Examples 1 and 2 (SAV7to12.BAS and
LOD7to12.BAS) have been written specifically for SCREENs 7, 8, 9, or
12, and examples 3 and 4 (SAV13.BAS and LOD13.BAS) have been written
for SCREEN 13.
PICEM210 is a freeware graphics file viewing utility that can display
.GIF, .PCX, and .PIC file formats, and is required to make these programs
run. PICEM210 is available as a freeware product. For more information on
PICEM, please read its README file PICEM210.DOC, or query on the following
word:
MORE INFORMATION
You only need to use example program 1 or 3 once to convert the
graphics image. You will use example program 2 or 4 every time you
wish to display the graphics image. All four programs use the
INTERRUPTX routine in the QuickBasic QB.QLB Quick library (or QBX.QLB
for Microsoft Basic PDS) to retrieve or set the graphics image's color
registers. To use this Quick library's procedures, you must load the
Quick library with the environment by typing QB/L (or QBX/L for
Microsoft Basic PDS) at the command prompt.
The examples can be used independently. If you add them to an existing
program, the DECLARE SUB ConvrtPic(), the TYPE colortype ... END TYPE,
and 'INCLUDE: 'qb.bi' (or '$INCLUDE: 'qbx.bi' for Microsoft Basic
PDS) statements must be moved to the existing program's main module
level code. The introduction on each example lists which variables
need to be altered by the programmer. The programs themselves contain
suggested values for the variables when necessary.
Example 1: (SAV7TO12.BAS)
'REQUIREMENT: must have PICEM210.EXE
'This program uses PICEM210 to display a .PCX, .PIC, or .GIF
'graphics image file onto the screen so that QuickBasic can
'then BSAVE it. It BSAVEs the picture and the color
'registers for SCREEN 7,8,9, or 12. The values of the
'variables MODE%, Z, TOTAL!,and YOURFILE must be written
'into the code. PICEM210.EXE should be in the default directory.
DECLARE SUB ConvrtPic ()
TYPE colortype
red AS STRING * 1
green AS STRING * 1
blue AS STRING * 1
END TYPE
'$INCLUDE: 'qb.bi'
''$INCLUDE: 'qbx.bi' for Basic PDS
CALL ConvrtPic()
END
SUB Convrt Pic()
DIM inregsx AS RegTypeX
DIM outregsx AS RegTypeX
DIM colorbuf(15) AS colortype
SCREEN MODE%
'where MODE% = 7 for screen 7
' = 8 for screen 8
' = 9 for screen 9
' = 12 for screen 12.
SHELL "PICEM210 /e/v:Z YOURFILE.PCX"
'where Z = j for screen 7
' = d for screen 8
' = g for screen 9(ega)
' = i for screen 9(vga)
' = m for screen 12
'if other options for PICEM210 are desired, refer to
'PICEM210.DOC for alternate choices
'where YOURFILE.PCX is the .pcx,.pic,or.gif file to be 'converted
DEF SEG = &HA000
FOR i% = 0 TO 3
'BSAVing 4 files with .b_0,.b_1,.b_2,.b_3 extensions.
'The 4 files contain the 4 bit planes
OUT &H3CE, 4
'makes the port at &H3CE enable the data register at &H3CF
OUT &H3CF, i%
'selects next bit plane
f$ = "YOURFILE" + ".b_" + CHR$(i% + 48)
'where YOURFILE is the filename to be used for the
'BSAVEd graphics image files after conversion.
BSAVE f$, 0, TOTAL!
'where TOTAL! = 8000 for screen 7
' = 16000 for screen 8
' = 28000 for screen 9
' = 38400 for screen 12
NEXT i%
DEF SEG
'BIOS interrupt to get palette registers
inregsx.ax = &H1017
inregsx.bx = 0
inregsx.cx = 16
inregsx.es = VARSEG(colorbuf(0))
inregsx.dx = VARPTR(colorbuf(0))
CALL INTERRUPTX(&H10, inregsx, outregsx)
'BSAVE palette registers
DEF SEG = VARSEG(colorbuf(0))
BSAVE "YOURFILE.REG", VARPTR(colorbuf(0)), 48
'where YOURFILE is the filename to be used for the BSAVEd
'color registers
DEF SEG
END SUB
EXAMPLE 2: (LOD7TO12.BAS)
'This program loads BSAVEd files from disk into video
'memory and restores the graphics image's registers
'for screen 7,8,9, or 12. It assumes the picture files
'were BSAVEd using code from SAV7TO12.BAS. The values of
'the variables MODE%, and YOURFILE must be written into
'the code. The graphics image files should be in the default
'directory.
DECLARE SUB ConvrtPic ()
TYPE colortype
red AS STRING * 1
green AS STRING * 1
blue AS STRING * 1
END TYPE
'$INCLUDE: 'qb.bi'
''$INCLUDE: 'qbx.bi' for Basic PDS
CALL ConvrtPic()
END
SUB Convrt Pic()
DIM inregx AS RegTypeX
DIM outregx AS RegTypeX
DIM colorbuf(15) AS colortype
SCREEN MODE%
'where MODE% = 7 for screen 7
' = 8 for screen 8
' = 9 for screen 9
' = 12 for screen 12
CLS
'if necessary, save the current color registers of the
'existing screen using code from SAV7TO12.BAS before
'changing colors to the graphics image's palette
'BLOAD the graphics image's palette into array
DEF SEG = VARSEG(colorbuf(0))
BLOAD "YOURFILE.REG", VARPTR(colorbuf(0))
'where YOURFILE.REG is the BSAVEd file created in
'SAV7TO12.BAS which contains the color registers
DEF SEG
'call interrupt to restore graphics image's palette to registers
inregx.ax = &H1012
inregx.bx = 0
inregx.cx = 16
inregx.es = VARSEG(colorbuf(0))
inregx.dx = VARPTR(colorbuf(0))
CALL INTERRUPTX(&H10, inregx, outregx)
'BLOAD 4 bit planes created in SAV7TO12.BAS
DEF SEG = &HA000
FOR k = 0 TO 3
OUT &H3C4, 2
'makes the port at &H3C4 enable the data register at &H3C5
OUT &H3C5, 2 ^ k
'selects next bit plane
f$ = "YOURFILE.B_" + CHR$(k + 48)
'where YOURFILE.B_ is the filename of the converted graphics
'image
BLOAD f$, 0
NEXT k
DEF SEG
END SUB
Example 3: (SAV13.BAS)
'REQUIREMENT: must have PICEM210.EXE
'This program uses PICEM210 to display a .PCX, .PIC, or .GIF
'file onto the screen so that QuickBasic can then BSAVE it.
'It BSAVEs the picture and the color registers for SCREEN
'13. The value of the variable YOURFILE must be written into
'the code. PICEM210.EXE should be in the default directory.
DECLARE SUB ConvrtPic ()
TYPE colortype
red AS STRING * 1
green AS STRING * 1
blue AS STRING * 1
END TYPE
'$INCLUDE: 'qb.bi'
''$INCLUDE: 'qbx.bi' for Basic PDS
CALL ConvrtPic()
END
SUB Convrt Pic()
DIM inregsx AS RegTypeX
DIM outregsx AS RegTypeX
DIM colorbuf(255) AS colortype
SCREEN 13
SHELL "PICEM210 /e/v:l YOURFILE.pcx"
'where YOURFILE.pcx is the filename of the pcx,.pic, or .gif
'graphics image to be converted
'BSAVE graphics image
DEF SEG = &HA000
BSAVE "YOURFILE.sav", 0, 64000
'where YOURFILE is the filename for the converted graphic image
DEF SEG
'BIOS interrupt to get palette registers
inregsx.ax = &H1017
inregsx.bx = 0
inregsx.cx = 256
inregsx.es = VARSEG(colorbuf(0))
inregsx.dx = VARPTR(colorbuf(0))
CALL INTERRUPTX(&H10, inregsx, outregsx)
'BSAVE palette registers
DEF SEG = VARSEG(colorbuf(0))
BSAVE "YOURFILE.reg", VARPTR(colorbuf(0)), 3 * 256
'where YOURFILE is the filename for the BSAVEd color registers
DEF SEG
END SUB
Example 4: (LOD13.BAS)
'This program loads BSAVEd files from disk into video
'memory and restores the graphics image's registers
'for screen 13. It assumes the picture files were BSAVEd
'using code from SAV13.BAS. The value of the variable
'YOURFILE must be written into the code. The graphics image
'files should be in the default directory.
DECLARE SUB ConvrtPic ()
TYPE ColorType
red AS STRING * 1
green AS STRING * 1
blue AS STRING * 1
END TYPE
'$INCLUDE: 'qb.bi' ' use for QuickBasic 4.0, 4.0b, or 4.5
''$INCLUDE: 'qbx.bi ' use for Basic PDS 7.0 or 7.1
CALL ConvrtPic()
END
SUB Convrt Pic()
DIM inregx AS RegTypeX
DIM outregx AS RegTypeX
DIM colorbuf(255) AS ColorType
SCREEN 13
CLS
'if necessary, save the current color registers of the
'existing screen using code from SAV13.BAS before changing
'colors to the graphics image's palette
'BLOAD the picture's palette
DEF SEG = VARSEG(colorbuf(0))
BLOAD "YOURFILE.reg", VARPTR(colorbuf(0))
'where YOURFILE is the filename containing the graphics
'image's color registers
DEF SEG
'call interrupt to restore graphics image's palette
inregx.ax = &H1012
inregx.bx = 0
inregx.cx = 256
inregx.es = VARSEG(colorbuf(0))
inregx.dx = VARPTR(colorbuf(0))
CALL INTERRUPTX(&H10, inregx, outregx)
'BLOAD picture
DEF SEG = &HA000
BLOAD "YOURFILE.sav", 0
'where YOURFILE is the filename of the converted graphics
'image
DEF SEG
END SUB
Modification Type: |
Minor |
Last Reviewed: |
1/9/2003 |
Keywords: |
KB78888 |
|