Archived

This topic is now archived and is closed to further replies.

PCX file question

This topic is 6588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

are you doing your RGB conversions correctly? if you are using 16 bit colour, you have to find out whether your graphics card does 16 bit as 5-6-5 or 5-5-5. i was getting wierd colours with my engine until i discovered that my card did 16 bit as 5 red, 5 green, and 5 blue, instead of 6 green. or you might be reading the pcx file wrong, or storing it incorrectly. post some more info and maybe some code, and you might get more help.

------------------

_________________Gecko___

Share this post


Link to post
Share on other sites
well here is the function that loads the pcx file


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;

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hmmm...that looks like Lamothe code which is notorious for not loading images
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

Share this post


Link to post
Share on other sites
Yes it is Lamothe code and yes it is all dos.... I'm begining to think that all of this is not really worth it. I mean let's face it after I get going here I am of course going to abandon Dos entirly in favor of direct X so i'm starting to think that maybe I should just Go ahead and get "windows game programming for dummies" or "tricks of the windows game programming gurus" or both... the only thing is that I have never used windows before so is that a problem?

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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I've read both Teach Yourself Game Programming in 21 Days and Tricks of the Windows Game Programming Gurus (in that order).
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.

Share this post


Link to post
Share on other sites
I am using some library functions to display pcx files on screen (well actually i'm not good enough to write my own functions so i'm just modifying the functions in "Teach YourSelf Game Programming in 21 Days") Anyways I wrote a test program to display an all red pcx file on screen and the file came up as a whitish color? Any ideas as to what is wrong?

Share this post


Link to post
Share on other sites