[comp.sys.sgi] Getting compor map colors.

markov@cs.ruu.nl (Mark Overmars) (04/22/91)

I have the following problem. I want to draw colormap images inside a RGB
window. As a result I need to find out what the colors in the colormap are. To
this end I thought I should use the routine

  getmcolor()

Unfortunately, this routine only work when you are in colormap mode, not when
you are in RGB mode. (Why?) So the question is, how do I do it. To make this
precise: I have an RGB window open, and I want a routine my_color(col) that
sets the current RGB color to the color in index col in the colormap.

(I need this for making the forms in the FORMS library into RGB windows and
still maintaining the current behaviour of the package.)

Mark Overmars

kurt@cashew.asd.sgi.com (Kurt Akeley) (04/24/91)

In article <1991Apr22.153229.7358@cs.ruu.nl>, markov@cs.ruu.nl (Mark Overmars) writes:
|> I have the following problem. I want to draw colormap images inside a RGB
|> window. As a result I need to find out what the colors in the colormap are. To
|> this end I thought I should use the routine
|> 
|>   getmcolor()
|> 
|> Unfortunately, this routine only work when you are in colormap mode, not when
|> you are in RGB mode. (Why?)

Because the colormap is indexed as a function of your framebuffer configuration,
and the required information is not available in an RGB window.  Specifically,
color index windows are either in single-map or multi-map mode.  When in multi-
map mode, they access the differently than when in single-map mode.  It is
cleaner and more correct to disallow color map access to RGB windows.

|> So the question is, how do I do it. To make this
|> precise: I have an RGB window open, and I want a routine my_color(col) that
|> sets the current RGB color to the color in index col in the colormap.

Simply open another window using the desired color index mode, and use
it to interrogate the colormap contents.  I have included an example program
below.  Note that it calls noport() before opening the color index window,
so that this window does not appear on the screen.

|> (I need this for making the forms in the FORMS library into RGB windows and
|> still maintaining the current behaviour of the package.)
|> 
|> Mark Overmars

-- Kurt

-------------------------------- cut here ----------------------------------

/* Open an RGB window to draw into, and a color index drawing context to */
/* allow interrogation of the color map */

#include <stdio.h>
#include <gl/gl.h>
#include <gl/device.h>

main() {
    long ciid, rgbid;
    short r,g,b;
    register i;

    rgbid = winopen("rgb");
    RGBmode();
    gconfig();

    noport();
    ciid = winopen("ci");

    winset(rgbid);
    cpack(0);
    clear();
    sleep(2);

    winset(ciid);
    for (i=0; i<8; i++) {
	getmcolor(i,&r,&g,&b);
	printf("%2d: %2x %2x %2x\n",i,r,g,b);
    }

    winset(rgbid);
    cpack(0xffffff);
    clear();
    sleep(2);

    winset(ciid);
    for (i=0; i<8; i++) {
	getmcolor(i,&r,&g,&b);
	printf("%2d: %2x %2x %2x\n",i,r,g,b);
    }
}

tjh@bucrf11.bu.edu (Tim Hall) (04/24/91)

In article <1991Apr22.153229.7358@cs.ruu.nl>, markov@cs.ruu.nl (Mark Overmars) writes:
|> I have the following problem. I want to draw colormap images inside a RGB
|> window. As a result I need to find out what the colors in the colormap are. To
|> this end I thought I should use the routine
|> 
|>   getmcolor()
|> 
|> Unfortunately, this routine only work when you are in colormap mode, not when
|> you are in RGB mode. (Why?) 

Dunno why, but you could always do somthing like......

	current_window = winget();   /* Remember what the current window is */

	noport();                    /* Open a window that never appears */
	color_window = winopen( NULL);

	Read the color map here.

	winclose( color_window );

	if ( current_window > 0 )  /* >= ????   I forget.... */
		winset( current_window );

Yuk, what a kludge.

|> Mark Overmars

-- 
-Tim Hall
tjh@bu-pub.bu.edu

The night is filled with the cries of dispossessed children in search
of paradise.  -Dead Can Dance

markov@cs.ruu.nl (Mark Overmars) (04/25/91)

In <80085@bu.edu.bu.edu> tjh@bucrf11.bu.edu (Tim Hall) writes:

>In article <1991Apr22.153229.7358@cs.ruu.nl>, markov@cs.ruu.nl (Mark Overmars) writes:
>|> I have the following problem. I want to draw colormap images inside a RGB
>|> window. As a result I need to find out what the colors in the colormap are. To
>|> this end I thought I should use the routine
>|> 
>|>   getmcolor()
>|> 
>|> Unfortunately, this routine only work when you are in colormap mode, not when
>|> you are in RGB mode. (Why?) 
>
>	current_window = winget();   /* Remember what the current window is */
>
>	noport();                    /* Open a window that never appears */
>	color_window = winopen( NULL);
>
>	Read the color map here.
>
>	winclose( color_window );
>
>	if ( current_window > 0 )  /* >= ????   I forget.... */
>		winset( current_window );

The problem with this solution is that it is way too slow. Even keeping the
color window open and doing a winset on it whenever I need a colormap entry
slows the drawing of e.g. rectangles down by a factor of three (winset seems
to be an expensive call), at least on a GTX. On a 25/TG there was almost no
speed penalty (????). What I do now is to keep my own colormap and reading it in
only once. Of course, in this way I don't see it when the application changes
the colormap but it works fast. (Strangely enough, doing this on a 25/TG was
faster than drawing normal in colormap mode.)

Mark Overmars

drb@eecg.toronto.edu (David R. Blythe) (04/29/91)

In article <1991Apr25.130848.25198@cs.ruu.nl> markov@cs.ruu.nl (Mark Overmars) writes:
>In <80085@bu.edu.bu.edu> tjh@bucrf11.bu.edu (Tim Hall) writes:
>
>>In article <1991Apr22.153229.7358@cs.ruu.nl>, markov@cs.ruu.nl (Mark Overmars) writes:
>>|> I have the following problem. I want to draw colormap images inside a RGB
>>|> window. As a result I need to find out what the colors in the colormap are. To
>>|> this end I thought I should use the routine
>>|> 
>>|>   getmcolor()
>>|> 
>>|> Unfortunately, this routine only work when you are in colormap mode, not when
>>|> you are in RGB mode. (Why?) 
>>
>>	current_window = winget();   /* Remember what the current window is */
>>
>>	noport();                    /* Open a window that never appears */
>>	color_window = winopen( NULL);
>>
>>	Read the color map here.
>>
>>	winclose( color_window );
>>
>>	if ( current_window > 0 )  /* >= ????   I forget.... */
>>		winset( current_window );
>
>The problem with this solution is that it is way too slow. Even keeping the
>color window open and doing a winset on it whenever I need a colormap entry
>slows the drawing of e.g. rectangles down by a factor of three (winset seems
>to be an expensive call), at least on a GTX. On a 25/TG there was almost no
>speed penalty (????). What I do now is to keep my own colormap and reading it in
>only once. Of course, in this way I don't see it when the application changes
>the colormap but it works fast. (Strangely enough, doing this on a 25/TG was
>faster than drawing normal in colormap mode.)
>
>Mark Overmars

I saw a performance posting a couple of weeks ago that showed wildly varying
performance with colormap manipulation across the various platforms, I think
the PI was faster than the GT (then again maybe not).  I think the keeping
the window open solution should get even faster as the pressure to have
cheap (X-like) windows is answered (in 4.0?).  On the other hand, having
a window manager color map changed event also would be handy and is probably
necessary for total X'ness anyway ...
	-drb