Colour.h
上传用户:lhwx1029
上传日期:2013-03-07
资源大小:1173k
文件大小:7k
源码类别:

3D图形编程

开发平台:

Visual C++

  1. #if !defined(_COLOUR_H_)
  2. #define _COLOUR_H_
  3. /** 3DGPL *************************************************
  4.  * ()                                                     *
  5.  * Header for colour related stuff.                       *
  6.  *                                                        *
  7.  * Ifdefs:                                                *
  8.  *  _CI_                     Colour/Intensity model;      *
  9.  *  _RGB_                    RGB model;                   *
  10.  *  _8BPP_                   8 bits per pixel;            *
  11.  *  _16BPP_                  16 bits per pixel;           *
  12.  *  _32BPP_                  32 bits per pixel.           *
  13.  *                                                        *
  14.  * Files:                                                 *
  15.  *  colour.c                 Hardware specific stuff.     *
  16.  *                                                        *
  17.  * (c) 1995-98 Sergei Savchenko, (savs@cs.mcgill.ca)      *
  18. **********************************************************/
  19. #include "RayTracing.h"           /* HW_pixel */
  20. #if defined(_CI_)                           /* palette based model */
  21. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  22.  * CI colour model.                                      *
  23.  * Represents each colour as an index (C) and its        *
  24.  * intensity (I). Limited number of colours is placed    *
  25.  * into the hardware palette and a square lookup table   *
  26.  * is maintained mapping colour indices and intensities  *
  27.  * to colours in the palette.                            *
  28. * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  29. #define CL_LNG_COLOUR           1           /* intensity */
  30. #define CL_COLOUR_LEVELS      256           /* number of colours */
  31. #define CL_LIGHT_LEVELS        32           /* gradations of light intensity */
  32. #define CL_LOG_COLOUR_LEVELS    8           
  33. #define CL_LIGHT_MASK        0x1f           /* for clamping light */
  34. #define CL_clamp_light(colour) (((colour)>CL_LIGHT_MASK)?CL_LIGHT_MASK:(colour))
  35. /**********************************************************
  36.  * A colour.                                              *
  37.  *                                                        *
  38.  * +----------+                                           *
  39.  * | cl_red   |                                           *
  40.  * | cl_green |                                           *
  41.  * | cl_blue  |                                           *
  42.  * +----------+                                           *
  43.  *                                                        *
  44. **********************************************************/
  45. struct CL_colour                            /* describes colour */
  46. {
  47.  int cl_red;
  48.  int cl_green;
  49.  int cl_blue;                               /* intensity components */
  50. };
  51. /**********************************************************
  52.  * A palette.                                             *
  53.  *                                                        *
  54.  * +---------------+                                      *
  55.  * | cl_no_colours |                                      *
  56.  * |               |   +-----------+--  -+                *
  57.  * | cl_colours------->| CL_colour | ... |                *
  58.  * |               |   +-----------+-----+                *
  59.  * +---------------+                                      *
  60.  *                                                        *
  61. **********************************************************/
  62. struct CL_palette                           /* describes a palette */
  63. {
  64.  int cl_no_colours;
  65.  struct CL_colour *cl_colours;              /* actual colours */
  66.  HW_pixel *cl_intensity_table;
  67. };
  68. extern struct CL_palette *CL_colours;
  69. void CL_init_colour(struct CL_palette *palette);
  70. HW_pixel CL_light(HW_pixel colour,int light);
  71. #endif
  72. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  73.  * RGB colour model.                                     *
  74.  * Each colour is represented as three intensities one   *
  75.  * for each of the pure components red, green and blue.  *
  76. * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  77. #if defined(_RGB_)                          /* component based model */
  78. #define CL_LNG_COLOUR           3           /* R G B */
  79. #if defined(_8BPP_)                         /* 8 bits per pixel */
  80. #define CL_COLOUR_LEVELS        8           /* number of colours */
  81. #define CL_LIGHT_LEVELS       256           /* gradations of light intensity */
  82. #define CL_COLOUR_MASK_RED   0x07           /* for clamping colours */
  83. #define CL_COLOUR_MASK_GREEN 0x03           
  84. #define CL_COLOUR_MASK_BLUE  0x07           
  85. #define CL_LIGHT_MASK        0xff           /* for clamping light */
  86. #define CL_RED_SHIFT            5           /* offset for red */
  87. #define CL_GREEN_SHIFT          3           /* offset for green */
  88. #define CL_BLUE_SHIFT           0           /* offset for blue */
  89. #endif
  90. #if defined(_16BPP_)                        /* 16 bits per pixel */
  91. #define CL_COLOUR_LEVELS       32           /* number of colours */
  92. #define CL_LIGHT_LEVELS       256           /* gradations of light intensity */
  93. #define CL_COLOUR_MASK_RED   0x1f           /* for clamping colours */
  94. #define CL_COLOUR_MASK_GREEN 0x1f           
  95. #define CL_COLOUR_MASK_BLUE  0x1f           
  96. #define CL_LIGHT_MASK        0xff           /* for clamping light */
  97. #define CL_RED_SHIFT           11           /* offset for red */
  98. #define CL_GREEN_SHIFT          6           /* offset for green */
  99. #define CL_BLUE_SHIFT           0           /* offset for blue */
  100. #endif
  101. #if defined(_32BPP_)                        /* 32 bits per pixel */
  102. #define CL_COLOUR_LEVELS      256           /* number of colours */
  103. #define CL_LIGHT_LEVELS       256           /* gradations of light intensity */
  104. #define CL_COLOUR_MASK_RED   0xff           /* for clamping colours */
  105. #define CL_COLOUR_MASK_GREEN 0xff           
  106. #define CL_COLOUR_MASK_BLUE  0xff           
  107. #define CL_LIGHT_MASK        0xff           /* for clamping light */
  108. #define CL_RED_SHIFT           16           /* offset for red */
  109. #define CL_GREEN_SHIFT          8           /* offset for green */
  110. #define CL_BLUE_SHIFT           0           /* offset for blue */
  111. #endif
  112. #define CL_clamp_red(colour)   (((colour)>CL_COLOUR_MASK_RED)?CL_COLOUR_MASK_RED:(colour))
  113. #define CL_clamp_green(colour) (((colour)>CL_COLOUR_MASK_GREEN)?CL_COLOUR_MASK_GREEN:(colour))
  114. #define CL_clamp_blue(colour)  (((colour)>CL_COLOUR_MASK_BLUE)?CL_COLOUR_MASK_BLUE:(colour))
  115. #define CL_clamp_light(colour) (((colour)>CL_LIGHT_MASK)?CL_LIGHT_MASK:(colour))
  116. #define CL_red(colour)   (((colour)>>CL_RED_SHIFT)&CL_COLOUR_MASK_RED)
  117. #define CL_green(colour) (((colour)>>CL_GREEN_SHIFT)&CL_COLOUR_MASK_GREEN)
  118. #define CL_blue(colour)  (((colour)>>CL_BLUE_SHIFT)&CL_COLOUR_MASK_BLUE)
  119. void CL_init_colour(void);
  120. HW_pixel CL_colour(int red_light,
  121.                    int green_light,
  122.                    int blue_light
  123.                   );
  124. HW_pixel CL_light(HW_pixel colour,int red_light,
  125.                                   int green_light,
  126.                                   int blue_light
  127.                  );
  128. #endif
  129. /**********************************************************/
  130. #endif