FilesHeaders.h 1.7 KB

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