mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-02-16 12:05:38 +00:00
Avoided unnecessary SVG file parsing for images previously found to be invalid.
This commit is contained in:
parent
3a38af6e66
commit
d2ca019a75
|
@ -80,15 +80,21 @@ void ImageComponent::setImage(const std::string& path, bool tile)
|
||||||
if (isScalable) {
|
if (isScalable) {
|
||||||
mTexture = TextureResource::get(path, tile, mForceLoad, mDynamic, mLinearInterpolation,
|
mTexture = TextureResource::get(path, tile, mForceLoad, mDynamic, mLinearInterpolation,
|
||||||
mMipmapping, 0, 0, 0.0f, 0.0f);
|
mMipmapping, 0, 0, 0.0f, 0.0f);
|
||||||
if (tile && (mTileWidth == 0.0f || mTileHeight == 0.0f))
|
if (mTexture->getIsInvalidSVGFile()) {
|
||||||
setTileAxes();
|
mTexture.reset();
|
||||||
resize(false);
|
}
|
||||||
mTexture.reset();
|
else {
|
||||||
mTexture = TextureResource::get(path, tile, mForceLoad, mDynamic, mLinearInterpolation,
|
if (tile && (mTileWidth == 0.0f || mTileHeight == 0.0f))
|
||||||
mMipmapping, static_cast<size_t>(mSize.x),
|
setTileAxes();
|
||||||
static_cast<size_t>(mSize.y), mTileWidth, mTileHeight);
|
resize(false);
|
||||||
mTexture->rasterizeAt(mSize.x, mSize.y);
|
mTexture.reset();
|
||||||
onSizeChanged();
|
mTexture =
|
||||||
|
TextureResource::get(path, tile, mForceLoad, mDynamic, mLinearInterpolation,
|
||||||
|
mMipmapping, static_cast<size_t>(mSize.x),
|
||||||
|
static_cast<size_t>(mSize.y), mTileWidth, mTileHeight);
|
||||||
|
mTexture->rasterizeAt(mSize.x, mSize.y);
|
||||||
|
onSizeChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mTexture = TextureResource::get(path, tile, mForceLoad, mDynamic, mLinearInterpolation,
|
mTexture = TextureResource::get(path, tile, mForceLoad, mDynamic, mLinearInterpolation,
|
||||||
|
|
|
@ -61,7 +61,8 @@ bool TextureData::initSVGFromMemory(const std::string& fileData)
|
||||||
auto svgImage = lunasvg::Document::loadFromData(fileData);
|
auto svgImage = lunasvg::Document::loadFromData(fileData);
|
||||||
|
|
||||||
if (svgImage == nullptr) {
|
if (svgImage == nullptr) {
|
||||||
// LOG(LogError) << "Couldn't parse SVG image:" << mPath;
|
LOG(LogDebug) << "TextureData::initSVGFromMemory(): Couldn't parse SVG image \"" << mPath
|
||||||
|
<< "\"";
|
||||||
mInvalidSVGFile = true;
|
mInvalidSVGFile = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,9 +73,10 @@ public:
|
||||||
const bool getPendingRasterization() { return mPendingRasterization; }
|
const bool getPendingRasterization() { return mPendingRasterization; }
|
||||||
|
|
||||||
const bool getScalable() { return mScalable; }
|
const bool getScalable() { return mScalable; }
|
||||||
std::vector<unsigned char>& getRawRGBAData() { return mDataRGBA; }
|
const std::vector<unsigned char>& getRawRGBAData() { return mDataRGBA; }
|
||||||
std::string getTextureFilePath() { return mPath; }
|
const std::string& getTextureFilePath() { return mPath; }
|
||||||
bool getTiled() { return mTile; }
|
const bool getTiled() { return mTile; }
|
||||||
|
const bool getIsInvalidSVGFile() { return mInvalidSVGFile; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Renderer* mRenderer;
|
Renderer* mRenderer;
|
||||||
|
|
|
@ -23,6 +23,7 @@ TextureResource::TextureResource(const std::string& path,
|
||||||
bool mipmapping,
|
bool mipmapping,
|
||||||
bool scalable)
|
bool scalable)
|
||||||
: mTextureData {nullptr}
|
: mTextureData {nullptr}
|
||||||
|
, mInvalidSVGFile {false}
|
||||||
, mForceLoad {false}
|
, mForceLoad {false}
|
||||||
{
|
{
|
||||||
// Create a texture data object for this texture.
|
// Create a texture data object for this texture.
|
||||||
|
@ -38,6 +39,8 @@ TextureResource::TextureResource(const std::string& path,
|
||||||
data->setMipmapping(mipmapping);
|
data->setMipmapping(mipmapping);
|
||||||
// Force the texture manager to load it using a blocking load.
|
// Force the texture manager to load it using a blocking load.
|
||||||
sTextureDataManager.load(data, true);
|
sTextureDataManager.load(data, true);
|
||||||
|
if (scalable)
|
||||||
|
mInvalidSVGFile = data->getIsInvalidSVGFile();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mTextureData = std::shared_ptr<TextureData>(new TextureData(tile));
|
mTextureData = std::shared_ptr<TextureData>(new TextureData(tile));
|
||||||
|
@ -48,6 +51,8 @@ TextureResource::TextureResource(const std::string& path,
|
||||||
data->setMipmapping(mipmapping);
|
data->setMipmapping(mipmapping);
|
||||||
// Load it so we can read the width/height.
|
// Load it so we can read the width/height.
|
||||||
data->load();
|
data->load();
|
||||||
|
if (scalable)
|
||||||
|
mInvalidSVGFile = data->getIsInvalidSVGFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
mSize = glm::ivec2 {static_cast<int>(data->width()), static_cast<int>(data->height())};
|
mSize = glm::ivec2 {static_cast<int>(data->width()), static_cast<int>(data->height())};
|
||||||
|
|
|
@ -61,6 +61,7 @@ public:
|
||||||
|
|
||||||
void rasterizeAt(float width, float height);
|
void rasterizeAt(float width, float height);
|
||||||
glm::vec2 getSourceImageSize() const { return mSourceSize; }
|
glm::vec2 getSourceImageSize() const { return mSourceSize; }
|
||||||
|
const bool getIsInvalidSVGFile() const { return mInvalidSVGFile; }
|
||||||
|
|
||||||
virtual ~TextureResource();
|
virtual ~TextureResource();
|
||||||
|
|
||||||
|
@ -101,6 +102,7 @@ private:
|
||||||
|
|
||||||
glm::ivec2 mSize;
|
glm::ivec2 mSize;
|
||||||
glm::vec2 mSourceSize;
|
glm::vec2 mSourceSize;
|
||||||
|
bool mInvalidSVGFile;
|
||||||
bool mForceLoad;
|
bool mForceLoad;
|
||||||
|
|
||||||
// File path, tile, linear interpolation, scalable/SVG, width, height.
|
// File path, tile, linear interpolation, scalable/SVG, width, height.
|
||||||
|
|
Loading…
Reference in a new issue