color.hh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #ifndef I4_COLOR_HH
  9. #define I4_COLOR_HH
  10. #include "arch.hh"
  11. inline w16 i4_32bpp_to_16bpp(w32 color)
  12. {
  13. w32 r=(color>>16)&0xff, g=(color>>8)&0xff, b=(color>>0)&0xff;
  14. r=(r>>3);
  15. g=(g>>2);
  16. b=(b>>3);
  17. return (r<<(5+6)) | (g<<5) | b;
  18. }
  19. inline w16 i4_32bpp_to_15bpp(w32 color)
  20. {
  21. w32 r=(color>>(16+3)) & (1 | 2 | 4 | 8 | 16);
  22. w32 g=(color>>(8+3)) & (1 | 2 | 4 | 8 | 16);
  23. w32 b=(color>>(0+3)) & (1 | 2 | 4 | 8 | 16);
  24. return (r<<(5+5)) | (g<<5) | b;
  25. }
  26. inline void i4_32bpp_to_rgb(w32 color, w8 &r, w8 &g, w8 &b)
  27. {
  28. r=(color>>16)&0xff;
  29. g=(color>>8)&0xff;
  30. b=color&0xff;
  31. }
  32. inline w32 i4_15bpp_to_32bpp(w32 color)
  33. {
  34. return ((((color & ((1 | 2 | 4 | 8 | 16)<<0)) >> 0) << (3+0)) |
  35. (((color & ((1 | 2 | 4 | 8 | 16)<<5)) >> 5) << (3+8)) |
  36. (((color & ((1 | 2 | 4 | 8 | 16)<<10)) >> 10) << (3+16)));
  37. }
  38. inline w32 i4_16bpp_to_32bpp(w32 color)
  39. {
  40. w32 r=((color>>11) & (1|2|4|8|16)) <<3;
  41. w32 g=((color>>5) & (1|2|4|8|16|32))<<2;
  42. w32 b=((color>>0) & (1|2|4|8|16)) <<3;
  43. return (r<<16)|(g<<8)|b;
  44. }
  45. inline w32 i4_rgb_to_32bit(w8 r, w8 g, w8 b)
  46. {
  47. return (r<<16) | (g<<8) | b;
  48. }
  49. #if (I4_SCREEN_DEPTH==15)
  50. inline w16 i4_32bpp_to_screen(w32 color, w32 *pal)
  51. {
  52. return i4_32bpp_to_15bpp(color);
  53. }
  54. #endif
  55. #if (I4_SCREEN_DEPTH==16)
  56. inline w16 i4_32bpp_to_screen(w32 color, w32 *pal)
  57. {
  58. return i4_32bpp_to_16bpp(color);
  59. }
  60. #endif
  61. #if (I4_SCREEN_DEPTH==32)
  62. inline w16 i4_32bpp_to_screen(w32 color, w32 *pal)
  63. {
  64. return color;
  65. }
  66. #endif
  67. #if (I4_SCREEN_DEPTH==8)
  68. #error need to solve this problem
  69. inline w16 i4_32bpp_to_screen(w32 color, w32 *pal)
  70. { return 0; }
  71. #endif
  72. #endif