NO

Author Topic: PCX decoder?  (Read 8282 times)

localmotion34

  • Guest
PCX decoder?
« on: April 13, 2007, 03:53:48 PM »
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...


JohnF

  • Guest
Re: PCX decoder?
« Reply #1 on: April 13, 2007, 05:13:43 PM »
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

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: PCX decoder?
« Reply #2 on: April 13, 2007, 06:46:53 PM »
Your attached code returns a HGLOBAL, not a HBITMAP. Use the Windows API functions: GlobalLock(), CreateDIBitmap(), GlobalUnlock().

...but John's suggestion is probably better...
/Pelle

localmotion34

  • Guest
Re: PCX decoder?
« Reply #3 on: April 13, 2007, 07:23:30 PM »
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:

Code: [Select]
  _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. 

JohnF

  • Guest
Re: PCX decoder?
« Reply #4 on: April 14, 2007, 09:56:37 AM »
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

localmotion34

  • Guest
Re: PCX decoder?
« Reply #5 on: April 15, 2007, 10:03:22 PM »
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. 

JohnF

  • Guest
Re: PCX decoder?
« Reply #6 on: April 15, 2007, 11:07:56 PM »
Yes, the 8bit and 24bit need implementing.

Btw, the code I wrote did not free the DIB memory on exit.

John