mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 07:35: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) {
|
||||
mTexture = TextureResource::get(path, tile, mForceLoad, mDynamic, mLinearInterpolation,
|
||||
mMipmapping, 0, 0, 0.0f, 0.0f);
|
||||
if (tile && (mTileWidth == 0.0f || mTileHeight == 0.0f))
|
||||
setTileAxes();
|
||||
resize(false);
|
||||
mTexture.reset();
|
||||
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();
|
||||
if (mTexture->getIsInvalidSVGFile()) {
|
||||
mTexture.reset();
|
||||
}
|
||||
else {
|
||||
if (tile && (mTileWidth == 0.0f || mTileHeight == 0.0f))
|
||||
setTileAxes();
|
||||
resize(false);
|
||||
mTexture.reset();
|
||||
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 {
|
||||
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);
|
||||
|
||||
if (svgImage == nullptr) {
|
||||
// LOG(LogError) << "Couldn't parse SVG image:" << mPath;
|
||||
LOG(LogDebug) << "TextureData::initSVGFromMemory(): Couldn't parse SVG image \"" << mPath
|
||||
<< "\"";
|
||||
mInvalidSVGFile = true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -73,9 +73,10 @@ public:
|
|||
const bool getPendingRasterization() { return mPendingRasterization; }
|
||||
|
||||
const bool getScalable() { return mScalable; }
|
||||
std::vector<unsigned char>& getRawRGBAData() { return mDataRGBA; }
|
||||
std::string getTextureFilePath() { return mPath; }
|
||||
bool getTiled() { return mTile; }
|
||||
const std::vector<unsigned char>& getRawRGBAData() { return mDataRGBA; }
|
||||
const std::string& getTextureFilePath() { return mPath; }
|
||||
const bool getTiled() { return mTile; }
|
||||
const bool getIsInvalidSVGFile() { return mInvalidSVGFile; }
|
||||
|
||||
private:
|
||||
Renderer* mRenderer;
|
||||
|
|
|
@ -23,6 +23,7 @@ TextureResource::TextureResource(const std::string& path,
|
|||
bool mipmapping,
|
||||
bool scalable)
|
||||
: mTextureData {nullptr}
|
||||
, mInvalidSVGFile {false}
|
||||
, mForceLoad {false}
|
||||
{
|
||||
// Create a texture data object for this texture.
|
||||
|
@ -38,6 +39,8 @@ TextureResource::TextureResource(const std::string& path,
|
|||
data->setMipmapping(mipmapping);
|
||||
// Force the texture manager to load it using a blocking load.
|
||||
sTextureDataManager.load(data, true);
|
||||
if (scalable)
|
||||
mInvalidSVGFile = data->getIsInvalidSVGFile();
|
||||
}
|
||||
else {
|
||||
mTextureData = std::shared_ptr<TextureData>(new TextureData(tile));
|
||||
|
@ -48,6 +51,8 @@ TextureResource::TextureResource(const std::string& path,
|
|||
data->setMipmapping(mipmapping);
|
||||
// Load it so we can read the width/height.
|
||||
data->load();
|
||||
if (scalable)
|
||||
mInvalidSVGFile = data->getIsInvalidSVGFile();
|
||||
}
|
||||
|
||||
mSize = glm::ivec2 {static_cast<int>(data->width()), static_cast<int>(data->height())};
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
|
||||
void rasterizeAt(float width, float height);
|
||||
glm::vec2 getSourceImageSize() const { return mSourceSize; }
|
||||
const bool getIsInvalidSVGFile() const { return mInvalidSVGFile; }
|
||||
|
||||
virtual ~TextureResource();
|
||||
|
||||
|
@ -101,6 +102,7 @@ private:
|
|||
|
||||
glm::ivec2 mSize;
|
||||
glm::vec2 mSourceSize;
|
||||
bool mInvalidSVGFile;
|
||||
bool mForceLoad;
|
||||
|
||||
// File path, tile, linear interpolation, scalable/SVG, width, height.
|
||||
|
|
Loading…
Reference in a new issue