Files
pixelarium/lib/imaging/IPixelariumImage.hpp
T

96 lines
3.2 KiB
C++
Raw Normal View History

2025-09-22 23:13:28 +02:00
#pragma once
#include <filesystem>
#include <functional>
#include <memory>
#include <opencv2/core/mat.hpp>
#include <string>
namespace pixelarium::imaging
{
using ImageQueryFunctor = std::function<void(const std::string&, void*, int*)>;
2025-09-25 09:15:22 +02:00
/// @brief Enumeration of supported image file types.
2025-09-22 23:13:28 +02:00
enum class ImageFileType
{
2025-09-25 09:15:22 +02:00
/// @brief Represents an unknown or unsupported file type.
2025-10-07 12:18:00 +02:00
kUnknown = -10,
2025-09-25 09:15:22 +02:00
/// @brief Represents an abstract image type (e.g., a placeholder).
2025-10-07 12:18:00 +02:00
kAbstract = 0,
2025-09-25 09:15:22 +02:00
/// @brief Represents a PNG image file.
2025-10-07 12:18:00 +02:00
kPng = 1,
2025-09-25 09:15:22 +02:00
/// @brief Represents a JPG image file.
2025-10-07 12:18:00 +02:00
kJpg = 2,
2025-09-25 09:15:22 +02:00
/// @brief Represents a CZI image file.
2025-10-07 12:18:00 +02:00
kCzi = 3,
2025-10-12 21:47:17 +02:00
/// @brief Represents a TIFF image file.
kTiff = 4,
/// @brief Represents an in-memory image.
kMemory = 5,
2025-09-22 23:13:28 +02:00
};
/// @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;
2025-09-25 09:15:22 +02:00
/// @brief Attempts to retrieve the image.
/// @return A unique pointer to a Mat object containing the image data,
/// or nullptr if the image is not found or cannot be retrieved.
/// May throw exceptions for multidimensional images.
2025-09-23 21:57:08 +02:00
virtual std::unique_ptr<cv::Mat> TryGetImage() = 0;
2025-09-22 23:13:28 +02:00
2025-09-25 09:15:22 +02:00
/// @brief Attempts to retrieve the image.
2025-10-08 13:00:09 +02:00
/// @param query The query object defining the images to retrieve.
2025-09-25 09:15:22 +02:00
/// @return A unique pointer to a Mat object containing the image data,
/// or nullptr if the image is not found or cannot be retrieved.
2025-09-26 21:09:51 +02:00
virtual std::unique_ptr<cv::Mat> TryGetImage(const IImageQuery& query) = 0;
2025-09-22 23:13:28 +02:00
2025-09-25 09:15:22 +02:00
/// @brief Attempts to retrieve a collection of images based on a query.
/// @param query The query object defining the images to retrieve.
/// @return A vector of unique pointers to cv::Mat objects. Each element is an image.
/// Returns an empty vector if no images are found or if an error occurs.
2025-09-26 21:09:51 +02:00
virtual std::vector<std::unique_ptr<cv::Mat>> TryGetImages(const IImageQuery& query) = 0;
2025-09-22 23:13:28 +02:00
2025-09-25 09:15:22 +02:00
/// @brief Checks if the image is empty.
/// @return true if the image is empty, false otherwise.
2025-09-22 23:13:28 +02:00
virtual bool Empty() const noexcept = 0;
2025-09-23 21:57:08 +02:00
// default implemented
public:
2025-09-25 09:15:22 +02:00
/// @brief Gets the resource identifier as a file path.
/// @return @c std::filesystem::path of the underlying resource.
2025-09-23 21:57:08 +02:00
virtual std::filesystem::path Uri() const noexcept { return this->uri_; }
2025-09-25 09:15:22 +02:00
/// @brief Gets the resource name.
/// @note Implementations of IPixelariumImage that live in memory
/// should override this to get something meaningful as the name
/// cannot be fetched from the resource uri in that case.
/// @return The name of the underlying resource.
2025-09-23 21:57:08 +02:00
virtual std::string Name() const noexcept
{
if (!this->uri_.empty())
{
return this->uri_.filename().string();
}
return {};
}
2025-09-22 23:13:28 +02:00
public:
2025-10-07 12:18:00 +02:00
const static ImageFileType type_{ImageFileType::kAbstract};
2025-09-22 23:13:28 +02:00
protected:
std::filesystem::path uri_;
};
} // namespace pixelarium::imaging