IImage.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. VCMI_LIB_NAMESPACE_BEGIN
  12. class PlayerColor;
  13. class Rect;
  14. class Point;
  15. VCMI_LIB_NAMESPACE_END
  16. struct SDL_Surface;
  17. struct SDL_Color;
  18. class ColorFilter;
  19. /// Defines which blit method will be selected when image is used for rendering
  20. enum class EImageBlitMode : uint8_t
  21. {
  22. /// Image can have no transparency and can be only used as background
  23. OPAQUE,
  24. /// Image can have only a single color as transparency and has no semi-transparent areas
  25. COLORKEY,
  26. /// Image might have full alpha transparency range, e.g. shadows
  27. ALPHA
  28. };
  29. /*
  30. * Base class for images, can be used for non-animation pictures as well
  31. */
  32. class IImage
  33. {
  34. public:
  35. using SpecialPalette = std::vector<SDL_Color>;
  36. static constexpr int32_t SPECIAL_PALETTE_MASK_CREATURES = 0b11110011;
  37. //draws image on surface "where" at position
  38. virtual void draw(SDL_Surface * where, int posX = 0, int posY = 0, const Rect * src = nullptr) const = 0;
  39. virtual void draw(SDL_Surface * where, const Rect * dest, const Rect * src) const = 0;
  40. virtual std::shared_ptr<IImage> scaleFast(const Point & size) const = 0;
  41. virtual void exportBitmap(const boost::filesystem::path & path) const = 0;
  42. //Change palette to specific player
  43. virtual void playerColored(PlayerColor player)=0;
  44. //set special color for flag
  45. virtual void setFlagColor(PlayerColor player)=0;
  46. //test transparency of specific pixel
  47. virtual bool isTransparent(const Point & coords) const = 0;
  48. virtual Point dimensions() const = 0;
  49. int width() const;
  50. int height() const;
  51. //only indexed bitmaps, 16 colors maximum
  52. virtual void shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove) = 0;
  53. virtual void adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask) = 0;
  54. virtual void resetPalette(int colorID) = 0;
  55. virtual void resetPalette() = 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 setSpecialPallete(const SpecialPalette & SpecialPalette, uint32_t colorsToSkipMask) = 0;
  60. virtual void horizontalFlip() = 0;
  61. virtual void verticalFlip() = 0;
  62. virtual void doubleFlip() = 0;
  63. IImage();
  64. virtual ~IImage();
  65. /// loads image from specified file. Returns 0-sized images on failure
  66. static std::shared_ptr<IImage> createFromFile( const std::string & path );
  67. static std::shared_ptr<IImage> createFromFile( const std::string & path, EImageBlitMode mode );
  68. /// temporary compatibility method. Creates IImage from existing SDL_Surface
  69. /// Surface will be shared, called must still free it with SDL_FreeSurface
  70. static std::shared_ptr<IImage> createFromSurface( SDL_Surface * source );
  71. };