From 177dd23b7caa7e31b42b3d15abbf7fb4ada47556 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 21 Jun 2023 22:52:25 +0200 Subject: [PATCH] Added a setRawImage function to ImageComponent to load raw pixel data into textures --- es-core/src/components/ImageComponent.cpp | 9 +++++++++ es-core/src/components/ImageComponent.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index 801d2b4ed..e3e88d70f 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -128,6 +128,15 @@ void ImageComponent::setImage(const std::shared_ptr& texture, b resize(); } +void ImageComponent::setRawImage(const unsigned char* data, float width, float height) +{ + mTexture.reset(); + mTexture = TextureResource::get(""); + mTexture->initFromPixels(data, width, height); + + resize(); +} + void ImageComponent::setGameOverrideImage(const std::string& basename, const std::string& system) { if (mGameOverridePath == "") diff --git a/es-core/src/components/ImageComponent.h b/es-core/src/components/ImageComponent.h index 152058af9..91774c7da 100644 --- a/es-core/src/components/ImageComponent.h +++ b/es-core/src/components/ImageComponent.h @@ -29,6 +29,8 @@ public: void setImage(const char* data, size_t length, bool tile = false); // Use an already existing texture. void setImage(const std::shared_ptr& texture, bool resizeTexture = true); + // Loads a texture using raw image pixel data. + void setRawImage(const unsigned char* data, float width, float height); // Sets per-game overrides of static images using the game file basename. void setGameOverrideImage(const std::string& basename, const std::string& system) override;