CDefFile.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * CDefFile.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../../lib/vcmi_endian.h"
  12. class IImageLoader;
  13. struct SDL_Color;
  14. /// Class for def loading
  15. /// After loading will store general info (palette and frame offsets) and pointer to file itself
  16. class CDefFile
  17. {
  18. private:
  19. PACKED_STRUCT_BEGIN
  20. struct SSpriteDef
  21. {
  22. ui32 size;
  23. ui32 format; /// format in which pixel data is stored
  24. ui32 fullWidth; /// full width and height of frame, including borders
  25. ui32 fullHeight;
  26. ui32 width; /// width and height of pixel data, borders excluded
  27. ui32 height;
  28. si32 leftMargin;
  29. si32 topMargin;
  30. } PACKED_STRUCT_END;
  31. //offset[group][frame] - offset of frame data in file
  32. std::map<size_t, std::vector <size_t> > offset;
  33. std::unique_ptr<ui8[]> data;
  34. std::unique_ptr<SDL_Color[]> palette;
  35. public:
  36. CDefFile(std::string Name);
  37. ~CDefFile();
  38. //load frame as SDL_Surface
  39. void loadFrame(size_t frame, size_t group, IImageLoader &loader) const;
  40. const std::map<size_t, size_t> getEntries() const;
  41. };