mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Fixes for Sonar issues
This commit is contained in:
parent
75c727afaa
commit
b3158c52ba
@ -54,8 +54,8 @@ Canvas::Canvas(const Canvas & other, const Rect & newClipRect):
|
||||
|
||||
Canvas::Canvas(const Point & size, CanvasScalingPolicy scalingPolicy):
|
||||
scalingPolicy(scalingPolicy),
|
||||
renderArea(Point(0,0), size * getScalingFactor()),
|
||||
surface(CSDL_Ext::newSurface(size * getScalingFactor()))
|
||||
surface(CSDL_Ext::newSurface(size * getScalingFactor())),
|
||||
renderArea(Point(0,0), size * getScalingFactor())
|
||||
{
|
||||
CSDL_Ext::fillSurface(surface, CSDL_Ext::toSDL(Colors::TRANSPARENCY) );
|
||||
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
|
||||
|
@ -41,13 +41,13 @@ void IFont::renderTextLeft(SDL_Surface * surface, const std::string & data, cons
|
||||
|
||||
void IFont::renderTextRight(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const
|
||||
{
|
||||
Point size = Point((int)getStringWidth(data), (int)getLineHeight()) * getScalingFactor();
|
||||
Point size = Point(getStringWidth(data), getLineHeight()) * getScalingFactor();
|
||||
renderText(surface, data, color, pos - size);
|
||||
}
|
||||
|
||||
void IFont::renderTextCenter(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const
|
||||
{
|
||||
Point size = Point((int)getStringWidth(data), (int)getLineHeight()) * getScalingFactor();
|
||||
Point size = Point(getStringWidth(data), getLineHeight()) * getScalingFactor();
|
||||
renderText(surface, data, color, pos - size / 2);
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ void IFont::renderTextLinesLeft(SDL_Surface * surface, const std::vector<std::st
|
||||
void IFont::renderTextLinesRight(SDL_Surface * surface, const std::vector<std::string> & data, const ColorRGBA & color, const Point & pos) const
|
||||
{
|
||||
Point currPos = pos;
|
||||
currPos.y -= (int)data.size() * (int)getLineHeight() * getScalingFactor();
|
||||
currPos.y -= data.size() * getLineHeight() * getScalingFactor();
|
||||
|
||||
for(const std::string & line : data)
|
||||
{
|
||||
@ -77,7 +77,7 @@ void IFont::renderTextLinesRight(SDL_Surface * surface, const std::vector<std::s
|
||||
void IFont::renderTextLinesCenter(SDL_Surface * surface, const std::vector<std::string> & data, const ColorRGBA & color, const Point & pos) const
|
||||
{
|
||||
Point currPos = pos;
|
||||
currPos.y -= (int)data.size() * (int)getLineHeight() / 2 * getScalingFactor();
|
||||
currPos.y -= data.size() * getLineHeight() / 2 * getScalingFactor();
|
||||
|
||||
for(const std::string & line : data)
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ VCMI_LIB_NAMESPACE_END
|
||||
|
||||
struct SDL_Surface;
|
||||
|
||||
class IFont
|
||||
class IFont : boost::noncopyable
|
||||
{
|
||||
protected:
|
||||
/// Internal function to render font, see renderTextLeft
|
||||
|
@ -34,7 +34,7 @@ struct AtlasLayout
|
||||
|
||||
/// Attempts to pack provided list of images into 2d box of specified size
|
||||
/// Returns resulting layout on success and empty optional on failure
|
||||
static std::optional<AtlasLayout> tryAtlasPacking(Point dimensions, std::map<int, Point> images)
|
||||
static std::optional<AtlasLayout> tryAtlasPacking(Point dimensions, const std::map<int, Point> & images)
|
||||
{
|
||||
// Simple atlas packing algorithm. Can be extended if needed, however optimal solution is NP-complete problem, so 'perfect' solution is too costly
|
||||
|
||||
@ -71,9 +71,9 @@ static std::optional<AtlasLayout> tryAtlasPacking(Point dimensions, std::map<int
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Arranges images to fit into texture atlas with automatic selection of iamge size
|
||||
/// Arranges images to fit into texture atlas with automatic selection of image size
|
||||
/// Returns images arranged into 2d box
|
||||
static AtlasLayout doAtlasPacking(std::map<int, Point> images)
|
||||
static AtlasLayout doAtlasPacking(const std::map<int, Point> & images)
|
||||
{
|
||||
// initial size of an atlas. Smaller size won't even fit tiniest H3 font
|
||||
Point dimensions(128, 128);
|
||||
@ -181,20 +181,19 @@ CBitmapFont::CBitmapFont(const std::string & filename):
|
||||
storedEntry.rightOffset = symbol.second.rightOffset;
|
||||
storedEntry.positionInAtlas = atlas.images.at(symbol.first);
|
||||
|
||||
// Copy pixel data to atlas
|
||||
uint8_t *dstPixels = static_cast<uint8_t*>(atlasImage->pixels);
|
||||
uint8_t *dstLine = dstPixels + storedEntry.positionInAtlas.y * atlasImage->pitch;
|
||||
uint8_t *dst = dstLine + storedEntry.positionInAtlas.x;
|
||||
|
||||
for (size_t i = 0; i < storedEntry.positionInAtlas.h; ++i)
|
||||
{
|
||||
// Copy pixel data to atlas
|
||||
uint8_t *dstPixels = (uint8_t*)atlasImage->pixels;
|
||||
uint8_t *dstLine = dstPixels + storedEntry.positionInAtlas.y * atlasImage->pitch;
|
||||
uint8_t *dst = dstLine + storedEntry.positionInAtlas.x;
|
||||
const uint8_t *srcPtr = symbol.second.pixels.data() + i * storedEntry.positionInAtlas.w;
|
||||
uint8_t * dstPtr = dst + i * atlasImage->pitch;
|
||||
|
||||
for (size_t i = 0; i < storedEntry.positionInAtlas.h; ++i)
|
||||
{
|
||||
const uint8_t *srcPtr = symbol.second.pixels.data() + i * storedEntry.positionInAtlas.w;
|
||||
uint8_t * dstPtr = dst + i * atlasImage->pitch;
|
||||
|
||||
std::copy_n(srcPtr, storedEntry.positionInAtlas.w, dstPtr);
|
||||
}
|
||||
std::copy_n(srcPtr, storedEntry.positionInAtlas.w, dstPtr);
|
||||
}
|
||||
|
||||
chars[symbol.first] = storedEntry;
|
||||
}
|
||||
|
||||
@ -256,7 +255,6 @@ void CBitmapFont::renderCharacter(SDL_Surface * surface, const BitmapChar & char
|
||||
|
||||
if (atlasImage->format->palette)
|
||||
SDL_SetPaletteColors(atlasImage->format->palette, &sdlColor, 255, 1);
|
||||
// atlasImage->format->palette->colors[255] = CSDL_Ext::toSDL(color);
|
||||
else
|
||||
SDL_SetSurfaceColorMod(atlasImage, color.r, color.g, color.b);
|
||||
|
||||
|
@ -17,7 +17,7 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
class ResourcePath;
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
class CBitmapFont : public IFont
|
||||
class CBitmapFont final : public IFont
|
||||
{
|
||||
SDL_Surface * atlasImage;
|
||||
|
||||
|
@ -18,7 +18,7 @@ VCMI_LIB_NAMESPACE_END
|
||||
class CBitmapFont;
|
||||
|
||||
/// supports multi-byte characters for such languages like Chinese
|
||||
class CBitmapHanFont : public IFont
|
||||
class CBitmapHanFont final : public IFont
|
||||
{
|
||||
std::unique_ptr<CBitmapFont> fallback;
|
||||
// data, directly copied from file
|
||||
|
@ -19,7 +19,7 @@ class CBitmapFont;
|
||||
|
||||
using TTF_Font = struct _TTF_Font;
|
||||
|
||||
class CTrueTypeFont : public IFont
|
||||
class CTrueTypeFont final : public IFont
|
||||
{
|
||||
std::unique_ptr<CBitmapFont> fallbackFont;
|
||||
const std::pair<std::unique_ptr<ui8[]>, ui64> data;
|
||||
|
@ -26,7 +26,7 @@
|
||||
class SDLImageLoader;
|
||||
|
||||
//First 8 colors in def palette used for transparency
|
||||
static const SDL_Color sourcePalette[8] = {
|
||||
static constexpr std::array<SDL_Color, 8> sourcePalette = {{
|
||||
{0, 255, 255, SDL_ALPHA_OPAQUE},
|
||||
{255, 150, 255, SDL_ALPHA_OPAQUE},
|
||||
{255, 100, 255, SDL_ALPHA_OPAQUE},
|
||||
@ -35,9 +35,9 @@ static const SDL_Color sourcePalette[8] = {
|
||||
{255, 255, 0, SDL_ALPHA_OPAQUE},
|
||||
{180, 0, 255, SDL_ALPHA_OPAQUE},
|
||||
{0, 255, 0, SDL_ALPHA_OPAQUE}
|
||||
};
|
||||
}};
|
||||
|
||||
static const ColorRGBA targetPalette[8] = {
|
||||
static constexpr std::array<ColorRGBA, 8> targetPalette = {{
|
||||
{0, 0, 0, 0 }, // 0 - transparency ( used in most images )
|
||||
{0, 0, 0, 64 }, // 1 - shadow border ( used in battle, adventure map def's )
|
||||
{0, 0, 0, 64 }, // 2 - shadow border ( used in fog-of-war def's )
|
||||
@ -46,7 +46,7 @@ static const ColorRGBA targetPalette[8] = {
|
||||
{0, 0, 0, 0 }, // 5 - selection / owner flag ( used in battle, adventure map def's )
|
||||
{0, 0, 0, 128}, // 6 - shadow body below selection ( used in battle def's )
|
||||
{0, 0, 0, 64 } // 7 - shadow border below selection ( used in battle def's )
|
||||
};
|
||||
}};
|
||||
|
||||
static ui8 mixChannels(ui8 c1, ui8 c2, ui8 a1, ui8 a2)
|
||||
{
|
||||
@ -59,7 +59,7 @@ static ColorRGBA addColors(const ColorRGBA & base, const ColorRGBA & over)
|
||||
mixChannels(over.r, base.r, over.a, base.a),
|
||||
mixChannels(over.g, base.g, over.a, base.a),
|
||||
mixChannels(over.b, base.b, over.a, base.a),
|
||||
ui8(over.a + base.a * (255 - over.a) / 256)
|
||||
static_cast<ui8>(over.a + base.a * (255 - over.a) / 256)
|
||||
);
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ int IImage::height() const
|
||||
return dimensions().y;
|
||||
}
|
||||
|
||||
SDLImageShared::SDLImageShared(CDefFile * data, size_t frame, size_t group)
|
||||
SDLImageShared::SDLImageShared(const CDefFile * data, size_t frame, size_t group)
|
||||
: surf(nullptr),
|
||||
margins(0, 0),
|
||||
fullSize(0, 0),
|
||||
@ -205,7 +205,7 @@ void SDLImageShared::optimizeSurface()
|
||||
{
|
||||
for (int y = 0; y < surf->h; ++y)
|
||||
{
|
||||
const uint8_t * row = (uint8_t *)surf->pixels + y * surf->pitch;
|
||||
const uint8_t * row = static_cast<uint8_t *>(surf->pixels) + y * surf->pitch;
|
||||
for (int x = 0; x < surf->w; ++x)
|
||||
{
|
||||
if (row[x] != 0)
|
||||
@ -288,7 +288,7 @@ std::shared_ptr<ISharedImage> SDLImageShared::scaleInteger(int factor, SDL_Palet
|
||||
// TODO: compare performance and size of images, recheck values for potentially better parameters
|
||||
const int granulation = std::clamp(surf->h / 64 * 8, 8, 64);
|
||||
|
||||
tbb::parallel_for(tbb::blocked_range<size_t>(0, intermediate->h, granulation), [&](const tbb::blocked_range<size_t> & r)
|
||||
tbb::parallel_for(tbb::blocked_range<size_t>(0, intermediate->h, granulation), [factor, srcPixels, dstPixels, intermediate](const tbb::blocked_range<size_t> & r)
|
||||
{
|
||||
xbrz::scale(factor, srcPixels, dstPixels, intermediate->w, intermediate->h, xbrz::ColorFormat::ARGB, {}, r.begin(), r.end());
|
||||
});
|
||||
|
@ -42,7 +42,7 @@ class SDLImageShared final : public ISharedImage, public std::enable_shared_from
|
||||
|
||||
public:
|
||||
//Load image from def file
|
||||
SDLImageShared(CDefFile *data, size_t frame, size_t group=0);
|
||||
SDLImageShared(const CDefFile *data, size_t frame, size_t group=0);
|
||||
//Load from bitmap file
|
||||
SDLImageShared(const ImagePath & filename);
|
||||
//Create using existing surface, extraRef will increase refcount on SDL_Surface
|
||||
|
@ -675,7 +675,7 @@ SDL_Surface * CSDL_Ext::scaleSurfaceIntegerFactor(SDL_Surface * surf, int factor
|
||||
// TODO: compare performance and size of images, recheck values for potentially better parameters
|
||||
const int granulation = std::clamp(surf->h / 64 * 8, 8, 64);
|
||||
|
||||
tbb::parallel_for(tbb::blocked_range<size_t>(0, intermediate->h, granulation), [&](const tbb::blocked_range<size_t> & r)
|
||||
tbb::parallel_for(tbb::blocked_range<size_t>(0, intermediate->h, granulation), [factor, srcPixels, dstPixels, intermediate](const tbb::blocked_range<size_t> & r)
|
||||
{
|
||||
xbrz::scale(factor, srcPixels, dstPixels, intermediate->w, intermediate->h, xbrz::ColorFormat::ARGB, {}, r.begin(), r.end());
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user