From 16c10a5c4aa568d1f4459163be8a35e942e4213d Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Wed, 26 Nov 2025 00:10:41 +0100 Subject: [PATCH] optimizations --- implementations/Crafter.Graphics-ImageElement.cpp | 9 +++++++-- implementations/Crafter.Graphics-RenderingElement.cpp | 4 ---- implementations/Crafter.Graphics-TextElement.cpp | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/implementations/Crafter.Graphics-ImageElement.cpp b/implementations/Crafter.Graphics-ImageElement.cpp index 03afb90..ea1629c 100644 --- a/implementations/Crafter.Graphics-ImageElement.cpp +++ b/implementations/Crafter.Graphics-ImageElement.cpp @@ -34,7 +34,7 @@ ImageElement::ImageElement() : RenderingElement() { } -ImageElement::ImageElement(const std::string_view imagePath, std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : RenderingElement(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling) { +ImageElement::ImageElement(const std::string_view imagePath, std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : RenderingElement(false, anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling) { RenderImage(imagePath); } @@ -42,7 +42,8 @@ void ImageElement::RenderImage(const std::string_view path) { std::filesystem::path abs = std::filesystem::absolute(path); int xSize; int ySize; - unsigned char* bgData = stbi_load(abs.string().c_str(), &xSize, &ySize, nullptr, 4); + int channels; + unsigned char* bgData = stbi_load(abs.string().c_str(), &xSize, &ySize, &channels, 4); ResizeBuffer(xSize, ySize); @@ -55,4 +56,8 @@ void ImageElement::RenderImage(const std::string_view path) { buffer[x*ySize+y].a = bgData[idx+3]; } } + + if(channels != 4) { + opaque = true; + } } \ No newline at end of file diff --git a/implementations/Crafter.Graphics-RenderingElement.cpp b/implementations/Crafter.Graphics-RenderingElement.cpp index c05c322..238a8fc 100644 --- a/implementations/Crafter.Graphics-RenderingElement.cpp +++ b/implementations/Crafter.Graphics-RenderingElement.cpp @@ -18,10 +18,6 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -module; -#define STB_IMAGE_IMPLEMENTATION -#include "../lib/stb_image.h" -#include "../lib/stb_truetype.h" module Crafter.Graphics:RenderingElement_impl; import :RenderingElement; import :Window; diff --git a/implementations/Crafter.Graphics-TextElement.cpp b/implementations/Crafter.Graphics-TextElement.cpp index 11b462d..ea7e4de 100644 --- a/implementations/Crafter.Graphics-TextElement.cpp +++ b/implementations/Crafter.Graphics-TextElement.cpp @@ -34,7 +34,7 @@ TextElement::TextElement() : RenderingElement() { } -TextElement::TextElement(const std::string_view text, float size, Pixel_BU8_GU8_RU8_AU8 pixel, Font& font, std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : RenderingElement(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling) { +TextElement::TextElement(const std::string_view text, float size, Pixel_BU8_GU8_RU8_AU8 pixel, Font& font, std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : RenderingElement(false, anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling) { RenderText(text, size, pixel, font); }