PCX Files
Hi does anyone know where i can find a tutorial or any type of help on loading and displaying a pcx file in direct draw?
January 14, 2000 10:08 PM
Well, just steal some generic PCX code and either
load it into a buffer or draw it with DirectX. All
the DOS game programming books and lots of pages
like cdrom.com or simtel.net will have the code.
load it into a buffer or draw it with DirectX. All
the DOS game programming books and lots of pages
like cdrom.com or simtel.net will have the code.
January 14, 2000 10:19 PM
You mean like this????
//////////////////////////////////////////////////////////////////////////////
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
//////////////////////////////////////////////////////////////////////////////
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
damn i can't get this!!! ok in the code above, the image data is taken from the file and stored in the unsigned char data, right? if so then how to i put this data on a Direct Draw surface?
i also don't quite understand what was done with the pcx_picture_ptr image?
does anyone else have any source code that's not done in dos, but directx?
Edited by - +AA_970+ on 1/15/00 12:04:38 PM
i also don't quite understand what was done with the pcx_picture_ptr image?
does anyone else have any source code that's not done in dos, but directx?
Edited by - +AA_970+ on 1/15/00 12:04:38 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement