Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pixmap -- Xlib

Status
Not open for further replies.

Anto35

Technical User
May 16, 2002
25
0
0
FR
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(&quot;XWriteBitmapFile: could not open file %s for writing.\n&quot;,filename);
exit(-1);
break;

case BitmapNoMemory:
printf(&quot;XWriteBitmapFile: Not enough memory.\n&quot;);
exit(-1);
break;

case BadDrawable:
printf(&quot;A value for a Drawable argument does not name a defined Window or Pixmap.\n&quot;);
exit(-1);
break;

case BadMatch:
printf(&quot;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&quot;);
exit(-1);
break;
}

/* Free memory */
XFreePixmap(display ,motif);
XCloseDisplay(display);
printf(&quot;screen.bmp generated\n&quot;);
}
/*-------------------------------------------------------------------------------

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...
 
Is there a way to check the Pixmap validity???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top