From fec5c08aaa62044d6b0d9cd34a9ce6b75b8520f5 Mon Sep 17 00:00:00 2001 From: m-aXimilian <56168660+m-aXimilian@users.noreply.github.com> Date: Tue, 7 Oct 2025 12:18:00 +0200 Subject: [PATCH] Transition to C++23 (#11) * enum field renaming * renderer cleanups * compiling for C++23 * version bump * fix build --- CMakeLists.txt | 10 ++++----- doc/versions.md | 1 + lib/imaging/IPixelariumImage.hpp | 12 +++++------ lib/imaging/PixelariumImageFactory.cpp | 10 ++++----- lib/imaging/PixelariumImageFactory.hpp | 8 +++---- lib/imaging/impl/PixelariumCzi.hpp | 2 +- lib/imaging/impl/PixelariumJpg.hpp | 2 +- lib/imaging/impl/PixelariumPng.hpp | 2 +- lib/rendering/CvMatRender.cpp | 22 ++++++++++++-------- lib/rendering/ImageViewFactory.cpp | 10 ++++----- lib/rendering/PixelariumImageViewCzi.cpp | 2 +- lib/rendering/PixelariumImageViewDefault.cpp | 2 +- lib/utilities/ILog.hpp | 10 ++++----- lib/utilities/SpdLogger.cpp | 20 +++++++++--------- src/main.cpp | 2 +- 15 files changed, 60 insertions(+), 55 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47989df..32e49ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 3.23) -project(pixelarium VERSION 0.0.4) +project(pixelarium VERSION 0.0.5) set(CMAKE_VERBOSE_MAKEFILE ON) -set(CXX_STANDARD 20) +set(CXX_STANDARD 23) set(CXX_STANDARD_REQUIRED true) # setting global module directories @@ -28,13 +28,13 @@ option(PIXELARIUM_BUILD_DOCS "Generate Documentation" ON) if(WIN32) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set(CMAKE_CXX_FLAGS "/std:c++20 /Zi /EHsc") + set(CMAKE_CXX_FLAGS "/std:c++23 /Zi /EHsc") else() - set(CMAKE_CXX_FLAGS "-Wall -Wextra -g --std=c++20") + set(CMAKE_CXX_FLAGS "-Wall -Wextra -g --std=c++23") endif() endif() if(UNIX) - set(CMAKE_CXX_FLAGS "-Wall -Wextra -g --std=c++20") + set(CMAKE_CXX_FLAGS "-Wall -Wextra -g --std=c++23") endif() string(TOUPPER "${CMAKE_PROJECT_NAME}" PIXELARIUM_TITLE) diff --git a/doc/versions.md b/doc/versions.md index 573a16d..92e482c 100644 --- a/doc/versions.md +++ b/doc/versions.md @@ -2,6 +2,7 @@ | Version | Description | |:-------:|:------------------------------------------------------------------------| +| 0.0.5 | Compile for C++23 and code style adaptions | | 0.0.4 | Fix MSVC build, some cosmetics, explicit initial window size for images | | 0.0.3 | Fetch subblocks based on the dimension selection sliders | | 0.0.2 | Add Dimension selector sliders to CZI image view | diff --git a/lib/imaging/IPixelariumImage.hpp b/lib/imaging/IPixelariumImage.hpp index 0390afd..2d5bd95 100644 --- a/lib/imaging/IPixelariumImage.hpp +++ b/lib/imaging/IPixelariumImage.hpp @@ -14,15 +14,15 @@ using ImageQueryFunctor = std::function; enum class ImageFileType { /// @brief Represents an unknown or unsupported file type. - UNKNOWN = -10, + kUnknown = -10, /// @brief Represents an abstract image type (e.g., a placeholder). - ABSTRACT = 0, + kAbstract = 0, /// @brief Represents a PNG image file. - PNG = 1, + kPng = 1, /// @brief Represents a JPG image file. - JPG = 2, + kJpg = 2, /// @brief Represents a CZI image file. - CZI = 3, + kCzi = 3, }; /// @brief An abstract interface to define a semantic query @@ -83,7 +83,7 @@ class IPixelariumImage } public: - const static ImageFileType type_{ImageFileType::ABSTRACT}; + const static ImageFileType type_{ImageFileType::kAbstract}; protected: std::filesystem::path uri_; diff --git a/lib/imaging/PixelariumImageFactory.cpp b/lib/imaging/PixelariumImageFactory.cpp index cb67e26..84b6c2c 100644 --- a/lib/imaging/PixelariumImageFactory.cpp +++ b/lib/imaging/PixelariumImageFactory.cpp @@ -16,19 +16,19 @@ pixelarium::imaging::PixelariumImageFactory::CreateImage(const std::string& uri, switch (target_type) { - case ImageFileType::UNKNOWN: + case ImageFileType::kUnknown: return {}; break; - case ImageFileType::ABSTRACT: + case ImageFileType::kAbstract: return {}; break; - case ImageFileType::PNG: + case ImageFileType::kPng: return std::make_unique(uri); break; - case ImageFileType::JPG: + case ImageFileType::kJpg: return std::make_unique(uri); break; - case ImageFileType::CZI: + case ImageFileType::kCzi: return std::make_unique(uri, log); break; } diff --git a/lib/imaging/PixelariumImageFactory.hpp b/lib/imaging/PixelariumImageFactory.hpp index d3da42b..39cebea 100644 --- a/lib/imaging/PixelariumImageFactory.hpp +++ b/lib/imaging/PixelariumImageFactory.hpp @@ -13,18 +13,18 @@ constexpr pixelarium::imaging::ImageFileType ExtensionToType(const std::string& if (lower_ext == ".jpg" || lower_ext == ".jpeg") { - return pixelarium::imaging::ImageFileType::JPG; + return pixelarium::imaging::ImageFileType::kJpg; } if (lower_ext == ".png") { - return pixelarium::imaging::ImageFileType::PNG; + return pixelarium::imaging::ImageFileType::kPng; } if (lower_ext == ".czi") { - return pixelarium::imaging::ImageFileType::CZI; + return pixelarium::imaging::ImageFileType::kCzi; } - return pixelarium::imaging::ImageFileType::UNKNOWN; + return pixelarium::imaging::ImageFileType::kUnknown; } /// @brief Factory for instantiating implementations of IPixelariumImage based on the given file type. diff --git a/lib/imaging/impl/PixelariumCzi.hpp b/lib/imaging/impl/PixelariumCzi.hpp index a1b7ec7..599f394 100644 --- a/lib/imaging/impl/PixelariumCzi.hpp +++ b/lib/imaging/impl/PixelariumCzi.hpp @@ -46,7 +46,7 @@ class PixelariumCzi : public IPixelariumImage const libCZI::SubBlockStatistics& GetStatistics() const { return this->image_statistics_; } public: - const static ImageFileType type_{ImageFileType::CZI}; + const static ImageFileType type_{ImageFileType::kCzi}; private: std::unique_ptr SubblockToCvMat(int index); diff --git a/lib/imaging/impl/PixelariumJpg.hpp b/lib/imaging/impl/PixelariumJpg.hpp index 9e66007..100b4cf 100644 --- a/lib/imaging/impl/PixelariumJpg.hpp +++ b/lib/imaging/impl/PixelariumJpg.hpp @@ -32,7 +32,7 @@ class PixelariumJpg : public IPixelariumImage bool Empty() const noexcept override { return this->is_empty_; } public: - const static ImageFileType type_{ImageFileType::JPG}; + const static ImageFileType type_{ImageFileType::kJpg}; private: // this should be set by each image getter diff --git a/lib/imaging/impl/PixelariumPng.hpp b/lib/imaging/impl/PixelariumPng.hpp index dacf31f..29be769 100644 --- a/lib/imaging/impl/PixelariumPng.hpp +++ b/lib/imaging/impl/PixelariumPng.hpp @@ -32,7 +32,7 @@ class PixelariumPng : public IPixelariumImage bool Empty() const noexcept override { return this->is_empty_; } public: - const static ImageFileType type_{ImageFileType::PNG}; + const static ImageFileType type_{ImageFileType::kPng}; private: // this should be set by each image getter diff --git a/lib/rendering/CvMatRender.cpp b/lib/rendering/CvMatRender.cpp index 402ca92..ef65228 100644 --- a/lib/rendering/CvMatRender.cpp +++ b/lib/rendering/CvMatRender.cpp @@ -55,21 +55,25 @@ GLuint pixelarium::render::CvMatRender::uploadTexture() const int width = img_.cols; const int height = img_.rows; - - switch (img_.type()) { + // see + // https://stackoverflow.com/questions/10167534/how-to-find-out-what-type-of-a-mat-object-is-with-mattype-in-opencv + // for pixel a pixel type table + switch (img_.type()) + { + case CV_8U: + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_BYTE, img_.data); + break; case CV_16U: case CV_16UC3: - case 26: - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + case CV_16UC4: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT, img_.data); break; - case 5: - case 29: - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, img_.data); + case CV_32F: + case CV_32FC4: + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, + img_.data); break; default: - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img_.cols, img_.rows, 0, GL_RGBA, GL_UNSIGNED_BYTE, img_.data); break; } diff --git a/lib/rendering/ImageViewFactory.cpp b/lib/rendering/ImageViewFactory.cpp index 15bffcb..4ab3796 100644 --- a/lib/rendering/ImageViewFactory.cpp +++ b/lib/rendering/ImageViewFactory.cpp @@ -33,15 +33,15 @@ std::unique_ptr pixelarium::render::Im switch (type) { - case imaging::ImageFileType::UNKNOWN: - case imaging::ImageFileType::ABSTRACT: + case imaging::ImageFileType::kUnknown: + case imaging::ImageFileType::kAbstract: return {}; - case imaging::ImageFileType::PNG: - case imaging::ImageFileType::JPG: + case imaging::ImageFileType::kPng: + case imaging::ImageFileType::kJpg: log_.Info(std::format("{}: Creating a Default View", __PRETTY_FUNCTION__)); // beware: here we copy the actual image resource over to the new image return std::make_unique(img); - case imaging::ImageFileType::CZI: + case imaging::ImageFileType::kCzi: log_.Info(std::format("{}: Creating a CZI View", __PRETTY_FUNCTION__)); // beware: here we copy the actual image resource over to the new image return std::make_unique(img, log_); diff --git a/lib/rendering/PixelariumImageViewCzi.cpp b/lib/rendering/PixelariumImageViewCzi.cpp index 3f59489..a761a11 100644 --- a/lib/rendering/PixelariumImageViewCzi.cpp +++ b/lib/rendering/PixelariumImageViewCzi.cpp @@ -51,7 +51,7 @@ void pixelarium::render::PixelariumImageViewCzi::ShowImage() this->is_dirty_ = false; } - if (czi_img->Empty() || this->img_->type_ == imaging::ImageFileType::UNKNOWN || !cached_image_ || + if (czi_img->Empty() || this->img_->type_ == imaging::ImageFileType::kUnknown || !cached_image_ || czi_img->Name().empty()) { // do nothing diff --git a/lib/rendering/PixelariumImageViewDefault.cpp b/lib/rendering/PixelariumImageViewDefault.cpp index 03f24dc..4af5d5f 100644 --- a/lib/rendering/PixelariumImageViewDefault.cpp +++ b/lib/rendering/PixelariumImageViewDefault.cpp @@ -18,7 +18,7 @@ void pixelarium::render::PixelariumImageViewDefault::ShowImage() this->is_dirty_ = false; } - if (this->img_->Empty() || this->img_->type_ == imaging::ImageFileType::UNKNOWN || !cached_image_ || + if (this->img_->Empty() || this->img_->type_ == imaging::ImageFileType::kUnknown || !cached_image_ || this->img_->Name().empty()) { // do nothing diff --git a/lib/utilities/ILog.hpp b/lib/utilities/ILog.hpp index 8bd9217..274e28f 100644 --- a/lib/utilities/ILog.hpp +++ b/lib/utilities/ILog.hpp @@ -10,11 +10,11 @@ namespace pixelarium::utils::log { enum class LogLevel { - Trace = 1 << 0, - Debug = 1 << 1, - Info = 1 << 2, - Warn = 1 << 3, - Error = 1 << 4, + kTrace = 1 << 0, + kDebug = 1 << 1, + kInfo = 1 << 2, + kWarn = 1 << 3, + kError = 1 << 4, }; /// @brief Interface for logging implementations. class ILog diff --git a/lib/utilities/SpdLogger.cpp b/lib/utilities/SpdLogger.cpp index 112c526..071771a 100644 --- a/lib/utilities/SpdLogger.cpp +++ b/lib/utilities/SpdLogger.cpp @@ -30,15 +30,15 @@ void SpdLogger::ChangeLevel(LogLevel lvl) const { switch (l) { - case LogLevel::Trace: + case LogLevel::kTrace: return "Trace"; - case LogLevel::Debug: + case LogLevel::kDebug: return "Debug"; - case LogLevel::Info: + case LogLevel::kInfo: return "Info"; - case LogLevel::Warn: + case LogLevel::kWarn: return "Warn"; - case LogLevel::Error: + case LogLevel::kError: return "Error"; default: return "Not Found"; @@ -47,23 +47,23 @@ void SpdLogger::ChangeLevel(LogLevel lvl) const switch (lvl) { - case LogLevel::Trace: + case LogLevel::kTrace: this->logger_->set_level(spdlog::level::trace); spdlog::flush_on(spdlog::level::trace); break; - case LogLevel::Info: + case LogLevel::kInfo: this->logger_->set_level(spdlog::level::info); spdlog::flush_on(spdlog::level::info); break; - case LogLevel::Warn: + case LogLevel::kWarn: this->logger_->set_level(spdlog::level::warn); spdlog::flush_on(spdlog::level::warn); break; - case LogLevel::Error: + case LogLevel::kError: this->logger_->set_level(spdlog::level::err); spdlog::flush_on(spdlog::level::err); break; - case LogLevel::Debug: + case LogLevel::kDebug: default: this->logger_->set_level(spdlog::level::debug); spdlog::flush_on(spdlog::level::debug); diff --git a/src/main.cpp b/src/main.cpp index dad80ae..5316fe1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,7 +17,7 @@ int main(int argc, char** argv) #endif logger->Info(std::format("{}: Starting Application {}", __FUNCTION__, "Pixelarium")); - logger->ChangeLevel(utils::log::LogLevel::Debug); + logger->ChangeLevel(utils::log::LogLevel::kDebug); auto image_pool{std::make_unique()}; pixelarium::ui::DefaultApp app = pixelarium::ui::DefaultApp(*logger, *image_pool);