GRAPHICS IN QBASIC TUTORIAL (PART 2), by "Hacker" aka Damian Nikodem · Hacker@alphalink.com.au
For todays lesson we will be covering PCX images! Now because we are covering a FILE FORMAT I will split the Tutorial into Diffrent Sections. The sections needed for PCX images are:
The header is ALWAYS 128 bytes and most of the data you will not even use so I will not cover it here. But if you really want it you can goto: www.alphalink.com.au/~hacker/pcxinfo.htm for all of the information but trust me its not really worth the download time but there is a slight bit of information that is very useful and that is the X and Y sizes of the image. But that would make the program a LOT larger than I would want to send (I have a VERY slow conection to my mail server) but here is the formula for figuring out the size of the image - 11pcxsiz.bas
All of that just to see what the size of the image is. This wouldnt be to hard to implement into a normal pcx loader but the problem is that my loader writes to memory (like I explained in part 1) and because it is only designed to handle 320x200 it works a LOT faster.
The data in the image is easy to handle A pcx image is almost a direct screen to memory dump with 1 single execption. If the number that is read is over 192 and under or equal to 255 then it starts a small loop and this lets us get a small compression ratio (1/1.2) on the average image without much work being done. Well heres the code to load a 320x200 image - 11pcxvie.bas
Now what have you notaiced about that code apart from you cant make heads or tails of it??? If you run it the colors off. Do you remember what I said in part one about the palette and how you can redefine the colors well you can now put it into action!
The palette in a PCX file is not all ways the exact same palette as the standard so the last 768 bytes of a pcx image are just palette data. The format for the pallete data is quite simple. it contains 256 * 3 ascii charecters. Each charecter is one part of the color so the first charecter is the red value for color 0 the second is the Green value for the color 0, the third charecter is the blue value for color 0,and so on this is repeated until color 255 is reached. Here is the final piece of code for the PCX loader - 11pcxvi2.bas
Now you know how to load PCX images in basic! Keep this code (The entire loader) because next issue I will be discussing RANDOMIC GRAPHICS. The jpg loader is being postponed until I fully understand the format this may be a few months ( or years have you seen the size of the DOCS)
Also go down to the store and BUY quake 2 it is well worth it! if you dont have the money at least download the shareware (11 Mb) from www.quake2.com I will be using screen shots from the game in the next part also
- Hacker firstname.lastname@example.org