Enhance image type support (#18)

* adds tiff support

* doc update

* adds memory-based =IPixelariumImage= implementation

* add usage example for custom user control

* enhance

* clang-format

fix readme

fix docs
This commit is contained in:
m-aXimilian
2025-10-12 21:47:17 +02:00
committed by Maximilian Kueffner
parent 356f966d01
commit e3e161ce52
16 changed files with 385 additions and 15 deletions
+1
View File
@@ -1,2 +1,3 @@
add_subdirectory(simple)
add_subdirectory(custom_0)
add_subdirectory(custom_1)
+22
View File
@@ -0,0 +1,22 @@
set(SRC
${CMAKE_CURRENT_SOURCE_DIR}/custom_1.cpp)
set(CUSTOM_1_NAME "${PROJECT_NAME}_custom1_app")
add_executable(${CUSTOM_1_NAME} ${SRC})
target_link_libraries(${CUSTOM_1_NAME}
PRIVATE pixelariumimagelib
PRIVATE pixelariumrenderlib
PRIVATE pixelariumutilslib
PRIVATE pixelariumresourcelib
PRIVATE pixelariumapplicationlib)
target_include_directories(${CUSTOM_1_NAME}
PRIVATE ${PROJECT_SOURCE_DIR}/src
PRIVATE ${PROJECT_SOURCE_DIR}/lib
PRIVATE ${PROJECT_SOURCE_DIR}/lib/imaging
PRIVATE ${PROJECT_SOURCE_DIR}/lib/app
PRIVATE ${spdlog_DIR}/include
PRIVATE ${LIBCZI_INCLUDE_DIR}
PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+146
View File
@@ -0,0 +1,146 @@
#include <opencv2/core/hal/interface.h>
#include <ctime>
#include <memory>
#include <opencv2/core/base.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/imgproc.hpp>
#include <string>
#include "DefaultApp.hpp"
#include "IPixelariumImage.hpp"
#include "imgui.h"
#include "impl/PixelariumMem.hpp"
#include "resources/resource.hpp"
#include "utilities/ILog.hpp"
#include "utilities/SpdLogger.hpp"
using namespace pixelarium;
using namespace std;
using Log = utils::log::ILog;
using Pool = resources::ImageResourcePool;
// setup a logger
#ifdef _WIN32
unique_ptr<Log> logger{
make_unique<utils::log::SpdLogger>(string(getenv("APPDATA")) + "/pixelarium/simple_app.log", "default")};
#else
unique_ptr<Log> logger{
make_unique<utils::log::SpdLogger>(string(getenv("HOME")) + "/.cache/pixelarium/simple_app.log", "default")};
#endif
// instantiate an image pool for the application
resources::ImageResourcePool image_pool;
class Selector
{
using Pool = resources::ImageResourcePool;
Pool& pool_;
std::string preview_0_{"None"};
std::string preview_1_{"None"};
resources::ResourceKey selected_key_0;
resources::ResourceKey selected_key_1;
int idx_{0};
public:
Selector(resources::ImageResourcePool& pool) : pool_(pool) {}
void SelectImage()
{
ImGui::Begin("Image Multiply");
static int selected_idx_0{0};
static int selected_idx_1{0};
if (ImGui::BeginCombo("Select first image", preview_0_.c_str()))
{
pool_.Enumerate(
[&](resources::ResourceKey key, size_t idx, const imaging::IPixelariumImage& img) -> void
{
const bool is_selected = static_cast<int>(idx) == selected_idx_0;
if (ImGui::Selectable(img.Name().c_str(), is_selected))
{
selected_idx_0 = idx;
preview_0_ = img.Name();
selected_key_0 = key;
}
if (is_selected)
{
ImGui::SetItemDefaultFocus();
}
});
ImGui::EndCombo();
}
if (ImGui::BeginCombo("Select second image", preview_1_.c_str()))
{
pool_.Enumerate(
[&](resources::ResourceKey key, size_t idx, const imaging::IPixelariumImage& img) -> void
{
const bool is_selected = static_cast<int>(idx) == selected_idx_1;
if (ImGui::Selectable(img.Name().c_str(), is_selected))
{
selected_idx_1 = idx;
preview_1_ = img.Name();
selected_key_1 = key;
}
if (is_selected)
{
ImGui::SetItemDefaultFocus();
}
});
ImGui::EndCombo();
}
if (ImGui::Button("Process"))
{
auto img0 = pool_.GetResource(selected_key_0);
auto img_mat0 = img0.lock()->TryGetImage();
auto img1 = pool_.GetResource(selected_key_1);
auto img_mat1 = img1.lock()->TryGetImage();
if (img_mat0 == nullptr || img_mat1 == nullptr || img_mat0->empty() || img_mat1->empty()) return;
if (img_mat0->size != img_mat1->size) return;
cv::multiply(*img_mat0, *img_mat1, *img_mat0);
std::string name{std::format("Multiply_{}", idx_)};
pool_.SetResource(std::make_unique<imaging::PixelariumMem>(*img_mat0, name, *logger));
++idx_;
}
ImGui::End();
}
};
// create a custom app inheriting from the library's default app
class MyApp : public application::DefaultApp
{
Selector select_;
public:
MyApp(const Log& log, Pool& pool) : application::DefaultApp(log, pool), select_(pool) {}
// override some of the defaults member functions
void Run() override;
};
int main()
{
// some initial log message
logger->Info(std::format("{}: Starting Application {}", __FUNCTION__, "Pixelarium"));
// create a custom application, inject its dependencies and start it
auto app{MyApp(*logger, image_pool)};
app.Start();
}
void MyApp::Run()
{
application::DefaultApp::Run();
select_.SelectImage();
}