2
0

SDLImage.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 = nullptr;
  26. SDL_Palette * originalPalette = nullptr;
  27. //size of left and top borders
  28. Point margins;
  29. //total size including borders
  30. Point fullSize;
  31. std::atomic_bool upscalingInProgress = false;
  32. // Keep the original palette, in order to do color switching operation
  33. void savePalette();
  34. void optimizeSurface();
  35. public:
  36. //Load image from def file
  37. SDLImageShared(const CDefFile *data, size_t frame, size_t group=0);
  38. //Load from bitmap file
  39. SDLImageShared(const ImagePath & filename);
  40. //Create using existing surface, extraRef will increase refcount on SDL_Surface
  41. SDLImageShared(SDL_Surface * from);
  42. ~SDLImageShared();
  43. /// Creates image at specified scaling factor from source image
  44. static std::shared_ptr<SDLImageShared> createScaled(const SDLImageShared * from, int integerScaleFactor, EScalingAlgorithm algorithm);
  45. void scaledDraw(SDL_Surface * where, SDL_Palette * palette, const Point & scaling, const Point & dest, const Rect * src, const ColorRGBA & colorMultiplier, uint8_t alpha, EImageBlitMode mode) const override;
  46. void draw(SDL_Surface * where, SDL_Palette * palette, const Point & dest, const Rect * src, const ColorRGBA & colorMultiplier, uint8_t alpha, EImageBlitMode mode) const override;
  47. void exportBitmap(const boost::filesystem::path & path, SDL_Palette * palette) const override;
  48. Point dimensions() const override;
  49. bool isTransparent(const Point & coords) const override;
  50. Rect contentRect() const override;
  51. bool isLoading() const override;
  52. const SDL_Palette * getPalette() const override;
  53. [[nodiscard]] std::shared_ptr<const ISharedImage> horizontalFlip() const override;
  54. [[nodiscard]] std::shared_ptr<const ISharedImage> verticalFlip() const override;
  55. [[nodiscard]] std::shared_ptr<const ISharedImage> scaleInteger(int factor, SDL_Palette * palette, EImageBlitMode blitMode) const override;
  56. [[nodiscard]] std::shared_ptr<const ISharedImage> scaleTo(const Point & size, SDL_Palette * palette) const override;
  57. friend class SDLImageLoader;
  58. };