# -------------------------------------------------------------------
# COLOR                                 (c) Copyright 1995 KKP & Nat!
# -------------------------------------------------------------------
# These are some of the results/guesses that Klaus and I Nat! found
# out about the Jaguar with a few helpful hints by other people, 
# who'd prefer to remain anonymous.
# Thanks go to NEUROMANCER for the RGB-Cry table.
#
# Since we are not under NDA or anything from Atari we feel free to 
# give this to you for educational purposes only.
#
# Please note, that this is not official documentation from Atari
# or derived work thereof (both of us have never seen the Atari docs)
# and Atari isn't connected with this in any way.
#
# Please use this informationphile as a starting point for your own
# exploration and not as a reference. If you find anything inaccurate,
# missing, needing more explanation etc. by all means please write
# to us:
#    nat@zumdick.ruhr.de
# or
#    kp@eegholm.dk
#
# If you could do us a small favor, don't use this information for
# those lame flamewars on r.g.v.a or the mailing list.
#
# HTML soon ?
# -------------------------------------------------------------------
# $Id: jag_col.htm,v 1.20 1997/11/16 18:14:41 nat Exp $              
# -------------------------------------------------------------------
# Note: This is definetely the weakest doc so far. High bull content!
# --------------------------------------------------------------------

1 Quest For Color
=================

These are the different color representations used in the Jaguar.
The documentation is a bit hardware independent in presentation, as
you will notice. This should be a reference page, when perusing the
OP or Video dox.

There can be 3 major color modes identified called 
CrY (chroma-intensity), RGB (Red-Green-Blue) and Palette. 


1.1 CrY Color Image (16 bit/pixel)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

A CrY color is always represented with 16 bits. There are two different
schemes in use 8-8 CrY and 8-7 CrY.

8-8 is like this:
         16                              0
         +-------^-------+-------^-------+
         |    Chroma     |       Y       |
         +---------------+---------------+
           15.........8    7...........0

8-7 looks like this:
         16                              0
         +-------^-------+-------^----+--+
         |    Chroma     |       Y    | 1|
         +---------------+------------+--+
           15.........8    7........1   0
      
Y has nothing to do with Yellow, but is the intensity or luminance of 
the color chosen by Chroma! The color on the screen is calculated by 
the formula:

                color-Trans[ Cr ]
     color   =  ----------------- * Y,  Color = {Red, Green, Blue}
                       255

The cry colors aren't contigous as on the Atari 8-bit. Instead they
are sorta two dimensionally organized:
 
         major nybble
         
        blue \0    lightblue    magenta
            0 +---------------+          m
              |               |          i
              |               |          n
              |               |          o n
      purple  |     white     | green    r y  
              |               |            b 
              |               |            b
              |               |            l
              +---------------+            e
         red        orange      yellow


Imagine a blue lamp shining from the corner marked 'blue' ($0,$0) a
red lamp shining from the 'red' corner ($0,$F) and a green lamp shining
from the middle of the right edge ($F,$7). The resulting mix of colors
will be very similiar to the cry colors. So another way to visualize
a Cry Pixel would be:

 16       12        8        4        0
  +--------^--------^--------^--------+
  | ColMSB | ColLSN |    luminance    |
  +--------+--------+-----------------+
   15...12   11...8   7.............0 


Here are the RGB-CrY tables:


RED
~~~~
  0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
----------------------------------------------------------------
  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0         0?
 34  34  34  34  34  34  34  34  34  34  34  34  34  34  19   0         1?
 68  68  68  68  68  68  68  68  68  68  68  68  64  43  21   0         2?
102 102 102 102 102 102 102 102 102 102 102  95  71  47  23   0         3?
135 135 135 135 135 135 135 135 135 135 135 104  78  52  26   0         4?
169 169 169 169 169 169 169 169 169 170 141 113  85  56  28   0         5?
203 203 203 203 203 203 203 203 203 203 153 122  91  61  30   0         6?
237 237 237 237 237 237 237 237 230 197 164 131  98  65  32   0         7?
255 255 255 255 255 255 255 255 247 214 181 148 115  82  49  17         8?
255 255 255 255 255 255 255 255 255 235 204 173 143 112  81  51         9?
255 255 255 255 255 255 255 255 255 255 227 198 170 141 113  85         a?
255 255 255 255 255 255 255 255 255 255 249 223 197 171 145 119         b?
255 255 255 255 255 255 255 255 255 255 255 248 224 200 177 153         c?
255 255 255 255 255 255 255 255 255 255 255 255 252 230 208 187         d?
255 255 255 255 255 255 255 255 255 255 255 255 255 255 240 221         e?
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255         f?


GREEN
~~~~~
  0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
