QGearsTexFile.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. -----------------------------------------------------------------------------
  3. The MIT License (MIT)
  4. Copyright (c) 2013-07-30 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 __QGearsTexFile_H__
  23. #define __QGearsTexFile_H__
  24. #include <vector>
  25. #include <boost/cstdint.hpp>
  26. #include <OgreImageCodec.h>
  27. #include <OgrePlatform.h>
  28. #include "common/TypeDefine.h"
  29. namespace QGears
  30. {
  31. class TexFile
  32. {
  33. public:
  34. TexFile();
  35. virtual ~TexFile();
  36. void read( Ogre::DataStreamPtr& input );
  37. void readHeader( Ogre::DataStreamPtr& input );
  38. void readPalleted( Ogre::DataStreamPtr& input );
  39. Ogre::MemoryDataStream* getPixelData() const;
  40. Ogre::ImageCodec::ImageData* getImageData() const;
  41. typedef Ogre::int32 entry_t;
  42. #if OGRE_COMPILER == OGRE_COMPILER_MSVC
  43. #pragma pack (push, 1)
  44. #else
  45. #pragma pack (1)
  46. #endif
  47. struct BitData
  48. {
  49. entry_t color_min;
  50. entry_t color_max;
  51. entry_t alpha_min;
  52. entry_t alpha_max;
  53. entry_t pixel_min;
  54. entry_t pixel_max;
  55. };
  56. struct ImageData
  57. {
  58. entry_t bit_depth;
  59. entry_t width;
  60. entry_t height;
  61. entry_t pitch;
  62. };
  63. struct PaletteData
  64. {
  65. entry_t flag;
  66. entry_t index_bits;
  67. entry_t index_8bit;
  68. entry_t total_color_count;
  69. entry_t colors_per_palette;
  70. };
  71. struct RGBAData
  72. {
  73. entry_t red;
  74. entry_t green;
  75. entry_t blue;
  76. entry_t alpha;
  77. };
  78. struct PixelFormat
  79. {
  80. entry_t bits_per_pixel;
  81. entry_t bytes_per_pixel;
  82. RGBAData bit_count;
  83. RGBAData bit_mask;
  84. RGBAData bit_shift;
  85. RGBAData bit_count_unused;
  86. RGBAData shades;
  87. };
  88. struct Header
  89. {
  90. entry_t version;
  91. entry_t unknown_0x04;
  92. entry_t color_key_flag;
  93. entry_t unknown_0x0C;
  94. entry_t unknown_0x10;
  95. BitData bit_data;
  96. entry_t palette_type;
  97. entry_t palette_count;
  98. entry_t palette_total_color_count;
  99. ImageData image_data;
  100. entry_t unknown_0x48;
  101. PaletteData palette_data;
  102. entry_t runtime_data_ptr_palette_data;
  103. PixelFormat pixel_format;
  104. entry_t color_key_array_flag;
  105. entry_t runtime_data_ptr_color_key_array;
  106. entry_t reference_alpha;
  107. entry_t runtime_data_02;
  108. entry_t unknown_0xCC;
  109. entry_t runtime_data_palette_index;
  110. entry_t runtime_data_ptr_image_data;
  111. entry_t runtime_data_04;
  112. entry_t unknown_06;
  113. entry_t unknown_07;
  114. entry_t unknown_08;
  115. entry_t unknown_09;
  116. } m_header;
  117. // reversing ff7 code
  118. // structure @ 0x3c
  119. // size 0x80
  120. struct rev_TextureFormat
  121. {
  122. entry_t width;
  123. entry_t height;
  124. entry_t pitch;
  125. entry_t unknown_0x48;
  126. entry_t palette_flag;
  127. entry_t bits_per_palette_index;
  128. entry_t palette_index_8bit;
  129. entry_t palette_size;
  130. entry_t palette_color_count;
  131. entry_t runtime_data_ptr_palette_data;
  132. PixelFormat pixel_format;
  133. };
  134. #if OGRE_COMPILER == OGRE_COMPILER_MSVC
  135. #pragma pack (pop)
  136. #else
  137. #pragma pack ()
  138. #endif
  139. enum PaletteType
  140. {
  141. // as in ogre, eg msb -> lsb
  142. PF_A8R8G8B8 = 0x00
  143. ,PF_FLOAT32_ARGB = 0x01
  144. ,PF_B8G8R8A8 = 0x02
  145. };
  146. typedef ColorA8R8G8B8 Color;
  147. typedef std::vector<Color> t_Palette;
  148. typedef std::vector<Color> t_ImageData;
  149. t_Palette m_palette;
  150. t_ImageData m_image_data;
  151. private:
  152. void flipEndian(void * pData, size_t size, size_t count) const;
  153. void flipEndian(void * pData, size_t size) const;
  154. static const Ogre::uint8 USE_REFERENCE_ALPHA;
  155. };
  156. }
  157. #endif // __QGearsTexFile_H__