Title: | DECWINDOWS 26-JAN-89 to 29-NOV-90 |
Notice: | See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit |
Moderator: | STAR::VATNE |
Created: | Mon Oct 30 1989 |
Last Modified: | Mon Dec 31 1990 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 3726 |
Total number of notes: | 19516 |
I am trying to create a bitmap out of the contents of a window. The logic path is as follows: 1) Create a pixmap of depth 1 2) Create an XImage of XYBitmap type 3) Do an XGetImage of the window into a XImage of type XYPixmap and mask AllPlanes 4) step through the XImage, using XGetPixel, set (with XPutPixel) each bit in the XYBitmap image which corresponds to a pixel set to fg in the XYPixmap image. 5) Use XCreatePixmapFromBitmapData, using the data field in the XYBitmap image structure, to write bitmap data into the pixmap. 6) Use XWriteBitmapFile to get the bitmap in X11 format. What I am ending up with is a blank bitmap (no bits set). A code example is below.. ------------------------------------------------------------------- void xbm_op(widget,tag,ret) Widget widget; unsigned long tag; DwtTogglebuttonCallbackStruct ret; { extern unsigned long fg, bg; unsigned int depth, w, h; unsigned long pix; char *outfile = "acad.xbm", *data, buf[80], ws[10], hs[10], hl[10], *XtMalloc(); FILE *fp, *fopen(); Arg arg[10]; int status, i, count, x, y, raster_length, format, offset, bitmap_pad, bytes_per_line; Drawable d; Pixmap pixmap_1; XWindowAttributes watb; XImage *ximage, *new_ximage; d = XtWindow(graph_win); /* get dimensions of graphics window */ XGetWindowAttributes(display,XtWindow(graph_win),&watb); w = watb.width; h = watb.height; /* create a pixmap with depth = 1 */ pixmap_1 = XCreatePixmap(display,d,w+6,h+6,1); /* format the output ximage */ bytes_per_line = (w + 7) / 8; raster_length = bytes_per_line * h; depth = 1; format = XYBitmap; offset = 0; data = XtMalloc(raster_length); bitmap_pad = 8; bytes_per_line = 0; new_ximage = XCreateImage(display,visual,depth,format,offset, data,w,h,bitmap_pad,bytes_per_line); /* fetch window contents*/ ximage = XGetImage(display,d,0,0,w,h,AllPlanes,XYPixmap); for (x = 0; x < w; x++) for (y = 0; y < h; y++) { if (XGetPixel(ximage,x,y)) XPutPixel(new_ximage,x,y,0x01); else XPutPixel(new_ximage,x,y,0x00); } XCreatePixmapFromBitmapData(display,pixmap_1,new_ximage->data, w,h,fg,bg,1); strcpy(buf,"writing output file..."); DwtSTextSetString(info,buf); status=XWriteBitmapFile(display,outfile,pixmap_1,w,h,-1,-1); if (status == BitmapSuccess) { strcpy(buf,"done................"); DwtSTextReplace(info,0,40,buf); } else { strcpy(buf,"bitmap file not written"); DwtSTextReplace(info,0,40,buf); } XFreePixmap(display,pixmap_1); XDestroyImage(ximage); XDestroyImage(new_ximage); XtUnmanageChild(XtParent(widget)); return; }
T.R | Title | User | Personal Name | Date | Lines |
---|---|---|---|---|---|
1042.1 | image.data != bitmap data | VINO::MCARLETON | Reality; what a concept! | Fri Jun 30 1989 10:10 | 13 |
I don't think you can use the image data as if it were bitmap data. The bitmap data is encoded using ascii characters 0-9 and A-F to represent sets of four bits where '0' = 0000 and 'F' = 1111. The data field in the image structure is binary data that packs 8 pixels to a byte in a 1 bit deap image. Bitmap data can only encode 4 bits per byte. Try replacing the XCreatePixmapFromBitmapData() call with a XCreatePixmap() to make a pixmap of depth 1 and a XPutImage() to put the image data into the Pixmap. You should then be able to dump the Pixmap out with XWriteBitmapFile(). MJC | |||||
1042.2 | SX4GTO::HOLT | Robert, UCS | Fri Jun 30 1989 12:27 | 23 | |
Thanks for the suggestion, and for pointing out the diff between bitmap and image->data format, but PutImage doesn't seem to like the pixmap. It returns the X Error: X Protocol error detected by server: parameter mismatch Failed request major op code 72 X_PutImage Failed request minor op code 0 (if applicable) ResourceID 0x40001e in failed request (if applicable) Serial number of failed request 305 Current serial number in output stream 306 ResourceID 0x40001e is the pixmap of depth 1. Hmmm.... | |||||
1042.3 | PSW::WINALSKI | Careful with that VAX, Eugene | Fri Jun 30 1989 13:06 | 6 | |
Try using XCopyPlane to move the data from ximage to new_ximage. You are getting the badMatch error because the depth of the two drawables must be the same for XPutImage. --PSW | |||||
1042.4 | SX4GTO::HOLT | Robert, UCS | Fri Jun 30 1989 16:56 | 74 | |
Well, it still doesn't seem to like the pixmap with depth = 1... dbx) r X Protocol error detected by server: parameter mismatch Failed request major op code 63 X_CopyPlane Failed request minor op code 0 (if applicable) ResourceID 0x50001f in failed request (if applicable) Serial number of failed request 292 Current serial number in output stream 293 (ResourceID 0x50001f == pixmap_1) ------------------------------------------------------------- void xbm_op(widget,tag,ret) Widget widget; unsigned long tag; DwtTogglebuttonCallbackStruct ret; { extern unsigned long fg, bg; unsigned int depth, w, h; unsigned long plane_mask = 0x00000001; char *outfile = "acad.xbm", *data, buf[80], ws[10], hs[10], hl[10], *XtMalloc(); FILE *fp, *fopen(); Arg arg[10]; int status, i, count, x, y, raster_length, format, offset, bitmap_pad, bytes_per_line; Drawable d,r; Pixmap pixmap_1,pixmap_d; XWindowAttributes watb; XImage *ximage; d = XtWindow(graph_win); r = XtWindow(main_window); plane_mask = 0x01; /* get dimensions of graphics window */ XGetWindowAttributes(display,XtWindow(graph_win),&watb); w = watb.width; h = watb.height; /* create pixmaps */ pixmap_1 = XCreatePixmap(display,r,w+6,h+6,1); pixmap_d = XCreatePixmap(display,r,w+6,h+6,8); /* fetch window contents*/ ximage = XGetImage(display,d,0,0,w,h,AllPlanes,XYPixmap); XPutImage(display,pixmap_d,gc,ximage,0,0,3,3,w,h); XCopyPlane(display,pixmap_d,pixmap_1,gc,0,0,w,h,3,3,plane_mask); /* put bits into file */ strcpy(buf,"writing output file..."); DwtSTextSetString(info,buf); status=XWriteBitmapFile(display,outfile,pixmap_1,w,h,-1,-1); if (status == BitmapSuccess) { strcpy(buf,"done................"); DwtSTextReplace(info,0,30,buf); } else { strcpy(buf,"bitmap file not written"); DwtSTextReplace(info,0,30,buf); } XFreePixmap(display,pixmap_1); XDestroyImage(ximage); XtUnmanageChild(XtParent(widget)); return; } | |||||
1042.5 | PSW::WINALSKI | Careful with that VAX, Eugene | Mon Jul 03 1989 15:03 | 5 | |
How is the graphics context "gc" set up? Is it compatible with a depth-1 drawable? --PSW | |||||
1042.6 | SX4GTO::HOLT | Robert, UCS | Wed Jul 05 1989 14:58 | 3 | |
That was it.... | |||||
1042.7 | GC affects the depth of a drawable???? | CSC32::B_KEMP | Thu Jan 25 1990 14:04 | 35 | |
I am trying to understand the difference between creating an image with and image_form of XYBitmap and XYPixmap with a depth of one. The code that does this with XCreateImage and then puts the image to a drawable with XPutImage will work when the image_form is XYBitmap but returns the error below when the image_form is XYPixmap with a depth of one. Are not the two the same? I see it mentioned that the Graphics Context of the drawable has to be compatible with the depth of the image or the BadMatch occurs, but isn't a pixmap of depth one the same as a bitmap. And, how can your Graphics Context specify a depth compatibility? If you want to see some code, please let me know. BTW, can a window be created with a different depth than its parent (shallower) when the display has a depth of eight? Buffaloed in Colorado...? Bill X error event received from server: BadMatch - parameter mismatch Failed request major op code 72 (X_PutImage) Failed request minor op code 0 (if applicable) ResourceID 0x8006b in failed request (if applicable) Serial number of failed request 41 Current serial number in output stream 41 %XLIB-E-ERROREVENT, error event received from server %TRACE-E-TRACEBACK, symbolic stack dump follows module name routine name line rel PC abs PC 000F1E70 000F1E70 000F1C95 000F1C95 000F35E3 000F35E3 000F146E 000F146E 000E8753 000E8753 00079B25 00079B25 00079141 00079141 00079129 00079129 XYPIX main 9890 000001C0 000007C0 | |||||
1042.8 | Bit vs Pix | DECWIN::FISHER | Burns Fisher 381-1466, ZKO3-4/W23 | Mon Jan 29 1990 12:46 | 13 |
No, they are not the same. XYBitmap ALWAYS sends a depth-1 image, but at the server end, 1's are replaced by the GC foreground color, and 0's are replaced by the gc background color. You can PutImage in Bitmap mode to any depth of window, since the data that gets written into the window comes from the gc. XYPixmap send a variable depth. Since you have specified 1, it is sending 1. It wants to write the 1s and 0s directly into the frame buffer. However, with XYPixmap, the depth you send must match the depth of the variable. In your case, it does not. Burns |