2025-09-13 14:49:59 +02:00
|
|
|
#include "ImageViewFactory.hpp"
|
|
|
|
|
|
2025-09-26 21:09:51 +02:00
|
|
|
#include <format>
|
2025-09-13 14:49:59 +02:00
|
|
|
#include <memory>
|
2025-09-26 21:09:51 +02:00
|
|
|
|
2025-09-23 21:57:08 +02:00
|
|
|
#include "imaging/PixelariumImageFactory.hpp"
|
|
|
|
|
#include "rendering/IPixelariumImageView.hpp"
|
2025-09-25 19:25:17 +02:00
|
|
|
#include "rendering/PixelariumImageViewCzi.hpp"
|
2025-09-23 21:57:08 +02:00
|
|
|
#include "rendering/PixelariumImageViewDefault.hpp"
|
2025-09-13 14:49:59 +02:00
|
|
|
|
|
|
|
|
/// @brief Creates a PixelariumImageView from a resource image.
|
|
|
|
|
/// @param image_id The ID of the image resource to render.
|
2025-09-26 21:09:51 +02:00
|
|
|
/// @return A unique pointer to the PixelariumImageView, or nullptr if the image resource is not found or is empty. The
|
|
|
|
|
/// image data is copied.
|
2025-09-23 21:57:08 +02:00
|
|
|
std::unique_ptr<pixelarium::render::IPixelariumImageView> pixelarium::render::ImageViewFactory::RenderImage(
|
2025-09-26 21:09:51 +02:00
|
|
|
resources::ResourceKey image_id)
|
2025-09-13 14:49:59 +02:00
|
|
|
{
|
2025-09-22 23:13:28 +02:00
|
|
|
auto res{this->image_pool_.GetResource(image_id)};
|
2025-09-13 14:49:59 +02:00
|
|
|
|
2025-09-23 21:57:08 +02:00
|
|
|
auto img{res.lock()};
|
|
|
|
|
|
|
|
|
|
if (img == nullptr)
|
2025-09-13 14:49:59 +02:00
|
|
|
{
|
2025-09-22 23:13:28 +02:00
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (img->Empty())
|
|
|
|
|
{
|
|
|
|
|
return {};
|
2025-09-13 14:49:59 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-23 21:57:08 +02:00
|
|
|
auto type = imaging::ExtensionToType(img->Uri().extension().string());
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
2025-10-07 12:18:00 +02:00
|
|
|
case imaging::ImageFileType::kUnknown:
|
|
|
|
|
case imaging::ImageFileType::kAbstract:
|
2025-09-23 21:57:08 +02:00
|
|
|
return {};
|
2025-10-07 12:18:00 +02:00
|
|
|
case imaging::ImageFileType::kPng:
|
|
|
|
|
case imaging::ImageFileType::kJpg:
|
2025-09-26 21:09:51 +02:00
|
|
|
log_.Info(std::format("{}: Creating a Default View", __PRETTY_FUNCTION__));
|
2025-09-23 21:57:08 +02:00
|
|
|
// beware: here we copy the actual image resource over to the new image
|
|
|
|
|
return std::make_unique<PixelariumImageViewDefault>(img);
|
2025-10-07 12:18:00 +02:00
|
|
|
case imaging::ImageFileType::kCzi:
|
2025-09-26 21:09:51 +02:00
|
|
|
log_.Info(std::format("{}: Creating a CZI View", __PRETTY_FUNCTION__));
|
2025-09-23 21:57:08 +02:00
|
|
|
// beware: here we copy the actual image resource over to the new image
|
2025-09-26 21:09:51 +02:00
|
|
|
return std::make_unique<PixelariumImageViewCzi>(img, log_);
|
2025-09-23 21:57:08 +02:00
|
|
|
default:
|
|
|
|
|
return {};
|
|
|
|
|
}
|
2025-09-13 14:49:59 +02:00
|
|
|
}
|