IImage.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. /// Image can have no transparency and can be only used as background
  24. OPAQUE,
  25. /// Image can have only a single color as transparency and has no semi-transparent areas
  26. COLORKEY,
  27. /// Image might have full alpha transparency range, e.g. shadows
  28. ALPHA
  29. };
  30. /*
  31. * Base class for images, can be used for non-animation pictures as well
  32. */
  33. class IImage
  34. {
  35. public:
  36. using SpecialPalette = std::vector<ColorRGBA>;
  37. static constexpr int32_t SPECIAL_PALETTE_MASK_CREATURES = 0b11110011;
  38. //draws image on surface "where" at position
  39. virtual void draw(SDL_Surface * where, const Point & pos, const Rect * src = nullptr) const = 0;
  40. //virtual void draw(SDL_Surface * where, const Rect * dest, const Rect * src) const = 0;
  41. virtual void scaleFast(const Point & size) = 0;
  42. virtual void exportBitmap(const boost::filesystem::path & path) const = 0;
  43. //Change palette to specific player
  44. virtual void playerColored(PlayerColor player)=0;
  45. //set special color for flag
  46. virtual void setFlagColor(PlayerColor player)=0;
  47. //test transparency of specific pixel
  48. virtual bool isTransparent(const Point & coords) const = 0;
  49. virtual Point dimensions() const = 0;
  50. int width() const;
  51. int height() const;
  52. //only indexed bitmaps, 16 colors maximum
  53. virtual void shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove) = 0;
  54. virtual void adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask) = 0;
  55. virtual void setAlpha(uint8_t value) = 0;
  56. virtual void setBlitMode(EImageBlitMode mode) = 0;
  57. //only indexed bitmaps with 7 special colors
  58. virtual void setSpecialPalette(const SpecialPalette & SpecialPalette, uint32_t colorsToSkipMask) = 0;
  59. virtual void horizontalFlip() = 0;
  60. virtual void verticalFlip() = 0;
  61. virtual ~IImage() = default;
  62. };
  63. class IConstImage
  64. {
  65. public:
  66. virtual Point dimensions() const = 0;
  67. virtual void exportBitmap(const boost::filesystem::path & path) const = 0;
  68. virtual bool isTransparent(const Point & coords) const = 0;
  69. virtual std::shared_ptr<IImage> createImageReference() = 0;
  70. virtual ~IConstImage() = default;
  71. };