XForms: separate colormap for canvas - problems

Michal Szymanski (msz@bulge.astrouw.edu.pl)
Fri, 21 Nov 1997 22:30:51 +0100 (MET)

To subscribers of the xforms list from msz@bulge.astrouw.edu.pl (Michal Szymanski) :

Hi XFormers,

I have written an XForms-based image display program. The image is
displayed in gray scale in a canvas. Normally it uses shared color
cells (just to avoid color flashing). But if the default colormap
has too few cells available, I'd like to create a new colormap for the
canvas (or for the whole form).

What I am actually doing now is:

...
vclass=fl_get_form_vclass(fd_image->image)
cmap = fl_get_canvas_colormap(fd_image->canvas);
for (i=0; i<ngray; i++) {
unsigned long lev,pix;
lev = (i*65535)/(ngray-1);
gray.red = gray.green = gray.blue = lev;
if ( XAllocColor(fl_display, cmap, &gray) == 0 ) break;
graypix[i] = gray.pixel;
}
if ( i < ngray ) {
XFreeColors(fl_display,cmap,graypix,i,0);
cmap = fl_create_colormap(fl_state[vclass].xvinfo, 16);
fl_set_canvas_colormap(fd_image->canvas, cmap);
for (i=0; i<ngray; i++) {
unsigned long lev,pix;
lev = (i*65535)/(ngray-1);
gray.red = gray.green = gray.blue = lev;
if ( XAllocColor(fl_display, cmap, &gray) == 0 ) break;
graypix[i] = gray.pixel;
}
}
...

Unfortunately, this does not work as I expected. It is OK if it
allocates all colors in the first loop. But when this fails,
program creates new colormap, successfully allocates all colors (!)
but on the screen I get majority of colors in the image canvas
being not gray but brown/green/blue. And there is no color flashing when
I move mouse pointer in/out the canvas (what I expected should happen if
the canvas has different colormap - it is even mentioned in the XForms
manual in fl_create_colormap description).

I know I can run my program with "-private" option but this is not what
I'd like to do. I prefer to try shared colormap (which usually works - I
need only 30-50 gray shadows) and move to a private colormap only if
neccesary.

Probably I'm doing something wrong. But I need to know what.

Any hints will be much appreciated,

with best regards,

Michal.

****************************************************************************
Michal Szymanski Internet: msz@sirius.astrouw.edu.pl
Warsaw University Observatory Bitnet: msz@plwauw61.bitnet
Al. Ujazdowskie 4 Voice: 48-22-6294011 ext 23
00-478 Warszawa, POLAND FAX: 48-22-6294967
****************************************************************************

_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/