home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mesa5.zip / mesa5src.zip / colors.h < prev    next >
C/C++ Source or Header  |  2002-11-30  |  12KB  |  495 lines

  1. /*    File name    :    colors.h
  2.  *  Version        :    2.3
  3.  *
  4.  *  Header file for display driver for Mesa 2.3  under 
  5.  *    Windows95 and WindowsNT 
  6.  *    This file defines macros and global variables  needed
  7.  *    for converting color format
  8.  *
  9.  *    Copyright (C) 1996-  Li Wei
  10.  *  Address        :        Institute of Artificial Intelligence
  11.  *                :            & Robotics
  12.  *                :        Xi'an Jiaotong University
  13.  *  Email        :        liwei@aiar.xjtu.edu.cn
  14.  *  Web page    :        http://sun.aiar.xjtu.edu.cn
  15.  *
  16.  *  This file and its associations are partially based on the 
  17.  *  Windows NT driver for Mesa, written by Mark Leaming
  18.  *  (mark@rsinc.com).
  19.  */
  20.  
  21. /* $Log: ddcolors.h 1997/6/14 by Li Wei(liwei@aiar.xjtu.edu.cn)
  22.  * Macros for pixel format defined
  23.  */
  24.  
  25. /*
  26.  * $Log: colors.h,v $
  27.  * Revision 1.3  2002/01/15 18:14:34  kschultz
  28.  * Fixed pixel color component problem and clear code for 24-bit Windows
  29.  *   devices.  (Jeff Lewis)
  30.  *
  31.  * Revision 1.2  2002/01/15 18:11:36  kschultz
  32.  * Remove trailing CR's.   No logical changes.
  33.  *
  34.  * Revision 1.1.1.1  1999/08/19 00:55:42  jtg
  35.  * Imported sources
  36.  *
  37.  * Revision 1.2  1999/01/03 03:08:57  brianp
  38.  * Ted Jump's changes
  39.  *
  40.  * Revision 1.1  1999/01/03 03:08:12  brianp
  41.  * Initial revision
  42.  *
  43.  * Revision 2.0.2  1997/4/30 15:58:00  CST by Li Wei(liwei@aiar.xjtu.edu.cn)
  44.  * Add LUTs need for dithering
  45.  */
  46.  
  47. /* Values for wmesa->pixelformat: */
  48. #ifdef __OS2__
  49.  
  50. typedef unsigned long       DWORD;
  51. typedef unsigned short      WORD;
  52.  
  53. #endif
  54.  
  55. #define PF_8A8B8G8R    3    /* 32-bit TrueColor:  8-A, 8-B, 8-G, 8-R */
  56. #define PF_8R8G8B    4    /* 32-bit TrueColor:  8-R, 8-G, 8-B */
  57. #define PF_5R6G5B    5    /* 16-bit TrueColor:  5-R, 6-G, 5-B bits */
  58. #define PF_DITHER8    6    /* Dithered RGB using a lookup table */
  59. #define PF_LOOKUP    7    /* Undithered RGB using a lookup table */
  60. #define PF_GRAYSCALE    10    /* Grayscale or StaticGray */
  61. #define PF_BADFORMAT    11
  62. #define PF_INDEX8        12
  63.  
  64. char ColorMap16[] = {
  65. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  66. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  67. 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
  68. 0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
  69. 0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,
  70. 0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,
  71. 0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
  72. 0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,
  73. 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,
  74. 0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,
  75. 0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,
  76. 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,
  77. 0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,
  78. 0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,
  79. 0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,
  80. 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
  81. 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
  82. 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
  83. 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
  84. 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
  85. 0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,
  86. 0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
  87. 0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x16,
  88. 0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,
  89. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  90. 0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,
  91. 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,
  92. 0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,
  93. 0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,
  94. 0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,
  95. 0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,
  96. 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F};
  97.  
  98. #define BGR8(r,g,b)        (unsigned)(((BYTE)(b & 0xc0 | (g & 0xe0)>>2 | (r & 0xe0)>>5)))
  99.  
  100. #ifdef __OS2__
  101.     #define BGR16(r,g,b)    ((WORD)(((BYTE)(ColorMap16[b]) | ((BYTE)(g&0xfc) << 3)) | (((WORD)(BYTE)(ColorMap16[r])) << 11)))
  102. //??
  103.     #define BGR24(r,g,b)    (unsigned long)(((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16))) /* <<8 ?? */)
  104. #else
  105.   #ifdef DDRAW
  106.     #define BGR16(r,g,b)    ((WORD)(((BYTE)(ColorMap16[b]) | ((BYTE)(g&0xfc) << 3)) | (((WORD)(BYTE)(ColorMap16[r])) << 11)))
  107.   #else
  108.     #define BGR16(r,g,b)    ((WORD)(((BYTE)(ColorMap16[b]) | ((BYTE)(ColorMap16[g]) << 5)) | (((WORD)(BYTE)(ColorMap16[r])) << 10)))
  109.   #endif
  110.   #define BGR24(r,g,b)  (unsigned long) ((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16)))
  111. #endif
  112.  
  113. #define BGR32(r,g,b)    (unsigned long)((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16)))
  114.  
  115.  
  116. /*
  117.  * If pixelformat==PF_8A8B8G8R:
  118.  */
  119. #define PACK_8A8B8G8R( R, G, B, A )    \
  120.     ( ((A) << 24) | ((B) << 16) | ((G) << 8) | (R) )
  121.  
  122.  
  123. /*
  124.  * If pixelformat==PF_8R8G8B:
  125.  */
  126. #define PACK_8R8G8B( R, G, B)     ( ((R) << 16) | ((G) << 8) | (B) )
  127.  
  128.  
  129. /*
  130.  * If pixelformat==PF_5R6G5B:
  131.  */
  132.  
  133.  
  134. #ifdef __OS2__
  135.   #define PACK_5R6G5B( R, G, B) ((WORD)(((BYTE)(ColorMap16[B]) | ((BYTE)(G&0xfc) << 3)) | (((WORD)(BYTE)(ColorMap16[R])) << 11)))
  136. #else
  137.   #ifdef DDRAW
  138.    #define PACK_5R6G5B( R, G, B) ((WORD)(((BYTE)(ColorMap16[B]) | ((BYTE)(G&0xfc) << 3)) | (((WORD)(BYTE)(ColorMap16[R])) << 11)))
  139.   #else
  140.    #define PACK_5R6G5B( R, G, B) ((WORD)(((BYTE)(ColorMap16[B]) | ((BYTE)(ColorMap16[G]) << 5)) | (((WORD)(BYTE)(ColorMap16[R])) << 10)))
  141.   #endif
  142. #endif
  143. /*----------------------------------------------------------------------------
  144.  
  145. Division lookup tables.  These tables compute 0-255 divided by 51 and
  146. modulo 51.  These tables could approximate gamma correction.
  147.  
  148. */
  149.  
  150. char unsigned const aDividedBy51Rounded[256] =
  151. {
  152.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  153.   0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  154.   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  155.   1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  156.   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  157.   2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  158.   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  159.   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  160.   4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  161.   4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  162.   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  163. };
  164.  
  165. char unsigned const aDividedBy51[256] =
  166. {
  167.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  168.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  169.   0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  170.   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  171.   1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  172.   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  173.   2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  174.   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  175.   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  176.   4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  177.   4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 
  178. };
  179.  
  180. char unsigned const aModulo51[256] =
  181. {
  182.   0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  183.   20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
  184.   38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, 4, 5, 6,
  185.   7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
  186.   26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
  187.   44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  188.   13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
  189.   31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
  190.   49, 50, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
  191.   18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
  192.   36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3,
  193.   4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
  194.   23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  195.   41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, 
  196. };
  197.  
  198. /*----------------------------------------------------------------------------
  199.  
  200. Multiplication LUTs.  These compute 0-5 times 6 and 36.
  201.  
  202. */
  203.  
  204. char unsigned const aTimes6[6] =
  205. {
  206.   0, 6, 12, 18, 24, 30
  207. };
  208.  
  209. char unsigned const aTimes36[6] =
  210. {
  211.   0, 36, 72, 108, 144, 180
  212. };
  213.  
  214.  
  215. /*----------------------------------------------------------------------------
  216.  
  217. Dither matrices for 8 bit to 2.6 bit halftones.
  218.  
  219. */
  220.  
  221. char unsigned const aHalftone16x16[256] =
  222. {
  223.   0, 44, 9, 41, 3, 46, 12, 43, 1, 44, 10, 41, 3, 46, 12, 43,
  224.   34, 16, 25, 19, 37, 18, 28, 21, 35, 16, 26, 19, 37, 18, 28, 21,
  225.   38, 6, 47, 3, 40, 9, 50, 6, 38, 7, 47, 4, 40, 9, 49, 6,
  226.   22, 28, 13, 31, 25, 31, 15, 34, 22, 29, 13, 32, 24, 31, 15, 34,
  227.   2, 46, 12, 43, 1, 45, 10, 42, 2, 45, 11, 42, 1, 45, 11, 42,
  228.   37, 18, 27, 21, 35, 17, 26, 20, 36, 17, 27, 20, 36, 17, 26, 20,
  229.   40, 8, 49, 5, 38, 7, 48, 4, 39, 8, 48, 5, 39, 7, 48, 4,
  230.   24, 30, 15, 33, 23, 29, 13, 32, 23, 30, 14, 33, 23, 29, 14, 32,
  231.   2, 46, 12, 43, 0, 44, 10, 41, 3, 47, 12, 44, 0, 44, 10, 41,
  232.   37, 18, 27, 21, 35, 16, 25, 19, 37, 19, 28, 22, 35, 16, 25, 19,
  233.   40, 9, 49, 5, 38, 7, 47, 4, 40, 9, 50, 6, 38, 6, 47, 3,
  234.   24, 30, 15, 34, 22, 29, 13, 32, 25, 31, 15, 34, 22, 28, 13, 31,
  235.   1, 45, 11, 42, 2, 46, 11, 42, 1, 45, 10, 41, 2, 46, 11, 43,
  236.   36, 17, 26, 20, 36, 17, 27, 21, 35, 16, 26, 20, 36, 18, 27, 21,
  237.   39, 8, 48, 4, 39, 8, 49, 5, 38, 7, 48, 4, 39, 8, 49, 5,
  238.   23, 29, 14, 33, 24, 30, 14, 33, 23, 29, 13, 32, 24, 30, 14, 33,
  239. };
  240.  
  241. char unsigned const aHalftone8x8[64] =
  242. {
  243.    0, 38,  9, 47,  2, 40, 11, 50,
  244.   25, 12, 35, 22, 27, 15, 37, 24,
  245.    6, 44,  3, 41,  8, 47,  5, 43,
  246.   31, 19, 28, 15, 34, 21, 31, 18,
  247.    1, 39, 11, 49,  0, 39, 10, 48,
  248.   27, 14, 36, 23, 26, 13, 35, 23,
  249.    7, 46,  4, 43,  7, 45,  3, 42,
  250.   33, 20, 30, 17, 32, 19, 29, 16,
  251. };
  252.  
  253. char unsigned const aHalftone4x4_1[16] =
  254. {
  255.   0, 25, 6, 31,
  256.   38, 12, 44, 19,
  257.   9, 35, 3, 28,
  258.   47, 22, 41, 15
  259. };
  260.  
  261. char unsigned const aHalftone4x4_2[16] =
  262. {
  263.   41, 3, 9, 28,
  264.   35, 15, 22, 47,
  265.   6, 25, 38, 0,
  266.   19, 44, 31, 12
  267. };
  268.  
  269. /***************************************************************************
  270.   aWinGHalftoneTranslation
  271.  
  272.   Translates a 2.6 bit-per-pixel halftoned representation into the
  273.   slightly rearranged WinG Halftone Palette.
  274. */
  275.  
  276. char unsigned const aWinGHalftoneTranslation[216] =
  277. {
  278.   0,
  279.   29,
  280.   30,
  281.   31,
  282.   32,
  283.   249,
  284.   33,
  285.   34,
  286.   35,
  287.   36,
  288.   37,
  289.   38,
  290.   39,
  291.   40,
  292.   41,
  293.   42,
  294.   43,
  295.   44,
  296.   45,
  297.   46,
  298.   47,
  299.   48,
  300.   49,
  301.   50,
  302.   51,
  303.   52,
  304.   53,
  305.   54,
  306.   55,
  307.   56,
  308.   250,
  309.   250,
  310.   57,
  311.   58,
  312.   59,
  313.   251,
  314.   60,
  315.   61,
  316.   62,
  317.   63,
  318.   64,
  319.   65,
  320.   66,
  321.   67,
  322.   68,
  323.   69,
  324.   70,
  325.   71,
  326.   72,
  327.   73,
  328.   74,
  329.   75,
  330.   76,
  331.   77,
  332.   78,
  333.   79,
  334.   80,
  335.   81,
  336.   82,
  337.   83,
  338.   84,
  339.   85,
  340.   86,
  341.   87,
  342.   88,
  343.   89,
  344.   250,
  345.   90,
  346.   91,
  347.   92,
  348.   93,
  349.   94,
  350.   95,
  351.   96,
  352.   97,
  353.   98,
  354.   99,
  355.   100,
  356.   101,
  357.   102,
  358.   103,
  359.   104,
  360.   105,
  361.   106,
  362.   107,
  363.   108,
  364.   109,
  365.   110,
  366.   111,
  367.   227,
  368.   112,
  369.   113,
  370.   114,
  371.   115,
  372.   116,
  373.   117,
  374.   118,
  375.   119,
  376.   151,
  377.   120,
  378.   121,
  379.   122,
  380.   123,
  381.   124,
  382.   228,
  383.   125,
  384.   126,
  385.   229,
  386.   133,
  387.   162,
  388.   135,
  389.   131,
  390.   132,
  391.   137,
  392.   166,
  393.   134,
  394.   140,
  395.   130,
  396.   136,
  397.   143,
  398.   138,
  399.   139,
  400.   174,
  401.   141,
  402.   142,
  403.   177,
  404.   129,
  405.   144,
  406.   145,
  407.   146,
  408.   147,
  409.   148,
  410.   149,
  411.   150,
  412.   157,
  413.   152,
  414.   153,
  415.   154,
  416.   155,
  417.   156,
  418.   192,
  419.   158,
  420.   159,
  421.   160,
  422.   161,
  423.   196,
  424.   163,
  425.   164,
  426.   165,
  427.   127,
  428.   199,
  429.   167,
  430.   168,
  431.   169,
  432.   170,
  433.   171,
  434.   172,
  435.   173,
  436.   207,
  437.   175,
  438.   176,
  439.   210,
  440.   178,
  441.   179,
  442.   180,
  443.   181,
  444.   182,
  445.   183,
  446.   184,
  447.   185,
  448.   186,
  449.   187,
  450.   188,
  451.   189,
  452.   190,
  453.   191,
  454.   224,
  455.   193,
  456.   194,
  457.   195,
  458.   252,
  459.   252,
  460.   197,
  461.   198,
  462.   128,
  463.   253,
  464.   252,
  465.   200,
  466.   201,
  467.   202,
  468.   203,
  469.   204,
  470.   205,
  471.   206,
  472.   230,
  473.   208,
  474.   209,
  475.   231,
  476.   211,
  477.   212,
  478.   213,
  479.   214,
  480.   215,
  481.   216,
  482.   217,
  483.   218,
  484.   219,
  485.   220,
  486.   221,
  487.   222,
  488.   254,
  489.   223,
  490.   232,
  491.   225,
  492.   226,
  493.   255,
  494. };
  495.