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:
@@ -295,7 +295,7 @@ std::shared_ptr<SDLImageShared> RenderHandler::loadScaledImage(const ImageLocato
|
|||||||
bool generateOverlay = locator.generateOverlay && (*locator.generateOverlay) != SharedImageLocator::OverlayMode::OVERLAY_NONE;
|
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 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;
|
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)
|
if(isOverlay && !generateOverlay)
|
||||||
imagePathString += "-OVERLAY";
|
imagePathString += "-OVERLAY";
|
||||||
@@ -313,11 +313,11 @@ std::shared_ptr<SDLImageShared> RenderHandler::loadScaledImage(const ImageLocato
|
|||||||
std::shared_ptr<SDLImageShared> img = nullptr;
|
std::shared_ptr<SDLImageShared> img = nullptr;
|
||||||
|
|
||||||
if(CResourceHandler::get()->existsResource(imagePathSprites))
|
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))
|
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))
|
else if(CResourceHandler::get()->existsResource(imagePath))
|
||||||
img = std::make_shared<SDLImageShared>(imagePath, requiredBorderAfterOptimize);
|
img = std::make_shared<SDLImageShared>(imagePath, optimizeImage);
|
||||||
|
|
||||||
if(img)
|
if(img)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ SDLImageShared::SDLImageShared(SDL_Surface * from)
|
|||||||
fullSize.y = surf->h;
|
fullSize.y = surf->h;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDLImageShared::SDLImageShared(const ImagePath & filename, int keepBorder)
|
SDLImageShared::SDLImageShared(const ImagePath & filename, bool optimizeImage)
|
||||||
: surf(nullptr),
|
: surf(nullptr),
|
||||||
margins(0, 0),
|
margins(0, 0),
|
||||||
fullSize(0, 0),
|
fullSize(0, 0),
|
||||||
@@ -89,7 +89,8 @@ SDLImageShared::SDLImageShared(const ImagePath & filename, int keepBorder)
|
|||||||
fullSize.x = surf->w;
|
fullSize.x = surf->w;
|
||||||
fullSize.y = surf->h;
|
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);
|
SDL_SetSurfacePalette(surf, originalPalette);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLImageShared::optimizeSurface(int keepBorder)
|
void SDLImageShared::optimizeSurface()
|
||||||
{
|
{
|
||||||
assert(upscalingInProgress == false);
|
assert(upscalingInProgress == false);
|
||||||
if (!surf)
|
if (!surf)
|
||||||
@@ -217,7 +218,7 @@ void SDLImageShared::optimizeSurface(int keepBorder)
|
|||||||
|
|
||||||
SDLImageOptimizer optimizer(surf, Rect(margins, fullSize));
|
SDLImageOptimizer optimizer(surf, Rect(margins, fullSize));
|
||||||
|
|
||||||
optimizer.optimizeSurface(surf, keepBorder);
|
optimizer.optimizeSurface(surf);
|
||||||
SDL_FreeSurface(surf);
|
SDL_FreeSurface(surf);
|
||||||
|
|
||||||
surf = optimizer.acquireResultSurface();
|
surf = optimizer.acquireResultSurface();
|
||||||
|
|||||||
@@ -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
|
// Keep the original palette, in order to do color switching operation
|
||||||
void savePalette();
|
void savePalette();
|
||||||
|
|
||||||
void optimizeSurface(int keepBorder = 0);
|
void optimizeSurface();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//Load image from def file
|
//Load image from def file
|
||||||
SDLImageShared(const CDefFile *data, size_t frame, size_t group=0);
|
SDLImageShared(const CDefFile *data, size_t frame, size_t group=0);
|
||||||
//Load from bitmap file
|
//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
|
//Create using existing surface, extraRef will increase refcount on SDL_Surface
|
||||||
SDLImageShared(SDL_Surface * from);
|
SDLImageShared(SDL_Surface * from);
|
||||||
~SDLImageShared();
|
~SDLImageShared();
|
||||||
|
|||||||
@@ -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)
|
if (!surf)
|
||||||
return;
|
return;
|
||||||
@@ -79,11 +79,6 @@ void SDLImageOptimizer::optimizeSurface(SDL_Surface * formatSourceSurface, int k
|
|||||||
if (left == surf->w)
|
if (left == surf->w)
|
||||||
return;
|
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)
|
if (left != 0 || top != 0 || right != surf->w - 1 || bottom != surf->h - 1)
|
||||||
{
|
{
|
||||||
// non-zero border found
|
// non-zero border found
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class SDLImageOptimizer : boost::noncopyable
|
|||||||
public:
|
public:
|
||||||
SDLImageOptimizer(SDL_Surface * surf, const Rect & virtualDimensions);
|
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
|
/// Aquires resulting surface and transfers surface ownership to the caller
|
||||||
/// May return nullptr if input image was empty
|
/// May return nullptr if input image was empty
|
||||||
|
|||||||
Reference in New Issue
Block a user