What's wrong with this code????
/*-----------------------------------------------------------------------------
VOID lcd_BmpGeneration(VOID)
{
char filename[60] = "/blabla/screen.bmp";
unsigned char w, h, bx, by, val;
Display * display;
GC gc;
XID xid;
Pixmap motif;
XGCValues gc_val;
int depth;
int screen;
int fg, bg;
int retCode;
/* Initialization of std variable */
if((display = XOpenDisplay(NULL)) == NULL)
{
printf("Error in lcd_BmpGeneration:\n"
;
printf("Can't connect to serveur %s.\n",XDisplayName(NULL));
exit(-1);
}
screen = DefaultScreen(display);
xid = DefaultRootWindow(display);
depth = DefaultDepth(display,screen);
fg = BlackPixel(display,screen);
bg = WhitePixel(display,screen);
/* pixmap and Graphic context creation */
motif = XCreatePixmap(display, xid, 5*K_l1_X_WIDE, 5*K_l1_Y_PIX_WIDE, depth);
gc = XCreateGC(display, xid, NULL, &gc_val);
/* Initialize screen */
XSetForeground(display, gc, bg);
XFillRectangle(display, xid, gc, 0, 0, 5*K_l1_X_WIDE, 5*K_l1_Y_PIX_WIDE);
/* Generate screen in Pixmap */
for (w = 0; w < K_l1_X_WIDE; w++)
{
bx = w;
for (h=0; h < K_l1_Y_PIX_WIDE; h++)
{
by = h/8;
val = *(puc_l1_LCDMemory+M_l1_LCDMEM(bx,by));
val &= 1 << (7-(h%8));
if (val)
{
XSetForeground(display, gc, fg);
XFillRectangle(display, xid, gc, w*5, (K_l1_Y_PIX_WIDE-h-1)*5, 4, 4);
}
}
}
XFlush(display);
/* Save Pixmap into a Bmp file */
retCode = XWriteBitmapFile(display ,filename ,motif , K_l1_X_WIDE*5 , K_l1_Y_PIX_WIDE*5 ,-1 ,-1 );
switch (retCode) {
case BitmapOpenFailed:
printf("XWriteBitmapFile: could not open file %s for writing.\n",filename);
exit(-1);
break;
case BitmapNoMemory:
printf("XWriteBitmapFile: Not enough memory.\n"
;
exit(-1);
break;
case BadDrawable:
printf("A value for a Drawable argument does not name a defined Window or Pixmap.\n"
;
exit(-1);
break;
case BadMatch:
printf("Some argument or pair of arguments has the correct type and range but fails to match in some other way required by the request\n"
;
exit(-1);
break;
}
/* Free memory */
XFreePixmap(display ,motif);
XCloseDisplay(display);
printf("screen.bmp generated\n"
;
}
/*-------------------------------------------------------------------------------
The pixmap seems to be well done (I get the expected value in the variable val).
The problem is in the XWriteBitmapFile function, when it is called it blocks my process. When I change the size of the bitmap file (... XWriteBitmapFile(display ,filename ,motif , K_l1_X_WIDE*1 , K_l1_Y_PIX_WIDE*1 ,-1 ,-1 ); ...) a .bmp file is generated but it only contains zero!!!
Thanks for your help...
/*-----------------------------------------------------------------------------
VOID lcd_BmpGeneration(VOID)
{
char filename[60] = "/blabla/screen.bmp";
unsigned char w, h, bx, by, val;
Display * display;
GC gc;
XID xid;
Pixmap motif;
XGCValues gc_val;
int depth;
int screen;
int fg, bg;
int retCode;
/* Initialization of std variable */
if((display = XOpenDisplay(NULL)) == NULL)
{
printf("Error in lcd_BmpGeneration:\n"
printf("Can't connect to serveur %s.\n",XDisplayName(NULL));
exit(-1);
}
screen = DefaultScreen(display);
xid = DefaultRootWindow(display);
depth = DefaultDepth(display,screen);
fg = BlackPixel(display,screen);
bg = WhitePixel(display,screen);
/* pixmap and Graphic context creation */
motif = XCreatePixmap(display, xid, 5*K_l1_X_WIDE, 5*K_l1_Y_PIX_WIDE, depth);
gc = XCreateGC(display, xid, NULL, &gc_val);
/* Initialize screen */
XSetForeground(display, gc, bg);
XFillRectangle(display, xid, gc, 0, 0, 5*K_l1_X_WIDE, 5*K_l1_Y_PIX_WIDE);
/* Generate screen in Pixmap */
for (w = 0; w < K_l1_X_WIDE; w++)
{
bx = w;
for (h=0; h < K_l1_Y_PIX_WIDE; h++)
{
by = h/8;
val = *(puc_l1_LCDMemory+M_l1_LCDMEM(bx,by));
val &= 1 << (7-(h%8));
if (val)
{
XSetForeground(display, gc, fg);
XFillRectangle(display, xid, gc, w*5, (K_l1_Y_PIX_WIDE-h-1)*5, 4, 4);
}
}
}
XFlush(display);
/* Save Pixmap into a Bmp file */
retCode = XWriteBitmapFile(display ,filename ,motif , K_l1_X_WIDE*5 , K_l1_Y_PIX_WIDE*5 ,-1 ,-1 );
switch (retCode) {
case BitmapOpenFailed:
printf("XWriteBitmapFile: could not open file %s for writing.\n",filename);
exit(-1);
break;
case BitmapNoMemory:
printf("XWriteBitmapFile: Not enough memory.\n"
exit(-1);
break;
case BadDrawable:
printf("A value for a Drawable argument does not name a defined Window or Pixmap.\n"
exit(-1);
break;
case BadMatch:
printf("Some argument or pair of arguments has the correct type and range but fails to match in some other way required by the request\n"
exit(-1);
break;
}
/* Free memory */
XFreePixmap(display ,motif);
XCloseDisplay(display);
printf("screen.bmp generated\n"
}
/*-------------------------------------------------------------------------------
The pixmap seems to be well done (I get the expected value in the variable val).
The problem is in the XWriteBitmapFile function, when it is called it blocks my process. When I change the size of the bitmap file (... XWriteBitmapFile(display ,filename ,motif , K_l1_X_WIDE*1 , K_l1_Y_PIX_WIDE*1 ,-1 ,-1 ); ...) a .bmp file is generated but it only contains zero!!!
Thanks for your help...