Files
pixelarium/lib/rendering/ImageViewFactory.cpp
T

30 lines
808 B
C++
Raw Normal View History

2025-09-13 14:49:59 +02:00
#include "ImageViewFactory.hpp"
#include <memory>
#include <optional>
/// @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::PixelariumImageView> pixelarium::render::ImageViewFactory::RenderImage(
size_t image_id)
{
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-22 23:13:28 +02:00
if (!res.has_value())
2025-09-13 14:49:59 +02:00
{
2025-09-22 23:13:28 +02:00
return {};
}
auto img {res.value().lock()};
if (img->Empty())
{
return {};
2025-09-13 14:49:59 +02:00
}
// beware: here we copy the actual image resource over to the new image
2025-09-22 23:13:28 +02:00
return std::make_unique<PixelariumImageView>(img);
2025-09-13 14:49:59 +02:00
}