pal.hh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 __PALETTE_HPP_
  9. #define __PALETTE_HPP_
  10. #include "arch.hh"
  11. #include "isllist.hh"
  12. #include "init/init.hh"
  13. enum i4_pixel_depth
  14. {
  15. I4_32BIT=0, // 16.7 mil & alpha
  16. I4_16BIT=1, // 64K color
  17. I4_8BIT=2, // 256 color
  18. I4_4BIT=3, // 16 color
  19. I4_2BIT=4 // 2 color
  20. } ;
  21. class i4_file_class;
  22. struct i4_pixel_format
  23. {
  24. // these not valid for 2,4, and 8 bit pixel depths
  25. w32 red_mask, red_shift, red_bits;
  26. w32 green_mask, green_shift, green_bits;
  27. w32 blue_mask, blue_shift, blue_bits;
  28. w32 alpha_mask, alpha_shift, alpha_bits;
  29. // lookup is not valid for 16 & 32 bit pixel depths
  30. w32 *lookup;
  31. i4_pixel_depth pixel_depth;
  32. void calc_shift();
  33. void default_format();
  34. w32 write(i4_file_class *f);
  35. void read(i4_file_class *f);
  36. };
  37. class i4_pal
  38. {
  39. public:
  40. i4_pal *next;
  41. i4_pixel_format source;
  42. virtual i4_bool can_convert(const i4_pixel_format *source_fmt,
  43. const i4_pixel_format *dest_fmt) const = 0;
  44. virtual i4_color convert(const i4_color source_pixel,
  45. const i4_pixel_format *dest_fmt) const = 0;
  46. virtual ~i4_pal() { ; }
  47. };
  48. class i4_lookup_pal : public i4_pal
  49. {
  50. public:
  51. virtual i4_bool can_convert(const i4_pixel_format *source,
  52. const i4_pixel_format *dest) const;
  53. virtual i4_color convert(const i4_color source,
  54. const i4_pixel_format *dest) const;
  55. i4_lookup_pal(i4_pixel_format *source);
  56. virtual ~i4_lookup_pal();
  57. };
  58. class i4_rgb_pal : public i4_pal
  59. {
  60. public:
  61. i4_rgb_pal(i4_pixel_format *source);
  62. virtual i4_bool can_convert(const i4_pixel_format *source,
  63. const i4_pixel_format *dest) const;
  64. virtual i4_color convert(const i4_color source,
  65. const i4_pixel_format *dest) const;
  66. };
  67. class i4_pal_manager_class : public i4_init_class
  68. {
  69. i4_isl_list<i4_pal> pal_list;
  70. i4_pal *def32, *def_na_32, *def8;
  71. public:
  72. void init();
  73. void uninit();
  74. i4_pal *register_pal(i4_pixel_format *format);
  75. // c will be converted from 32bit color to dest_format
  76. i4_color convert_32_to(i4_color c, const i4_pixel_format *dest_format) const;
  77. // c will be converted from source_format to 32bit color
  78. i4_color convert_to_32(i4_color c, const i4_pal *source_format) const;
  79. const i4_pal *default_no_alpha_32() { return def_na_32; }
  80. const i4_pal *default_32() { return def32; }
  81. const i4_pal *default_8() { return def8; }
  82. } ;
  83. extern i4_pal_manager_class i4_pal_man;
  84. w32 g1_light_color(w32 color_32bit, float intensity);
  85. #endif