[comp.windows.x] How to copy from depth 1 to depth n

dsr@luke.mitre.org (Douglas S. Rand) (07/24/90)

I'm a little stuck.  I can create a pixmap from a bitmap file
with XReadBitmapData.  Great.  Now what do I do to create
a pixmap with the same depth as my display but with the same
bitmap data?  What I don't want to do (and the only alternative I 
see) is to do a XGetImage and XGetPixel along with a separate
XCreatePixmap (right depth).  Will someone please tell me
I'm wrong (but be right about it OK? :) .

Douglas S. Rand 
Internet:   <dsrand@mitre.org>
Snail:	    MITRE, Burlington Road, Bedford, MA 
Disclaimer: MITRE might agree with me - then again...
Amateur Radio: KC1KJ

mouse@LARRY.MCRCIM.MCGILL.EDU (07/25/90)

> I can create a pixmap from a bitmap file with XReadBitmapData.
> Great.  Now what do I do to create a pixmap with the same depth as my
> display but with the same bitmap data?

What you're probably looking for is XCopyPlane.

					der Mouse

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

west@gsrc.dec.com (Jim West (Stealth Contractor)) (07/25/90)

In article <114409@linus.mitre.org>, dsr@luke.mitre.org (Douglas S. Rand) writes...
>I'm a little stuck.  I can create a pixmap from a bitmap file
>with XReadBitmapData.  Great.  Now what do I do to create
>a pixmap with the same depth as my display but with the same
>bitmap data?  What I don't want to do (and the only alternative I 
>see) is to do a XGetImage and XGetPixel along with a separate
>XCreatePixmap (right depth).  Will someone please tell me
>I'm wrong (but be right about it OK? :) .
> 
>Douglas S. Rand 
>Internet:   <dsrand@mitre.org>
>Snail:	    MITRE, Burlington Road, Bedford, MA 
>Disclaimer: MITRE might agree with me - then again...
>Amateur Radio: KC1KJ

  The following code bits are in Ada but I think you'll get the idea.


  x.read_bitmap_file (
    status		=> status,
    display		=> display,
    drawable_id		=> root,
    file_name		=> file_name (1 .. file_name_len),
    width_return	=> width,
    height_return	=> height,
    bitmap_id_return	=> bitmap_id,
    x_hot_coord_return	=> hot_x,
    y_hot_coord_return	=> hot_y);

  x.create_pixmap (
    result	=> pixmap_id,
    display	=> display,
    drawable_id	=> root,
    width	=> width,
    height	=> height,
    depth	=> depth); -- default depth of screen

  x.copy_plane (
    display	    => display,
    src_drawable_id => bitmap_id,
    dst_drawable_id => pixmap_id,
    gc_id	    => gc,
    src_x_coord	    => 0,
    src_y_coord	    => 0,
    width	    => width,
    height	    => height,
    dst_x_coord	    => 0,
    dst_y_coord	    => 0,
    plane	    => 1); -- Here is where the magic is


----------------------------------------------------------------------
 Jim West                      |  The Schainker Converse
 west@gsrc.dec.com             |  to Hoare's Law :
                               |
 These are my opinions.        |   Inside every small problem
 Digital has no idea           |     is a larger problem struggling
 what I'm  saying.             |       to get out.
----------------------------------------------------------------------

jimf@SABER.COM (07/26/90)

|I'm a little stuck.  I can create a pixmap from a bitmap file
|with XReadBitmapData.  Great.  Now what do I do to create
|a pixmap with the same depth as my display but with the same
|bitmap data?  What I don't want to do (and the only alternative I 
|see) is to do a XGetImage and XGetPixel along with a separate
|XCreatePixmap (right depth).  Will someone please tell me
|I'm wrong (but be right about it OK? :) .

XCopyPlane will work fine and you can even recolor the foreground and
background while you're at it.

jim frost
saber software
jimf@saber.com

erc@pai.UUCP (Eric Johnson) (07/26/90)

In article <114409@linus.mitre.org>, dsr@luke.mitre.org (Douglas S. Rand)writes:
> I'm a little stuck.  I can create a pixmap from a bitmap file
> with XReadBitmapData.  Great.  Now what do I do to create
> a pixmap with the same depth as my display but with the same
> bitmap data?  What I don't want to do (and the only alternative I 
> see) is to do a XGetImage and XGetPixel along with a separate
> XCreatePixmap (right depth). 
> 
> Douglas S. Rand 
> Internet:   <dsrand@mitre.org>
> Snail:	    MITRE, Burlington Road, Bedford, MA 
> Disclaimer: MITRE might agree with me - then again...

Here's a suggestion:

1) Create a pixmap of the proper size, but the same depth as the
drawable you want to display it on (e.g., the window you want to
show this image in). Create a Graphics Context (GC) for this pixmap.
DefaultDepth( display, screen ) can often give an acceptable value for
this depth.

2) Create your bitmap from data. What you'll get is a single-plane
depth pixmap.

3) Use XCopyPlane() to copy one plane from the single-plane
pixmap (your bitmap in #2) to the potentially multi-plane pixmap (created
in #1). Use the GC also created in #1:
	
        XCopyPlane( display,            /* display connection */
                single_plane_bitmap,    /* source drawable */
                multi_plane_pixmap,     /* destination drawable */
                gc,                     /* created in #1 */
                0, 0,                   /* source X, Y */
                width, height,          /* size of bitmap AND pixmap */
                0, 0,                   /* destination X, Y */
                0x01 );                 /* which plane to copy */

Note that your bitmap (really a Pixmap type) only has one plane. Your
destination pixmap may have many more planes (or one if on a monochrome
system).  So, you want to copy the one plane from the bitmap to the
pixmap.

For more information, you can check out Advanced X Window Applications
Programming, coming soon from MIS: Press (phone in USA: 1-800-MANUALS).

Hope this helps,
-Eric

-- 
Eric F. Johnson               phone: +1 612 894 0313    BTI: Industrial
Boulware Technologies, Inc.   fax:   +1 612 894 0316    automation systems
415 W. Travelers Trail        email: erc@pai.mn.org     and services
Burnsville, MN 55337 USA