FilesHeaders.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #include <SDL_endian.h>
  3. #include "CPaletteRGBA.h"
  4. namespace Gfx
  5. {
  6. #define RGB_PALETTE_SIZE 0x300
  7. #define H3PCX_HEADER_SIZE sizeof(SH3PcxFile)
  8. #define H3DEF_HEADER_SIZE sizeof(SH3DefFile)
  9. #define SELF_ADDR reinterpret_cast<const ui8*>(this)
  10. #ifdef _MSC_VER
  11. #pragma pack(1)
  12. #pragma warning(disable : 4200)
  13. #endif
  14. struct SH3PcxFile
  15. {
  16. ui32 size;
  17. ui32 width;
  18. ui32 height;
  19. ui8 data[];
  20. // palette = last 256*3 bytes of PCX
  21. inline const ColorRGB* palette(size_t sizeOfPcx) const {
  22. return (ColorRGB*) (SELF_ADDR + sizeOfPcx - RGB_PALETTE_SIZE);
  23. }
  24. };
  25. struct SH3DefSprite
  26. {
  27. ui32 size;
  28. ui32 format; /// format in which pixel data is stored
  29. ui32 fullWidth; /// full width and height of frame, including borders
  30. ui32 fullHeight;
  31. ui32 width; /// width and height of pixel data, borders excluded
  32. ui32 height;
  33. si32 leftMargin;
  34. si32 topMargin;
  35. ui8 data[];
  36. };
  37. struct SH3DefBlock {
  38. ui32 id;
  39. ui32 entriesCount;
  40. ui32 unknown1;
  41. ui32 unknown2;
  42. char names[][13]; // [entriesCount][13] - array of frames names
  43. inline ua_ui32_ptr offsets() const {
  44. return (ua_ui32_ptr)(names + SDL_SwapLE32(entriesCount));
  45. } // array of offsets of frames
  46. };
  47. struct SH3DefFile {
  48. ui32 type;
  49. ui32 width;
  50. ui32 height;
  51. ui32 totalBlocks;
  52. ColorRGB palette[256];
  53. // SDefHeader is followed by a series of SH3DefBlock
  54. SH3DefBlock firstBlock;
  55. // Number of entries (sprites) in first block
  56. inline ui32 fbEntrCount() const { return firstBlock.entriesCount; };
  57. inline SH3DefSprite& getSprite(ui32 offset) const {
  58. return *(SH3DefSprite*) (SELF_ADDR + offset);
  59. }
  60. };
  61. #ifdef _MSC_VER
  62. #pragma warning(default : 4200)
  63. #pragma pack()
  64. #endif
  65. #undef SELF_ADDR
  66. }