SDLImage.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * SDLImage.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 "../render/IImage.h"
  12. #include "../../lib/Point.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class JsonNode;
  15. VCMI_LIB_NAMESPACE_END
  16. class CDefFile;
  17. struct SDL_Surface;
  18. struct SDL_Palette;
  19. /*
  20. * Wrapper around SDL_Surface
  21. */
  22. class SDLImageShared final : public ISharedImage, public std::enable_shared_from_this<SDLImageShared>, boost::noncopyable
  23. {
  24. //Surface without empty borders
  25. SDL_Surface * surf;
  26. SDL_Palette * originalPalette;
  27. //size of left and top borders
  28. Point margins;
  29. //total size including borders
  30. Point fullSize;
  31. // Keep the original palette, in order to do color switching operation
  32. void savePalette();
  33. void optimizeSurface();
  34. public:
  35. //Load image from def file
  36. SDLImageShared(const CDefFile *data, size_t frame, size_t group=0);
  37. //Load from bitmap file
  38. SDLImageShared(const ImagePath & filename);
  39. //Create using existing surface, extraRef will increase refcount on SDL_Surface
  40. SDLImageShared(SDL_Surface * from);
  41. ~SDLImageShared();
  42. void draw(SDL_Surface * where, SDL_Palette * palette, const Point & dest, const Rect * src, const ColorRGBA & colorMultiplier, uint8_t alpha, EImageBlitMode mode) const override;
  43. void exportBitmap(const boost::filesystem::path & path, SDL_Palette * palette) const override;
  44. Point dimensions() const override;
  45. bool isTransparent(const Point & coords) const override;
  46. Rect contentRect() const override;
  47. const SDL_Palette * getPalette() const override;
  48. [[nodiscard]] std::shared_ptr<const ISharedImage> horizontalFlip() const override;
  49. [[nodiscard]] std::shared_ptr<const ISharedImage> verticalFlip() const override;
  50. [[nodiscard]] std::shared_ptr<const ISharedImage> scaleInteger(int factor, SDL_Palette * palette, EImageBlitMode blitMode) const override;
  51. [[nodiscard]] std::shared_ptr<const ISharedImage> scaleTo(const Point & size, SDL_Palette * palette) const override;
  52. friend class SDLImageLoader;
  53. };