Incorporating 16-Color Bitmap Images
Would uou like to incorporate your own 16-color bitmap images into your Pro-SiMPLE programs? Let's look at one of the ways in which it can be done.
A bitmap file consists of essentially two parts. The beginning of the file contains some header information which indicates the size of the picture, the number of bits per pixel, etc. (In a 16-color bitmap file the length of this header is 118 bytes.) Following the header is the actual picture data. (In a 16-color bitmap file the picture data consists of pairs of pixels packed one pair per byte.)
As an example of how you might incorporate a 16-color bitmap image, let's write a program that will display three copies of the 94x144 image of Woody Woodpecker that you see at the top of this page. (But first you will need to copy the image into the root directory of your hard drive. Simply right-click on the image and select: "Save Picture As...")
Pro-SiMPLE
graph on
Do x=230,310,40
plot woody (x, x/2, -1) @
Loop
Task plot woody (Int x, Int y, Int inv)
Common Int z[]={0,4,2,6,1,5,3,7,8,12,10,14,9,13,11,15}
Common Int xsize=94, ysize=144
Int data
command="read C:\\woody.bmp"
Open g (command)
skip (118) @
Do yy=ysize-1,0
Do xx=0,xsize-1,2
Read binary g (data, 0)
zz=z[data/16]; If (zz!=inv) Put pixel (x+xx, y+yy, zz)
If (xx=xsize-1) Break
zz=z[data%16]; If (zz!=inv) Put pixel (x+xx+1, y+yy, zz)
Loop
skip ((16384-(xsize+1)/2)%4) @
Loop
Close g
Task skip (Int n)
Do k=1,n,1
Read binary g (0, 0)
Loop
The plotwoody task assigns the woody.bmp file
to channel G and opens it for reading. Next, it skips past the 118 bytes of
header information (since we already know that the size of the image is 94x144).
It then it reads the picture data and plots it onto the screen.* And finally,
it closes the channel when it is all done.
*(The color value of each pixel must first be converted into the corres-
ponding SiMPLE color. Hence the use of
the z[] conversion array.)
When we run the program, we get three overlapping copies of the woody.bmp image:
Notice that each successive image was plotted onto the screen without regard for any prior images underneath it. But then also notice that the plotwoody task has a third calling parameter, inv , which allows you to specify an "invisible" color (i.e., one which doesn't get plotted). Since the gray background in woody.bmp is color #7, let's change the third calling parameter (in line three of the program) from -1 to 7:
[
Webmaster |
FAQ's |
Home Page |
Contact Us ]