home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / src / AOS / palettes.h < prev    next >
C/C++ Source or Header  |  1999-09-23  |  6KB  |  159 lines

  1. //#ifndef    AMIGAMESApal_H
  2. //#define    AMIGAMESApal_H
  3.  
  4. /*
  5.  * $Id: $
  6.  */
  7.  
  8. /*
  9.  * Mesa 3-D graphics library
  10.  * Version:  3.1
  11.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  12.  *
  13.  * This library is free software; you can redistribute it and/or
  14.  * modify it under the terms of the GNU Library General Public
  15.  * License as published by the Free Software Foundation; either
  16.  * version 2 of the License, or (at your option) any later version.
  17.  *
  18.  * This library is distributed in the hope that it will be useful,
  19.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21.  * Library General Public License for more details.
  22.  *
  23.  * You should have received a copy of the GNU Library General Public
  24.  * License along with this library; if not, write to the Free
  25.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26.  */
  27.  
  28. #ifdef    PALETTE_DEFS
  29. /* first part defines amigaMesa-specifig tag
  30.  * second part defines the choosen palette (aka modelling of available colors)
  31.  * third part defines methog to fetch data (aka encoding of given colors
  32.  *
  33.  * at the moment dithering is only available in RGBMode, that means if we are
  34.  * in index-mode the index-pixels are directly (without dither) mapped to
  35.  * pen-pixels, it could be an improvement to offer dithering even for index-modes
  36.  */
  37. typedef enum PaletteModeID {
  38.   /* dithering */
  39.   AMESA_HPCR_DITHER = -8,                    /* hp-color-recovery */
  40.   AMESA_GREY_DITHER = -4,
  41.   AMESA_WEIGHTED_DITHER = -2,                    /* default standard 0 */
  42.   AMESA_TRUECOLOR_DITHER = -1,                    /* matches below 0 */
  43.   /* matching */
  44.   AMESA_HPCR_MATCH = 8,                        /* hp-color-recovery */
  45.   AMESA_GREY_MATCH = 4,
  46.   AMESA_WEIGHTED_MATCH = 2,                    /* default standard 0 */
  47.   AMESA_TRUECOLOR_MATCH = 1,                    /* matches below 0 */
  48.   /* shifting */
  49.   AMESA_TRUECOLOR_SHIFT = 0,                    /* shifts above 0 */
  50.   /* invalid */
  51.   AMESA_DEADFOOD = 0xDEAD                    /* dead man */
  52. } palMode;
  53.  
  54. #define    MATCHtoDITHER(bool)        ((bool) = -(bool))    /* if in shift-mode dither isn't available */
  55. #define    DITHERtoMATCH(bool)        ((bool) = -(bool))    /* if in shift-mode dither isn't available */
  56.  
  57. #define    IS_HPCR(bool)            (((bool) ==  8) || ((bool) == -8))
  58. #define    IS_GREY(bool)            (((bool) ==  4) || ((bool) == -4))
  59. #define    IS_WEIGHTED(bool)        (((bool) ==  2) || ((bool) == -2))
  60. #define    IS_TRUECOLOR(bool)        (((bool) >= -1) && ((bool) <=  1))
  61.  
  62. #define    IS_DITHER(bool)            ((bool) <  0)
  63. #define    IS_MATCH(bool)            ((bool) >  0)
  64. #define    IS_SHIFT(bool)            ((bool) == 0)
  65.  
  66. /*****************************************************************************
  67.  *
  68.  * fetch-macros
  69.  */
  70.  
  71. /* compositions */
  72. #define c8toc32(x)            (((((((x) << 8) | (x)) << 8) | (x)) << 8) | (x))    /* byte-pen to pattern-pen */
  73. #define    c24tocg(r,g,b)            (((r << 5) + (g << 6) + (g << 5) + (b << 3) + b) >> 9)    /* rgb-color to 64-grey (quick approximation) */
  74. #define    c24toc8(r,g,b)            ((((r) & 0xE0) >> 0) |    \
  75.                      (((g) & 0xE0) >> 3) |    \
  76.                      (((b) & 0xE0) >> 6))                    /* rgb-color to 332-color */
  77.  
  78. /* TrueColor-RGB */
  79. #define TC_RGBA(r,g,b)            (((((((r) << 8) | (g)) << 8) | (b)) << 8) | (0))    /* byte-rgb to long-rgba */
  80. #define TC_ARGB(r,g,b)            (((((((0) << 8) | (r)) << 8) | (g)) << 8) | (b))    /* byte-rgb to long-argb */
  81. #define    TC_Color(col,rr,gg,bb,aa)    {col.r = (W3D_Float)rr;    \
  82.                      col.g = (W3D_Float)gg;    \
  83.                      col.b = (W3D_Float)bb;    \
  84.                      col.a = (W3D_Float)aa;}                /* rgba to float-rgba */
  85.  
  86. /* Grey-RGB */
  87. #define    GR_RGBA(am, r, g, b)        (am->Palette[c24tocg(r, g, b)].PenNo)            /* rgb-color to grey-pen */
  88.  
  89. /* Palette-Index */
  90. #define PLD_RGBA(am, r, g, b, x, y)    (GetPenDithered(r, g, b, am, x, y))            /* rgb-color to dithered-pen */
  91. #define PLG_RGBA(am, r, g, b)        (GetPen(r, g, b, am))                    /* rgb-color to pen */
  92. #define PL8_RGBA(am, r, g, b)        (am->Palette[c24toc8(r, g, b)].PenNo)            /* rgb-color to 332-pen */
  93.  
  94. /* the format of index is RGBI, red|green|blue|index */
  95. #define MakeRGBP(am, r, g, b, x, y)    (TC_RGBA(r, g, b) | PL_RGBA(am, r, g, b, x, y))        /* rgb to long-rgbp */
  96. #define MakeRGBA(am, r, g, b, a)    (TC_RGBA(r, g, b) | a)                    /* rgb to long-rgba */
  97. /* get the red/green/blue/pen from a given index */
  98. #define    GetRGBP(am, idx)        (am->ItoP[(GLubyte)(idx)])                /* index to pen */
  99. #define    GetRGBPLocal(idx)        (ItoP[(GLubyte)(idx)])                    /* index to pen */
  100. /* get the red/green/blue/index from a given pen */
  101. #define    GetIndex(am, idx)        (am->PtoI[(GLubyte)(idx)])                /* pen to index */
  102. #define    GetIndexLocal(idx)        (PtoI[(GLubyte)(idx)])                    /* pen to index */
  103.  
  104. /*****************************************************************************/
  105.  
  106. struct ColorEntry {
  107.   struct {
  108.     unsigned char r, g, b, a;
  109.   } orgEntry;
  110.   struct {
  111.     unsigned char r, g, b, a;
  112.   } mapEntry;
  113. /*ULONG PenNo; */
  114. #define    PenNo    mapEntry.a
  115. };
  116.  
  117. #define    CACHED    0xFF
  118. #define    INVALID    0x00
  119. struct ColorCache {
  120.   unsigned char PenCch, R, B, valid;
  121. };
  122.  
  123. #define palNumCols332    256
  124. #define palNumCols    189
  125. #define palNumColsGrey    64
  126. #define palNumColsHPCR    256
  127.  
  128. #define    palNumColsMax    256
  129.  
  130. #define    ERROR_RANGE    512    /* -255 = 0 - 255, 255 = 255 - 0: -255 -> 255 */
  131. #endif
  132.  
  133. /*****************************************************************************/
  134.  
  135. #ifdef    PALETTE_PROTOS
  136. ULONG GetPen(register unsigned char R __asm__("d0"),
  137.          register unsigned char G __asm__("d1"),
  138.          register unsigned char B __asm__("d2"),
  139.          register amigaMesaContext amesa __asm__("a0"));
  140. ULONG GetPenDithered(register unsigned char R __asm__("d0"),
  141.              register unsigned char G __asm__("d1"),
  142.              register unsigned char B __asm__("d2"),
  143.              register amigaMesaContext amesa __asm__("a0"),
  144.              register unsigned char X __asm__("d3"),    /* as the ditherkernel doesn't exceed 2^8    */
  145.              register unsigned char Y __asm__("d4"));    /* we can safe shrink the ccordinates to it    */
  146. void AllocCMap(amigaMesaContext, struct Screen *);
  147. void FreeCMap(amigaMesaContext, struct Screen *);
  148. void RethinkCMap(amigaMesaContext);
  149. void ConvertCMap(amigaMesaContext, palMode, struct Screen *Scr);
  150.  
  151. static inline GLuint PL_RGBA(amigaMesaContext am, GLubyte r, GLubyte g, GLubyte b, GLushort x, GLushort y) {
  152.   return IS_SHIFT(am->trueColor) ? PL8_RGBA(am, r, g, b) :
  153.      IS_MATCH(am->trueColor) ? PLG_RGBA(am, r, g, b) :
  154.                    PLD_RGBA(am, r, g, b, x, y);
  155. };
  156. #endif
  157.  
  158. //#endif
  159.