IImage.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /*
  20. * Base class for images, can be used for non-animation pictures as well
  21. */
  22. class IImage
  23. {
  24. public:
  25. using SpecialPalette = std::array<SDL_Color, 7>;
  26. //draws image on surface "where" at position
  27. virtual void draw(SDL_Surface * where, int posX = 0, int posY = 0, const Rect * src = nullptr) const = 0;
  28. virtual void draw(SDL_Surface * where, const Rect * dest, const Rect * src) const = 0;
  29. virtual std::shared_ptr<IImage> scaleFast(const Point & size) const = 0;
  30. virtual void exportBitmap(const boost::filesystem::path & path) const = 0;
  31. //Change palette to specific player
  32. virtual void playerColored(PlayerColor player)=0;
  33. //set special color for flag
  34. virtual void setFlagColor(PlayerColor player)=0;
  35. //test transparency of specific pixel
  36. virtual bool isTransparent(const Point & coords) const = 0;
  37. virtual Point dimensions() const = 0;
  38. int width() const;
  39. int height() const;
  40. //only indexed bitmaps, 16 colors maximum
  41. virtual void shiftPalette(int from, int howMany) = 0;
  42. virtual void adjustPalette(const ColorFilter & shifter, size_t colorsToSkip) = 0;
  43. virtual void resetPalette(int colorID) = 0;
  44. virtual void resetPalette() = 0;
  45. virtual void setAlpha(uint8_t value) = 0;
  46. //only indexed bitmaps with 7 special colors
  47. virtual void setSpecialPallete(const SpecialPalette & SpecialPalette) = 0;
  48. virtual void horizontalFlip() = 0;
  49. virtual void verticalFlip() = 0;
  50. IImage();
  51. virtual ~IImage();
  52. /// loads image from specified file. Returns 0-sized images on failure
  53. static std::shared_ptr<IImage> createFromFile( const std::string & path );
  54. /// temporary compatibility method. Creates IImage from existing SDL_Surface
  55. /// Surface will be shared, called must still free it with SDL_FreeSurface
  56. static std::shared_ptr<IImage> createFromSurface( SDL_Surface * source );
  57. };