sampson@attctc.Dallas.TX.US (Steve Sampson) (12/16/89)
I need to read in a pcx image that I made using Deluxe Paint II. It is EGA specific. Nothing cosmic. I wrote several attempts in the affected section, but never got it right. Can anyone help? Thankyou very much, Steve. Here's the culprit: /* * pcx.c * * This is a routine to read in a Deluxe Paint II * "PCX" drawing and then have dynamic data on top of that. * * EGA Specific */ #include <stdio.h> #include <fcntl.h> #include <alloc.h> #include <dos.h> #include <mem.h> #include <graphics.h> #define uchar unsigned char #define uint unsigned int #define ulong unsigned long #define EGA_BASE 0xA000 /* Base address of EGA graphics memory */ #define SEQ_ADDR_REG 0x03C4 /* Port address of EGA sequencer address register */ #define SET_RESET_REG 0x03CF /* Port address of EGA Set/Reset register */ #define RESET_REG 0x03C5 /* Port address of EGA sequencer reset register */ #define ADDR_REG 0x03CE /* Port addr. of EGA graphics 1 & 2 address register */ #define READ_MAP_REG 0x04 /* Index of EGA Read Map select register */ #define MAP_MASK_REG 0x02 /* Index of EGA sequencer Map Mask register */ typedef struct { char maker; /* 10 = ZSoft */ char version; char encoding; char bpp; /* bits per pixel */ int xmin; int ymin; int xmax; int ymax; int hres; /* create devices Hor resolution */ int vres; /* ' ' Vert resolution */ char triple[48]; /* color palette setting */ char reserved; /* reserved */ char nplanes; /* number of color planes */ int bpl; /* bytes per line */ char unused[60]; /* header is 128 bytes long */ } PCXHDR; int GraphDriver = DETECT, GraphMode; uchar far *buffer[4]; int pcx_getc(c, n, fp) uchar *c; int *n; FILE *fp; { uint i; *n = 1; if ((i = getc(fp)) == EOF) return EOF; if ((i & 0xc0) == 0xc0) { *n = i & 0x3f; if ((i = getc(fp)) == EOF) return EOF; } *c = i; return 0; } /* * A picture consists of a number of lines, each line having * a number of planes. Each plane is a bit map. */ void pcx_read(pic, fp) FILE *fp; PCXHDR *pic; { register int i, j; int k, n, row, nrows, bpl; uchar far *bufr; uchar c; /* * Get the Header */ if (fread((char *)pic, sizeof(PCXHDR), 1, fp) < 1) return; nrows = (pic->ymax - pic->ymin) + 1; bpl = pic->bpl; /* * Read in the info */ ||||| HOW?? ||||| } void main(argc, argv) int argc; char *argv[]; { register int i; PCXHDR *pic; FILE *fp; registerbgidriver(EGAVGA_driver); if (argc == 1) { puts("Usage: pcx filename\n"); exit(1); } if ((fp = fopen(argv[1], "rb")) == NULL) { puts("Graphics file is missing\n"); exit(1); } if ((pic = (PCXHDR *)malloc(sizeof(PCXHDR))) == NULL) { puts("Could not allocate pcx structure memory\n"); exit(1); } initgraph(&GraphDriver, &GraphMode, "");/* initialize graphics */ if (graphresult() < 0) { puts("Graphics Error\n"); exit(1); } if (GraphMode != EGAHI) { puts("Must have an EGA device\n"); exit(1); } for (i = 0; i < 4; i++) buffer[i] = (uchar far *)farmalloc(80); /* 80 * 8 = 640 */ pcx_read(pic, fp); getch(); for (i = 0; i < 4; i++) farfree(buffer[i]); fclose(fp); closegraph(); exit(0); } /* that is all */