diff options
author | B. Stack <bgstack15@gmail.com> | 2022-02-06 16:41:53 -0500 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2022-02-06 16:41:53 -0500 |
commit | f6b6d222dc1a79c95f6756c707c5fcc3a785c030 (patch) | |
tree | 374c62790fde0ce5514ef56750d0ff023d61b528 /wx+/image_resources.cpp | |
parent | add upstream 11.16 (diff) | |
download | FreeFileSync-f6b6d222dc1a79c95f6756c707c5fcc3a785c030.tar.gz FreeFileSync-f6b6d222dc1a79c95f6756c707c5fcc3a785c030.tar.bz2 FreeFileSync-f6b6d222dc1a79c95f6756c707c5fcc3a785c030.zip |
add upstream 11.17
Diffstat (limited to 'wx+/image_resources.cpp')
-rw-r--r-- | wx+/image_resources.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/wx+/image_resources.cpp b/wx+/image_resources.cpp index fbfeb0d8..c7260c55 100644 --- a/wx+/image_resources.cpp +++ b/wx+/image_resources.cpp @@ -73,6 +73,7 @@ ImageHolder xbrzScale(int width, int height, const unsigned char* imageRgb, cons auto getScalerTask(const std::string& imageName, const wxImage& img, int hqScale, Protected<std::vector<std::pair<std::string, ImageHolder>>>& result) { + assert(runningOnMainThread()); return [imageName, width = img.GetWidth(), // height = img.GetHeight(), //don't call wxWidgets functions from worker thread @@ -89,18 +90,20 @@ auto getScalerTask(const std::string& imageName, const wxImage& img, int hqScale class HqParallelScaler { public: - HqParallelScaler(int hqScale) : hqScale_(hqScale) { assert(hqScale > 1); } + explicit HqParallelScaler(int hqScale) : hqScale_(hqScale) { assert(hqScale > 1); } ~HqParallelScaler() { threadGroup_ = {}; } //imgKeeper_ must out-live threadGroup!!! void add(const std::string& imageName, const wxImage& img) { + assert(runningOnMainThread()); imgKeeper_.push_back(img); //retain (ref-counted) wxImage so that the rgb/alpha pointers remain valid after passed to threads threadGroup_->run(getScalerTask(imageName, img, hqScale_, result_)); } std::unordered_map<std::string, wxImage> waitAndGetResult() { + assert(runningOnMainThread()); threadGroup_->wait(); std::unordered_map<std::string, wxImage> output; @@ -184,14 +187,17 @@ ImageBuffer::ImageBuffer(const Zstring& zipPath) //throw FileError //do NOT rely on wxConvLocal! On failure shows unhelpful popup "Cannot convert from the charset 'Unknown encoding (-1)'!" while (const auto& entry = std::unique_ptr<wxZipEntry>(zipStream.GetNextEntry())) //take ownership! - if (std::string stream(entry->GetSize(), '\0'); !stream.empty() && zipStream.ReadAll(&stream[0], stream.size())) + if (std::string stream(entry->GetSize(), '\0'); + zipStream.ReadAll(stream.data(), stream.size())) streams.emplace_back(utfTo<Zstring>(entry->GetName()), std::move(stream)); else assert(false); } catch (FileError&) //fall back to folder { - traverseFolder(beforeLast(zipPath, Zstr(".zip"), IfNotFoundReturn::none), [&](const FileInfo& fi) + const Zstring fallbackFolder = beforeLast(zipPath, Zstr(".zip"), IfNotFoundReturn::none); + if (dirAvailable(fallbackFolder)) //Debug build (only!?) + traverseFolder(fallbackFolder, [&](const FileInfo& fi) { if (endsWith(fi.fullPath, Zstr(".png"))) { @@ -199,6 +205,8 @@ ImageBuffer::ImageBuffer(const Zstring& zipPath) //throw FileError streams.emplace_back(fi.itemName, std::move(stream)); } }, nullptr, nullptr, [](const std::wstring& errorMsg) { throw FileError(errorMsg); }); + else + throw; } //-------------------------------------------------------------------- |