problems reading PCX header

problems reading PCX header

Post by Toni Giaca » Mon, 07 Jun 1993 07:43:22



I'm trying to figure out PCX formats and am writing a program to just
read one made from Windows 3.1 Paintbrush.
One of my basic problems is that I can't always successfully read the
header from a PCX file created by Paintbrush.  It isn't consistent,
sometimes it works and sometimes it doesn't.
When it does work, it always works for that file.  But I'll create another
PCX file and it won't work on that one.  

A sample of the source code in question follows.    
Anybody know why this is happening?

Thanks in advance.
Toni Giacalone

typedef struct {
    char manufactuer;
    char version;
    char encoding;
    char bits;
    int xmin, ymin, xmax, ymax;
    int hres, vres;
    char palette[48];
    char reserved;
    char color_planes;
    int bytes_per_line;
    int palette_type;
    char filler[58];
    } PCXHEAD;

PCXHEAD pcx;

if (fread((char *)&pcx,1,sizeof(PCXHEAD),fp) != sizeof(PCXHEAD) ||
    pcx.manufactuer != 0x0a)
    {
      fclose(fp);   // it gets to here sometimes, bad header??
      return(BAD_FILE);    
    }
else
   {
     go on to read bytes, etc
   }

 
 
 

1. Solved PCX Header Problem :)

About a week ago I posted a problem I was having reading the header from
a PCX file.  I received some very helpful tips from people, implemented
them, and now I have no troubles whatsoever reading a PCX header :)

The first suggestion was to open the file with  f = fopen("pic.pcx","rb")
instead of using just the "r" option.

The second was to change the integers in the PCXHEAD structure to short
ints... this was probably the main culprit of my problems because a header
in a PCX file is exactly 128 bytes and since I wasn't specifying the size
of the variables I probably wasn't getting a 128-byte structure.
For those who are interested I've included a small bit of the code regarding
this issue.

Thanks for your responses!
Toni Giacalone

typedef struct {
        char manufacturer;
        char version;
        char encoding;
        char bits;
        short int xmin, ymin;
        short int xmax, ymax;
        short int hres, vres;
        char palette[48];
        char reserved;
        char color_planes;
        short int bytes_per_line;
        short int palette_type;
        char filler[58];
        } PCXHEAD;

PCXHEAD pcx;

void readpcx()

  FILE *f;
  f = fopen ("pic.pcx", "rb");
  if (f == NULL)
    printf("bad open\n");
  else
  {
    if ( fread ((char *)&pcx, 1, sizeof(PCXHEAD), f) != sizeof(PCXHEAD) ||
        pcx.manufacturer != 0x0a )
    {
        printf ("bad file\n");
        disphdr();
    }
    else
      go on to read bytes, etc

2. Games Artist Wanted

3. Problems reading PCX files.

4. WaveFilter - has it got out of beta?!

5. PCX file header question

6. Intel Based Apps?

7. Headers for .pcx?

8. Cheap CD-R's!! READ THIS!

9. .PCX, .GIF header info required

10. PCX header and color plane extraction question

11. How to read header of Graphics

12. How to read the graphic header in C