home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser 2002 January / STC_CD_01_2002.iso / JAGUAR / JAG_SRC / SOURCE / COLOR.C < prev    next >
C/C++ Source or Header  |  2001-08-15  |  9KB  |  204 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. // Jagulator: Atari Jaguar Console Emulation Project (color.c)
  3. // -----------------------------------------------------------------------------
  4. // Jagulator is the Copyright (c) RealityMan 1998-2001 and is provided "as is" 
  5. // without any expressed or implied warranty. I have no Trademarks, Legal or 
  6. // otherwise. Atari, Jaguar and the Atari Logo are copyright Hasbro Inc. All 
  7. // other Copyrights and Trademarks are acknowledged. This project is in no way 
  8. // linked to Atari/Hasbro or other associated Atari companies.                
  9.  
  10. #include "core.h"
  11.  
  12. ////////////////////////////////////////////////////////////////////////////////
  13. // Red Color Values for CrY<->RGB Color Conversion
  14.  
  15.    byte redcv[16][16] = {
  16.    //  0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
  17.    // ----------------------------------------------------------------------
  18.       0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,    // 0
  19.       34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 19, 0,    // 1
  20.       68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 64, 43, 21, 0,    // 2
  21.       102,102,102,102,102,102,102,102,102,102,102,95, 71, 47, 23, 0,    // 3
  22.       135,135,135,135,135,135,135,135,135,135,130,104,78, 52, 26, 0,    // 4
  23.       169,169,169,169,169,169,169,169,169,170,141,113,85, 56, 28, 0,    // 5
  24.       203,203,203,203,203,203,203,203,203,183,153,122,91, 61, 30, 0,    // 6
  25.       237,237,237,237,237,237,237,237,230,197,164,131,98, 65, 32, 0,    // 7
  26.       255,255,255,255,255,255,255,255,247,214,181,148,15, 82, 49, 7,    // 8
  27.       255,255,255,255,255,255,255,255,255,235,204,173,143,112,81, 51,   // 9
  28.       255,255,255,255,255,255,255,255,255,255,227,198,170,141,113,85,   // A
  29.       255,255,255,255,255,255,255,255,255,255,249,223,197,171,145,119,  // B
  30.       255,255,255,255,255,255,255,255,255,255,255,248,224,200,177,153,  // C
  31.       255,255,255,255,255,255,255,255,255,255,255,255,252,230,208,187,  // D
  32.       255,255,255,255,255,255,255,255,255,255,255,255,255,255,240,221,  // E
  33.       255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255   // F
  34.    };
  35.  
  36. ////////////////////////////////////////////////////////////////////////////////
  37. // Green Color Values for CrY<->RGB Color Conversion
  38.  
  39.    byte greencv[16][16] = {
  40.    //  0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
  41.    // ----------------------------------------------------------------------
  42.       0,  17, 34, 51,68, 85, 102,119,136,153,170,187,204,221,238,255,   // 0
  43.       0,  19, 38, 57,77, 96, 115,134,154,173,192,211,231,250,255,255,   // 1
  44.       0,  21, 43, 64,86, 107,129,150,172,193,215,236,255,255,255,255,   // 2
  45.       0,  23, 47, 71,95, 119,142,166,190,214,238,255,255,255,255,255,   // 3
  46.       0,  26, 52, 78,104,130,156,182,208,234,255,255,255,255,255,255,   // 4
  47.       0,  28, 56, 85,113,141,170,198,226,255,255,255,255,255,255,255,   // 5
  48.       0,  30, 61, 91,122,153,183,214,244,255,255,255,255,255,255,255,   // 6
  49.       0,  32, 65, 98,131,164,197,230,255,255,255,255,255,255,255,255,   // 7
  50.       0,  32, 65, 98,131,164,197,230,255,255,255,255,255,255,255,255,   // 8
  51.       0,  30, 61, 91,122,153,183,214,244,255,255,255,255,255,255,255,   // 9
  52.       0,  28, 56, 85,113,141,170,198,226,255,255,255,255,255,255,255,   // A
  53.       0,  26, 52, 78,104,130,156,182,208,234,255,255,255,255,255,255,   // B
  54.       0,  23, 47, 71,95, 119,142,166,190,214,238,255,255,255,255,255,   // C
  55.       0,  21, 43, 64,86, 107,129,150,172,193,215,236,255,255,255,255,   // D
  56.       0,  19, 38, 57,77, 96, 115,134,154,173,192,211,231,250,255,255,   // E
  57.       0,  17, 34, 51,68, 85, 102,119,136,153,170,187,204,221,238,255    // F
  58.    };
  59.    
  60. ////////////////////////////////////////////////////////////////////////////////
  61. // Blue Color Values for CrY<->RGB Color Conversion
  62.  
  63.    byte bluecv[16][16] = {
  64.    //  0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
  65.    // ----------------------------------------------------------------------
  66.       255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // 0
  67.       255,255,255,255,255,255,255,255,255,255,255,255,255,255,240,221,  // 1
  68.       255,255,255,255,255,255,255,255,255,255,255,255,252,230,208,187,  // 2
  69.       255,255,255,255,255,255,255,255,255,255,255,248,224,200,177,153,  // 3
  70.       255,255,255,255,255,255,255,255,255,255,249,223,197,171,145,119,  // 4
  71.       255,255,255,255,255,255,255,255,255,255,227,198,170,141,113,85,   // 5
  72.       255,255,255,255,255,255,255,255,255,235,204,173,143,112,81, 51,   // 6
  73.       255,255,255,255,255,255,255,255,247,214,181,148,115,82, 49, 17,   // 7
  74.       237,237,237,237,237,237,237,237,230,197,164,131,98, 65, 32, 0,    // 8
  75.       203,203,203,203,203,203,203,203,203,183,153,122,91, 61, 30, 0,    // 9
  76.       169,169,169,169,169,169,169,169,169,170,141,113,85, 56, 28, 0,    // A
  77.       135,135,135,135,135,135,135,135,135,135,130,104,78, 52, 26, 0,    // B
  78.       102,102,102,102,102,102,102,102,102,102,102,95, 71, 47, 23, 0,    // C
  79.       68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 64, 43, 21, 0,    // D
  80.       34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 19, 0,    // E
  81.       0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0     // F
  82.    };
  83.  
  84. ////////////////////////////////////////////////////////////////////////////////
  85. // Globals
  86.  
  87.    GLuint clut[256];                   // RGBA Translation of CrY CLUT Table
  88.  
  89. ////////////////////////////////////////////////////////////////////////////////
  90. // When CrY CLUT is Updated Create a RGBA Entry in Translated CLUT
  91.  
  92.    void color_ccry( unsigned addr, unsigned data )
  93.    {
  94.       dword chrm, chrl;                // R,G,B Cry Color Table Coordinates
  95.       dword y;                         // Luminance
  96.       float r, g, b;                   // RGB Values
  97.       dword cli;                       // CLUT Index
  98.  
  99.       chrm = (data & 0xF000) >> 12;    // Get CrY Values
  100.       chrl = (data & 0x0F00) >> 8;
  101.       y    = (data & 0x00FF);
  102.  
  103.       // Calculate RGB Values
  104.       r = (((float)(  redcv[chrm][chrl]) / 255 ) * y);
  105.       g = (((float)(greencv[chrm][chrl]) / 255 ) * y);
  106.       b = (((float)( bluecv[chrm][chrl]) / 255 ) * y);
  107.  
  108.       // Store in Internal RGBA Color Lookup Table
  109.       if( addr >= 0xF00600 ) addr -= 0x200;
  110.       cli = (addr - 0xF00400) / 2;
  111.       clut[cli]  = (dword)r;
  112.       clut[cli] |= (dword)(g) << 8;     
  113.       clut[cli] |= (dword)(b) << 16;
  114.  
  115.       // Make all Colors Opaque - OP Will Remove for Transparency
  116.       clut[cli] |= 0xFF000000;
  117.  
  118.       #ifdef DBGCLR
  119.       print( BROWN"CLUT[%03i]: CrY(0x%04X) --> R(%03i), G(%03i), B(%03i), A(%03i)\n",
  120.              cli, data, (dword)r, (dword)g, (dword)b, (clut[cli] & 0xFF000000) >> 24 );
  121.       #endif
  122.    }
  123.    
  124. ////////////////////////////////////////////////////////////////////////////////
  125. // When RGB16 CLUT is Updated Create a RGBA Entry in Translated CLUT
  126.  
  127.    void color_crgb( unsigned addr, unsigned data )
  128.    {
  129.       dword cli;                       // CLUT Index
  130.       static dword r, g, b;            // RGB Values
  131.  
  132.       r = (data & 0xF800) >> 8;
  133.       b = (data & 0x07C0) >> 3;
  134.       g = (data & 0x003F) << 2;
  135.  
  136.       // Store in Internal RGBA Color Lookup Table
  137.       if( addr >= 0xF00600 ) addr -= 0x200;
  138.       cli = (addr - 0xF00400) / 2;
  139.       clut[cli]  = (dword)r;
  140.       clut[cli] |= (dword)(g) << 8;     
  141.       clut[cli] |= (dword)(b) << 16;
  142.  
  143.       // Make all Colors Opaque - OP Will Remove for Transparency
  144.       clut[cli] |= 0xFF000000;
  145.  
  146.       #ifdef DBGCLR
  147.       print( BROWN"CLUT[%03i]: RGB16(0x%04X) --> R(%03i), G(%03i), B(%03i), A(%03i)\n",
  148.              cli, data, (dword)r, (dword)g, (dword)b, (clut[cli] & 0xFF000000) >> 24 );
  149.       #endif
  150.    }
  151.  
  152. ////////////////////////////////////////////////////////////////////////////////
  153. // Convert RGB16 to RGB32
  154.    
  155.    dword rgb16_rgb32( dword rgb16, int trans )
  156.    {
  157.       static dword rgb32;
  158.       static dword r, g, b;                   // RGB Values
  159.  
  160.       r = (rgb16 & 0xF800) >> 8;
  161.       b = (rgb16 & 0x07C0) >> 3;
  162.       g = (rgb16 & 0x003F) << 2;
  163.  
  164.       rgb32  = r;
  165.       rgb32 |= g << 8;
  166.       rgb32 |= b << 16;
  167.  
  168.       if( !rgb32 && trans ) return( rgb32 );
  169.  
  170.       rgb32 |= 0xFF000000;
  171.  
  172.       return( rgb32 );
  173.    }
  174.  
  175. ////////////////////////////////////////////////////////////////////////////////
  176. // Convert CRY16 to RGB32
  177.    
  178.    dword cry16_rgb32( dword cry16, int trans )
  179.    {
  180.       dword chrm, chrl;                // R,G,B Cry Color Table Coordinates
  181.       dword y;                         // Luminance
  182.       float r, g, b;                   // RGB Values
  183.       dword rgb32;
  184.  
  185.       chrm = (cry16 & 0xF000) >> 12;   // Get CrY Values
  186.       chrl = (cry16 & 0x0F00) >> 8;
  187.       y    = (cry16 & 0x00FF);
  188.  
  189.       // Calculate RGB Values
  190.       r = (((float)(  redcv[chrm][chrl]) / 255 ) * y);
  191.       g = (((float)(greencv[chrm][chrl]) / 255 ) * y);
  192.       b = (((float)( bluecv[chrm][chrl]) / 255 ) * y);
  193.  
  194.       rgb32  = (dword)r;
  195.       rgb32 |= (dword)(g) << 8;     
  196.       rgb32 |= (dword)(b) << 16;
  197.  
  198.       if( !rgb32 && trans ) return( rgb32 );
  199.  
  200.       rgb32 |= 0xFF000000;
  201.  
  202.       return( rgb32 );
  203.    }
  204.