From bb807ea0fd605c486bb7ec928ad8edc819ec9c2b Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 2 Oct 2015 14:54:58 +0200 Subject: 6.15 --- wx+/image_tools.h | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'wx+/image_tools.h') diff --git a/wx+/image_tools.h b/wx+/image_tools.h index cb8da60b..b53d42ea 100644 --- a/wx+/image_tools.h +++ b/wx+/image_tools.h @@ -33,10 +33,10 @@ wxImage stackImages(const wxImage& img1, const wxImage& img2, ImageStackLayout d wxImage createImageFromText(const wxString& text, const wxFont& font, const wxColor& col); +wxBitmap layOver(const wxBitmap& foreground, const wxBitmap& background); //merge wxImage greyScale(const wxImage& img); //greyscale + brightness adaption wxBitmap greyScale(const wxBitmap& bmp); // -wxBitmap layOver(const wxBitmap& foreground, const wxBitmap& background); //merge //void moveImage(wxImage& img, int right, int up); void adjustBrightness(wxImage& img, int targetLevel); @@ -45,6 +45,8 @@ void brighten(wxImage& img, int level); //level: delta per channel in points bool isEqual(const wxBitmap& lhs, const wxBitmap& rhs); //pixel-wise equality (respecting alpha channel) +void convertToVanillaImage(wxImage& img); //add alpha channel if missing + remove mask if existing + //wxColor gradient(const wxColor& from, const wxColor& to, double fraction); //maps fraction within [0, 1] to an intermediate color //wxColour hsvColor(double h, double s, double v); //h within [0, 360), s, v within [0, 1] @@ -147,15 +149,15 @@ void adjustBrightness(wxImage& img, int targetLevel) inline wxBitmap layOver(const wxBitmap& foreground, const wxBitmap& background) { - wxBitmap output = background; + assert(foreground.HasAlpha() == background.HasAlpha()); //we don't support mixed-mode brittleness! + + wxBitmap output(background.ConvertToImage()); //attention: wxBitmap/wxImage use ref-counting without copy on write! { - wxMemoryDC dc; - dc.SelectObject(output); + wxMemoryDC dc(output); const int offsetX = (background.GetWidth () - foreground.GetWidth ()) / 2; const int offsetY = (background.GetHeight() - foreground.GetHeight()) / 2; - dc.DrawBitmap(foreground, offsetX, offsetY, true); - dc.SelectObject(wxNullBitmap); + dc.DrawBitmap(foreground, offsetX, offsetY); } return output; } @@ -179,13 +181,14 @@ bool isEqual(const wxBitmap& lhs, const wxBitmap& rhs) if (imLhs.HasAlpha() != imRhs.HasAlpha()) return false; - if (imLhs.HasAlpha()) - { + if (!std::equal(imLhs.GetData(), imLhs.GetData() + pixelCount * 3, imRhs.GetData())) + return false; + + if (imLhs.HasAlpha()) if (!std::equal(imLhs.GetAlpha(), imLhs.GetAlpha() + pixelCount, imRhs.GetAlpha())) return false; - } - return std::equal(imLhs.GetData(), imLhs.GetData() + pixelCount * 3, imRhs.GetData()); + return true; } /* -- cgit