QGearsPaletteFileSerializer.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. -----------------------------------------------------------------------------
  3. The MIT License (MIT)
  4. Copyright (c) 2013-08-22 Tobias Peters <tobias.peters@kreativeffekt.at>
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. -----------------------------------------------------------------------------
  21. */
  22. #ifndef __QGearsPaletteFileSerializer_H__
  23. #define __QGearsPaletteFileSerializer_H__
  24. #include <OgrePixelFormat.h>
  25. #include "common/TypeDefine.h"
  26. #include "QGearsPaletteFile.h"
  27. #include "QGearsSerializer.h"
  28. namespace QGears
  29. {
  30. class PaletteFileSerializer : public Serializer
  31. {
  32. public:
  33. PaletteFileSerializer();
  34. virtual ~PaletteFileSerializer();
  35. virtual void importPaletteFile( Ogre::DataStreamPtr &stream, PaletteFile* pDest );
  36. enum {
  37. BIT_MASK_RED = 0x001F
  38. ,BIT_MASK_GREEN = 0x03E0
  39. ,BIT_MASK_BLUE = 0x7C00
  40. ,BIT_SIZE = 0x001F
  41. ,BIT_MASK_RGB = BIT_MASK_BLUE | BIT_MASK_GREEN | BIT_MASK_RED
  42. ,BIT_MASK_ALPHA = 0x8000
  43. };
  44. struct Header
  45. {
  46. uint32 file_size;
  47. uint16 pal_x;
  48. uint16 pal_y;
  49. uint16 colors_per_page;
  50. uint16 page_count;
  51. };
  52. typedef PaletteFile::Color Color;
  53. typedef PaletteFile::Page Page;
  54. protected:
  55. virtual void readFileHeader( Ogre::DataStreamPtr &stream );
  56. virtual void readObject( Ogre::DataStreamPtr &stream, Color &pDest );
  57. virtual void readObject( Ogre::DataStreamPtr &stream, Page &pDest );
  58. using Serializer::readObject;
  59. virtual void convertColour( uint16 &colour ) const;
  60. static const Ogre::PixelFormat PIXEL_FORMAT;
  61. template<typename ValueType> void
  62. readVector( Ogre::DataStreamPtr &stream, std::vector<ValueType> &pDest, size_t count )
  63. {
  64. pDest.clear();
  65. pDest.reserve( count );
  66. for( size_t i( count ); i--; )
  67. {
  68. ValueType in_tmp;
  69. readObject( stream, in_tmp );
  70. pDest.push_back( in_tmp );
  71. }
  72. }
  73. private:
  74. Header m_header;
  75. };
  76. }
  77. #endif // __QGearsPaletteFileSerializer_H__