gPalette.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GPALETTE_H_
  23. #define _GPALETTE_H_
  24. //Includes
  25. #ifndef _PLATFORM_H_
  26. #include "platform/platform.h"
  27. #endif
  28. #ifndef _COLOR_H_
  29. #include "graphics/gColor.h"
  30. #endif
  31. //-------------------------------------- Forward decls.
  32. class Stream;
  33. //------------------------------------------------------------------------------
  34. //-------------------------------------- GPalette
  35. //
  36. class GPalette
  37. {
  38. public:
  39. enum PaletteType {
  40. RGB,
  41. RGBA
  42. };
  43. protected:
  44. PaletteType m_paletteType;
  45. ColorI m_pColors[256];
  46. public:
  47. GPalette();
  48. virtual ~GPalette();
  49. PaletteType getPaletteType() const;
  50. void setPaletteType(const PaletteType pt) { m_paletteType = pt; }
  51. const ColorI* getColors() const;
  52. ColorI* getColors();
  53. const ColorI& getColor(const U32 in_index) const;
  54. ColorI& getColor(const U32 in_index);
  55. //-------------------------------------- Supplimentary output members
  56. public:
  57. bool readMSPalette(Stream& io_rStream);
  58. bool readMSPalette(const char* in_pFileName);
  59. bool writeMSPalette(Stream& io_rStream) const;
  60. bool writeMSPalette(const char* in_pFileName) const;
  61. //-------------------------------------- Persistent members
  62. public:
  63. bool read(Stream& io_rStream);
  64. bool write(Stream& io_rStream) const;
  65. private:
  66. static const U32 csm_fileVersion;
  67. };
  68. //------------------------------------------------------------------------------
  69. //-------------------------------------- Inlines (Trust)
  70. //
  71. inline GPalette::PaletteType
  72. GPalette::getPaletteType() const
  73. {
  74. return m_paletteType;
  75. }
  76. inline const ColorI*
  77. GPalette::getColors() const
  78. {
  79. return m_pColors;
  80. }
  81. inline ColorI*
  82. GPalette::getColors()
  83. {
  84. return m_pColors;
  85. }
  86. inline const ColorI&
  87. GPalette::getColor(const U32 in_index) const
  88. {
  89. AssertFatal(in_index < 256, "Out of range index");
  90. return m_pColors[in_index];
  91. }
  92. inline ColorI&
  93. GPalette::getColor(const U32 in_index)
  94. {
  95. AssertFatal(in_index < 256, "Out of range index");
  96. return m_pColors[in_index];
  97. }
  98. #endif //_GPALETTE_H_