IImage.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. class ColorFilter;
  20. /// Defines which blit method will be selected when image is used for rendering
  21. enum class EImageBlitMode
  22. {
  23. /// Preferred for images that don't need any background
  24. /// Indexed or RGBA: Image can have no transparency and can be only used as background
  25. OPAQUE,
  26. /// Preferred for images that may need transparency
  27. /// Indexed: Image can have only a single color as transparency and has no semi-transparent areas
  28. /// RGBA: full alpha transparency range, e.g. shadows
  29. COLORKEY,
  30. /// Should be avoided if possible, use only for images that use def's with semi-transparency
  31. /// Indexed or RGBA: Image might have full alpha transparency range, e.g. shadows
  32. ALPHA
  33. };
  34. /*
  35. * Base class for images, can be used for non-animation pictures as well
  36. */
  37. class IImage
  38. {
  39. public:
  40. using SpecialPalette = std::vector<ColorRGBA>;
  41. static constexpr int32_t SPECIAL_PALETTE_MASK_CREATURES = 0b11110011;
  42. //draws image on surface "where" at position
  43. virtual void draw(SDL_Surface * where, const Point & pos, const Rect * src = nullptr) const = 0;
  44. virtual void scaleFast(const Point & size) = 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. //set special color for flag
  49. virtual void setFlagColor(PlayerColor player) = 0;
  50. //test transparency of specific pixel
  51. virtual bool isTransparent(const Point & coords) const = 0;
  52. virtual Point dimensions() const = 0;
  53. int width() const;
  54. int height() const;
  55. //only indexed bitmaps, 16 colors maximum
  56. virtual void shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove) = 0;
  57. virtual void adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask) = 0;
  58. virtual void setAlpha(uint8_t value) = 0;
  59. virtual void setBlitMode(EImageBlitMode mode) = 0;
  60. //only indexed bitmaps with 7 special colors
  61. virtual void setSpecialPalette(const SpecialPalette & SpecialPalette, uint32_t colorsToSkipMask) = 0;
  62. virtual ~IImage() = default;
  63. };
  64. class IConstImage
  65. {
  66. public:
  67. virtual Point dimensions() const = 0;
  68. virtual void exportBitmap(const boost::filesystem::path & path) const = 0;
  69. virtual bool isTransparent(const Point & coords) const = 0;
  70. virtual std::shared_ptr<IImage> createImageReference(EImageBlitMode mode) = 0;
  71. virtual std::shared_ptr<IConstImage> horizontalFlip() const = 0;
  72. virtual std::shared_ptr<IConstImage> verticalFlip() const = 0;
  73. virtual ~IConstImage() = default;
  74. };