www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/24/03:05:35

Xref: news2.mv.net comp.os.msdos.djgpp:5316 rec.games.programmer:53519
From: matrix AT ionsys DOT com (MCheu)
Newsgroups: rec.games.programmer,comp.os.msdos.djgpp
Subject: Help -- Reading PCX Header
Date: Mon, 24 Jun 1996 07:34:22 GMT
Organization: ionsys.com
Lines: 102
Message-ID: <4ql5is$a37@maggie.ionsys.com>
NNTP-Posting-Host: ip-013.ionsys.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi 

Sorry to bother everyone with this, but I've been getting some wierd
numbers from the following programme.  It's supposed to read the
header from a pcx file and tell me about it.  The first 4 values from
the header come through ok (ID, version, encoding, bitdepth), but the
next 4 (Xmin, Ymin, Xmax, Ymax) are way off.  The last time I ran the
executable, I got the following:

Xmin = 0
Ymin =13041983
Xmax = 13107520
Ymax = -67108864

I was expecting something along the lines of 0, 0, 319, 199
respectively.  I've only run this with 256 colour PCX files that are
320x200 or smaller.   I've compared this  with the  code posted
recently by Mr. Anderson (from rec.games.programmer) as well as
sources from the GDM online,  and I "seem" to have done this
correctly.  Can anyone please tell me where I screwed up?   If it
helps, I'm compiling with DJGPP version2 under win95.

Thanks.
matrix AT ionsys DOT com
===============================

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>

/* PCX header structure */
typedef struct {
        char ID;  /* PCX id -- usually 10 */
        char ver; /* version */
        char encoding;   
        char bitdepth;    /* 8 for 256 colour files */
        int Xmin, Ymin;
        int Xmax, Ymax;
        int Hres;
        int Vres;
        unsigned char palette[48];
        char reserved;
        char ColourPlanes;
        int bytesPerLine;
        int paletteType;
        char Stuff[58];
        } pcxHead;


void ReadPCX (char *filename)
{
        FILE *pcxfile;
        char palette [792];
        int i, r;
        int tx, ty;
        pcxHead PCXHead;

        /* open file */
        pcxfile = fopen(filename, "rb");
        if (pcxfile==NULL) {
                printf("\nError -- could not open PCX file.\n");
                return;
                }

        /* Read header info */
        r = fread ( &PCXHead, 1, 128, pcxfile);
        if ( r!=128){
                printf("\n Error -- Failed to read header!\n");
                fclose(pcxfile);
                return;
                }

/*

        /* close file */
        printf (" Manufacturer   : %d\n",PCXHead.ID);
        printf (" PCX Version    : %d\n",PCXHead.ver);
        printf (" Encoding       : %d\n",PCXHead.encoding);
        printf (" Bits per Pixel : %d\n",PCXHead.bitdepth);
        printf ("          Xmin  : %d\n",PCXHead.Xmin);
        printf ("          Ymin  : %d\n",PCXHead.Ymin);
        printf ("          Xmax  : %d\n",PCXHead.Xmax);
        printf ("          Ymax  : %d\n",PCXHead.Ymax);
        tx = PCXHead.Xmax - PCXHead.Xmin + 1;
        ty = PCXHead.Ymax - PCXHead.Ymin + 1;
        printf (" PCX Resolution : %d x %d", tx, ty);
        fclose(pcxfile);
}

void main ( int argc, char **argv ) {
        if (argc==1) {
                printf ("\n Please specify a filename. \n");
                printf ("      eg. PCX filename.PCX\n");
                return;
                }
        ReadPCX (argv[1]);
        }




- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019