[net.graphics] HELP!! SUN specific graphics question.

phaedrus@eneevax.UUCP (The Sophist) (01/24/85)

Ok, here are the preliminaries:

	I am working on a Sun running Berkeley 4.2.
	I am working at the `pixrect' level.

What I need to do is to define a colormap so that I can make the pixels
be nine different and very distinct colors.  The Sun manuals have no
examples on how to set up the colormap and I don't have too much
experience with graphics so, I am going no where trying to figure it
out.  Could someone please tell me how to set up a colormap at the
pixrect level?  If that isn't possible, could someone send me an
example of a colormap that they have set up (liberally sprinkled with
comments)?  And if that isn't possible could someone explain to me how
the following routine (which sets up a colormap) works?  I don't quite
understand what all the shifting and the oring does.


int mak_col_map ()
{
    int     index;
    unsigned char   red[256],
                    blue[256],
                    green[256];
    int     r,
            b,
            g;

    for (b = 0; b < 4; b++) {
	for (g = 0; g < 8; g++) {
	    for (r = 0; r < 8; r++) {
		index = (b << 6) | (g << 3) | (r);
		blue[index] = b * 84;
		red[index] = r * 36;
		green[index] = g * 36;
	    }
	}
    }
    pr_putcolormap (col_mon, 0, 256, red, green, blue);
}

Thanks in advance.
-- 
			Pravin Kumar

Don't bother me! I'm on an emergency third rail power trip.

ARPA:   phaedrus!eneevax@maryland
UUCP:   {seismo,allegra,brl-bmd}!umcp-cs!eneevax!phaedrus

jsgray@watmath.UUCP (Jan Gray) (01/30/85)

> From eneevax!phaedrus 24 Jan 85 19:15:43 GMT
> ..........  And if that isn't possible could someone explain to me how
> the following routine (which sets up a colormap) works?  I don't quite
> understand what all the shifting and the oring does.
> 
> int mak_col_map ()
> {
>     int     index;
>     unsigned char   red[256],
>                     blue[256],
>                     green[256];
>     int     r,
>             b,
>             g;
> 
>     for (b = 0; b < 4; b++) {
> 	for (g = 0; g < 8; g++) {
> 	    for (r = 0; r < 8; r++) {
> 		index = (b << 6) | (g << 3) | (r);
> 		blue[index] = b * 84;
> 		red[index] = r * 36;
> 		green[index] = g * 36;
> 	    }
> 	}
>     }
>     pr_putcolormap (col_mon, 0, 256, red, green, blue);
> }

It looks like the program is building separate red, green and blue look
up tables, each of which has 256 entries and is 8 bits deep.  I expect that
you have an 8 bit frame buffer, and you set up the internal data paths
so that those eight bits index a red, green and blue intensity.

The program you include sets up the colour map so that a colour
contains two bits of blue, three bits of red, and three bits of green
intensity.  You therefore can select colours with three levels of blue
(plus black) and seven levels of red and green (plus black).

(84 == 255 / 3, and 36 == 255 / 7)

Colour 0   is 00 000 000	== no blue, no green, no red
Colour 1   is 00 000 001	== no blue, no green, 1/7 red	(36/255)
Colour 2   is 00 000 010	== no blue, no green, 2/7 red	(72/255)
...
Colour 255 is 11 111 111	== full blue, full green, full red


I expect this is a standard trick for 8 bit deep frame buffers with
separate rgb lookup tables.

I expect too much,

Jan Gray (jsgray@watmath.UUCP)   University of Waterloo   (519) 885-1211 x3870