summaryrefslogtreecommitdiff
path: root/wx+/image_holder.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <shieldwed@outlook.com>2018-05-09 00:11:35 +0200
committerDaniel Wilhelm <shieldwed@outlook.com>2018-05-09 00:11:35 +0200
commit015bb675d6eb177900c8ac94a6d35edc5ad90576 (patch)
treeedde4153ce9b2ba6bdaf9d3c0af0966ed6dfd717 /wx+/image_holder.h
parent9.8 (diff)
downloadFreeFileSync-015bb675d6eb177900c8ac94a6d35edc5ad90576.tar.gz
FreeFileSync-015bb675d6eb177900c8ac94a6d35edc5ad90576.tar.bz2
FreeFileSync-015bb675d6eb177900c8ac94a6d35edc5ad90576.zip
9.9
Diffstat (limited to 'wx+/image_holder.h')
-rwxr-xr-xwx+/image_holder.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/wx+/image_holder.h b/wx+/image_holder.h
new file mode 100755
index 00000000..6804d5fc
--- /dev/null
+++ b/wx+/image_holder.h
@@ -0,0 +1,52 @@
+// *****************************************************************************
+// * This file is part of the FreeFileSync project. It is distributed under *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
+// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
+// *****************************************************************************
+
+#ifndef IMAGE_HOLDER_H_284578426342567457
+#define IMAGE_HOLDER_H_284578426342567457
+
+#include <memory>
+
+//used by fs/abstract.h => check carefully before adding dependencies!
+//DO NOT add any wx/wx+ includes!
+
+namespace zen
+{
+struct ImageHolder //prepare conversion to wxImage as much as possible while staying thread-safe (in contrast to wxIcon/wxBitmap)
+{
+ ImageHolder() {}
+
+ ImageHolder(int w, int h, bool withAlpha) : //init with allocated memory
+ width_(w), height_(h),
+ rgb_(static_cast<unsigned char*>(::malloc(w * h * 3))),
+ alpha_(withAlpha ? static_cast<unsigned char*>(::malloc(w * h)) : nullptr) {}
+
+ ImageHolder (ImageHolder&& tmp) = default; //
+ ImageHolder& operator=(ImageHolder&& tmp) = default; //move semantics only!
+ ImageHolder (const ImageHolder&) = delete; //
+ ImageHolder& operator=(const ImageHolder&) = delete; //
+
+ explicit operator bool() const { return rgb_.get() != nullptr; }
+
+ int getWidth () const { return width_; }
+ int getHeight() const { return height_; }
+
+ unsigned char* getRgb () { return rgb_ .get(); }
+ unsigned char* getAlpha() { return alpha_.get(); }
+
+ unsigned char* releaseRgb () { return rgb_ .release(); }
+ unsigned char* releaseAlpha() { return alpha_.release(); }
+
+ struct CLibFree { void operator()(unsigned char* p) const { ::free(p); } }; //use malloc/free to allow direct move into wxImage!
+
+private:
+ int width_ = 0;
+ int height_ = 0;
+ std::unique_ptr<unsigned char, CLibFree> rgb_; //optional
+ std::unique_ptr<unsigned char, CLibFree> alpha_; //
+};
+}
+
+#endif //IMAGE_HOLDER_H_284578426342567457
bgstack15