Mail Archives: djgpp/1999/08/12/00:29:47
> hey there, I'm having some trouble decoding the pcx header. I hunted down
> the format and everything, but I still can't seem to be able to read the
> dimensions of the image from the header. If anybody knows anywhere I could
> get some info on doing this I'd really appreciate it. Basically, I've tried
> reading it as a text file and as a binary file, and I've tried reading
> character by character and through formatted input (ie using fscanf) but I
> can't seem to get it to work. Anyway, thanks for any help you can offer.
you should read the file as a binary file. there should be something like this:
int loadpcx(char fila[13],long dest,int mem_pitch,int loadpalette,palette pal)
{
FILE *f;
int pcx_width,pcx_height,bpl,y,x;
unsigned char scale,delta,r,g,b,ch,c,*pixel=(unsigned char
*)dest,nume[24]="pcx\\";
delta=(loadpalette>>8)&0xff;
scale=(loadpalette>>16)&0xff;
strcat(nume,fila);
f=fopen(nume,"rb");
if(!f)
return 1;
getc(f);
getc(f);
getc(f);
c=getc(f);
if(c!=8)
{
fclose(f);
return 2;
}
pcx_width=getc(f);
pcx_width+=256*getc(f);
pcx_height=getc(f);
pcx_height+=256*getc(f);
pcx_width+=getc(f)+1;
pcx_width+=256*getc(f);
pcx_height+=getc(f)+1;
pcx_height+=256*getc(f);
getc(f);
getc(f);
getc(f);
getc(f);
for(y=0;y<16;y++)
{
getc(f);
getc(f);
getc(f);
}
getc(f);
if(getc(f)!=1)
{
fclose(f);
return 3;
}
bpl=getc(f);
bpl+=256*getc(f);
for(y=0;y<60;y++)
getc(f);
for(y=0;y<pcx_height;y++)
{
x=0;
while(x<bpl)
{
ch=getc(f);
if((ch&0xC0)==0xC0)
{
c=(ch&0x3F);
ch=getc(f);
}
else
c=1;
while(c--)
{
#ifdef PCX_COLOR_KEY
if(ch!=0xff)
#endif
#ifdef PCX_SHIFT
*(pixel+x)=(ch+delta)<<scale;
#else
*(pixel+x)=ch;
#endif
x++;
}
}
pixel+=mem_pitch;
}
if((loadpalette&0xff)&&(getc(f)==12))
{
for(y=0;y<=255;y++)
{
r=getc(f)/4;
g=getc(f)/4;
b=getc(f)/4;
if(loadpalette&1)
setpal(y,r,g,b);
if(loadpalette&2)
{
pal[y].r=r;
pal[y].g=g;
pal[y].b=b;
}
}
}
fclose(f);
return 0;
}
- Raw text -