2010-10-18 18:08:59 +03:00
|
|
|
/*
|
2023-02-01 16:42:03 +02:00
|
|
|
* IImage.h, part of VCMI engine
|
2010-10-18 18:08:59 +03:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
class PlayerColor;
|
2023-01-18 17:32:57 +02:00
|
|
|
class Rect;
|
|
|
|
class Point;
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
|
|
|
struct SDL_Surface;
|
2023-01-17 22:01:35 +02:00
|
|
|
struct SDL_Color;
|
2022-12-15 23:24:03 +02:00
|
|
|
class ColorFilter;
|
2010-10-18 18:08:59 +03:00
|
|
|
|
2023-02-20 18:37:33 +02:00
|
|
|
/// Defines which blit method will be selected when image is used for rendering
|
|
|
|
enum class EImageBlitMode : uint8_t
|
|
|
|
{
|
|
|
|
/// Image can have no transparency and can be only used as background
|
|
|
|
OPAQUE,
|
|
|
|
|
|
|
|
/// Image can have only a single color as transparency and has no semi-transparent areas
|
|
|
|
COLORKEY,
|
|
|
|
|
|
|
|
/// Image might have full alpha transparency range, e.g. shadows
|
|
|
|
ALPHA
|
|
|
|
};
|
|
|
|
|
2011-02-06 19:26:27 +02:00
|
|
|
/*
|
|
|
|
* Base class for images, can be used for non-animation pictures as well
|
|
|
|
*/
|
|
|
|
class IImage
|
2010-10-18 18:08:59 +03:00
|
|
|
{
|
2011-02-06 19:26:27 +02:00
|
|
|
public:
|
2023-03-25 18:55:08 +02:00
|
|
|
using SpecialPalette = std::vector<SDL_Color>;
|
|
|
|
static constexpr int32_t SPECIAL_PALETTE_MASK_CREATURES = 0b11110011;
|
2010-10-18 18:08:59 +03:00
|
|
|
|
2011-02-06 19:26:27 +02:00
|
|
|
//draws image on surface "where" at position
|
2023-01-11 20:57:42 +02:00
|
|
|
virtual void draw(SDL_Surface * where, int posX = 0, int posY = 0, const Rect * src = nullptr) const = 0;
|
2023-01-17 22:01:35 +02:00
|
|
|
virtual void draw(SDL_Surface * where, const Rect * dest, const Rect * src) const = 0;
|
2016-11-07 23:19:53 +02:00
|
|
|
|
2023-01-30 17:18:59 +02:00
|
|
|
virtual std::shared_ptr<IImage> scaleFast(const Point & size) const = 0;
|
2010-10-18 18:08:59 +03:00
|
|
|
|
2016-11-25 14:23:28 +02:00
|
|
|
virtual void exportBitmap(const boost::filesystem::path & path) const = 0;
|
|
|
|
|
2011-02-06 19:26:27 +02:00
|
|
|
//Change palette to specific player
|
2013-03-03 20:06:03 +03:00
|
|
|
virtual void playerColored(PlayerColor player)=0;
|
2016-11-04 16:05:56 +02:00
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
//set special color for flag
|
|
|
|
virtual void setFlagColor(PlayerColor player)=0;
|
2016-11-04 16:05:56 +02:00
|
|
|
|
2022-11-25 11:46:47 +02:00
|
|
|
//test transparency of specific pixel
|
|
|
|
virtual bool isTransparent(const Point & coords) const = 0;
|
|
|
|
|
|
|
|
virtual Point dimensions() const = 0;
|
2022-12-11 22:09:57 +02:00
|
|
|
int width() const;
|
|
|
|
int height() const;
|
2016-11-07 23:15:46 +02:00
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
//only indexed bitmaps, 16 colors maximum
|
2023-02-19 22:05:19 +02:00
|
|
|
virtual void shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove) = 0;
|
2023-03-25 18:55:08 +02:00
|
|
|
virtual void adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask) = 0;
|
2022-12-15 23:24:03 +02:00
|
|
|
virtual void resetPalette(int colorID) = 0;
|
2020-01-25 11:21:26 +02:00
|
|
|
virtual void resetPalette() = 0;
|
2016-11-07 23:15:46 +02:00
|
|
|
|
2023-01-30 17:18:59 +02:00
|
|
|
virtual void setAlpha(uint8_t value) = 0;
|
2023-02-20 18:37:33 +02:00
|
|
|
virtual void setBlitMode(EImageBlitMode mode) = 0;
|
2023-01-30 17:18:59 +02:00
|
|
|
|
2022-12-14 12:04:37 +02:00
|
|
|
//only indexed bitmaps with 7 special colors
|
2023-03-25 18:55:08 +02:00
|
|
|
virtual void setSpecialPallete(const SpecialPalette & SpecialPalette, uint32_t colorsToSkipMask) = 0;
|
2017-09-05 17:59:26 +02:00
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
virtual void horizontalFlip() = 0;
|
|
|
|
virtual void verticalFlip() = 0;
|
2016-11-07 23:15:46 +02:00
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
IImage();
|
2018-04-07 13:34:11 +02:00
|
|
|
virtual ~IImage();
|
2022-11-25 00:26:14 +02:00
|
|
|
|
|
|
|
/// loads image from specified file. Returns 0-sized images on failure
|
|
|
|
static std::shared_ptr<IImage> createFromFile( const std::string & path );
|
2023-02-20 18:37:33 +02:00
|
|
|
static std::shared_ptr<IImage> createFromFile( const std::string & path, EImageBlitMode mode );
|
2023-01-30 17:18:59 +02:00
|
|
|
|
|
|
|
/// temporary compatibility method. Creates IImage from existing SDL_Surface
|
|
|
|
/// Surface will be shared, called must still free it with SDL_FreeSurface
|
|
|
|
static std::shared_ptr<IImage> createFromSurface( SDL_Surface * source );
|
2011-02-06 19:26:27 +02:00
|
|
|
};
|
2010-10-18 18:08:59 +03:00
|
|
|
|