Mail Archives: djgpp/1997/07/22/04:03:54
Isaac Waldron wrote:
>
> struct PCXHeader
> {
> char manufacturer;
> char version;
> char encoding;
> char bpp;
> int xStart, yStart;
> int xEnd, yEnd;
> int xRes, yRes;
> char egaPal[48];
> char reserved;
> char numPlanes;
> int bpl;
> int pType;
> char padding[58];
> };
DJGPP, as a 32-bit compiler, pads structure members to align them on 2
and 4 byte boundaries. The above structure is 148 bytes in DJGPP; you
may be reading too many bytes from the PCX file to get the header
information! Try using the __attribute__((packed)) gcc extension to
force the structure to take the minimum required space. Also, I assume
you are aware that integers in DJGPP are 32 bits wide? If you intend
those ints to be 16 bits, you must declare them as shorts.
Try this:
#define __PACK __attribute__((packed))
struct PCXHeader
{
char manufacturer __PACK;
char version __PACK;
char encoding __PACK;
char bpp __PACK;
short xStart, yStart __PACK;
short xEnd, yEnd __PACK;
short xRes, yRes __PACK;
char egaPal[48] __PACK;
char reserved __PACK;
char numPlanes __PACK;
short bpl __PACK;
short pType __PACK;
char padding[58] __PACK;
};
The new structure is 128 bytes long.
The most likely reason why this failed to work is that the wrong data
was being read into the xStart, yStart, xEnd, and yEnd members, and
bufsize was then calculated from this bad data. To test, try printing
the value of bufsize after you calculate it.
hth!
--
---------------------------------------------------------------------
| John M. Aldrich | "History does not record anywhere at |
| aka Fighteer I | any time a religion that has any |
| mailto:fighteer AT cs DOT com | rational basis." |
| http://www.cs.com/fighteer | - Lazarus Long |
---------------------------------------------------------------------
- Raw text -