summaryrefslogtreecommitdiff
path: root/wx+/image_resources.cpp
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-02-07 00:18:30 +0000
committerB. Stack <bgstack15@gmail.com>2022-02-07 00:18:30 +0000
commit4cba562d787bfc92aeadbbc2ef199d4856523247 (patch)
tree374c62790fde0ce5514ef56750d0ff023d61b528 /wx+/image_resources.cpp
parentMerge branch 'b11.16' into 'master' (diff)
parent add upstream 11.17 (diff)
downloadFreeFileSync-4cba562d787bfc92aeadbbc2ef199d4856523247.tar.gz
FreeFileSync-4cba562d787bfc92aeadbbc2ef199d4856523247.tar.bz2
FreeFileSync-4cba562d787bfc92aeadbbc2ef199d4856523247.zip
Merge branch 'b11.17' into 'master'11.17
add upstream 11.17 See merge request opensource-tracking/FreeFileSync!41
Diffstat (limited to 'wx+/image_resources.cpp')
-rw-r--r--wx+/image_resources.cpp14
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;
}
//--------------------------------------------------------------------
bgstack15