IImage.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * IImage.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/filesystem/ResourcePath.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class PlayerColor;
  14. class Rect;
  15. class Point;
  16. class ColorRGBA;
  17. VCMI_LIB_NAMESPACE_END
  18. struct SDL_Surface;
  19. struct SDL_Palette;
  20. class ColorFilter;
  21. class ISharedImage;
  22. /// Defines which blit method will be selected when image is used for rendering
  23. enum class EImageBlitMode : uint8_t
  24. {
  25. /// Preferred for images that don't need any background
  26. /// Indexed or RGBA: Image can have no transparency and can be only used as background
  27. OPAQUE,
  28. /// Preferred for images that may need transparency
  29. /// Indexed: Image can have only a single color as transparency and has no semi-transparent areas
  30. /// RGBA: full alpha transparency range, e.g. shadows
  31. COLORKEY,
  32. /// Should be avoided if possible, use only for images that use def's with semi-transparency
  33. /// Indexed or RGBA: Image might have full alpha transparency range, e.g. shadows
  34. ALPHA
  35. };
  36. /// Base class for images for use in client code.
  37. /// This class represents current state of image, with potential transformations applied, such as player coloring
  38. class IImage
  39. {
  40. public:
  41. //draws image on surface "where" at position
  42. virtual void draw(SDL_Surface * where, const Point & pos, const Rect * src = nullptr) const = 0;
  43. virtual void scaleTo(const Point & size) = 0;
  44. virtual void scaleInteger(int factor) = 0;
  45. virtual void exportBitmap(const boost::filesystem::path & path) const = 0;
  46. //Change palette to specific player
  47. virtual void playerColored(PlayerColor player) = 0;
  48. //test transparency of specific pixel
  49. virtual bool isTransparent(const Point & coords) const = 0;
  50. virtual Point dimensions() const = 0;
  51. int width() const;
  52. int height() const;
  53. //only indexed bitmaps, 16 colors maximum
  54. virtual void shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove) = 0;
  55. virtual void adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask) = 0;
  56. virtual void setAlpha(uint8_t value) = 0;
  57. virtual void setBlitMode(EImageBlitMode mode) = 0;
  58. //only indexed bitmaps with 7 special colors
  59. virtual void setOverlayColor(const ColorRGBA & color) = 0;
  60. virtual void setShadowEnabled(bool on) = 0;
  61. virtual void setBodyEnabled(bool on) = 0;
  62. virtual void setOverlayEnabled(bool on) = 0;
  63. virtual std::shared_ptr<const ISharedImage> getSharedImage() const = 0;
  64. virtual ~IImage() = default;
  65. };
  66. /// Base class for image data, mostly for internal use
  67. /// Represents unmodified pixel data, usually loaded from file
  68. /// This image can be shared between multiple image handlers (IImage instances)
  69. class ISharedImage
  70. {
  71. public:
  72. virtual Point dimensions() const = 0;
  73. virtual void exportBitmap(const boost::filesystem::path & path, SDL_Palette * palette) const = 0;
  74. virtual bool isTransparent(const Point & coords) const = 0;
  75. virtual void draw(SDL_Surface * where, SDL_Palette * palette, const Point & dest, const Rect * src, const ColorRGBA & colorMultiplier, uint8_t alpha, EImageBlitMode mode) const = 0;
  76. virtual std::shared_ptr<IImage> createImageReference(EImageBlitMode mode) const = 0;
  77. virtual std::shared_ptr<const ISharedImage> horizontalFlip() const = 0;
  78. virtual std::shared_ptr<const ISharedImage> verticalFlip() const = 0;
  79. virtual std::shared_ptr<const ISharedImage> scaleInteger(int factor, SDL_Palette * palette) const = 0;
  80. virtual std::shared_ptr<const ISharedImage> scaleTo(const Point & size, SDL_Palette * palette) const = 0;
  81. virtual ~ISharedImage() = default;
  82. };