hi guys,

i am new to X windows programming and i am having a hard time setting
my colormap to grayscale. i have tried everyting i found in the
internet but it doesn't seem to work for me. please help. i am
including my code below

---------------------------------------
int ShmMajor,ShmMinor,ShmPixmaps,i;

m_iWidth = 640;
m_iHeight = 512;

m_Display = XOpenDisplay(NULL);
if(!m_Display) throw CShmError("Cannot open display.");

if(!XShmQueryVersion(m_Display,&ShmMajor,&ShmMinor,&ShmPixmaps))
throw CShmError("SHM is not supported.");

m_Scrn = DefaultScreenOfDisplay(m_Display);
m_iScrnNum = DefaultScreen(m_Display);
m_Visual = DefaultVisualOfScreen(m_Scrn);
m_iDepth = DefaultDepth(m_Display, m_iScrnNum);

m_Window = XCreateWindow(m_Display, RootWindowOfScreen(m_Scrn),\
0, 0, m_iWidth, m_iHeight, 0, m_iDepth, InputOutput,\
m_Visual, 0, NULL);
if(!m_Window) throw CShmError("Cannot create window.");
m_GC = XCreateGC(m_Display, m_Window, 0, NULL);
if(!m_GC) throw CShmError("Cannot create GC.");

XMapRaised(m_Display, m_Window);

m_ShmInfo = (XShmSegmentInfo *)malloc(sizeof(XShmSegmentInfo));
if(!m_ShmInfo) throw CShmError("Cannot allocate m_ShmInfo");

memset(m_ShmInfo, 0, sizeof(XShmSegmentInfo));
m_XImage = XShmCreateImage(m_Display, m_Visual, m_iDepth, ZPixmap,\
NULL, m_ShmInfo, m_iWidth, m_iHeight);
if(!m_XImage) throw CShmError("Cannot create m_XImage");

m_iScrnSize = m_XImage->bytes_per_line * m_XImage->height;
m_ShmInfo->shmid = shmget(IPC_PRIVATE, m_iScrnSize, IPC_CREAT |
0777);
if(m_ShmInfo < 0) throw CShmError("Invalid shmid");

m_ShmInfo->shmaddr = (char*)shmat(m_ShmInfo->shmid, NULL, 0);
if(!m_ShmInfo->shmaddr) throw CShmError("Cannot attach segment to
this process");
printf("addr=%x\n", m_ShmInfo->shmaddr);

m_ShmInfo->readOnly = false;

m_pScrnBuffer = (unsigned char *)m_XImage->data =
m_ShmInfo->shmaddr;
if(!XShmAttach(m_Display, m_ShmInfo)) throw CShmError("Cannot attach
segment to server.");
----------------------------------

here is my class
----------------------------------
class CShm{
private:
CSmartcam CCamera;
Visual *m_Visual;
Screen *m_Scrn;
Colormap m_CMap;
XShmSegmentInfo *m_ShmInfo;
int m_iScrnSize, m_iDepth, m_iScrnNum;
public:
Display *m_Display;
Window m_Window;
GC m_GC;
XImage *m_XImage;
int m_iWidth, m_iHeight;
unsigned char *m_pScrnBuffer;
CShm() throw(CShmError);
~CShm();
int Convert(unsigned char*, int);
};//class
-----------------------------------

i want to display a grayscale image when i write data to
m_pScrnBuffer. Can somebody please help me? i am desperate coz i'm
on a deadline

desperada