Added a setRawImage function to ImageComponent to load raw pixel data into textures

This commit is contained in:
Leon Styhre 2023-06-21 22:52:25 +02:00
parent e7e3db7f6d
commit 177dd23b7c
2 changed files with 11 additions and 0 deletions

View file

@ -128,6 +128,15 @@ void ImageComponent::setImage(const std::shared_ptr<TextureResource>& texture, b
resize(); 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) void ImageComponent::setGameOverrideImage(const std::string& basename, const std::string& system)
{ {
if (mGameOverridePath == "") if (mGameOverridePath == "")

View file

@ -29,6 +29,8 @@ public:
void setImage(const char* data, size_t length, bool tile = false); void setImage(const char* data, size_t length, bool tile = false);
// Use an already existing texture. // Use an already existing texture.
void setImage(const std::shared_ptr<TextureResource>& texture, bool resizeTexture = true); void setImage(const std::shared_ptr<TextureResource>& 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. // Sets per-game overrides of static images using the game file basename.
void setGameOverrideImage(const std::string& basename, const std::string& system) override; void setGameOverrideImage(const std::string& basename, const std::string& system) override;