------------------
_________________Gecko___
PCX file question
_________________Gecko___Gecko Design
void PCX_Load(char *filename, pcx_picture_ptr image,int enable_palette)
{
// this function loads a pcx file into a /picture structure, the actual image
// data for the pcx file is decompressed and expanded into a secondary buffer
// within the picture structure, the separate images can be grabbed from this
// buffer later. also the header and palette are loaded
FILE *fp;
int num_bytes,index;
long count;
unsigned char data;
char far *temp_buffer;
// open the file
fp = fopen(filename,"rb");
// load the header
temp_buffer = (char far *)image;
for (index=0; index<128; index++)
{
temp_buffer[index] = (char)getc(fp);
} // end for index
// load the data and decompress into buffer
count=0;
while(count<=SCREEN_WIDTH * SCREEN_HEIGHT)
{
// get the first piece of data
data = (unsigned char)getc(fp);
// is this a rle?
if (data>=192 && data<=255)
{
// how many bytes in run?
num_bytes = data-192;
// get the actual data for the run
data = (unsigned char)getc(fp);
// replicate data in buffer num_bytes times
while(num_bytes-->0)
{
image->buffer[count++] = data;
} // end while
} // end if rle
else
{
// actual data, just copy it into buffer at next location
image->buffer[count++] = data;
} // end else not rle
} // end while
// move to end of file then back up 768 bytes i.e. to begining of palette
fseek(fp,-768L,SEEK_END);
// load the pallete into the palette
for (index=0; index<256; index++)
{
// get the red component
image->palette[index].red = (unsigned char)(getc(fp) >> 2);
// get the green component
image->palette[index].green = (unsigned char)(getc(fp) >> 2);
// get the blue component
image->palette[index].blue = (unsigned char)(getc(fp) >> 2);
} // end for index
fclose(fp);
// change the palette to newly loaded palette if commanded to do so
if (enable_palette)
{
// for each palette register set to the new color values
for (index=0; index<256; index++)
{
Set_Palette_Register(index,(RGB_color_ptr)&image->palette[index]);
} // end for index
} // end if change palette
} // end PCX_Load
and here are the pcx file structures:
typedef struct pcx_header_typ
{
char manufacturer;
char version;
char encoding;
char bits_per_pixel;
int x,y;
int width,height;
int horz_res;
int vert_res;
char ega_palette[48];
char reserved;
char num_color_planes;
int bytes_per_line;
int palette_type;
char padding[58];
} pcx_header, *pcx_header_ptr;
typedef struct pcx_picture_typ
{
pcx_header header;
RGB_color palette[256];
char far *buffer;
} pcx_picture, *pcx_picture_ptr;
with odd dimensions correctly, since it doesn't check for zero padding. Try
loading a 128x128 PCX file. I think it needs to be divisible by 8. Or use
the images provided on the CD. They should all work, but notice the bitmap
dimensions he uses. Programming in 21 Days is all DOS stuff, right?
Whistle
I have this question going in the general forum but I would like to see what kind of response it gets here too.
any opinions
It took me forever to get that 21 days book done, mainly because I had to learn 80x86 ASM as I went, but I got through it no worse for wear.
Anyway, I kind of abandoned C++ for a while, didn't use it for a little over a year. I was focusing in Java and making applets and all that stuff. Then I came back to C++, for the first time in quite some time, and I got Tricks of the Windows Game Programming Gurus.
That book is THE MAN! It taught me everything I needed to know about windows (though not much more...but hey, he has a page count to keep down) and it explained DirectX in ENGLISH. Then it got down to the nitty gritty with AI, Physics, and all that stuff that actually makes the game.
I can truthfully say that Tricks of the Windows Programming Gurus is Andre's best work. I didn't have the slightest clue how Windows worked, and with that single book I'm now writing DirectX applications. The only thing he doesn't cover in the book is Direct3D, that'll be in volume II (due out sometime in the spring, he said).
So, to answer your question : you need no prior windows knowledge to use that book, and you may as well abandon DOS, but the stuff you learn in that 21 days book is a good foundation, so reading through it before you go to windows isn't a bad idea.