Pixmap management

This forum is read only. No new submissions are accepted.

Questions about motif? Contact us

3 posts / 0 new
Last post
Pixmap management

Submitted by Anonymous on Wed, 04/24/2002 - 14:17. Developers
Hi to everybody,
I have a big problem with the management of pixmaps.
I need to copy a colored pixmap (ie. 24 bits per pixels) to a monochrome bitmap (1 bit per pixel). As Windows allows me to do it easily through a BitBlt function, do you know if a similar functionality exist in Linux?
Thanks a lot
Kappa

ICS_support

It`s not really a Linux question -- does the facility exist in Xlib? In short, yes, but you may need to do some manipulation.

In Xlib, using a pixmap, you can take a slice to get a rough approximation of a two-color bitmap. See XCopyPlane() (http//www.motifzone.com/resources/man/XCopyArea.html).

But that isn`t really right. You want to be able to go through the image and decide if light green should be 0 or 1. For that, you can get an image (http//www.motifzone.com/resources/man/XGetImage.html) and iterate through the associated data structure directly. Then render the image back into a pixmap.

If the data is in a file to begin with, it is probably easiest to manipulate the file using ImageMagick or netpbm or GIMP or another such tool.

Anonymous

Crap! The second time I lost this message (excuse me... )

X has BitBLT. I don`t know exactly which X functions map onto the calls though. The nice thing is that you don`t need to know )

By the way, bitblt requires you to get then set the pixelformat for the client display context in windows. Not all window`s OS`s use the same pixelformat (like NT). Also windows doesn`t garuntee that the blt will work properly. That also depends on the driver and lockups are common at that point. Its all very hardware touch & go at the bit blitting level.

In Windows youd use CreateDIBSection (setdib, etc...) and you could exchange between any formats whether or no they could be set on screen - beginning with any style bitmap.

Blt and its masks are more for providing sprites or icons with images pre-prepared for the screen depth of the cdc. Like a CImageList.

This is likely why X doesn`t (by default) have BitBLT built in. Infact - you wouldn`t want it because it`d garuntee that much of the increadible X design wouldn`t no longer work in the manner it can now.

Pixmaps are pretty low level and I don`t see and likely built in routines for them.

If you going to stick with Xlib try

XPutImage, XGetImage, XGetSubImage
- transfer images (images are created from pixmaps).

But *not* CopyImage or CopyGC (src & dest must be same pixelformat). For example, GetImage will get the image in a differing format than the source image.

If your going to put your pixmap in a GC you have many available built in tools to use (in Xt). ChangeGC allows in-place change of formatting of its contents. Xt even has color-matching APIs (note - a shared lib exists that has leverage that to make color control more collated and functional).

libxpm might even be convenient for you and the user if your in its color range.

On the other hand there`s loads of shared libs for image tasks. All you do is #include the header for it, supply the linker with an extra option. In the code you merely call a single shared-lib open function (simple). Whala. You can now use any function in the shared lib!! Directions on this are abundant.

Motif Zone`s xmthemes (background image support for motif) uses shared image libs.

(the -ldl is for `dlopen` -- `direct link open` which is for the open call that opens shared libs)

(greetings.c is a simple .c file with no main - just the greetings function )
# make your own shared lib, not required )
cc -c greetings.c
ld -shared greetings.o -soname greetings.so -o greetings.so
/* in main.c */
/* open any named shared lib */
handle = dlopen("/root/dlopen-1.1/greetings.so", RTLD_LAZY);
fptr = (xamplefuncptr)dlsym(handle, "greetings");
(*fptr) /* executes the shared library function */
/* build it */
cc -c main.c
cc -o progname main.c -ldl

And of course shared libs are *tons* better than undocumented `dll`, right? `Course it is! You now have access to so many nice library functions its worrysome )

Personally, I`d try CreateImage then GetImage to start with (if BitBLT is really all you needed).

Have fun...

John Hendrickson