* get image returns optional<Mat> instead of unique_ptr<Mat>

* introduce complexity

* rename image load function

* add example for a basic reader for binary image files

* fix windows build?

* add a status bar underneath the menu bar

* use status bar in custom_0 example app

* clang formats

* packing w/ pragma push

* add "Save As" functions to image views

* resize over reserve

* rm local override uri

* add simple thread pool

* rename to simple_thread_pool

* get rid of useless renderlib

* document version inc

* extract hardcoded values to in-header

* clang format patch

* clone registered image in custom_0

* document binary-file header

* minor fixes

* clang format

* rm unused render cmake
This commit is contained in:
m-aXimilian
2026-01-23 23:00:35 +00:00
committed by Maximilian Kueffner
parent e3e161ce52
commit b37814204f
52 changed files with 712 additions and 207 deletions
+7 -6
View File
@@ -5,7 +5,9 @@
#include <functional>
#include <mutex>
using pixelarium::imaging::IPixelariumImage;
#include "imaging/IPixelariumImage.hpp"
using Image = pixelarium::imaging::IPixelariumImageCvMat;
using namespace std;
namespace
@@ -21,7 +23,7 @@ size_t GenerateId() { return id_.fetch_add(1, memory_order_relaxed); }
/// @brief Retrieves a resource from the pool.
/// @param id The ID of the resource to retrieve.
/// @return A pointer to the resource if found, otherwise an empty optional.
std::weak_ptr<IPixelariumImage> pixelarium::resources::ImageResourcePool::GetResource(ResourceKey id) const
std::weak_ptr<Image> pixelarium::resources::ImageResourcePool::GetResource(ResourceKey id) const
{
auto search{this->resources_.find(id)};
if (search == this->resources_.end()) return {};
@@ -32,7 +34,7 @@ std::weak_ptr<IPixelariumImage> pixelarium::resources::ImageResourcePool::GetRes
/// @brief Sets a resource in the pool.
/// @param res A unique pointer to the resource to set.
/// @return The ID of the new resource.
size_t pixelarium::resources::ImageResourcePool::SetResource(unique_ptr<IPixelariumImage> res)
size_t pixelarium::resources::ImageResourcePool::SetResource(unique_ptr<Image> res)
{
if (res == nullptr)
{
@@ -52,8 +54,7 @@ size_t pixelarium::resources::ImageResourcePool::SetResource(unique_ptr<IPixelar
/// @param id The ID of the resource to update.
/// @param res A unique pointer to the new resource.
/// @return True if the resource was updated, false otherwise.
bool pixelarium::resources::ImageResourcePool::ModifyResource(ResourceKey id,
std::unique_ptr<imaging::IPixelariumImage> res)
bool pixelarium::resources::ImageResourcePool::ModifyResource(ResourceKey id, std::unique_ptr<Image> res)
{
auto search{this->resources_.find(id)};
if (search == this->resources_.end()) return false;
@@ -80,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
/// to a PixelariumImage.
void pixelarium::resources::ImageResourcePool::EnumerateResources(
const std::function<void(ResourceKey, size_t, const imaging::IPixelariumImage&)>& func)
const std::function<void(ResourceKey, size_t, const imaging::IPixelariumImage<cv::Mat>&)>& func)
{
size_t idx{0};
for (const auto& e : this->resources_)
+9 -9
View File
@@ -38,7 +38,7 @@ concept ResT = requires(R& r) { static_cast<IResource&>(r); };
/// @brief Defines an interface for a resource pool
/// @tparam ResT defines the resource type that is accepted by the pool
template <typename ResT>
template <typename ResT, class Data>
class IResourcePool
{
public:
@@ -48,7 +48,7 @@ class IResourcePool
virtual bool ModifyResource(ResourceKey id, std::unique_ptr<ResT> res) = 0;
virtual bool DeleteResource(ResourceKey id) = 0;
virtual void EnumerateResources(
const std::function<void(ResourceKey, size_t, const imaging::IPixelariumImage&)>& func) = 0;
const std::function<void(ResourceKey, size_t, const imaging::IPixelariumImage<Data>&)>& func) = 0;
virtual size_t GetTotalSize() const = 0;
virtual void Clear() = 0;
};
@@ -58,7 +58,7 @@ class IResourcePool
// reside with the =ResourcePool=!
// 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.
class ImageResourcePool : public IResourcePool<imaging::IPixelariumImage>
class ImageResourcePool : public IResourcePool<imaging::IPixelariumImageCvMat, cv::Mat>
{
public:
ImageResourcePool() = default;
@@ -68,17 +68,17 @@ class ImageResourcePool : public IResourcePool<imaging::IPixelariumImage>
ImageResourcePool& operator=(ImageResourcePool&) = delete;
ImageResourcePool& operator=(ImageResourcePool&&) = delete;
std::weak_ptr<imaging::IPixelariumImage> GetResource(ResourceKey id) const override;
ResourceKey SetResource(std::unique_ptr<imaging::IPixelariumImage> res) override;
bool ModifyResource(ResourceKey id, std::unique_ptr<imaging::IPixelariumImage> res) override;
std::weak_ptr<imaging::IPixelariumImageCvMat> GetResource(ResourceKey id) const override;
ResourceKey SetResource(std::unique_ptr<imaging::IPixelariumImageCvMat> res) override;
bool ModifyResource(ResourceKey id, std::unique_ptr<imaging::IPixelariumImageCvMat> res) override;
bool DeleteResource(ResourceKey id) override;
void Clear() override { this->resources_.clear(); }
void EnumerateResources(
const std::function<void(ResourceKey, size_t, const imaging::IPixelariumImage&)>& func) override;
const std::function<void(ResourceKey, size_t, const imaging::IPixelariumImage<cv::Mat>&)>& func) override;
template <typename Callable>
requires std::invocable<Callable, ResourceKey, size_t, const imaging::IPixelariumImage&>
requires std::invocable<Callable, ResourceKey, size_t, const imaging::IPixelariumImageCvMat&>
void Enumerate(Callable&& func) const
{
size_t idx{0};
@@ -91,7 +91,7 @@ class ImageResourcePool : public IResourcePool<imaging::IPixelariumImage>
size_t GetTotalSize() const override { return resources_.size(); }
private:
std::unordered_map<size_t, std::shared_ptr<imaging::IPixelariumImage>> resources_;
std::unordered_map<size_t, std::shared_ptr<imaging::IPixelariumImageCvMat>> resources_;
std::mutex mut_;
};
} // namespace pixelarium::resources