From 167dc1f9d43f4beee1b2b2423cd2051a720185b5 Mon Sep 17 00:00:00 2001 From: "Kueffner, Maximilian" Date: Fri, 23 May 2025 15:15:01 +0200 Subject: [PATCH] micro improvements --- .gitignore | 1 + lib/imaging/Image.cpp | 7 +++++-- lib/imaging/Image.hpp | 13 ++++++------- lib/rendering/CvMatRender.cpp | 4 +++- lib/rendering/CvMatRender.hpp | 2 +- src/AppGLFW.cpp | 2 +- src/main.cpp | 3 ++- 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 744582f..93f8500 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build/ out/ .vs/ +.cache/ *~ \ No newline at end of file diff --git a/lib/imaging/Image.cpp b/lib/imaging/Image.cpp index 1f3988f..22f187b 100644 --- a/lib/imaging/Image.cpp +++ b/lib/imaging/Image.cpp @@ -1,15 +1,18 @@ #include "Image.hpp" #include +#include +#include #include #include +#include pixelarium::imaging::Image::Image(const std::string& uri) { if (!std::filesystem::exists(uri)) { - throw std::runtime_error("File not found"); + throw std::runtime_error(std::format("File not {} found", uri)); } - this->_img = cv::imread(uri); + this->_img = std::make_unique(cv::imread(uri)); } \ No newline at end of file diff --git a/lib/imaging/Image.hpp b/lib/imaging/Image.hpp index 564b8db..7f43f6d 100644 --- a/lib/imaging/Image.hpp +++ b/lib/imaging/Image.hpp @@ -1,10 +1,7 @@ #pragma once -#include #include #include -#include -#include #include namespace pixelarium::imaging @@ -17,16 +14,18 @@ class Image // get back the defaults Image() = default; - Image(const Image& other) = default; + // we cannot copy an Image since this conflicts with the _img field + Image(const Image& other) = delete; Image(Image&& other) noexcept = default; - Image& operator=(const Image& other) = default; + // requires a copy ctor which we don't have + Image& operator=(const Image& other) = delete; Image& operator=(Image&& other) noexcept = default; ~Image() = default; - const cv::Mat& GetImage() const { return this->_img; } + const cv::Mat& GetImage() const { return *this->_img.get(); } private: - cv::Mat _img; + std::unique_ptr _img; }; } // namespace pixelarium::imaging \ No newline at end of file diff --git a/lib/rendering/CvMatRender.cpp b/lib/rendering/CvMatRender.cpp index a632e5f..9017806 100644 --- a/lib/rendering/CvMatRender.cpp +++ b/lib/rendering/CvMatRender.cpp @@ -7,15 +7,17 @@ #include #include #include "imaging/Image.hpp" +#include using namespace pixelarium::imaging; pixelarium::render::CvMatRender::CvMatRender(const std::shared_ptr& img) : _base(img), _texture(0) { - this->_img = this->_base->GetImage().clone(); + // this->_img = this->_base->GetImage().clone(); // // storing a copy of the to-be-rendered image with a "well-behaved" // cv::cvtColor(this->_img, this->_img, cv::COLOR_BGR2RGBA); + this->_img = this->_base->GetImage().clone(); } /*static*/ void pixelarium::render::matToTexture(const cv::Mat& image, diff --git a/lib/rendering/CvMatRender.hpp b/lib/rendering/CvMatRender.hpp index 6a94bcb..5d4d374 100644 --- a/lib/rendering/CvMatRender.hpp +++ b/lib/rendering/CvMatRender.hpp @@ -1,5 +1,5 @@ #pragma once -// windows. must come before GL/GL.h here. +// windows.h must come before GL/GL.h here. // clang format would change this, effectively rendering the build broken. // clang-format off #include diff --git a/src/AppGLFW.cpp b/src/AppGLFW.cpp index 0e1065f..876980d 100644 --- a/src/AppGLFW.cpp +++ b/src/AppGLFW.cpp @@ -221,7 +221,7 @@ void pixelarium::ui::AppGLFW::LoadImageProt() // __FUNCTION__); if (this->_logger) { - this->_logger->Warn("Creating image"); + this->_logger->Warn(std::format("Creating image {}", p)); } // this->_img = Image(p); this->_img = std::make_shared(p); diff --git a/src/main.cpp b/src/main.cpp index d287020..1955dc2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,7 @@ #include "AppGLFW.hpp" #include "utilities/ILog.hpp" #include "utilities/SpdLogger.hpp" +#include "uiresources.h" int main(int argc, char** argv) { @@ -16,7 +17,7 @@ int main(int argc, char** argv) auto app = pixelarium::ui::AppGLFW(logger); // auto app = pixelarium::ui::AppGLFW(); - logger->Info("Starting Application"); + logger->Info(std::format("Starting Application {}", PIXELARIUM_TITLE)); logger->Error("Starting Application"); return app.Run(); } \ No newline at end of file