[comp.graphics] 24 bit SUN Rasterfile and Quaternions

marsha@acsu.buffalo.edu (john c marsha) (06/30/91)

ANY advice on this would be EXTREMELY helpful (i'm at the end of my rope)

I am almost finished with a program that raytraces Quaternions. I am
using an intensity function which returns the intensity values
in red, blue, and green for each pixel. I'd like to see the results
placed in a SUN Rasterfile format (RT_STANDARD,RGB_EQUAL_RGB is what i'm 
using now) but here are the problems:

1) With the ras_depth = 8, there are 256 color to choose from. Does
   anyone have a good algorithim for creating a 256 color colormap
   from the calculated intensites?

(e.g. If red[0],green[0],blue[0] intensites represent the first pixel
 on the screen, how can a colormap be created that allows red[500],
 green[500], blue[500] be the 501st  (0 to 500 is 501 numbers)
 pixel and still access 256 colors, obviously some of the 
 intensites have to be comprimised.) 


2) Is it possible for a SUN rasterfile to support 24 or higher bit depth?
   With 24 Bits:
   One could reference 16,777,215 colors.
   (this would mean a 200x200 image would have a length of
    120,000 bytes and the colormap length would be 360,000 bytes)

3) Isn't there a way to just say "here is the Red, Green and Blue
   intensites (relative to some scale i.e. 0 dark 255 bright) without
   using an actual image map? (ras_length = 0 but the maplength would
   be depth * width * height * 3 (one for each color).
   r[0],b[0],g[0] would actually be the pixel 0,0, not the 
   "reference" to the color)  

ARRRRGH!!!!!
(I have the image but I cant see it properly!!!!!!!)

If this is making no sense, i'll re-word it for a kind, helping soul.


Kevin (using a friend's account) 

BTW: If it helps, I'm running this on a SUN Sparc IPC w/ a 1024x1024 (?)
     screen.

falk@peregrine.Sun.COM (Ed Falk) (07/01/91)

In article <81735@eerie.acsu.Buffalo.EDU> marsha@acsu.buffalo.edu (john c marsha) writes:
>
>
>1) With the ras_depth = 8, there are 256 color to choose from. Does
>   anyone have a good algorithim for creating a 256 color colormap
>   from the calculated intensites?

There are two issues here; choosing a good colormap to use, and
converting rgb colors to use that colormap.  The best all-around
algorithm is Heckbert's median-cut algorithm referenced in the FAQ list.
This algorithm requires that the entire image be available in RGB format
before you start (i.e. it doesn't convert on the fly)

The next best algorithm uses a pre-determined colormap (called a "color
cube" since it represents a 3-d cube in rgb space) and is usually
combined with "dithering" to smooth out the errors.

These algorithms are both referenced in the FAQ list.  Software to
convert 24-bit images to 8-bit images is available in the PBM, FBM
and Utah Raster Toolkit packages.

>2) Is it possible for a SUN rasterfile to support 24 or higher bit depth?
>   With 24 Bits:
>   One could reference 16,777,215 colors.
>   (this would mean a 200x200 image would have a length of
>    120,000 bytes and the colormap length would be 360,000 bytes)

Yes and no.  24-bit and 32-bit formats exist (just set ras_depth to
24 or 32).  These are "direct color" images.  The pixels are not 24-bit
indices into gigantic colormaps.  Typically, you don't have a colormap
at all and the 24-bit values are 8 bits each of rgb.  You can provide
a colormap if you like, but the way it works is that the 'r' value of
a pixel is an index into the red map and so on with 'g' and 'b'.

>3) Isn't there a way to just say "here is the Red, Green and Blue
>   intensites (relative to some scale i.e. 0 dark 255 bright) without
>   using an actual image map? (ras_length = 0 but the maplength would
>   be depth * width * height * 3 (one for each color).
>   r[0],b[0],g[0] would actually be the pixel 0,0, not the 
>   "reference" to the color)  

Yes, see above.  What you want to do is set the maplength to 0 and
then raslength is width * height * 3.

[one note to people using sun rasterfiles: each scanline in an image is
rounded up to an even number of bytes.  If your image has an even
width, this doesn't have any effect.  If your image has an odd width,
then each scanline is one byte wider.  For example for 24-bit images
raslength = (width*3+1)*height.]

		-ed falk, sun microsystems
		 sun!falk, falk@sun.com

In the future, somebody will quote Andy Warhol every 15 minutes.