----------------------------------------------------------------
  0  17  34  51  68  85 102 119 136 153 170 187 204 221 238 255
  0  19  38  57  77  96 115 134 154 173 192 211 231 250 255 255
  0  21  43  64  86 107 129 150 172 193 215 236 255 255 255 255
  0  23  47  71  95 119 142 166 190 214 238 255 255 255 255 255
  0  26  52  78 104 130 156 182 208 234 255 255 255 255 255 255
  0  28  56  85 113 141 170 198 226 255 255 255 255 255 255 255
  0  30  61  91 133 153 183 214 244 255 255 255 255 255 255 255
  0  32  65  98 131 164 197 230 255 255 255 255 255 255 255 255
  0  32  65  98 131 164 197 230 255 255 255 255 255 255 255 255
  0  30  61  91 133 153 183 214 244 255 255 255 255 255 255 255
  0  28  56  85 113 141 170 198 226 255 255 255 255 255 255 255
  0  26  52  78 104 130 156 182 208 234 255 255 255 255 255 255
  0  23  47  71  95 119 142 166 190 214 238 255 255 255 255 255
  0  21  43  64  86 107 129 150 172 193 215 236 255 255 255 255
  0  19  38  57  77  96 115 134 154 173 192 211 231 250 255 255
  0  17  34  51  68  85 102 119 136 153 170 187 204 221 238 255


BLUE
~~~~
  0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
----------------------------------------------------------------
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255 255 255 255 255 240 221
255 255 255 255 255 255 255 255 255 255 255 255 252 230 208 187
255 255 255 255 255 255 255 255 255 255 255 248 224 200 177 153
255 255 255 255 255 255 255 255 255 255 249 223 197 171 145 119
255 255 255 255 255 255 255 255 255 255 227 198 170 141 113  85
255 255 255 255 255 255 255 255 255 235 204 173 143 112  81  51
255 255 255 255 255 255 255 255 247 214 181 148 115  82  49  17
237 237 237 237 237 237 237 237 230 197 164 131  98  65  32   0
203 203 203 203 203 203 203 203 203 203 153 122  91  61  30   0
169 169 169 169 169 169 169 169 169 170 141 113  85  56  28   0
135 135 135 135 135 135 135 135 135 135 135 104  78  52  26   0
102 102 102 102 102 102 102 102 102 102 102  95  71  47  23   0
 68  68  68  68  68  68  68  68  68  68  68  68  64  43  21   0
 34  34  34  34  34  34  34  34  34  34  34  34  34  34  19   0
  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0


1.2  RGB (15/16/24 bits/pixel)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Another color representation is Red Green Blue (RGB). Here the red, blue
and green intensities of a color are represented. There are three schemes
of RGB employed in the Jaguar, the most popular being 

the 5-5-6 scheme: (16 bit)

         +---------+---------+-----------+
         |   Red   |  Blue   |   Green   |
         +---------+---------+-----------+
         15......11 10......6 5..........0

the 5-5-5 scheme: (15/16 bit)

         +---------+---------+--------+--+
         |   Red   |  Blue   |  Green | 0|
         +---------+---------+--------+--+
          15.....11 10.....6   5.....1  0
 
and the 8-8-8 scheme: (24/32 bit)

              3       2      1      0
         +-------+-------+-------+-------+
         | Green |  Red  |  nc   | Blue  |      68K
         +-------+-------+-------+-------+
          31..24   23..16  15..8   7...0
or
         +-------+-------+-------+-------+
         |   nc  |  Blue | Green | Red   |      GPU/DSP
         +-------+-------+-------+-------+
          31..24   23..16  15..8   7...0



To convert to 5-5-6 RGB use something along the lines of:

; Input:
;  d5.5     : red
;  d6.6     : green
;  d7.5     : blue
; Output
;  d0.16    : packed TrueColor pixel
shiftcolor:
   move.w   d5,d0 ; d0 = red, now have [0]-[0]-[0]-[red]
   asl      #5,d0 ; shift red up, now have [0]-[0]-[red]-[0]
   or.w     d7,d0 ; add in blue, now have [0]-[0]-[red]-[blue]
   asl      #6,d0 ; shift red & blue up, now have [0]-[red]-[blue]-[0]
   or.w     d6,d0 ; add in green, now have [0]-[red]-[blue]-[green]
   rts


1.3  Palette Color Image (1,2,4,8 bits/pixel)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

This is basically just an indirection used for the previous two color
modes. Palette color can only be used with 16 bit color modes. Basically
the color information is used indirectly with a lookup table called
CLUT to produce a 16 bit value, which is then either interpreted as
a RGB or CrY color value:

Palette colors can have 1, 2, 4 or 8 bits per pixel.

In 8 bits/Pixel the pixel value is used directly as a index into the Clut.

For less than 8-bit pixels, the index depends also on the O_INDEX value of 
the current bitmap object (OP), lets just call this the offset for now:

In 1, 2 and 4 bits/pixel modes the Clut-Index for the displayed color is
calculated as   Clut-Index = 2 * offset + Pixel-Value.


Nat! (nat@zumdick.ruhr.de)
Klaus (kp@eegholm.dk)

$Id: jag_col.htm,v 1.20 1997/11/16 18:14:41 nat Exp $