🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

PCX question. C in dos

Started by
0 comments, last by GameDev.net 24 years, 8 months ago
i've created a program in turbo C++ that is supposed to get the main data from a pcx file and uncompress the rle values and save it as a dat file with just the pixel data and no palette or header. but it always crashes. could someone please help me figure out whats wrong with the source?


#include
#include

typedef unsigned char db;
typedef unsigned int dw;

int main(void)
{
db buffer[64000];
dw count=0;
db temp,index;
FILE *fp;
fp=fopen("pcx.pcx","rb");

fseek(fp,128,0);

count=0;
while(count<64000)
{
index=getc(fp);
if(index > 192)
{
index-=192;
temp=getc(fp);
while(index>0)
{
buffer[count++]=temp;
index--;
}
}
else
{
buffer[count++]=index;
}
}

fclose(fp);

fp=fopen("pcx.dat","wb");
for(count=0;count<64000;count++)
{
putc(buffer[count],fp);
}
fclose(fp);

return 1;
}

Advertisement
db buffer[64000];

I don't remember offhand, but I think TC had a problem with arrays this large nested in a function. That isn't the problem though.
---------------------------------

if(index > 192)
{
index-=192;
temp=getc(fp);
while(index>0)
{
buffer[count++]=temp;
index--;
}
}
else
{
buffer[count++]=index;
}
}
---------------------------------
change to:

if(index > 191)
{
index &= 63;
temp=getc(fp);
while(index>0)
{
buffer[count++]=temp;
index--;
}
}
else
{
buffer[count++]=index;
}
}
---------------------------------


That's all by memory, but see if that works.

------------------
Jim Adams
Co-Designer 'The Light Befallen'
tcm@pobox.com
http://www.lightbefallen.com

This topic is closed to new replies.

Advertisement