e3e161ce52
* adds tiff support * doc update * adds memory-based =IPixelariumImage= implementation * add usage example for custom user control * enhance * clang-format fix readme fix docs
60 lines
1.9 KiB
C++
60 lines
1.9 KiB
C++
#include "ImageViewFactory.hpp"
|
|
|
|
#include <format>
|
|
#include <memory>
|
|
|
|
#include "imaging/IPixelariumImage.hpp"
|
|
#include "imaging/PixelariumImageFactory.hpp"
|
|
#include "rendering/IPixelariumImageView.hpp"
|
|
#include "rendering/PixelariumImageViewCzi.hpp"
|
|
#include "rendering/PixelariumImageViewDefault.hpp"
|
|
|
|
/// @brief Creates a PixelariumImageView from a resource image.
|
|
/// @param image_id The ID of the image resource to render.
|
|
/// @return A unique pointer to the PixelariumImageView, or nullptr if the image resource is not found or is empty. The
|
|
/// image data is copied.
|
|
std::unique_ptr<pixelarium::render::IPixelariumImageView> pixelarium::render::ImageViewFactory::RenderImage(
|
|
resources::ResourceKey image_id)
|
|
{
|
|
using ImageType = imaging::ImageFileType;
|
|
auto res{this->image_pool_.GetResource(image_id)};
|
|
|
|
auto img{res.lock()};
|
|
|
|
if (img == nullptr)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
if (img->Empty())
|
|
{
|
|
return {};
|
|
}
|
|
|
|
auto type = imaging::ExtensionToType(img->Uri().extension().string());
|
|
if (img->Uri().empty())
|
|
{
|
|
log_.Info(std::format("{}: empty Uri for {}.", __PRETTY_FUNCTION__, img->Name()));
|
|
type = ImageType::kMemory;
|
|
}
|
|
|
|
switch (type)
|
|
{
|
|
case ImageType::kUnknown:
|
|
case ImageType::kAbstract:
|
|
case ImageType::kPng:
|
|
case ImageType::kJpg:
|
|
case ImageType::kTiff:
|
|
case ImageType::kMemory:
|
|
log_.Info(std::format("{}: Creating a Default View", __PRETTY_FUNCTION__));
|
|
// beware: here we copy the actual image resource over to the new image
|
|
return std::make_unique<PixelariumImageViewDefault>(img);
|
|
case ImageType::kCzi:
|
|
log_.Info(std::format("{}: Creating a CZI View", __PRETTY_FUNCTION__));
|
|
// beware: here we copy the actual image resource over to the new image
|
|
return std::make_unique<PixelariumImageViewCzi>(img, log_);
|
|
default:
|
|
return {};
|
|
}
|
|
}
|