Files
pixelarium/lib/rendering/ImageViewFactory.cpp
T

52 lines
1.7 KiB
C++
Raw Normal View History

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)
{
case imaging::ImageFileType::UNKNOWN:
case imaging::ImageFileType::ABSTRACT:
return {};
case imaging::ImageFileType::PNG:
case imaging::ImageFileType::JPG:
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);
case imaging::ImageFileType::CZI:
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
}