summaryrefslogtreecommitdiff
path: root/wx+/image_tools.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2015-10-02 14:54:58 +0200
committerDaniel Wilhelm <daniel@wili.li>2015-10-02 14:54:58 +0200
commitbb807ea0fd605c486bb7ec928ad8edc819ec9c2b (patch)
tree16fdbd4d91a290d43444dd812720c42948b27754 /wx+/image_tools.cpp
parent6.14 (diff)
downloadFreeFileSync-bb807ea0fd605c486bb7ec928ad8edc819ec9c2b.tar.gz
FreeFileSync-bb807ea0fd605c486bb7ec928ad8edc819ec9c2b.tar.bz2
FreeFileSync-bb807ea0fd605c486bb7ec928ad8edc819ec9c2b.zip
6.15
Diffstat (limited to 'wx+/image_tools.cpp')
-rw-r--r--wx+/image_tools.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/wx+/image_tools.cpp b/wx+/image_tools.cpp
index 1dbd5d46..859c9e5a 100644
--- a/wx+/image_tools.cpp
+++ b/wx+/image_tools.cpp
@@ -76,7 +76,6 @@ wxImage zen::stackImages(const wxImage& img1, const wxImage& img2, ImageStackLay
wxImage output(width, height);
output.SetAlpha();
::memset(output.GetAlpha(), wxIMAGE_ALPHA_TRANSPARENT, width * height);
- ::memset(output.GetData (), 0, 3 * width * height); //redundant due to transparent alpha
auto calcPos = [&](int imageExtent, int totalExtent)
{
@@ -185,3 +184,46 @@ wxImage zen::createImageFromText(const wxString& text, const wxFont& font, const
}
return output;
}
+
+
+void zen::convertToVanillaImage(wxImage& img)
+{
+ if (!img.HasAlpha())
+ {
+ unsigned char mask_r = 0;
+ unsigned char mask_g = 0;
+ unsigned char mask_b = 0;
+ const bool haveMask = img.HasMask() && img.GetOrFindMaskColour(&mask_r, &mask_g, &mask_b);
+ //check for mask before calling wxImage::GetOrFindMaskColour() to skip needlessly searching for new mask color
+
+ img.SetAlpha();
+ ::memset(img.GetAlpha(), wxIMAGE_ALPHA_OPAQUE, img.GetWidth() * img.GetHeight());
+
+ //wxWidgets, as always, tries to be more clever than it really is and fucks up wxStaticBitmap if wxBitmap is fully opaque:
+ img.GetAlpha()[img.GetWidth() * img.GetHeight() - 1] = 254;
+
+ if (haveMask)
+ {
+ img.SetMask(false);
+ unsigned char* alphaPtr = img.GetAlpha();
+ const unsigned char* dataPtr = img.GetData();
+
+ const int pixelCount = img.GetWidth() * img.GetHeight();
+ for (int i = 0; i < pixelCount; ++ i)
+ {
+ const unsigned char r = *dataPtr++;
+ const unsigned char g = *dataPtr++;
+ const unsigned char b = *dataPtr++;
+
+ if (r == mask_r &&
+ g == mask_g &&
+ b == mask_b)
+ alphaPtr[i] = wxIMAGE_ALPHA_TRANSPARENT;
+ }
+ }
+ }
+ else
+ {
+ assert(!img.HasMask());
+ }
+} \ No newline at end of file
bgstack15