Advertisement Jump to content


This topic is now archived and is closed to further replies.


Direct Draw and 24/32 bit PCX/Bitmap Loading

This topic is 6856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve been stumped for a long time on loading in 24 bit bitmaps or pcx files into a direct draw surface. what im looking for is a function of roughly the form LPDIRECTDRAWSURFACE4 LoadPic(int width, int height, int mem_flags, char *filename) to open the file, create a dd surface of correct size, and put the picture into the surface (the picture size and surface size being the same). Any help on 24 or 32 PCX or bitmaps would be helpful.

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
I''ve seen this question on this board alot, but no one ever posts code
on how to load 24-bit PCX files. Here''s the easy part, the header.
Maybe someone else can finish it:

typedef struct _PCXFILEHEADER {

BYTE Identifier; // 0xA0 = Z-Soft
BYTE Version; // 5 = palettes and 24-bit PCX files
BYTE Encoding; // 1 = RLE
BYTE BitPerPixel; // 1,2,4,8 (8 = 24-bit files)
WORD XStart; // Image dimensions (0,0,width-1,height-1)
WORD YStart;
WORD HorzRes; // 300 = horizontal resolution (dpi)
WORD VertRes; // 300 = vertical resolution (dpi)
BYTE Palette[48];
BYTE Reserved1; // zero
BYTE NumBitPlanes; // 3 = 24-bit
WORD BytesPerLine; // scanline (must be even)
WORD PaletteType; // 1=color, 0=b/w
WORD HorzScreenSize;
WORD VertScreenSize;
BYTE Reserved2[54]; // all zero


Basically, the header for any PCX file is always 128 bytes. For
a 24-bit PCX file, there is no 768 byte palette or any 1 byte 0C marker,
so the RLE data is directly after the header. Then you have to decode
the pixel runs. But, you''re not finished yet. After the data is
decoded, you have to re-order the RGB data so it is in the order of
R-G-B respectively. That''s because when the PCX file was written,
the RGB planes were separated first, then encoded. Finally, you can
copy it to a DD surface.

Get the file format info at:

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!