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:
m-aXimilian
2025-09-22 23:13:28 +02:00
committed by Maximilian Kueffner
parent bce12b0bb4
commit 0be064bb8e
31 changed files with 670 additions and 221 deletions
+39 -5
View File
@@ -5,13 +5,13 @@
#include <opencv2/imgproc.hpp>
#include <stdexcept>
#include "imaging/PixelariumImage.hpp"
#include "imaging/IPixelariumImage.hpp"
using namespace pixelarium::imaging;
/// @brief Constructor for the CvMatRender class.
/// @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
// 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.
/// @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->ResetRenderImage();
@@ -97,7 +97,11 @@ GLuint pixelarium::render::CvMatRender::Render() { return this->uploadTexture();
/// @return The ID of the OpenGL texture.
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();
}
@@ -108,7 +112,14 @@ GLuint pixelarium::render::CvMatRender::Render(float factor)
/// @return The ID of the OpenGL texture.
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; };
@@ -116,3 +127,26 @@ GLuint pixelarium::render::CvMatRender::Render(size_t width, size_t height)
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();
}
+5 -5
View File
@@ -13,7 +13,7 @@
#endif
#include <GLFW/glfw3.h> // Will drag system OpenGL headers
#endif
#include "imaging/PixelariumImage.hpp"
#include "imaging/IPixelariumImage.hpp"
// clang-format on
namespace pixelarium::render
@@ -33,18 +33,18 @@ class CvMatRender
CvMatRender& operator=(CvMatRender&) = default;
CvMatRender& operator=(CvMatRender&& other) = default;
~CvMatRender();
explicit CvMatRender(const std::shared_ptr<pixelarium::imaging::PixelariumImage>& img);
explicit CvMatRender(std::shared_ptr<pixelarium::imaging::IPixelariumImage>& img);
public:
GLuint Render();
GLuint Render(float factor);
GLuint Render(size_t width, size_t height);
void ResetRenderImage() { this->img_ = this->base_->GetImage().clone(); }
void ResetRenderImage(const std::shared_ptr<pixelarium::imaging::PixelariumImage>& img);
void ResetRenderImage();
void ResetRenderImage(std::shared_ptr<pixelarium::imaging::IPixelariumImage>& img);
private:
cv::Mat img_;
std::shared_ptr<pixelarium::imaging::PixelariumImage> base_;
std::shared_ptr<pixelarium::imaging::IPixelariumImage> base_;
GLuint texture_;
GLuint uploadTexture();
+11 -4
View File
@@ -9,14 +9,21 @@
std::unique_ptr<pixelarium::render::PixelariumImageView> pixelarium::render::ImageViewFactory::RenderImage(
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
return std::make_unique<PixelariumImageView>(std::make_shared<Image>(*img.value()));
return std::make_unique<PixelariumImageView>(img);
}
+1 -2
View File
@@ -1,13 +1,12 @@
#pragma once
#include "PixelariumImageView.hpp"
#include "imaging/PixelariumImage.hpp"
#include "resources/resource.hpp"
namespace pixelarium::render
{
class ImageViewFactory
{
using Image = imaging::PixelariumImage;
using Image = imaging::IPixelariumImage;
using Pool = resources::ImageResourcePool;
public:
+14 -8
View File
@@ -2,6 +2,7 @@
#include <format>
#include "imaging/IPixelariumImage.hpp"
#include "imgui.h"
/// @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 curr_dim The current dimensions.
/// @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 h_fact = (static_cast<float>(curr_dim.y) / img.GetImage().rows);
const auto w_fact = (curr_dim.x / raw_dim.x);
const auto h_fact = (curr_dim.y / raw_dim.y);
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.
@@ -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.
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
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();
auto new_dim = ImGui::GetContentRegionAvail();
@@ -57,10 +63,10 @@ void pixelarium::render::PixelariumImageView::ShowImage()
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)),
aspect_const_dimensions(*this->img_, new_dim));
aspect_const_dimensions(dim, new_dim));
ImGui::Separator();
ImGui::Text("%s", std::format(" Raw Dimensions W : {}, H: {}", dim.x, dim.y).c_str());
+5 -4
View File
@@ -2,7 +2,7 @@
#include <memory>
#include "imaging/PixelariumImage.hpp"
#include "imaging/IPixelariumImage.hpp"
#include "imgui.h"
#include "rendering/CvMatRender.hpp"
@@ -10,11 +10,11 @@ namespace pixelarium::render
{
class PixelariumImageView
{
using Image = imaging::PixelariumImage;
using Image = imaging::IPixelariumImage;
using Render = render::CvMatRender;
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(PixelariumImageView&) = delete;
PixelariumImageView(const PixelariumImageView&) = delete;
@@ -27,7 +27,8 @@ class PixelariumImageView
void ShowImage();
private:
const std::shared_ptr<Image> img_;
std::shared_ptr<Image> img_;
std::optional<std::unique_ptr<cv::Mat>> cached_image_ {};
Render render_;
bool open_p{true};
ImVec2 curr_dim_{};