14 if (!wx.IsOk() || wx.GetSize() != wxSize(size.
x, size.
y)) {
15 wx.Create(size.
x, size.
y, 32);
19 wxAlphaPixelData pixels(wx);
22 wxAlphaPixelData::Iterator iterator(pixels);
24 for (
int y = 0; y < bitmap.
size().y; ++y) {
25 for (
int x = 0; x < bitmap.
size().x; ++x) {
28 iterator.Red() = color.Red();
29 iterator.Green() = color.Green();
30 iterator.Blue() = color.Blue();
31 iterator.Alpha() =
clamp(
int(255.f * rgba.
a()), 0, 255);
42 wxNativePixelData pixels(wx);
44 wxNativePixelData::Iterator iterator(pixels);
47 std::is_same<std::decay_t<decltype(iterator.Red())>,
unsigned char>::value,
"expected unsigned char");
49 for (
int y = 0; y < bitmap.
size().y; ++y) {
50 for (
int x = 0; x < bitmap.
size().x; ++x) {
51 bitmap[
Pixel(x, y)] =
Rgba(wxColour(iterator.Red(), iterator.Green(), iterator.Blue()));
61 wx.SaveFile(path.
native().c_str(), wxBITMAP_TYPE_PNG);
71 wxLogNull logNullGuard;
73 if (!wx.LoadFile(path.
native().c_str())) {
78 throw IoError(
"Bitmap '" + path.
native() +
"' failed to load correctly");
#define SPH_ASSERT(x,...)
Bitmap< Rgba > loadBitmapFromFile(const Path &path)
Bitmap< Rgba > toBitmap(wxBitmap &wx)
void saveToFile(const wxBitmap &wx, const Path &path)
NAMESPACE_SPH_BEGIN void toWxBitmap(const Bitmap< Rgba > &bitmap, wxBitmap &wx)
Wrapper of wxBitmap, will be possibly replaced by custom implementation.
constexpr INLINE T clamp(const T &f, const T &f1, const T &f2)
#define NAMESPACE_SPH_END
Object representing a path on a filesystem, similar to std::filesystem::path in c++17.
Interface for executing tasks (potentially) asynchronously.
Exception thrown when file cannot be read, it has invalid format, etc.
Object representing a path on a filesystem.
std::string native() const
Returns the native version of the path.
Path parentPath() const
Returns the parent directory. If the path is empty or root, return empty path.
Outcome createDirectory(const Path &path, const Flags< CreateDirectoryFlag > flags=CreateDirectoryFlag::ALLOW_EXISTING)
Creates a directory with given path. Creates all parent directories as well.