summaryrefslogtreecommitdiff
path: root/wx+
diff options
context:
space:
mode:
authorDaniel Wilhelm <shieldwed@outlook.com>2020-02-23 22:12:27 +0000
committerDaniel Wilhelm <shieldwed@outlook.com>2020-02-23 22:12:27 +0000
commit450f803dd75f831f8ee14072fe0eb664bbe518df (patch)
treeb3e831d44df50348a20f3541b6062f7fbab6ff3d /wx+
parentMerge branch '10.19' into 'master' (diff)
parentremove upstream deleted files (diff)
downloadFreeFileSync-450f803dd75f831f8ee14072fe0eb664bbe518df.tar.gz
FreeFileSync-450f803dd75f831f8ee14072fe0eb664bbe518df.tar.bz2
FreeFileSync-450f803dd75f831f8ee14072fe0eb664bbe518df.zip
Merge branch '10.20' into 'master'10.20
add upstream 10.20 See merge request opensource-tracking/FreeFileSync!17
Diffstat (limited to 'wx+')
-rw-r--r--wx+/image_resources.cpp16
-rw-r--r--wx+/image_tools.h12
2 files changed, 19 insertions, 9 deletions
diff --git a/wx+/image_resources.cpp b/wx+/image_resources.cpp
index 2a3b7039..070b9112 100644
--- a/wx+/image_resources.cpp
+++ b/wx+/image_resources.cpp
@@ -187,7 +187,7 @@ void GlobalBitmaps::init(const Zstring& zipPath)
{
assert(bitmaps_.empty() && anims_.empty());
- std::vector<std::pair<Zstring /*file name*/, std::string /*byte stream*/>> streams;
+ std::vector<std::pair<wxString /*file name*/, std::string /*byte stream*/>> streams;
try //to load from ZIP first:
{
@@ -199,7 +199,7 @@ void GlobalBitmaps::init(const Zstring& zipPath)
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()))
- streams.emplace_back(utfTo<Zstring>(entry->GetName()), std::move(stream));
+ streams.emplace_back(entry->GetName(), std::move(stream));
else
assert(false);
}
@@ -211,7 +211,7 @@ void GlobalBitmaps::init(const Zstring& zipPath)
try
{
std::string stream = loadBinContainer<std::string>(fi.fullPath, nullptr /*notifyUnbufferedIO*/); //throw FileError
- streams.emplace_back(fi.itemName, std::move(stream));
+ streams.emplace_back(utfTo<wxString>(fi.itemName), std::move(stream));
}
catch (FileError&) { assert(false); }
}, nullptr, nullptr, [](const std::wstring& errorMsg) { assert(false); }); //errors are not really critical in this context
@@ -229,12 +229,10 @@ void GlobalBitmaps::init(const Zstring& zipPath)
for (const auto& [fileName, stream] : streams)
{
- const wxString& name = utfTo<wxString>(afterLast(fileName, FILE_NAME_SEPARATOR, IF_MISSING_RETURN_ALL));
-
wxMemoryInputStream wxstream(stream.c_str(), stream.size()); //stream does not take ownership of data
//bonus: work around wxWidgets bug: wxAnimation::Load() requires seekable input stream (zip-input stream is not seekable)
- if (endsWith(name, L".png"))
+ if (endsWith(fileName, L".png"))
{
wxImage img(wxstream, wxBITMAP_TYPE_PNG);
assert(img.IsOk());
@@ -244,14 +242,14 @@ void GlobalBitmaps::init(const Zstring& zipPath)
convertToVanillaImage(img);
if (dpiScaler_)
- dpiScaler_->add(name, img); //scale in parallel!
+ dpiScaler_->add(fileName, img); //scale in parallel!
else
- bitmaps_.emplace(name, img);
+ bitmaps_.emplace(fileName, img);
}
#if 0
else if (endsWith(name, L".gif"))
{
- [[maybe_unused]] const bool loadSuccess = anims_[name].Load(wxstream, wxANIMATION_TYPE_GIF);
+ [[maybe_unused]] const bool loadSuccess = anims_[fileName].Load(wxstream, wxANIMATION_TYPE_GIF);
assert(loadSuccess);
}
#endif
diff --git a/wx+/image_tools.h b/wx+/image_tools.h
index e2d42fb0..3e401f73 100644
--- a/wx+/image_tools.h
+++ b/wx+/image_tools.h
@@ -38,6 +38,8 @@ wxImage layOver(const wxImage& back, const wxImage& front, int alignment = wxALI
wxImage greyScale(const wxImage& img); //greyscale + brightness adaption
wxBitmap greyScale(const wxBitmap& bmp); //
+wxBitmap greyScaleIfDisabled(const wxBitmap& bmp, bool enabled);
+
//void moveImage(wxImage& img, int right, int up);
void adjustBrightness(wxImage& img, int targetLevel);
@@ -99,6 +101,16 @@ wxBitmap greyScale(const wxBitmap& bmp)
inline
+wxBitmap greyScaleIfDisabled(const wxBitmap& bmp, bool enabled)
+{
+ if (enabled) //avoid ternary WTF
+ return bmp;
+ else
+ return greyScale(bmp);
+}
+
+
+inline
double getAvgBrightness(const wxImage& img)
{
const int pixelCount = img.GetWidth() * img.GetHeight();
bgstack15