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

Xref: news2.mv.net comp.os.msdos.djgpp:5317 rec.games.programmer:53522
Newsgroups: rec.games.programmer,comp.os.msdos.djgpp
From: alexad3 AT icebox DOT iconline DOT com (Alexander J Russell)
Subject: Re: Help -- Reading PCX Header
Reply-To: alexad3 AT icebox DOT iceonlie DOT com
Sender: Newsposter AT iceonline DOT com (Newsposter)
Nntp-Posting-Host: ns.iceonline.com
Organization: ICE Online Internet news
Message-ID: <DtHow0.G87@iceonline.com>
References: <4ql5is$a37 AT maggie DOT ionsys DOT com>
Mime-Version: 1.0
Date: Mon, 24 Jun 1996 05:36:00 GMT
Lines: 112
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <4ql5is$a37 AT maggie DOT ionsys DOT com>, matrix AT ionsys DOT com says...
>
>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]);
>        }
>
>
>
>
Do you have your compiler switches set to PAD structs so all elements 
are aligned? If so try it with alignment set to off/Byte.
-- 
The AnArChIsT! Anarchy! Not Chaos!
aka
Alex Russell
alexad3 AT iceonline DOT com

- Raw text -


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