mirror of
https://github.com/leozide/leocad.git
synced 2026-10-27 06:20:55 +00:00
Share library texture decoding between loading paths
The worker and synchronous texture paths duplicated embedded data decoding and disk/archive source handling. Centralize CPU decoding in DecodeTextureData while keeping resizing and upload behavior in each caller. Report synchronous decode failures consistently with the worker path. Validation: debug build and ten CPU decoding checks covering valid, corrupt, missing, and invalid embedded, disk, and archive sources.
This commit is contained in:
1 parent
476ebc06bf
commit
e3b0c24ecd
2 files changed
+21
-34
No files matched your search
+20
-34
@@ -729,6 +729,16 @@ lcResult<QByteArray> lcPiecesLibrary::DecodeEmbeddedData(const lcEmbeddedData& D
|
||||
}
|
||||
|
||||
lcTextureBuildResult lcPiecesLibrary::BuildTextureData(const lcTextureSourceSnapshot& Source)
|
||||
{
|
||||
lcTextureBuildResult Result = DecodeTextureData(Source);
|
||||
|
||||
if (Result.DecodedImage)
|
||||
Result.DecodedImage->ResizePow2();
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
lcTextureBuildResult lcPiecesLibrary::DecodeTextureData(const lcTextureSourceSnapshot& Source)
|
||||
{
|
||||
lcTextureBuildResult Result;
|
||||
|
||||
@@ -773,9 +783,7 @@ lcTextureBuildResult lcPiecesLibrary::BuildTextureData(const lcTextureSourceSnap
|
||||
Loaded = Result.DecodedImage->FileLoad(TextureFile);
|
||||
}
|
||||
|
||||
if (Loaded)
|
||||
Result.DecodedImage->ResizePow2();
|
||||
else
|
||||
if (!Loaded)
|
||||
{
|
||||
Result.DecodedImage.reset();
|
||||
Result.Error = lcTextureLoadError::DecodeFailed;
|
||||
@@ -2298,41 +2306,19 @@ void lcPiecesLibrary::UnloadUnusedParts()
|
||||
|
||||
bool lcPiecesLibrary::LoadTexture(lcTexture* Texture)
|
||||
{
|
||||
if (Texture->mEmbeddedData)
|
||||
lcTextureBuildResult Result = DecodeTextureData(SnapshotTextureSource(Texture));
|
||||
|
||||
if (!Result.DecodedImage)
|
||||
{
|
||||
const lcResult<QByteArray> Decoded = DecodeEmbeddedData(*Texture->mEmbeddedData);
|
||||
|
||||
if (!Decoded)
|
||||
{
|
||||
Texture->mState = lcTextureState::Failed;
|
||||
Texture->mLoadFailure = lcTextureLoadError::DecodeFailed;
|
||||
Texture->mLoadFailureDetails = Decoded.error();
|
||||
return false;
|
||||
}
|
||||
|
||||
lcMemFile TextureFile;
|
||||
const QByteArray& Bytes = Decoded.value();
|
||||
TextureFile.WriteBuffer(Bytes.constData(), Bytes.size());
|
||||
TextureFile.Seek(0, SEEK_SET);
|
||||
|
||||
return Texture->Load(TextureFile);
|
||||
Texture->mState = lcTextureState::Failed;
|
||||
Texture->mLoadFailure = Result.Error;
|
||||
Texture->mLoadFailureDetails = std::move(Result.ErrorDetails);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Texture->mFilePath.isEmpty())
|
||||
return Texture->Load(Texture->mFilePath);
|
||||
Texture->SetImage(std::move(*Result.DecodedImage));
|
||||
|
||||
QMutexLocker Lock(&mTextureMutex);
|
||||
const int Type = Texture->mArchiveType;
|
||||
|
||||
if (Type < 0 || Type >= static_cast<int>(lcZipFileType::Count) || Texture->mArchiveIndex < 0 || !mZipFiles[Type])
|
||||
return false;
|
||||
|
||||
lcMemFile TextureFile;
|
||||
|
||||
if (!mZipFiles[Type]->ExtractFile(Texture->mArchiveIndex, TextureFile))
|
||||
return false;
|
||||
|
||||
return Texture->Load(TextureFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
void lcPiecesLibrary::ReleaseTexture(lcTexture* Texture)
|
||||
|
||||
@@ -321,6 +321,7 @@ protected:
|
||||
bool WriteDirectoryCacheFile(const QString& FileName, lcMemFile& CacheFile);
|
||||
|
||||
static lcResult<QByteArray> DecodeEmbeddedData(const lcEmbeddedData& Data);
|
||||
lcTextureBuildResult DecodeTextureData(const lcTextureSourceSnapshot& Source);
|
||||
static QString FindProjectTextureFile(const QString& ProjectPath, const QString& TextureName);
|
||||
static bool IsStudPrimitive(const char* FileName);
|
||||
static bool IsStudStylePrimitive(const char* FileName);
|
||||
|
||||
Reference in new issue
Block a user