[comp.windows.x] Pixmap conversion

pere@HAL.NTA.NO (Per Einar Dybvik FDX) (10/26/90)

My program crashes on a Color display, because of
the Pixmap used is of depth 1. Is there any way that I
can read a bitmapfile and convert this into a Pixmap
with depth > 1?

Per E. Dybvik
Norwegian Telecom Research Dept.
email: pere@odin.nta.no or pere@hal.nta.no

mouse@LARRY.MCRCIM.MCGILL.EDU (10/26/90)

> My program crashes on a Color display, because of the Pixmap used is
> of depth 1.  Is there any way that I can read a bitmapfile and
> convert this into a Pixmap with depth > 1?

From the Xlib document...

	To create a pixmap and then store bitmap-format data into
	it, use XCreatePixmapFromBitmapData.
	
	Pixmap XCreatePixmapFromBitmapData(display, d, data, width, height, fg, bg, depth)
	     Display *display;
	     Drawable d;
	     char *data;
	     unsigned int width, height;
	     unsigned long fg, bg;
	     unsigned int depth;
	
	display   Specifies the connection to the X server.
	
	d         Specifies the drawable that indicates the screen.
	
	data      Specifies the data in bitmap format.
	
	width
	height    Specify the width and height.
	
	fg
	bg        Specify the foreground and background pixel values
	          to use.
	
	depth     Specifies the depth of the pixmap.
	
	The XCreatePixmapFromBitmapData function creates a pixmap of
	the given depth and then does a bitmap-format XPutImage of
	the data into it.  The depth must be supported by the screen
	of the specified drawable, or a BadMatch error results.
	
	XCreatePixmapFromBitmapData can generate BadAlloc and Bad-
	Match errors.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu

etaylor@wilkins.iaims.bcm.tmc.edu (Eric Taylor) (10/26/90)

Your X server should never barf on a Pixmap of depth 1.
You need to include more information and a code sample.
How are you using the Pixmap?  Are you using XCopyArea?
Are you using XCopyPlanes?  Are you just using a widget?

But in answer to your question use XCreatePixmapFromBitmapData.
It should return you a multi-plane pixmap using bitmap data.

Here is the general rule :

	Using XCopyArea, the depths have to match.
	Using XCopyPlane, the source should probably be depth 1.
		XCopyPlane uses the foreground and background as
		replacements for 1 and 0 respectively.

The Athena label widget uses XCopyPlane for 1-bit pixmaps, and
XCopyArea for multi-plane pixmaps (a small hack, but works most of the time).
-- 
					Eric Taylor
					Baylor College of Medicine
					etaylor@wilkins.bmc.tmc.edu
					(713) 798-3776

klee@wsl.dec.com (Ken Lee) (10/27/90)

In article <9010260843.AA05138@hal.nta.no>, pere@HAL.NTA.NO (Per Einar Dybvik FDX) writes:
|> My program crashes on a Color display, because of
|> the Pixmap used is of depth 1. Is there any way that I
|> can read a bitmapfile and convert this into a Pixmap
|> with depth > 1?

I take it that your problem is that you're doing a XCopyArea from a
depth = 1 pixmap to a depth > 1 window.  If this is this case, try
using XCopyPlane instead.

-- 
Ken Lee
DEC Western Software Laboratory, Palo Alto, Calif.
Internet: klee@wsl.dec.com
uucp: uunet!decwrl!klee