Does anyone have a PXC decoder, or could anyone help me fix this old code to decode a PCX and return a valid hbitmap? the source for the static LIB i am attaching returns a non-null number for hbitmap, but the hbitmap cannot be loaded into any static control, and does not work with getobject ect.
I have tried just about everything i know, and have yet to be able to properly decode a PCX. i understand the format and all, but the main problem is properly recognizing and decoding 1, 4, 8, and 24 bit images with a correct palette.
thanks for any help anyone can give...
You can download the FreeImage Library source code here
http://freeimage.sourceforge.net/
It has many different loading modules, for example there is PluginPNG.c, PluginPCX.c, PluginTIFF.c etc.
John
Your attached code returns a HGLOBAL, not a HBITMAP. Use the Windows API functions: GlobalLock(), CreateDIBitmap(), GlobalUnlock().
...but John's suggestion is probably better...
I have used FreeImage quite a bit, but i cant stand always having to go back and forth between HBITMAP and FBITMAP. I am writing my own set of encoders/decoders, and have been trying to get a handle on the PCX format. ive based everything ive written off this C example, which didnt seem to work. Im not that great at C yet, i know much more PowerBasic and PureBasic. But i would still like to be able to compile this so at least i know that this method actually works. so far with my other code, i get some form of an image, but the palette is messed up.
i have tried using this code at the end:
_lclose(fileHandle);
GlobalUnlock(dib);
bmp.bmType=0;
bmp.bmWidth=1 + pcxHeader.maxX - pcxHeader.minX;
bmp.bmHeight=1 + pcxHeader.maxY - pcxHeader.minY;
bmp.bmWidthBytes=(1 + pcxHeader.maxX - pcxHeader.minX)*4;
bmp.bmPlanes=1;
bmp.bmBitsPixel=32;
bmp.bmBits=pixels;
bitmap=CreateBitmapIndirect(&bmp);
return bitmap;
but it doesnt seem to work when i try to set the result into a static control.
I've made a Win32 project from your files and added various other functions that hopefully will help you to debug. However, it appears to be working, I've replaced all Globalxxx calls with malloc/free.
The added functions are
IsNewDibFormat
DIBNumColours
ColourTableSize
DrawDIB
DIBWidth
DIBHeight
John
thank you so much. i got it to work too. although it doesn't load every type of PCX file, i now know the code actually works, and i can then play around with it to see if i can load all variants of PCX bits per pixel.
Yes, the 8bit and 24bit need implementing.
Btw, the code I wrote did not free the DIB memory on exit.
John