Gerneric image codec abstraction init (#6)
* remove raw pointer from resource manager
* towards generic images
* 💅 and pin libCZI module
* remove raw pointer from resource manager
* towards generic images
* fix rendering
* fix rendering
* fix unit tests
* fix pipeline
* fix gcc build
* re-enable tests
* add czi impl
* remove resource button
* refactor user code app to being a "default app"
* ui resources
* missing lib?
* init czi render support
* typos
This commit is contained in:
committed by
Maximilian Kueffner
parent
bce12b0bb4
commit
0be064bb8e
@@ -23,8 +23,8 @@ jobs:
|
|||||||
- name: configure
|
- name: configure
|
||||||
run: cmake --preset gcc-debug
|
run: cmake --preset gcc-debug
|
||||||
- name: build
|
- name: build
|
||||||
run: cmake --build build --preset debug
|
run: cmake --build build --preset gcc-debug
|
||||||
- name: test
|
- name: test
|
||||||
run: |
|
run: |
|
||||||
cd ${{github.workspace}}/build
|
cd ${{github.workspace}}/build/gcc-debug
|
||||||
ctest -C Debug
|
ctest -C Debug
|
||||||
|
|||||||
@@ -31,17 +31,12 @@ if(UNIX)
|
|||||||
set(CMAKE_CXX_FLAGS "-Wall -Wextra -g --std=c++20")
|
set(CMAKE_CXX_FLAGS "-Wall -Wextra -g --std=c++20")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin/Debug)
|
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/Release)
|
|
||||||
|
|
||||||
add_subdirectory(${pfd_DIR})
|
add_subdirectory(${pfd_DIR})
|
||||||
add_subdirectory(${spdlog_DIR})
|
add_subdirectory(${spdlog_DIR})
|
||||||
add_subdirectory(${glfw3_module_DIR})
|
add_subdirectory(${glfw3_module_DIR})
|
||||||
add_subdirectory(src)
|
|
||||||
add_subdirectory(lib)
|
add_subdirectory(lib)
|
||||||
|
|
||||||
set(SRC
|
set(SRC
|
||||||
src/MyApp.cpp
|
|
||||||
src/main.cpp)
|
src/main.cpp)
|
||||||
|
|
||||||
#====================
|
#====================
|
||||||
@@ -66,7 +61,6 @@ target_include_directories(${PROJECT_NAME}
|
|||||||
PUBLIC ${PROJECT_SOURCE_DIR}/lib/imaging
|
PUBLIC ${PROJECT_SOURCE_DIR}/lib/imaging
|
||||||
PUBLIC ${PROJECT_SOURCE_DIR}/lib/app
|
PUBLIC ${PROJECT_SOURCE_DIR}/lib/app
|
||||||
PUBLIC ${spdlog_DIR}/include
|
PUBLIC ${spdlog_DIR}/include
|
||||||
PUBLIC ${pfd_DIR}
|
|
||||||
PUBLIC ${LIBCZI_INCLUDE_DIR}
|
PUBLIC ${LIBCZI_INCLUDE_DIR}
|
||||||
PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
|
|||||||
+22
-13
@@ -10,34 +10,35 @@
|
|||||||
"name": "default",
|
"name": "default",
|
||||||
"hidden": true,
|
"hidden": true,
|
||||||
"generator": "Ninja",
|
"generator": "Ninja",
|
||||||
"binaryDir": "build",
|
"binaryDir": "${sourceDir}/build/${presetName}",
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
"CMAKE_C_COMPILER": "clang",
|
|
||||||
"CMAKE_CXX_COMPILER": "clang++",
|
|
||||||
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
|
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
|
||||||
"FETCHCONTENT_FULLY_DISCONNECTED": "OFF"
|
"FETCHCONTENT_FULLY_DISCONNECTED": "OFF",
|
||||||
|
"CMAKE_VERBOSE_MAKEFILE": "ON",
|
||||||
|
"PIXELARIUM_BUILD_UNITTESTS": "ON"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "clang-release",
|
"name": "clang-release",
|
||||||
"inherits": "default",
|
"inherits": "default",
|
||||||
"binaryDir": "build/clang-release",
|
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
|
"CMAKE_C_COMPILER": "clang",
|
||||||
|
"CMAKE_CXX_COMPILER": "clang++",
|
||||||
"CMAKE_BUILD_TYPE": "Release"
|
"CMAKE_BUILD_TYPE": "Release"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "clang-debug",
|
"name": "clang-debug",
|
||||||
"binaryDir": "build/clang-debug",
|
|
||||||
"inherits": "default",
|
"inherits": "default",
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
|
"CMAKE_C_COMPILER": "clang",
|
||||||
|
"CMAKE_CXX_COMPILER": "clang++",
|
||||||
"CMAKE_BUILD_TYPE": "Debug"
|
"CMAKE_BUILD_TYPE": "Debug"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "gcc-release",
|
"name": "gcc-release",
|
||||||
"inherits": "default",
|
"inherits": "default",
|
||||||
"binaryDir": "build/gcc-release",
|
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
"CMAKE_C_COMPILER": "gcc",
|
"CMAKE_C_COMPILER": "gcc",
|
||||||
"CMAKE_CXX_COMPILER": "g++",
|
"CMAKE_CXX_COMPILER": "g++",
|
||||||
@@ -47,7 +48,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gcc-debug",
|
"name": "gcc-debug",
|
||||||
"inherits": "default",
|
"inherits": "default",
|
||||||
"binaryDir": "build/gcc-debug",
|
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
"CMAKE_C_COMPILER": "gcc",
|
"CMAKE_C_COMPILER": "gcc",
|
||||||
"CMAKE_CXX_COMPILER": "g++",
|
"CMAKE_CXX_COMPILER": "g++",
|
||||||
@@ -59,18 +59,27 @@
|
|||||||
{
|
{
|
||||||
"name": "default",
|
"name": "default",
|
||||||
"hidden": true,
|
"hidden": true,
|
||||||
"configurePreset": "clang-debug",
|
|
||||||
"jobs": 10
|
"jobs": 10
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "release",
|
"name": "clang-release",
|
||||||
"inherits": "default",
|
"inherits": "default",
|
||||||
"configuration": "Release"
|
"configurePreset": "clang-release"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "debug",
|
"name": "clang-debug",
|
||||||
"inherits": "default",
|
"inherits": "default",
|
||||||
"configuration": "Debug"
|
"configurePreset": "clang-debug"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "gcc-release",
|
||||||
|
"inherits": "default",
|
||||||
|
"configurePreset": "gcc-release"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "gcc-debug",
|
||||||
|
"inherits": "default",
|
||||||
|
"configurePreset": "gcc-debug"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/app_resources_default.h.in
|
|||||||
|
|
||||||
set(APPLIBSRC
|
set(APPLIBSRC
|
||||||
AppGLFW.cpp
|
AppGLFW.cpp
|
||||||
|
DefaultApp.cpp
|
||||||
${imgui_DIR}/imgui.cpp
|
${imgui_DIR}/imgui.cpp
|
||||||
${imgui_DIR}/imgui_demo.cpp
|
${imgui_DIR}/imgui_demo.cpp
|
||||||
${imgui_DIR}/imgui_draw.cpp
|
${imgui_DIR}/imgui_draw.cpp
|
||||||
@@ -18,7 +19,9 @@ add_library(${APPLIBNAME}
|
|||||||
STATIC ${APPLIBSRC})
|
STATIC ${APPLIBSRC})
|
||||||
|
|
||||||
target_link_libraries(${APPLIBNAME}
|
target_link_libraries(${APPLIBNAME}
|
||||||
PRIVATE pixelariumutilslib)
|
PRIVATE pixelariumutilslib
|
||||||
|
PRIVATE pixelariumimagelib
|
||||||
|
PRIVATE pixelariumrenderlib)
|
||||||
|
|
||||||
# This needs to be public to let the consumer know about it.
|
# This needs to be public to let the consumer know about it.
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
@@ -40,5 +43,7 @@ endif()
|
|||||||
target_include_directories(${APPLIBNAME}
|
target_include_directories(${APPLIBNAME}
|
||||||
PRIVATE ${CMAKE_BINARY_DIR}
|
PRIVATE ${CMAKE_BINARY_DIR}
|
||||||
PRIVATE ${PROJECT_SOURCE_DIR}/lib
|
PRIVATE ${PROJECT_SOURCE_DIR}/lib
|
||||||
|
PRIVATE ${PROJECT_SOURCE_DIR}/lib/imaging
|
||||||
|
PUBLIC ${pfd_DIR}
|
||||||
PUBLIC ${imgui_DIR}
|
PUBLIC ${imgui_DIR}
|
||||||
PUBLIC ${imgui_DIR}/backends)
|
PUBLIC ${imgui_DIR}/backends)
|
||||||
|
|||||||
@@ -1,39 +1,39 @@
|
|||||||
#include "MyApp.hpp"
|
#include "DefaultApp.hpp"
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "PixelariumImageFactory.hpp"
|
||||||
#include "app_resources_default.h"
|
#include "app_resources_default.h"
|
||||||
#include "app_resources_local.h"
|
|
||||||
#include "imaging/PixelariumImage.hpp"
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "portable-file-dialogs.h"
|
#include "portable-file-dialogs.h"
|
||||||
#include "rendering/RenderImageManager.hpp"
|
#include "rendering/RenderImageManager.hpp"
|
||||||
|
#include "resources/resource.hpp"
|
||||||
#include "utilities/ILog.hpp"
|
#include "utilities/ILog.hpp"
|
||||||
|
|
||||||
using namespace pixelarium::imaging;
|
using namespace pixelarium::imaging;
|
||||||
|
|
||||||
void pixelarium::ui::MyApp::MenuBarOptionsColumn1()
|
void pixelarium::ui::DefaultApp::MenuBarOptionsColumn1()
|
||||||
{
|
{
|
||||||
ImGui::MenuItem(SHOWIMGUIDEMOS, NULL, &this->demop_);
|
ImGui::MenuItem(SHOWIMGUIDEMOS, NULL, &this->demop_);
|
||||||
ImGui::MenuItem(SHOWIMAGEGALLERY, NULL, &this->image_listp_);
|
ImGui::MenuItem(SHOWIMAGEGALLERY, NULL, &this->image_listp_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pixelarium::ui::MyApp::MenuBarOptionsColumn2()
|
void pixelarium::ui::DefaultApp::MenuBarOptionsColumn2()
|
||||||
{
|
{
|
||||||
if (ImGui::BeginMenu(FILEMENUNAME))
|
if (ImGui::BeginMenu(FILEMENUNAME))
|
||||||
{
|
{
|
||||||
if (ImGui::MenuItem("Load File"))
|
if (ImGui::MenuItem(LOADIMAGE))
|
||||||
{
|
{
|
||||||
this->LoadImageProt();
|
this->LoadImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pixelarium::ui::MyApp::Run()
|
void pixelarium::ui::DefaultApp::Run()
|
||||||
{
|
{
|
||||||
if (demop_) ImGui::ShowDemoWindow(&this->demop_);
|
if (demop_) ImGui::ShowDemoWindow(&this->demop_);
|
||||||
if (image_listp_) this->ImageGalleryRender();
|
if (image_listp_) this->ImageGalleryRender();
|
||||||
@@ -41,7 +41,7 @@ void pixelarium::ui::MyApp::Run()
|
|||||||
this->RenderImages();
|
this->RenderImages();
|
||||||
}
|
}
|
||||||
|
|
||||||
void pixelarium::ui::MyApp::RenderImages()
|
void pixelarium::ui::DefaultApp::RenderImages()
|
||||||
{
|
{
|
||||||
this->render_manager_->Enumerate(
|
this->render_manager_->Enumerate(
|
||||||
[&](resources::ResourceKey key, render::RenderImageStateWrapper& render_state)
|
[&](resources::ResourceKey key, render::RenderImageStateWrapper& render_state)
|
||||||
@@ -55,10 +55,10 @@ void pixelarium::ui::MyApp::RenderImages()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void pixelarium::ui::MyApp::ImageGalleryRender()
|
void pixelarium::ui::DefaultApp::ImageGalleryRender()
|
||||||
{
|
{
|
||||||
ImGui::SetNextWindowSize(ImVec2(300, 500));
|
ImGui::SetNextWindowSize(ImVec2(300, 500));
|
||||||
ImGui::Begin(SHOWIMAGEGALLERY);
|
ImGui::Begin(SHOWIMAGEGALLERY, &this->image_listp_);
|
||||||
|
|
||||||
// this updates the render collection
|
// this updates the render collection
|
||||||
// essentially deleting render views that were
|
// essentially deleting render views that were
|
||||||
@@ -71,7 +71,7 @@ void pixelarium::ui::MyApp::ImageGalleryRender()
|
|||||||
if (ImGui::BeginListBox("Image List", ImVec2(200, 400)))
|
if (ImGui::BeginListBox("Image List", ImVec2(200, 400)))
|
||||||
{
|
{
|
||||||
pool_.EnumerateResources(
|
pool_.EnumerateResources(
|
||||||
[&](size_t id, size_t idx, const imaging::PixelariumImage& img) -> void
|
[&](size_t id, size_t idx, const imaging::IPixelariumImage& img) -> void
|
||||||
{
|
{
|
||||||
const bool is_selected = selected_index == idx;
|
const bool is_selected = selected_index == idx;
|
||||||
if (ImGui::Selectable(std::format("{}", img.Name()).c_str(), is_selected))
|
if (ImGui::Selectable(std::format("{}", img.Name()).c_str(), is_selected))
|
||||||
@@ -98,10 +98,28 @@ void pixelarium::ui::MyApp::ImageGalleryRender()
|
|||||||
this->render_manager_->Add(this->selected_image_);
|
this->render_manager_->Add(this->selected_image_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImGui::Button(LOADIMAGE))
|
||||||
|
{
|
||||||
|
this->LoadImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::Button(REMOVEIMAGE))
|
||||||
|
{
|
||||||
|
this->render_manager_->MarkForDeletion(this->selected_image_);
|
||||||
|
this->pool_.DeleteResource(this->selected_image_);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button(CLEARALL))
|
||||||
|
{
|
||||||
|
this->render_manager_->Clear();
|
||||||
|
this->pool_.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::End(); // end gallery window
|
ImGui::End(); // end gallery window
|
||||||
}
|
}
|
||||||
|
|
||||||
void pixelarium::ui::MyApp::LoadImageProt()
|
void pixelarium::ui::DefaultApp::LoadImage()
|
||||||
{
|
{
|
||||||
size_t last_id{};
|
size_t last_id{};
|
||||||
auto res{pfd::open_file("Load Inputs", pfd::path::home(), {"All Files", "*"}, pfd::opt::multiselect).result()};
|
auto res{pfd::open_file("Load Inputs", pfd::path::home(), {"All Files", "*"}, pfd::opt::multiselect).result()};
|
||||||
@@ -109,6 +127,13 @@ void pixelarium::ui::MyApp::LoadImageProt()
|
|||||||
{
|
{
|
||||||
this->logger_.Debug(std::format("{}: Creating image {}", __FUNCTION__, p));
|
this->logger_.Debug(std::format("{}: Creating image {}", __FUNCTION__, p));
|
||||||
|
|
||||||
pool_.SetResource(std::make_unique<PixelariumImage>(p));
|
try
|
||||||
|
{
|
||||||
|
pool_.SetResource(PixelariumImageFactory::CreateImage(p));
|
||||||
|
}
|
||||||
|
catch (pixelarium::resources::empty_resource_exception& e)
|
||||||
|
{
|
||||||
|
logger_.Error(std::format("{}: Failed to load file '{}' with '{}'", __PRETTY_FUNCTION__, p, e.what()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,10 +11,10 @@
|
|||||||
|
|
||||||
namespace pixelarium::ui
|
namespace pixelarium::ui
|
||||||
{
|
{
|
||||||
class MyApp : public application::AppGLFW
|
class DefaultApp : public application::AppGLFW
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyApp(const utils::log::ILog& log, pixelarium::resources::ImageResourcePool& pool)
|
DefaultApp(const utils::log::ILog& log, pixelarium::resources::ImageResourcePool& pool)
|
||||||
: application::AppGLFW(log),
|
: application::AppGLFW(log),
|
||||||
pool_(pool),
|
pool_(pool),
|
||||||
render_manager_(std::make_unique<render::RenderImageManager>(pool, log))
|
render_manager_(std::make_unique<render::RenderImageManager>(pool, log))
|
||||||
@@ -27,7 +27,7 @@ class MyApp : public application::AppGLFW
|
|||||||
void Run() override;
|
void Run() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void LoadImageProt();
|
void LoadImage();
|
||||||
void ImageGalleryRender();
|
void ImageGalleryRender();
|
||||||
void RenderImages();
|
void RenderImages();
|
||||||
|
|
||||||
@@ -5,9 +5,17 @@
|
|||||||
|
|
||||||
#cmakedefine PIXELARIUM_TITLE "@PIXELARIUM_TITLE@"
|
#cmakedefine PIXELARIUM_TITLE "@PIXELARIUM_TITLE@"
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
#define MAINMENUNAME "Menu"
|
#define MAINMENUNAME "Menu"
|
||||||
#define FILEMENUNAME "File"
|
#define FILEMENUNAME "File"
|
||||||
#define LOGLEVELSELECT "Log Level"
|
#define LOGLEVELSELECT "Log Level"
|
||||||
|
#define SHOWIMGUIDEMOS "ImGui Demos"
|
||||||
|
#define SHOWIMAGEGALLERY "Image Gallery"
|
||||||
|
#define AUTOSHOWSELECTED "Auto View"
|
||||||
|
#define OPENIMAGE "Open"
|
||||||
|
#define LOADIMAGE "Load Image"
|
||||||
|
#define REMOVEIMAGE "Remove Image"
|
||||||
|
#define CLEARALL "Clear All"
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
inline constexpr std::array<std::string_view, 5> LOGLEVELS = {"Trace", "Debug", "Info", "Warning", "Error"};
|
inline constexpr std::array<std::string_view, 5> LOGLEVELS = {"Trace", "Debug", "Info", "Warning", "Error"};
|
||||||
|
|||||||
@@ -6,7 +6,12 @@ message(STATUS "Found opencv: " ${OpenCV_INCLUDE_DIRS})
|
|||||||
message(STATUS "OpenCV_LIBs from: " ${OpenCV_LIBS})
|
message(STATUS "OpenCV_LIBs from: " ${OpenCV_LIBS})
|
||||||
|
|
||||||
set(IMAGELIBSRC
|
set(IMAGELIBSRC
|
||||||
PixelariumImage.cpp)
|
IPixelariumImage.hpp
|
||||||
|
PixelariumImageFactory.cpp
|
||||||
|
impl/PixelariumJpg.cpp
|
||||||
|
impl/PixelariumPng.cpp
|
||||||
|
impl/PixelariumCzi.cpp
|
||||||
|
)
|
||||||
|
|
||||||
set(IMAGELIBLIBNAME pixelariumimagelib)
|
set(IMAGELIBLIBNAME pixelariumimagelib)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <opencv2/core/mat.hpp>
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace pixelarium::imaging
|
||||||
|
{
|
||||||
|
using ImageQueryFunctor = std::function<void(const std::string&, void*, int*)>;
|
||||||
|
|
||||||
|
enum class ImageFileType
|
||||||
|
{
|
||||||
|
UNKNOWN = -10,
|
||||||
|
ABSTRACT = 0,
|
||||||
|
PNG = 1,
|
||||||
|
JPG = 2,
|
||||||
|
CZI = 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief An abstract interface to define a semantic query
|
||||||
|
/// for a multi-dimensional image.
|
||||||
|
struct IImageQuery
|
||||||
|
{
|
||||||
|
virtual ~IImageQuery() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief This aims to be a generic image abstraction
|
||||||
|
/// meant for codec specific implementation.
|
||||||
|
class IPixelariumImage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IPixelariumImage() = default;
|
||||||
|
|
||||||
|
// this will have to throw or something for multidimensional images
|
||||||
|
virtual std::optional<std::unique_ptr<cv::Mat>> TryGetImage() = 0;
|
||||||
|
|
||||||
|
virtual std::optional<std::unique_ptr<cv::Mat>> TryGetImage(const IImageQuery&) = 0;
|
||||||
|
|
||||||
|
virtual std::string Name() const noexcept = 0;
|
||||||
|
|
||||||
|
virtual bool Empty() const noexcept = 0;
|
||||||
|
|
||||||
|
virtual std::filesystem::path Uri() const noexcept = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
const static ImageFileType type_{ImageFileType::ABSTRACT};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::filesystem::path uri_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace pixelarium::imaging
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#include "PixelariumImage.hpp"
|
|
||||||
|
|
||||||
#include <filesystem>
|
|
||||||
#include <format>
|
|
||||||
#include <memory>
|
|
||||||
#include <opencv2/imgcodecs.hpp>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
pixelarium::imaging::PixelariumImage::PixelariumImage(const std::string& uri)
|
|
||||||
{
|
|
||||||
if (!std::filesystem::exists(uri))
|
|
||||||
{
|
|
||||||
throw std::runtime_error(std::format("File not {} found", uri));
|
|
||||||
}
|
|
||||||
|
|
||||||
this->uri_ = std::filesystem::path(uri);
|
|
||||||
this->img_ = std::make_unique<cv::Mat>(cv::imread(uri));
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <filesystem>
|
|
||||||
#include <functional>
|
|
||||||
#include <memory>
|
|
||||||
#include <opencv2/core/mat.hpp>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace pixelarium::imaging
|
|
||||||
{
|
|
||||||
using AccessorFunctor = std::function<void(const std::string&, void*, int*)>;
|
|
||||||
|
|
||||||
enum class ImageFileType
|
|
||||||
{
|
|
||||||
ABSRACT = 0,
|
|
||||||
PNG = 1,
|
|
||||||
JPG = 2,
|
|
||||||
CZI = 3,
|
|
||||||
};
|
|
||||||
/// @brief This aims to be a generic image abstraction
|
|
||||||
/// meant for codec specific implementation.
|
|
||||||
|
|
||||||
/// Todo: the above implies that most of the below implementations don't make sense for this class (c.f. cv::Mat
|
|
||||||
/// generation et.al.)
|
|
||||||
class PixelariumImage
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// get back the defaults
|
|
||||||
// this means, that there has to be and API option to set
|
|
||||||
// a resource which should trigger some sort of action
|
|
||||||
// after setting
|
|
||||||
|
|
||||||
explicit PixelariumImage(const std::string& uri);
|
|
||||||
|
|
||||||
PixelariumImage() = default;
|
|
||||||
PixelariumImage(const PixelariumImage& other)
|
|
||||||
{
|
|
||||||
// be ware!!
|
|
||||||
// we make a copy of the image data here!
|
|
||||||
img_ = std::make_unique<cv::Mat>(*other.img_);
|
|
||||||
uri_ = other.uri_;
|
|
||||||
};
|
|
||||||
PixelariumImage(PixelariumImage&& other) noexcept : img_(std::move(other.img_)) {}
|
|
||||||
PixelariumImage& operator=(const PixelariumImage& other) = delete;
|
|
||||||
PixelariumImage& operator=(PixelariumImage&& other) noexcept
|
|
||||||
{
|
|
||||||
if (this != &other)
|
|
||||||
{
|
|
||||||
img_ = std::move(other.img_);
|
|
||||||
uri_ = other.uri_;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
// this should probably vanish as it makes no sense
|
|
||||||
// for multidimensional images (more than one frame)
|
|
||||||
// -> we need some sort of accessor functionality
|
|
||||||
|
|
||||||
~PixelariumImage() = default;
|
|
||||||
|
|
||||||
const cv::Mat& GetImage() const { return *this->img_.get(); }
|
|
||||||
|
|
||||||
const std::string Name() const noexcept
|
|
||||||
{
|
|
||||||
if (!this->uri_.empty())
|
|
||||||
{
|
|
||||||
return this->uri_.filename().string();
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Empty() const noexcept { return this->img_->empty(); }
|
|
||||||
|
|
||||||
static ImageFileType Type() { return PixelariumImage::type_; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::unique_ptr<cv::Mat> img_;
|
|
||||||
|
|
||||||
std::filesystem::path uri_;
|
|
||||||
|
|
||||||
static ImageFileType type_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace pixelarium::imaging
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
#include "PixelariumImageFactory.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cctype>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "impl/PixelariumCzi.hpp"
|
||||||
|
#include "impl/PixelariumJpg.hpp"
|
||||||
|
#include "impl/PixelariumPng.hpp"
|
||||||
|
|
||||||
|
constexpr pixelarium::imaging::ImageFileType ExtensionToType(const std::string& extension)
|
||||||
|
{
|
||||||
|
std::string lower_ext{extension};
|
||||||
|
std::ranges::transform(extension, lower_ext.begin(), [](const char c) -> char { return std::tolower(c); });
|
||||||
|
|
||||||
|
if (lower_ext == ".jpg" || lower_ext == ".jpeg")
|
||||||
|
{
|
||||||
|
return pixelarium::imaging::ImageFileType::JPG;
|
||||||
|
}
|
||||||
|
if (lower_ext == ".png")
|
||||||
|
{
|
||||||
|
return pixelarium::imaging::ImageFileType::PNG;
|
||||||
|
}
|
||||||
|
if (lower_ext == ".czi")
|
||||||
|
{
|
||||||
|
return pixelarium::imaging::ImageFileType::CZI;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pixelarium::imaging::ImageFileType::UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*static*/ std::unique_ptr<pixelarium::imaging::IPixelariumImage>
|
||||||
|
pixelarium::imaging::PixelariumImageFactory::CreateImage(const std::string& uri)
|
||||||
|
{
|
||||||
|
const auto res{std::filesystem::path(uri)};
|
||||||
|
const auto target_type{ExtensionToType(res.extension().string())};
|
||||||
|
|
||||||
|
switch (target_type)
|
||||||
|
{
|
||||||
|
case ImageFileType::UNKNOWN:
|
||||||
|
return {};
|
||||||
|
break;
|
||||||
|
case ImageFileType::ABSTRACT:
|
||||||
|
return {};
|
||||||
|
break;
|
||||||
|
case ImageFileType::PNG:
|
||||||
|
return std::make_unique<PixelariumPng>(uri);
|
||||||
|
break;
|
||||||
|
case ImageFileType::JPG:
|
||||||
|
return std::make_unique<PixelariumJpg>(uri);
|
||||||
|
break;
|
||||||
|
case ImageFileType::CZI:
|
||||||
|
return std::make_unique<PixelariumCzi>(uri);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "IPixelariumImage.hpp"
|
||||||
|
namespace pixelarium::imaging
|
||||||
|
{
|
||||||
|
class PixelariumImageFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static std::unique_ptr<IPixelariumImage> CreateImage(const std::string& uri);
|
||||||
|
};
|
||||||
|
} // namespace pixelarium::imaging
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
#include "PixelariumCzi.hpp"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "libCZI.h"
|
||||||
|
|
||||||
|
std::unique_ptr<cv::Mat> CZISubBlockToCvMat(std::shared_ptr<libCZI::IBitmapData> bitmap, libCZI::PixelType pixeltype)
|
||||||
|
{
|
||||||
|
size_t pixel_size{0};
|
||||||
|
int target_type;
|
||||||
|
|
||||||
|
switch (pixeltype)
|
||||||
|
{
|
||||||
|
case libCZI::PixelType::Gray8:
|
||||||
|
pixel_size = 1;
|
||||||
|
target_type = CV_8U;
|
||||||
|
break;
|
||||||
|
case libCZI::PixelType::Gray16:
|
||||||
|
pixel_size = 2;
|
||||||
|
target_type = CV_16U;
|
||||||
|
break;
|
||||||
|
case libCZI::PixelType::Bgr24:
|
||||||
|
pixel_size = 3;
|
||||||
|
target_type = CV_8UC3;
|
||||||
|
break;
|
||||||
|
case libCZI::PixelType::Bgra32:
|
||||||
|
target_type = CV_8UC4;
|
||||||
|
case libCZI::PixelType::Gray32:
|
||||||
|
target_type = CV_32S;
|
||||||
|
case libCZI::PixelType::Gray32Float:
|
||||||
|
target_type = CV_32F;
|
||||||
|
pixel_size = 4;
|
||||||
|
break;
|
||||||
|
// case libCZI::PixelType::Gray64ComplexFloat:
|
||||||
|
// case libCZI::PixelType::Gray64Float:
|
||||||
|
// target_type =
|
||||||
|
// pixel_size = 8;
|
||||||
|
// break;
|
||||||
|
default:
|
||||||
|
pixel_size = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pixel_size < 0) return nullptr;
|
||||||
|
|
||||||
|
size_t height{bitmap->GetHeight()};
|
||||||
|
size_t width{bitmap->GetWidth()};
|
||||||
|
auto fill_mat = std::make_unique<cv::Mat>(height, width, target_type);
|
||||||
|
|
||||||
|
auto bitmap_info = bitmap->Lock();
|
||||||
|
|
||||||
|
for (size_t h{0}; h < height; ++h)
|
||||||
|
{
|
||||||
|
unsigned char* source_row = ((unsigned char*)bitmap_info.ptrDataRoi) + bitmap_info.stride * h;
|
||||||
|
unsigned char* target_row = fill_mat->ptr(h);
|
||||||
|
|
||||||
|
for (size_t w{0}; w < width; ++w)
|
||||||
|
{
|
||||||
|
switch (pixel_size)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
target_row[w] = source_row[w];
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
reinterpret_cast<unsigned short*>(target_row)[w] = reinterpret_cast<unsigned short*>(source_row)[w];
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
target_row[3 * w] = source_row[3 * w];
|
||||||
|
target_row[3 * w + 1] = source_row[3 * w + 1];
|
||||||
|
target_row[3 * w + 2] = source_row[3 * w + 2];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw std::runtime_error("Unknown pixel type requested!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bitmap->Unlock();
|
||||||
|
return fill_mat;
|
||||||
|
}
|
||||||
|
|
||||||
|
pixelarium::imaging::PixelariumCzi::PixelariumCzi(const std::string& uri)
|
||||||
|
{
|
||||||
|
if (!std::filesystem::exists(uri))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Render file not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
this->is_empty_ = false;
|
||||||
|
this->uri_ = std::filesystem::path(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::unique_ptr<cv::Mat>> pixelarium::imaging::PixelariumCzi::TryGetImage()
|
||||||
|
{
|
||||||
|
auto stream = libCZI::CreateStreamFromFile(this->uri_.wstring().c_str());
|
||||||
|
auto cziReader = libCZI::CreateCZIReader();
|
||||||
|
cziReader->Open(stream);
|
||||||
|
auto block = cziReader->ReadSubBlock(0);
|
||||||
|
auto bitmap = block->CreateBitmap();
|
||||||
|
auto res = CZISubBlockToCvMat(bitmap, block->GetSubBlockInfo().pixelType);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "../IPixelariumImage.hpp"
|
||||||
|
|
||||||
|
namespace pixelarium::imaging
|
||||||
|
{
|
||||||
|
class PixelariumCzi : public IPixelariumImage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit PixelariumCzi(const std::string& uri);
|
||||||
|
|
||||||
|
// IPixelariumImage member implementations
|
||||||
|
public:
|
||||||
|
std::optional<std::unique_ptr<cv::Mat>> TryGetImage() override;
|
||||||
|
|
||||||
|
std::optional<std::unique_ptr<cv::Mat>> TryGetImage(const IImageQuery&) override
|
||||||
|
{
|
||||||
|
// ToDo: proper error
|
||||||
|
throw std::runtime_error("Not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Name() const noexcept override
|
||||||
|
{
|
||||||
|
if (!this->uri_.empty())
|
||||||
|
{
|
||||||
|
return this->uri_.filename().string();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::filesystem::path Uri() const noexcept override { return this->uri_.string(); }
|
||||||
|
|
||||||
|
bool Empty() const noexcept override { return this->is_empty_; }
|
||||||
|
|
||||||
|
public:
|
||||||
|
const static ImageFileType type_{ImageFileType::CZI};
|
||||||
|
|
||||||
|
private:
|
||||||
|
// this should be set by each image getter
|
||||||
|
// after a new cv::Mat could be instantiated
|
||||||
|
bool is_empty_{true};
|
||||||
|
};
|
||||||
|
} // namespace pixelarium::imaging
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#include "PixelariumJpg.hpp"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <memory>
|
||||||
|
#include <opencv2/imgcodecs.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
pixelarium::imaging::PixelariumJpg::PixelariumJpg(const std::string& uri)
|
||||||
|
{
|
||||||
|
if (!std::filesystem::exists(uri))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Render file not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
this->is_empty_ = false;
|
||||||
|
this->uri_ = std::filesystem::path(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::unique_ptr<cv::Mat>> pixelarium::imaging::PixelariumJpg::TryGetImage()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto img = std::make_unique<cv::Mat>(cv::imread(this->uri_.string()));
|
||||||
|
|
||||||
|
this->is_empty_ = false;
|
||||||
|
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
this->is_empty_ = true;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "../IPixelariumImage.hpp"
|
||||||
|
|
||||||
|
namespace pixelarium::imaging
|
||||||
|
{
|
||||||
|
class PixelariumJpg : public IPixelariumImage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit PixelariumJpg(const std::string& url);
|
||||||
|
|
||||||
|
// IPixelariumImage member implementations
|
||||||
|
public:
|
||||||
|
std::optional<std::unique_ptr<cv::Mat>> TryGetImage() override;
|
||||||
|
|
||||||
|
std::optional<std::unique_ptr<cv::Mat>> TryGetImage(const IImageQuery&) override
|
||||||
|
{
|
||||||
|
// ToDo: proper error
|
||||||
|
throw std::runtime_error("Not possible with jpg.");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Name() const noexcept override
|
||||||
|
{
|
||||||
|
if (!this->uri_.empty())
|
||||||
|
{
|
||||||
|
return this->uri_.filename().string();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::filesystem::path Uri() const noexcept override
|
||||||
|
{
|
||||||
|
return this->uri_.string();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Empty() const noexcept override { return this->is_empty_; }
|
||||||
|
|
||||||
|
public:
|
||||||
|
const static ImageFileType type_{ImageFileType::JPG};
|
||||||
|
|
||||||
|
private:
|
||||||
|
// this should be set by each image getter
|
||||||
|
// after a new cv::Mat could be instantiated
|
||||||
|
bool is_empty_{true};
|
||||||
|
};
|
||||||
|
} // namespace pixelarium::imaging
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#include "PixelariumPng.hpp"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <memory>
|
||||||
|
#include <opencv2/imgcodecs.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
pixelarium::imaging::PixelariumPng::PixelariumPng(const std::string& uri)
|
||||||
|
{
|
||||||
|
if (!std::filesystem::exists(uri))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Render file not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
this->is_empty_ = false;
|
||||||
|
this->uri_ = std::filesystem::path(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::unique_ptr<cv::Mat>> pixelarium::imaging::PixelariumPng::TryGetImage()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto img = std::make_unique<cv::Mat>(cv::imread(this->uri_.string()));
|
||||||
|
|
||||||
|
this->is_empty_ = false;
|
||||||
|
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
this->is_empty_ = true;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "../IPixelariumImage.hpp"
|
||||||
|
|
||||||
|
namespace pixelarium::imaging
|
||||||
|
{
|
||||||
|
class PixelariumPng : public IPixelariumImage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit PixelariumPng(const std::string& url);
|
||||||
|
|
||||||
|
// IPixelariumImage member implementations
|
||||||
|
public:
|
||||||
|
std::optional<std::unique_ptr<cv::Mat>> TryGetImage() override;
|
||||||
|
|
||||||
|
std::optional<std::unique_ptr<cv::Mat>> TryGetImage(const IImageQuery&) override
|
||||||
|
{
|
||||||
|
// ToDo: proper error
|
||||||
|
throw std::runtime_error("Not possible with png.");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Name() const noexcept override
|
||||||
|
{
|
||||||
|
if (!this->uri_.empty())
|
||||||
|
{
|
||||||
|
return this->uri_.filename().string();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::filesystem::path Uri() const noexcept override
|
||||||
|
{
|
||||||
|
return this->uri_.string();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Empty() const noexcept override { return this->is_empty_; }
|
||||||
|
|
||||||
|
public:
|
||||||
|
const static ImageFileType type_{ImageFileType::PNG};
|
||||||
|
|
||||||
|
private:
|
||||||
|
// this should be set by each image getter
|
||||||
|
// after a new cv::Mat could be instantiated
|
||||||
|
bool is_empty_{true};
|
||||||
|
};
|
||||||
|
} // namespace pixelarium::imaging
|
||||||
@@ -5,13 +5,13 @@
|
|||||||
#include <opencv2/imgproc.hpp>
|
#include <opencv2/imgproc.hpp>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "imaging/PixelariumImage.hpp"
|
#include "imaging/IPixelariumImage.hpp"
|
||||||
|
|
||||||
using namespace pixelarium::imaging;
|
using namespace pixelarium::imaging;
|
||||||
|
|
||||||
/// @brief Constructor for the CvMatRender class.
|
/// @brief Constructor for the CvMatRender class.
|
||||||
/// @param img A shared pointer to the PixelariumImage to be rendered.
|
/// @param img A shared pointer to the PixelariumImage to be rendered.
|
||||||
pixelarium::render::CvMatRender::CvMatRender(const std::shared_ptr<PixelariumImage>& img) : base_(img), texture_(0)
|
pixelarium::render::CvMatRender::CvMatRender(std::shared_ptr<pixelarium::imaging::IPixelariumImage>& img) : base_(img), texture_(0)
|
||||||
{
|
{
|
||||||
// storing a copy of the to-be-rendered image
|
// storing a copy of the to-be-rendered image
|
||||||
// because it will be resized and filtered eventually which we absolutely
|
// because it will be resized and filtered eventually which we absolutely
|
||||||
@@ -33,7 +33,7 @@ pixelarium::render::CvMatRender::~CvMatRender()
|
|||||||
|
|
||||||
/// @brief Resets the render image with a new PixelariumImage.
|
/// @brief Resets the render image with a new PixelariumImage.
|
||||||
/// @param img A shared pointer to the new PixelariumImage.
|
/// @param img A shared pointer to the new PixelariumImage.
|
||||||
void pixelarium::render::CvMatRender::ResetRenderImage(const std::shared_ptr<pixelarium::imaging::PixelariumImage>& img)
|
void pixelarium::render::CvMatRender::ResetRenderImage(std::shared_ptr<pixelarium::imaging::IPixelariumImage>& img)
|
||||||
{
|
{
|
||||||
this->base_ = img;
|
this->base_ = img;
|
||||||
this->ResetRenderImage();
|
this->ResetRenderImage();
|
||||||
@@ -97,7 +97,11 @@ GLuint pixelarium::render::CvMatRender::Render() { return this->uploadTexture();
|
|||||||
/// @return The ID of the OpenGL texture.
|
/// @return The ID of the OpenGL texture.
|
||||||
GLuint pixelarium::render::CvMatRender::Render(float factor)
|
GLuint pixelarium::render::CvMatRender::Render(float factor)
|
||||||
{
|
{
|
||||||
cv::resize(this->base_->GetImage(), this->img_, cv::Size(0, 0), factor, factor, cv::INTER_LINEAR_EXACT);
|
auto res_val {this->base_->TryGetImage()};
|
||||||
|
if (res_val.has_value())
|
||||||
|
{
|
||||||
|
cv::resize(*res_val.value(), this->img_, cv::Size(0, 0), factor, factor, cv::INTER_LINEAR_EXACT);
|
||||||
|
}
|
||||||
|
|
||||||
return this->uploadTexture();
|
return this->uploadTexture();
|
||||||
}
|
}
|
||||||
@@ -108,7 +112,14 @@ GLuint pixelarium::render::CvMatRender::Render(float factor)
|
|||||||
/// @return The ID of the OpenGL texture.
|
/// @return The ID of the OpenGL texture.
|
||||||
GLuint pixelarium::render::CvMatRender::Render(size_t width, size_t height)
|
GLuint pixelarium::render::CvMatRender::Render(size_t width, size_t height)
|
||||||
{
|
{
|
||||||
const auto sz{this->base_->GetImage().size()};
|
auto res_val {this->base_->TryGetImage()};
|
||||||
|
|
||||||
|
if (!res_val.has_value())
|
||||||
|
{
|
||||||
|
return this->Render(1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto sz{res_val.value()->size()};
|
||||||
|
|
||||||
const auto get_factor = [](auto opt1, auto opt2) -> float { return opt1 < opt2 ? opt1 : opt2; };
|
const auto get_factor = [](auto opt1, auto opt2) -> float { return opt1 < opt2 ? opt1 : opt2; };
|
||||||
|
|
||||||
@@ -116,3 +127,26 @@ GLuint pixelarium::render::CvMatRender::Render(size_t width, size_t height)
|
|||||||
|
|
||||||
return this->Render(factor);
|
return this->Render(factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pixelarium::render::CvMatRender::ResetRenderImage()
|
||||||
|
{
|
||||||
|
if (this->base_ == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto root_res = this->base_->TryGetImage();
|
||||||
|
|
||||||
|
if (!root_res.has_value())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root_res.value() == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we copy here
|
||||||
|
this->img_ = (*root_res.value()).clone();
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <GLFW/glfw3.h> // Will drag system OpenGL headers
|
#include <GLFW/glfw3.h> // Will drag system OpenGL headers
|
||||||
#endif
|
#endif
|
||||||
#include "imaging/PixelariumImage.hpp"
|
#include "imaging/IPixelariumImage.hpp"
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
namespace pixelarium::render
|
namespace pixelarium::render
|
||||||
@@ -33,18 +33,18 @@ class CvMatRender
|
|||||||
CvMatRender& operator=(CvMatRender&) = default;
|
CvMatRender& operator=(CvMatRender&) = default;
|
||||||
CvMatRender& operator=(CvMatRender&& other) = default;
|
CvMatRender& operator=(CvMatRender&& other) = default;
|
||||||
~CvMatRender();
|
~CvMatRender();
|
||||||
explicit CvMatRender(const std::shared_ptr<pixelarium::imaging::PixelariumImage>& img);
|
explicit CvMatRender(std::shared_ptr<pixelarium::imaging::IPixelariumImage>& img);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GLuint Render();
|
GLuint Render();
|
||||||
GLuint Render(float factor);
|
GLuint Render(float factor);
|
||||||
GLuint Render(size_t width, size_t height);
|
GLuint Render(size_t width, size_t height);
|
||||||
void ResetRenderImage() { this->img_ = this->base_->GetImage().clone(); }
|
void ResetRenderImage();
|
||||||
void ResetRenderImage(const std::shared_ptr<pixelarium::imaging::PixelariumImage>& img);
|
void ResetRenderImage(std::shared_ptr<pixelarium::imaging::IPixelariumImage>& img);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cv::Mat img_;
|
cv::Mat img_;
|
||||||
std::shared_ptr<pixelarium::imaging::PixelariumImage> base_;
|
std::shared_ptr<pixelarium::imaging::IPixelariumImage> base_;
|
||||||
GLuint texture_;
|
GLuint texture_;
|
||||||
|
|
||||||
GLuint uploadTexture();
|
GLuint uploadTexture();
|
||||||
|
|||||||
@@ -9,14 +9,21 @@
|
|||||||
std::unique_ptr<pixelarium::render::PixelariumImageView> pixelarium::render::ImageViewFactory::RenderImage(
|
std::unique_ptr<pixelarium::render::PixelariumImageView> pixelarium::render::ImageViewFactory::RenderImage(
|
||||||
size_t image_id)
|
size_t image_id)
|
||||||
{
|
{
|
||||||
auto img{this->image_pool_.GetResource(image_id)};
|
auto res{this->image_pool_.GetResource(image_id)};
|
||||||
|
|
||||||
if (!img.has_value() || img.value()->Empty())
|
if (!res.has_value())
|
||||||
{
|
{
|
||||||
return nullptr;
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto img {res.value().lock()};
|
||||||
|
|
||||||
|
if (img->Empty())
|
||||||
|
{
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// beware: here we copy the actual image resource over to the new image
|
// beware: here we copy the actual image resource over to the new image
|
||||||
return std::make_unique<PixelariumImageView>(std::make_shared<Image>(*img.value()));
|
return std::make_unique<PixelariumImageView>(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "PixelariumImageView.hpp"
|
#include "PixelariumImageView.hpp"
|
||||||
#include "imaging/PixelariumImage.hpp"
|
|
||||||
#include "resources/resource.hpp"
|
#include "resources/resource.hpp"
|
||||||
namespace pixelarium::render
|
namespace pixelarium::render
|
||||||
{
|
{
|
||||||
class ImageViewFactory
|
class ImageViewFactory
|
||||||
{
|
{
|
||||||
using Image = imaging::PixelariumImage;
|
using Image = imaging::IPixelariumImage;
|
||||||
using Pool = resources::ImageResourcePool;
|
using Pool = resources::ImageResourcePool;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <format>
|
#include <format>
|
||||||
|
|
||||||
|
#include "imaging/IPixelariumImage.hpp"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
|
|
||||||
/// @brief Checks if the dimensions of two ImVec2 vectors have changed significantly.
|
/// @brief Checks if the dimensions of two ImVec2 vectors have changed significantly.
|
||||||
@@ -23,14 +24,14 @@ static bool dim_changed_p(const ImVec2& ref_rect, const ImVec2& new_rect)
|
|||||||
/// @param img The input image.
|
/// @param img The input image.
|
||||||
/// @param curr_dim The current dimensions.
|
/// @param curr_dim The current dimensions.
|
||||||
/// @return The calculated dimensions maintaining aspect ratio.
|
/// @return The calculated dimensions maintaining aspect ratio.
|
||||||
ImVec2 aspect_const_dimensions(const pixelarium::imaging::PixelariumImage& img, const ImVec2& curr_dim)
|
ImVec2 aspect_const_dimensions(const ImVec2& raw_dim, const ImVec2& curr_dim)
|
||||||
{
|
{
|
||||||
const auto w_fact = (static_cast<float>(curr_dim.x) / img.GetImage().cols);
|
const auto w_fact = (curr_dim.x / raw_dim.x);
|
||||||
const auto h_fact = (static_cast<float>(curr_dim.y) / img.GetImage().rows);
|
const auto h_fact = (curr_dim.y / raw_dim.y);
|
||||||
|
|
||||||
const auto fact = w_fact < h_fact ? w_fact : h_fact;
|
const auto fact = w_fact < h_fact ? w_fact : h_fact;
|
||||||
|
|
||||||
return ImVec2(img.GetImage().cols * fact, img.GetImage().rows * fact);
|
return ImVec2(raw_dim.x * fact, raw_dim.y * fact);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Displays the image in an ImGui window.
|
/// @brief Displays the image in an ImGui window.
|
||||||
@@ -40,13 +41,18 @@ ImVec2 aspect_const_dimensions(const pixelarium::imaging::PixelariumImage& img,
|
|||||||
/// fit the available window space. The raw and rendered dimensions are displayed below the image.
|
/// fit the available window space. The raw and rendered dimensions are displayed below the image.
|
||||||
void pixelarium::render::PixelariumImageView::ShowImage()
|
void pixelarium::render::PixelariumImageView::ShowImage()
|
||||||
{
|
{
|
||||||
if (this->img_ == nullptr || this->img_->Empty() || this->img_->Name().empty())
|
if (!this->cached_image_.has_value())
|
||||||
|
{
|
||||||
|
this->cached_image_ = this->img_->TryGetImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->img_->Empty() || this->img_->type_ == imaging::ImageFileType::UNKNOWN || !cached_image_.has_value() || this->img_->Name().empty())
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Begin(img_->Name().c_str(), &this->open_p, ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar);
|
ImGui::Begin(this->img_->Name().c_str(), &this->open_p, ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar);
|
||||||
|
|
||||||
this->curr_dim_ = ImGui::GetContentRegionAvail();
|
this->curr_dim_ = ImGui::GetContentRegionAvail();
|
||||||
auto new_dim = ImGui::GetContentRegionAvail();
|
auto new_dim = ImGui::GetContentRegionAvail();
|
||||||
@@ -57,10 +63,10 @@ void pixelarium::render::PixelariumImageView::ShowImage()
|
|||||||
|
|
||||||
this->curr_dim_ = new_dim;
|
this->curr_dim_ = new_dim;
|
||||||
|
|
||||||
ImVec2 dim(this->img_->GetImage().cols, this->img_->GetImage().rows);
|
ImVec2 dim(cached_image_.value()->cols, cached_image_.value()->rows);
|
||||||
|
|
||||||
ImGui::Image(reinterpret_cast<ImTextureID>(reinterpret_cast<void*>(texture)),
|
ImGui::Image(reinterpret_cast<ImTextureID>(reinterpret_cast<void*>(texture)),
|
||||||
aspect_const_dimensions(*this->img_, new_dim));
|
aspect_const_dimensions(dim, new_dim));
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
ImGui::Text("%s", std::format(" Raw Dimensions W : {}, H: {}", dim.x, dim.y).c_str());
|
ImGui::Text("%s", std::format(" Raw Dimensions W : {}, H: {}", dim.x, dim.y).c_str());
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "imaging/PixelariumImage.hpp"
|
#include "imaging/IPixelariumImage.hpp"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "rendering/CvMatRender.hpp"
|
#include "rendering/CvMatRender.hpp"
|
||||||
|
|
||||||
@@ -10,11 +10,11 @@ namespace pixelarium::render
|
|||||||
{
|
{
|
||||||
class PixelariumImageView
|
class PixelariumImageView
|
||||||
{
|
{
|
||||||
using Image = imaging::PixelariumImage;
|
using Image = imaging::IPixelariumImage;
|
||||||
using Render = render::CvMatRender;
|
using Render = render::CvMatRender;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PixelariumImageView(const std::shared_ptr<Image>& img) : img_(img) { render_ = Render(img_); }
|
explicit PixelariumImageView(std::shared_ptr<Image> img) : img_(img) { render_ = Render(img_); }
|
||||||
PixelariumImageView() = delete;
|
PixelariumImageView() = delete;
|
||||||
PixelariumImageView(PixelariumImageView&) = delete;
|
PixelariumImageView(PixelariumImageView&) = delete;
|
||||||
PixelariumImageView(const PixelariumImageView&) = delete;
|
PixelariumImageView(const PixelariumImageView&) = delete;
|
||||||
@@ -27,7 +27,8 @@ class PixelariumImageView
|
|||||||
void ShowImage();
|
void ShowImage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::shared_ptr<Image> img_;
|
std::shared_ptr<Image> img_;
|
||||||
|
std::optional<std::unique_ptr<cv::Mat>> cached_image_ {};
|
||||||
Render render_;
|
Render render_;
|
||||||
bool open_p{true};
|
bool open_p{true};
|
||||||
ImVec2 curr_dim_{};
|
ImVec2 curr_dim_{};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
using pixelarium::imaging::PixelariumImage;
|
using pixelarium::imaging::IPixelariumImage;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@@ -22,19 +22,24 @@ size_t GenerateId() { return id_.fetch_add(1, memory_order_relaxed); }
|
|||||||
/// @brief Retrieves a resource from the pool.
|
/// @brief Retrieves a resource from the pool.
|
||||||
/// @param id The ID of the resource to retrieve.
|
/// @param id The ID of the resource to retrieve.
|
||||||
/// @return A pointer to the resource if found, otherwise an empty optional.
|
/// @return A pointer to the resource if found, otherwise an empty optional.
|
||||||
std::optional<const PixelariumImage*> pixelarium::resources::ImageResourcePool::GetResource(ResourceKey id) const
|
std::optional<std::weak_ptr<IPixelariumImage>> pixelarium::resources::ImageResourcePool::GetResource(ResourceKey id) const
|
||||||
{
|
{
|
||||||
auto search{this->resources_.find(id)};
|
auto search{this->resources_.find(id)};
|
||||||
if (search == this->resources_.end()) return std::nullopt;
|
if (search == this->resources_.end()) return std::nullopt;
|
||||||
|
|
||||||
return search->second.get();
|
return search->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Sets a resource in the pool.
|
/// @brief Sets a resource in the pool.
|
||||||
/// @param res A unique pointer to the resource to set.
|
/// @param res A unique pointer to the resource to set.
|
||||||
/// @return The ID of the new resource.
|
/// @return The ID of the new resource.
|
||||||
size_t pixelarium::resources::ImageResourcePool::SetResource(unique_ptr<PixelariumImage> res)
|
size_t pixelarium::resources::ImageResourcePool::SetResource(unique_ptr<IPixelariumImage> res)
|
||||||
{
|
{
|
||||||
|
if (res == nullptr)
|
||||||
|
{
|
||||||
|
throw empty_resource_exception();
|
||||||
|
}
|
||||||
|
|
||||||
auto key{::GenerateId()};
|
auto key{::GenerateId()};
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(this->mut_);
|
std::lock_guard<std::mutex> guard(this->mut_);
|
||||||
@@ -49,7 +54,7 @@ size_t pixelarium::resources::ImageResourcePool::SetResource(unique_ptr<Pixelari
|
|||||||
/// @param res A unique pointer to the new resource.
|
/// @param res A unique pointer to the new resource.
|
||||||
/// @return True if the resource was updated, false otherwise.
|
/// @return True if the resource was updated, false otherwise.
|
||||||
bool pixelarium::resources::ImageResourcePool::ModifyResource(ResourceKey id,
|
bool pixelarium::resources::ImageResourcePool::ModifyResource(ResourceKey id,
|
||||||
std::unique_ptr<imaging::PixelariumImage> res)
|
std::unique_ptr<imaging::IPixelariumImage> res)
|
||||||
{
|
{
|
||||||
auto search{this->resources_.find(id)};
|
auto search{this->resources_.find(id)};
|
||||||
if (search == this->resources_.end()) return false;
|
if (search == this->resources_.end()) return false;
|
||||||
@@ -76,7 +81,7 @@ bool pixelarium::resources::ImageResourcePool::DeleteResource(ResourceKey id)
|
|||||||
/// @param func A function to call for each resource. The function should accept the resource ID and a const reference
|
/// @param func A function to call for each resource. The function should accept the resource ID and a const reference
|
||||||
/// to a PixelariumImage.
|
/// to a PixelariumImage.
|
||||||
void pixelarium::resources::ImageResourcePool::EnumerateResources(
|
void pixelarium::resources::ImageResourcePool::EnumerateResources(
|
||||||
const std::function<void(ResourceKey, size_t, const imaging::PixelariumImage&)>& func)
|
const std::function<void(ResourceKey, size_t, const imaging:: IPixelariumImage&)>& func)
|
||||||
{
|
{
|
||||||
size_t idx{0};
|
size_t idx{0};
|
||||||
for (const auto& e : this->resources_)
|
for (const auto& e : this->resources_)
|
||||||
|
|||||||
+25
-10
@@ -7,11 +7,22 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "imaging/PixelariumImage.hpp"
|
#include "imaging/IPixelariumImage.hpp"
|
||||||
|
|
||||||
namespace pixelarium::resources
|
namespace pixelarium::resources
|
||||||
{
|
{
|
||||||
using ResourceKey = size_t;
|
using ResourceKey = size_t;
|
||||||
|
|
||||||
|
struct empty_resource_exception : public std::exception
|
||||||
|
{
|
||||||
|
empty_resource_exception() {};
|
||||||
|
empty_resource_exception(const char* msg) : message_(msg) {};
|
||||||
|
const char* what() { return message_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char* message_ = "Empty Resource";
|
||||||
|
};
|
||||||
|
|
||||||
struct IResource
|
struct IResource
|
||||||
{
|
{
|
||||||
virtual ~IResource() = default;
|
virtual ~IResource() = default;
|
||||||
@@ -25,12 +36,14 @@ class IResourcePool
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IResourcePool() = default;
|
virtual ~IResourcePool() = default;
|
||||||
virtual std::optional<const ResT*> GetResource(size_t id) const = 0;
|
virtual std::optional<std::weak_ptr<ResT>> GetResource(size_t id) const = 0;
|
||||||
virtual ResourceKey SetResource(std::unique_ptr<ResT> res) = 0;
|
virtual ResourceKey SetResource(std::unique_ptr<ResT> res) = 0;
|
||||||
virtual bool ModifyResource(ResourceKey id, std::unique_ptr<ResT> res) = 0;
|
virtual bool ModifyResource(ResourceKey id, std::unique_ptr<ResT> res) = 0;
|
||||||
virtual bool DeleteResource(ResourceKey id) = 0;
|
virtual bool DeleteResource(ResourceKey id) = 0;
|
||||||
virtual void EnumerateResources(const std::function<void(ResourceKey, size_t, const imaging::PixelariumImage&)>& func) = 0;
|
virtual void EnumerateResources(
|
||||||
|
const std::function<void(ResourceKey, size_t, const imaging::IPixelariumImage&)>& func) = 0;
|
||||||
virtual size_t GetTotalSize() const = 0;
|
virtual size_t GetTotalSize() const = 0;
|
||||||
|
virtual void Clear() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Now with the =GetResource= method, I do not want to transfer ownership to the caller of that method. The ownership
|
// Now with the =GetResource= method, I do not want to transfer ownership to the caller of that method. The ownership
|
||||||
@@ -38,7 +51,7 @@ class IResourcePool
|
|||||||
// reside with the =ResourcePool=!
|
// reside with the =ResourcePool=!
|
||||||
// In fact, the intention is, that there is no way back once the =ResourcePool= took ownership of an object.
|
// In fact, the intention is, that there is no way back once the =ResourcePool= took ownership of an object.
|
||||||
// Callers can get references, but no ownership. A caller might delete a resource though.
|
// Callers can get references, but no ownership. A caller might delete a resource though.
|
||||||
class ImageResourcePool : public IResourcePool<imaging::PixelariumImage>
|
class ImageResourcePool : public IResourcePool<imaging::IPixelariumImage>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ImageResourcePool() = default;
|
ImageResourcePool() = default;
|
||||||
@@ -48,15 +61,17 @@ class ImageResourcePool : public IResourcePool<imaging::PixelariumImage>
|
|||||||
ImageResourcePool& operator=(ImageResourcePool&) = delete;
|
ImageResourcePool& operator=(ImageResourcePool&) = delete;
|
||||||
ImageResourcePool& operator=(ImageResourcePool&&) = delete;
|
ImageResourcePool& operator=(ImageResourcePool&&) = delete;
|
||||||
|
|
||||||
std::optional<const imaging::PixelariumImage*> GetResource(ResourceKey id) const override;
|
std::optional<std::weak_ptr<imaging::IPixelariumImage>> GetResource(ResourceKey id) const override;
|
||||||
ResourceKey SetResource(std::unique_ptr<imaging::PixelariumImage> res) override;
|
ResourceKey SetResource(std::unique_ptr<imaging::IPixelariumImage> res) override;
|
||||||
bool ModifyResource(ResourceKey id, std::unique_ptr<imaging::PixelariumImage> res) override;
|
bool ModifyResource(ResourceKey id, std::unique_ptr<imaging::IPixelariumImage> res) override;
|
||||||
bool DeleteResource(ResourceKey id) override;
|
bool DeleteResource(ResourceKey id) override;
|
||||||
|
void Clear() override { this->resources_.clear(); }
|
||||||
|
|
||||||
void EnumerateResources(const std::function<void(ResourceKey, size_t, const imaging::PixelariumImage&)>& func) override;
|
void EnumerateResources(
|
||||||
|
const std::function<void(ResourceKey, size_t, const imaging::IPixelariumImage&)>& func) override;
|
||||||
|
|
||||||
template <typename Callable>
|
template <typename Callable>
|
||||||
requires std::invocable<Callable, ResourceKey, size_t, const imaging::PixelariumImage&>
|
requires std::invocable<Callable, ResourceKey, size_t, const imaging::IPixelariumImage&>
|
||||||
void Enumerate(Callable&& func) const
|
void Enumerate(Callable&& func) const
|
||||||
{
|
{
|
||||||
size_t idx{0};
|
size_t idx{0};
|
||||||
@@ -69,7 +84,7 @@ class ImageResourcePool : public IResourcePool<imaging::PixelariumImage>
|
|||||||
size_t GetTotalSize() const override { return resources_.size(); }
|
size_t GetTotalSize() const override { return resources_.size(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<size_t, std::unique_ptr<imaging::PixelariumImage>> resources_;
|
std::unordered_map<size_t, std::shared_ptr<imaging::IPixelariumImage>> resources_;
|
||||||
std::mutex mut_;
|
std::mutex mut_;
|
||||||
};
|
};
|
||||||
} // namespace pixelarium::resources
|
} // namespace pixelarium::resources
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
message(STATUS "Configuring Resources")
|
|
||||||
|
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/app_resources_local.h.in
|
|
||||||
${CMAKE_BINARY_DIR}/app_resources_local.h @ONLY)
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
// Currently, there is no need for this to be a configurable header.
|
|
||||||
// It is left as such to keep the API open for possible build-system
|
|
||||||
// injections in future.
|
|
||||||
// clang-format off
|
|
||||||
#define SHOWIMGUIDEMOS "ImGui Demos"
|
|
||||||
#define SHOWIMAGEGALLERY "Image Gallery"
|
|
||||||
#define AUTOSHOWSELECTED "Auto View"
|
|
||||||
#define OPENIMAGE "Open"
|
|
||||||
|
|
||||||
// clang-format on
|
|
||||||
+2
-4
@@ -1,7 +1,6 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "MyApp.hpp"
|
#include "DefaultApp.hpp"
|
||||||
#include "resources/resource.hpp"
|
#include "resources/resource.hpp"
|
||||||
#include "utilities/ILog.hpp"
|
#include "utilities/ILog.hpp"
|
||||||
#include "utilities/SpdLogger.hpp"
|
#include "utilities/SpdLogger.hpp"
|
||||||
@@ -10,7 +9,6 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
using namespace pixelarium;
|
using namespace pixelarium;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
cout << "ok\n";
|
|
||||||
unique_ptr<utils::log::ILog> logger;
|
unique_ptr<utils::log::ILog> logger;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
logger = make_unique<utils::log::SpdLogger>(string(getenv("APPDATA")) + "/pixelarium/logfile.log", "default");
|
logger = make_unique<utils::log::SpdLogger>(string(getenv("APPDATA")) + "/pixelarium/logfile.log", "default");
|
||||||
@@ -22,7 +20,7 @@ int main(int argc, char** argv)
|
|||||||
logger->ChangeLevel(utils::log::LogLevel::Debug);
|
logger->ChangeLevel(utils::log::LogLevel::Debug);
|
||||||
auto image_pool{std::make_unique<resources::ImageResourcePool>()};
|
auto image_pool{std::make_unique<resources::ImageResourcePool>()};
|
||||||
|
|
||||||
pixelarium::ui::MyApp app = pixelarium::ui::MyApp(*logger, *image_pool);
|
pixelarium::ui::DefaultApp app = pixelarium::ui::DefaultApp(*logger, *image_pool);
|
||||||
|
|
||||||
app.Start();
|
app.Start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,24 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "imaging/PixelariumImage.hpp"
|
|
||||||
#include "resources/resource.hpp"
|
#include "resources/resource.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
class DummyImage : public pixelarium::imaging::PixelariumImage
|
// A Mock implementation for tests requiring _any_ instance of a IPixelariumImage
|
||||||
|
class DummyImage : public pixelarium::imaging::IPixelariumImage
|
||||||
{
|
{
|
||||||
// Implement minimal interface if needed for test
|
public:
|
||||||
|
std::optional<std::unique_ptr<cv::Mat>> TryGetImage() override { return {}; }
|
||||||
|
|
||||||
|
std::optional<std::unique_ptr<cv::Mat>> TryGetImage(const pixelarium::imaging::IImageQuery&) override { return {}; }
|
||||||
|
|
||||||
|
std::string Name() const noexcept override { return {}; }
|
||||||
|
|
||||||
|
bool Empty() const noexcept override { return true; }
|
||||||
|
|
||||||
|
std::filesystem::path Uri() const noexcept override { return {}; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
@@ -23,18 +32,20 @@ TEST(ImageResourcePoolTest, SetAndGetResource)
|
|||||||
auto img = std::make_unique<DummyImage>();
|
auto img = std::make_unique<DummyImage>();
|
||||||
auto id = pool.SetResource(std::move(img));
|
auto id = pool.SetResource(std::move(img));
|
||||||
auto res = pool.GetResource(id);
|
auto res = pool.GetResource(id);
|
||||||
|
auto res_img = res.value().lock();
|
||||||
EXPECT_TRUE(res.has_value());
|
EXPECT_TRUE(res.has_value());
|
||||||
EXPECT_NE(res.value(), nullptr);
|
EXPECT_NE(res_img, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ImageResourcePoolTest, SetWrappedRawPointerGet)
|
TEST(ImageResourcePoolTest, SetWrappedRawPointerGet)
|
||||||
{
|
{
|
||||||
ImageResourcePool pool;
|
ImageResourcePool pool;
|
||||||
auto img = new DummyImage();
|
auto img = new DummyImage();
|
||||||
auto id = pool.SetResource(std::unique_ptr<pixelarium::imaging::PixelariumImage>(img));
|
auto id = pool.SetResource(std::unique_ptr<pixelarium::imaging::IPixelariumImage>(img));
|
||||||
auto res = pool.GetResource(id);
|
auto res = pool.GetResource(id);
|
||||||
|
auto res_img = res.value().lock();
|
||||||
EXPECT_TRUE(res.has_value());
|
EXPECT_TRUE(res.has_value());
|
||||||
EXPECT_NE(res.value(), nullptr);
|
EXPECT_NE(res_img, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ImageResourcePoolTest, GetNonExistentResourceReturnsEmptyOptional)
|
TEST(ImageResourcePoolTest, GetNonExistentResourceReturnsEmptyOptional)
|
||||||
@@ -50,8 +61,9 @@ TEST(ImageResourcePoolTest, ModifyResourceSuccess)
|
|||||||
auto new_img = std::make_unique<DummyImage>();
|
auto new_img = std::make_unique<DummyImage>();
|
||||||
EXPECT_TRUE(pool.ModifyResource(id, std::move(new_img)));
|
EXPECT_TRUE(pool.ModifyResource(id, std::move(new_img)));
|
||||||
auto res = pool.GetResource(id);
|
auto res = pool.GetResource(id);
|
||||||
|
auto res_img = res.value().lock();
|
||||||
EXPECT_TRUE(res.has_value());
|
EXPECT_TRUE(res.has_value());
|
||||||
EXPECT_NE(res.value(), nullptr);
|
EXPECT_NE(res_img, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ImageResourcePoolTest, ModifyResourceFail)
|
TEST(ImageResourcePoolTest, ModifyResourceFail)
|
||||||
@@ -82,7 +94,8 @@ TEST(ImageResourcePoolTest, EnumerateResources)
|
|||||||
auto id2 = pool.SetResource(std::make_unique<DummyImage>());
|
auto id2 = pool.SetResource(std::make_unique<DummyImage>());
|
||||||
std::vector<size_t> found_ids{};
|
std::vector<size_t> found_ids{};
|
||||||
|
|
||||||
pool.EnumerateResources([&found_ids](size_t id, size_t, const pixelarium::imaging::PixelariumImage&) { found_ids.push_back(id); });
|
pool.EnumerateResources([&found_ids](size_t id, size_t, const pixelarium::imaging::IPixelariumImage&)
|
||||||
|
{ found_ids.push_back(id); });
|
||||||
|
|
||||||
EXPECT_EQ(found_ids.size(), 2);
|
EXPECT_EQ(found_ids.size(), 2);
|
||||||
EXPECT_NE(std::find(found_ids.begin(), found_ids.end(), id1), found_ids.end());
|
EXPECT_NE(std::find(found_ids.begin(), found_ids.end(), id1), found_ids.end());
|
||||||
@@ -96,7 +109,8 @@ TEST(ImageResourcePoolTest, TemplatedEnumerate)
|
|||||||
auto id2 = pool.SetResource(std::make_unique<DummyImage>());
|
auto id2 = pool.SetResource(std::make_unique<DummyImage>());
|
||||||
std::vector<size_t> found_ids{};
|
std::vector<size_t> found_ids{};
|
||||||
|
|
||||||
pool.Enumerate([&found_ids](size_t id, size_t, const pixelarium::imaging::PixelariumImage&) { found_ids.push_back(id); });
|
pool.Enumerate([&found_ids](size_t id, size_t, const pixelarium::imaging::IPixelariumImage&)
|
||||||
|
{ found_ids.push_back(id); });
|
||||||
|
|
||||||
EXPECT_EQ(found_ids.size(), 2);
|
EXPECT_EQ(found_ids.size(), 2);
|
||||||
EXPECT_NE(std::find(found_ids.begin(), found_ids.end(), id1), found_ids.end());
|
EXPECT_NE(std::find(found_ids.begin(), found_ids.end(), id1), found_ids.end());
|
||||||
|
|||||||
Reference in New Issue
Block a user