2023-10-19 16:19:09 +02:00
|
|
|
/*
|
|
|
|
* SDLImage.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../render/IImage.h"
|
|
|
|
#include "../../lib/Point.h"
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
class JsonNode;
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
|
|
|
class CDefFile;
|
|
|
|
|
|
|
|
struct SDL_Surface;
|
|
|
|
struct SDL_Palette;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wrapper around SDL_Surface
|
|
|
|
*/
|
2024-07-24 15:04:45 +02:00
|
|
|
class SDLImageShared final : public ISharedImage, public std::enable_shared_from_this<SDLImageShared>, boost::noncopyable
|
2023-10-19 16:19:09 +02:00
|
|
|
{
|
|
|
|
//Surface without empty borders
|
|
|
|
SDL_Surface * surf;
|
2024-06-02 21:31:56 +02:00
|
|
|
|
|
|
|
SDL_Palette * originalPalette;
|
2023-10-19 16:19:09 +02:00
|
|
|
//size of left and top borders
|
|
|
|
Point margins;
|
|
|
|
//total size including borders
|
|
|
|
Point fullSize;
|
|
|
|
|
2024-11-03 14:38:15 +02:00
|
|
|
//pre scaled image
|
2024-11-07 03:32:06 +02:00
|
|
|
int preScaleFactor;
|
2024-11-03 14:38:15 +02:00
|
|
|
|
2024-06-04 13:46:45 +02:00
|
|
|
// Keep the original palette, in order to do color switching operation
|
|
|
|
void savePalette();
|
2023-10-19 16:19:09 +02:00
|
|
|
|
2024-07-25 20:22:27 +02:00
|
|
|
void optimizeSurface();
|
|
|
|
|
2023-10-19 16:19:09 +02:00
|
|
|
public:
|
|
|
|
//Load image from def file
|
2024-11-07 03:32:06 +02:00
|
|
|
SDLImageShared(const CDefFile *data, size_t frame, size_t group=0, int preScaleFactor=1);
|
2023-10-19 16:19:09 +02:00
|
|
|
//Load from bitmap file
|
2024-11-07 03:32:06 +02:00
|
|
|
SDLImageShared(const ImagePath & filename, int preScaleFactor=1);
|
2023-10-19 16:19:09 +02:00
|
|
|
//Create using existing surface, extraRef will increase refcount on SDL_Surface
|
2024-07-24 15:04:45 +02:00
|
|
|
SDLImageShared(SDL_Surface * from);
|
|
|
|
~SDLImageShared();
|
2023-10-19 16:19:09 +02:00
|
|
|
|
2024-07-25 12:38:48 +02:00
|
|
|
void draw(SDL_Surface * where, SDL_Palette * palette, const Point & dest, const Rect * src, const ColorRGBA & colorMultiplier, uint8_t alpha, EImageBlitMode mode) const override;
|
2023-10-19 16:19:09 +02:00
|
|
|
|
2024-09-12 18:11:03 +02:00
|
|
|
void exportBitmap(const boost::filesystem::path & path, SDL_Palette * palette) const override;
|
2023-10-19 16:19:09 +02:00
|
|
|
Point dimensions() const override;
|
2024-06-04 13:46:45 +02:00
|
|
|
bool isTransparent(const Point & coords) const override;
|
2024-06-08 09:35:13 +02:00
|
|
|
std::shared_ptr<IImage> createImageReference(EImageBlitMode mode) override;
|
2024-07-24 15:04:45 +02:00
|
|
|
std::shared_ptr<ISharedImage> horizontalFlip() const override;
|
|
|
|
std::shared_ptr<ISharedImage> verticalFlip() const override;
|
2024-07-25 20:22:27 +02:00
|
|
|
std::shared_ptr<ISharedImage> scaleInteger(int factor, SDL_Palette * palette) const override;
|
|
|
|
std::shared_ptr<ISharedImage> scaleTo(const Point & size, SDL_Palette * palette) const override;
|
2023-10-19 16:19:09 +02:00
|
|
|
|
2024-06-04 13:46:45 +02:00
|
|
|
friend class SDLImageLoader;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SDLImageBase : public IImage, boost::noncopyable
|
|
|
|
{
|
|
|
|
protected:
|
2024-07-25 12:38:48 +02:00
|
|
|
std::shared_ptr<ISharedImage> image;
|
2024-06-04 13:46:45 +02:00
|
|
|
|
|
|
|
uint8_t alphaValue;
|
|
|
|
EImageBlitMode blitMode;
|
|
|
|
|
|
|
|
public:
|
2024-07-25 12:38:48 +02:00
|
|
|
SDLImageBase(const std::shared_ptr<ISharedImage> & image, EImageBlitMode mode);
|
2024-06-04 13:46:45 +02:00
|
|
|
|
|
|
|
bool isTransparent(const Point & coords) const override;
|
|
|
|
Point dimensions() const override;
|
|
|
|
void setAlpha(uint8_t value) override;
|
|
|
|
void setBlitMode(EImageBlitMode mode) override;
|
2024-07-25 12:38:48 +02:00
|
|
|
std::shared_ptr<ISharedImage> getSharedImage() const override;
|
2024-06-04 13:46:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class SDLImageIndexed final : public SDLImageBase
|
|
|
|
{
|
|
|
|
SDL_Palette * currentPalette = nullptr;
|
2024-07-25 12:38:48 +02:00
|
|
|
SDL_Palette * originalPalette = nullptr;
|
2023-10-19 16:19:09 +02:00
|
|
|
|
2024-07-25 12:38:48 +02:00
|
|
|
bool bodyEnabled = true;
|
|
|
|
bool shadowEnabled = false;
|
|
|
|
bool overlayEnabled = false;
|
|
|
|
|
|
|
|
void setShadowTransparency(float factor);
|
2024-06-04 13:46:45 +02:00
|
|
|
public:
|
2024-07-25 12:38:48 +02:00
|
|
|
SDLImageIndexed(const std::shared_ptr<ISharedImage> & image, SDL_Palette * palette, EImageBlitMode mode);
|
2024-06-04 13:46:45 +02:00
|
|
|
~SDLImageIndexed();
|
|
|
|
|
|
|
|
void draw(SDL_Surface * where, const Point & pos, const Rect * src) const override;
|
2024-07-25 12:38:48 +02:00
|
|
|
void setOverlayColor(const ColorRGBA & color) override;
|
2024-06-04 13:46:45 +02:00
|
|
|
void playerColored(PlayerColor player) override;
|
2023-10-19 16:19:09 +02:00
|
|
|
void shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove) override;
|
|
|
|
void adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask) override;
|
2024-07-25 20:22:27 +02:00
|
|
|
void scaleInteger(int factor) override;
|
|
|
|
void scaleTo(const Point & size) override;
|
2024-09-12 18:11:03 +02:00
|
|
|
void exportBitmap(const boost::filesystem::path & path) const override;
|
2024-07-25 12:38:48 +02:00
|
|
|
|
|
|
|
void setShadowEnabled(bool on) override;
|
|
|
|
void setBodyEnabled(bool on) override;
|
|
|
|
void setOverlayEnabled(bool on) override;
|
2024-06-04 13:46:45 +02:00
|
|
|
};
|
2023-10-19 16:19:09 +02:00
|
|
|
|
2024-06-04 13:46:45 +02:00
|
|
|
class SDLImageRGB final : public SDLImageBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using SDLImageBase::SDLImageBase;
|
2023-10-19 16:19:09 +02:00
|
|
|
|
2024-06-04 13:46:45 +02:00
|
|
|
void draw(SDL_Surface * where, const Point & pos, const Rect * src) const override;
|
2024-07-25 12:38:48 +02:00
|
|
|
void setOverlayColor(const ColorRGBA & color) override;
|
2024-06-04 13:46:45 +02:00
|
|
|
void playerColored(PlayerColor player) override;
|
|
|
|
void shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove) override;
|
|
|
|
void adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask) override;
|
2024-07-25 20:22:27 +02:00
|
|
|
void scaleInteger(int factor) override;
|
|
|
|
void scaleTo(const Point & size) override;
|
2024-09-12 18:11:03 +02:00
|
|
|
void exportBitmap(const boost::filesystem::path & path) const override;
|
2024-07-25 12:38:48 +02:00
|
|
|
|
|
|
|
void setShadowEnabled(bool on) override;
|
|
|
|
void setBodyEnabled(bool on) override;
|
|
|
|
void setOverlayEnabled(bool on) override;
|
2023-10-19 16:19:09 +02:00
|
|
|
};
|