1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

revert algoritm on optimized

This commit is contained in:
Laserlicht
2025-07-14 01:40:56 +02:00
parent be56d6eff4
commit 2607767ab7
5 changed files with 13 additions and 17 deletions

View File

@@ -295,7 +295,7 @@ std::shared_ptr<SDLImageShared> RenderHandler::loadScaledImage(const ImageLocato
bool generateOverlay = locator.generateOverlay && (*locator.generateOverlay) != SharedImageLocator::OverlayMode::OVERLAY_NONE;
bool isShadow = locator.layer == EImageBlitMode::ONLY_SHADOW_HIDE_SELECTION || locator.layer == EImageBlitMode::ONLY_SHADOW_HIDE_FLAG_COLOR;
bool isOverlay = locator.layer == EImageBlitMode::ONLY_FLAG_COLOR || locator.layer == EImageBlitMode::ONLY_SELECTION;
int requiredBorderAfterOptimize = (isShadow && generateShadow) || (isOverlay && generateOverlay) ? 50 * locator.scalingFactor : 0;
bool optimizeImage = !(isShadow && generateShadow) && !(isOverlay && generateOverlay); // images needs to expanded
if(isOverlay && !generateOverlay)
imagePathString += "-OVERLAY";
@@ -313,11 +313,11 @@ std::shared_ptr<SDLImageShared> RenderHandler::loadScaledImage(const ImageLocato
std::shared_ptr<SDLImageShared> img = nullptr;
if(CResourceHandler::get()->existsResource(imagePathSprites))
img = std::make_shared<SDLImageShared>(imagePathSprites, requiredBorderAfterOptimize);
img = std::make_shared<SDLImageShared>(imagePathSprites, optimizeImage);
else if(CResourceHandler::get()->existsResource(imagePathData))
img = std::make_shared<SDLImageShared>(imagePathData, requiredBorderAfterOptimize);
img = std::make_shared<SDLImageShared>(imagePathData, optimizeImage);
else if(CResourceHandler::get()->existsResource(imagePath))
img = std::make_shared<SDLImageShared>(imagePath, requiredBorderAfterOptimize);
img = std::make_shared<SDLImageShared>(imagePath, optimizeImage);
if(img)
{

View File

@@ -70,7 +70,7 @@ SDLImageShared::SDLImageShared(SDL_Surface * from)
fullSize.y = surf->h;
}
SDLImageShared::SDLImageShared(const ImagePath & filename, int keepBorder)
SDLImageShared::SDLImageShared(const ImagePath & filename, bool optimizeImage)
: surf(nullptr),
margins(0, 0),
fullSize(0, 0),
@@ -89,7 +89,8 @@ SDLImageShared::SDLImageShared(const ImagePath & filename, int keepBorder)
fullSize.x = surf->w;
fullSize.y = surf->h;
optimizeSurface(keepBorder);
if(optimizeImage)
optimizeSurface();
}
}
@@ -209,7 +210,7 @@ void SDLImageShared::draw(SDL_Surface * where, SDL_Palette * palette, const Poin
SDL_SetSurfacePalette(surf, originalPalette);
}
void SDLImageShared::optimizeSurface(int keepBorder)
void SDLImageShared::optimizeSurface()
{
assert(upscalingInProgress == false);
if (!surf)
@@ -217,7 +218,7 @@ void SDLImageShared::optimizeSurface(int keepBorder)
SDLImageOptimizer optimizer(surf, Rect(margins, fullSize));
optimizer.optimizeSurface(surf, keepBorder);
optimizer.optimizeSurface(surf);
SDL_FreeSurface(surf);
surf = optimizer.acquireResultSurface();

View File

@@ -40,13 +40,13 @@ class SDLImageShared final : public ISharedImage, public std::enable_shared_from
// Keep the original palette, in order to do color switching operation
void savePalette();
void optimizeSurface(int keepBorder = 0);
void optimizeSurface();
public:
//Load image from def file
SDLImageShared(const CDefFile *data, size_t frame, size_t group=0);
//Load from bitmap file
SDLImageShared(const ImagePath & filename, int keepBorder = 0);
SDLImageShared(const ImagePath & filename, bool optimizeImage=true);
//Create using existing surface, extraRef will increase refcount on SDL_Surface
SDLImageShared(SDL_Surface * from);
~SDLImageShared();

View File

@@ -24,7 +24,7 @@ SDLImageOptimizer::SDLImageOptimizer(SDL_Surface * surf, const Rect & virtualDim
{
}
void SDLImageOptimizer::optimizeSurface(SDL_Surface * formatSourceSurface, int keepBorder)
void SDLImageOptimizer::optimizeSurface(SDL_Surface * formatSourceSurface)
{
if (!surf)
return;
@@ -79,11 +79,6 @@ void SDLImageOptimizer::optimizeSurface(SDL_Surface * formatSourceSurface, int k
if (left == surf->w)
return;
left = std::max(0, left - keepBorder);
top = std::max(0, top - keepBorder);
right = std::min(surf->w - 1, right + keepBorder);
bottom = std::min(surf->h - 1, bottom + keepBorder);
if (left != 0 || top != 0 || right != surf->w - 1 || bottom != surf->h - 1)
{
// non-zero border found

View File

@@ -21,7 +21,7 @@ class SDLImageOptimizer : boost::noncopyable
public:
SDLImageOptimizer(SDL_Surface * surf, const Rect & virtualDimensions);
void optimizeSurface(SDL_Surface * formatSourceSurface, int keepBorder = 0);
void optimizeSurface(SDL_Surface * formatSourceSurface);
/// Aquires resulting surface and transfers surface ownership to the caller
/// May return nullptr if input image was empty