Manual merge of fix png alpha channel support for gtk3 #5298
This commit is contained in:
parent
10be5d1361
commit
44dacdd4f8
1 changed files with 14 additions and 11 deletions
|
@ -7,14 +7,11 @@
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#if ! defined(WIN32) && ! defined(__APPLE__)
|
#ifdef __WXGTK2__
|
||||||
#define BROKEN_ALPHA
|
// Broken alpha workaround
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef BROKEN_ALPHA
|
|
||||||
#include <wx/mstream.h>
|
#include <wx/mstream.h>
|
||||||
#include <wx/rawbmp.h>
|
#include <wx/rawbmp.h>
|
||||||
#endif /* BROKEN_ALPHA */
|
#endif /* __WXGTK2__ */
|
||||||
|
|
||||||
#define NANOSVG_IMPLEMENTATION
|
#define NANOSVG_IMPLEMENTATION
|
||||||
#include "nanosvg/nanosvg.h"
|
#include "nanosvg/nanosvg.h"
|
||||||
|
@ -44,7 +41,8 @@ void BitmapCache::clear()
|
||||||
|
|
||||||
static wxBitmap wxImage_to_wxBitmap_with_alpha(wxImage &&image, float scale = 1.0f)
|
static wxBitmap wxImage_to_wxBitmap_with_alpha(wxImage &&image, float scale = 1.0f)
|
||||||
{
|
{
|
||||||
#ifdef BROKEN_ALPHA
|
#ifdef __WXGTK2__
|
||||||
|
// Broken alpha workaround
|
||||||
wxMemoryOutputStream stream;
|
wxMemoryOutputStream stream;
|
||||||
image.SaveFile(stream, wxBITMAP_TYPE_PNG);
|
image.SaveFile(stream, wxBITMAP_TYPE_PNG);
|
||||||
wxStreamBuffer *buf = stream.GetOutputStreamBuffer();
|
wxStreamBuffer *buf = stream.GetOutputStreamBuffer();
|
||||||
|
@ -68,7 +66,11 @@ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, size_t width, size_
|
||||||
wxBitmap *bitmap = nullptr;
|
wxBitmap *bitmap = nullptr;
|
||||||
auto it = m_map.find(bitmap_key);
|
auto it = m_map.find(bitmap_key);
|
||||||
if (it == m_map.end()) {
|
if (it == m_map.end()) {
|
||||||
bitmap = new wxBitmap(width, height);
|
bitmap = new wxBitmap(width, height
|
||||||
|
#ifdef __WXGTK3__
|
||||||
|
, 32
|
||||||
|
#endif
|
||||||
|
);
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
// Contrary to intuition, the `scale` argument isn't "please scale this to such and such"
|
// Contrary to intuition, the `scale` argument isn't "please scale this to such and such"
|
||||||
// but rather "the wxImage is sized for backing scale such and such".
|
// but rather "the wxImage is sized for backing scale such and such".
|
||||||
|
@ -83,7 +85,8 @@ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, size_t width, size_
|
||||||
if (size_t(bitmap->GetWidth()) != width || size_t(bitmap->GetHeight()) != height)
|
if (size_t(bitmap->GetWidth()) != width || size_t(bitmap->GetHeight()) != height)
|
||||||
bitmap->Create(width, height);
|
bitmap->Create(width, height);
|
||||||
}
|
}
|
||||||
#ifndef BROKEN_ALPHA
|
#if defined(WIN32) || defined(__APPLE__)
|
||||||
|
// Not needed or harmful for GTK2 and GTK3.
|
||||||
bitmap->UseAlpha();
|
bitmap->UseAlpha();
|
||||||
#endif
|
#endif
|
||||||
return bitmap;
|
return bitmap;
|
||||||
|
@ -131,8 +134,8 @@ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, const wxBitmap *beg
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BROKEN_ALPHA
|
#ifdef __WXGTK2__
|
||||||
|
// Broken alpha workaround
|
||||||
wxImage image(width, height);
|
wxImage image(width, height);
|
||||||
image.InitAlpha();
|
image.InitAlpha();
|
||||||
// Fill in with a white color.
|
// Fill in with a white color.
|
||||||
|
|
Loading…
Reference in a new issue