nodes: Added RGBA8 image visualizer

This commit is contained in:
WerWolv
2022-10-13 15:13:53 +02:00
parent 8b39c8f219
commit 1ab949b7ef
11 changed files with 75 additions and 2 deletions

View File

@@ -34,7 +34,7 @@ namespace ImGui {
class Texture {
public:
Texture() = default;
Texture(const ImU8 *buffer, int size);
Texture(const ImU8 *buffer, int size, int width = 0, int height = 0);
explicit Texture(const char *path);
Texture(const Texture&) = delete;
Texture(Texture&& other) noexcept;

View File

@@ -16,8 +16,17 @@
namespace ImGui {
Texture::Texture(const ImU8 *buffer, int size) {
Texture::Texture(const ImU8 *buffer, int size, int width, int height) {
unsigned char *imageData = stbi_load_from_memory(buffer, size, &this->m_width, &this->m_height, nullptr, 4);
if (imageData == nullptr) {
if (width * height * 4 > size)
return;
imageData = (unsigned char*) STBI_MALLOC(size);
std::memcpy(imageData, buffer, size);
this->m_width = width;
this->m_height = height;
}
if (imageData == nullptr)
return;