Files
pixelarium/lib/imaging/PixelariumImage.hpp
T

86 lines
2.1 KiB
C++
Raw Normal View History

2025-06-13 22:23:20 +00:00
#pragma once
2025-09-13 14:49:59 +02:00
#include <filesystem>
#include <functional>
2025-06-13 22:23:20 +00:00
#include <memory>
#include <opencv2/core/mat.hpp>
#include <string>
namespace pixelarium::imaging
{
2025-09-13 14:49:59 +02:00
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.)
2025-06-13 22:23:20 +00:00
class PixelariumImage
{
public:
2025-09-13 14:49:59 +02:00
// 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
2025-06-13 22:23:20 +00:00
explicit PixelariumImage(const std::string& uri);
PixelariumImage() = default;
2025-08-18 22:39:43 +00:00
PixelariumImage(const PixelariumImage& other)
{
// be ware!!
// we make a copy of the image data here!
img_ = std::make_unique<cv::Mat>(*other.img_);
2025-09-13 14:49:59 +02:00
uri_ = other.uri_;
2025-08-18 22:39:43 +00:00
};
2025-09-13 14:49:59 +02:00
PixelariumImage(PixelariumImage&& other) noexcept : img_(std::move(other.img_)) {}
2025-06-13 22:23:20 +00:00
PixelariumImage& operator=(const PixelariumImage& other) = delete;
PixelariumImage& operator=(PixelariumImage&& other) noexcept
{
if (this != &other)
{
img_ = std::move(other.img_);
2025-09-13 14:49:59 +02:00
uri_ = other.uri_;
2025-06-13 22:23:20 +00:00
}
return *this;
}
2025-09-13 14:49:59 +02:00
// this should probably vanish as it makes no sense
// for multidimensional images (more than one frame)
// -> we need some sort of accessor functionality
2025-06-13 22:23:20 +00:00
~PixelariumImage() = default;
const cv::Mat& GetImage() const { return *this->img_.get(); }
2025-09-13 14:49:59 +02:00
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_; }
2025-06-13 22:23:20 +00:00
protected:
std::unique_ptr<cv::Mat> img_;
2025-09-13 14:49:59 +02:00
std::filesystem::path uri_;
static ImageFileType type_;
2025-06-13 22:23:20 +00:00
};
} // namespace pixelarium::imaging