9#include <spdlog/spdlog.h>
12#include <QMutexLocker>
18 : QQuickPaintedItem(parent)
20 spdlog::debug(
"[PaintedImageItem:aintedImageItem]: Created");
27 if (!image || !image->isValid()) {
28 spdlog::warn(
"[PaintedImageItem::setImage]: Invalid image");
32 spdlog::info(
"[PaintedImageItem::setImage]: {}x{}", image->width(), image->height());
37 m_current_qimage = convertImageRegionToQImage(*
m_full_image);
45 if (!tile || !tile->isValid()) {
46 spdlog::warn(
"[PaintedImageItem::updateTile]: Invalid tile");
50 const int tile_w {
static_cast<int>(tile->width()) };
51 const int tile_h {
static_cast<int>(tile->height()) };
59 m_current_qimage = convertImageRegionToQImage(*
m_full_image);
62 spdlog::debug(
"[PaintedImageItem::updateTile]: Replaced with {}x{}", tile_w, tile_h);
65 QMetaObject::invokeMethod(
this, &QQuickItem::update, Qt::QueuedConnection);
71 if (!painter || !isImagePaintValid()) {
78 painter->translate(
m_pan);
80 painter->drawImage(QPointF(0, 0), m_current_qimage);
88 spdlog::error(
"[PaintedImageItem::convertImageRegionToQImage]: Invalid region");
92 const int w {
static_cast<int>(region.
width()) };
93 const int h {
static_cast<int>(region.
height()) };
96 reinterpret_cast<const uchar*
>(region.
m_data.data()),
98 w * 4 *
static_cast<int>(
sizeof(
float)),
99 QImage::Format_RGBA32FPx4
101 linear_img.setColorSpace(QColorSpace(QColorSpace::SRgbLinear));
103 return linear_img.convertedToColorSpace(QColorSpace(QColorSpace::SRgb))
104 .convertToFormat(QImage::Format_RGBA8888);
107bool PaintedImageItem::isImagePaintValid()
const
std::unique_ptr< Core::Common::ImageRegion > m_full_image
Unique pointer to the full image data displayed by this item.
QMutex m_image_mutex
Mutex protecting access to m_full_image and related state. Ensures thread-safe updates to the image d...
QPointF m_pan
Current pan offset applied to the image.
float m_zoom
Current zoom level applied to the image.
void paint(QPainter *painter) override
Paints the image using QPainter.
void onImageChanged() override
void onZoomChanged(float new_zoom) override
void onPanChanged(const QPointF &new_pan) override
void setImage(std::unique_ptr< Core::Common::ImageRegion > image) override
Sets the full image to be displayed.
void updateTile(std::unique_ptr< Core::Common::ImageRegion > tile) override
Updates a specific tile of the displayed image.
void imageSizeChanged()
Signal emitted when the image dimensions change (width or height).
void panChanged(const QPointF &pan)
Signal emitted when the pan offset changes.
PaintedImageItem(QQuickItem *parent=nullptr)
Constructs a new PaintedImageItem.
void zoomChanged(float zoom)
Signal emitted when the zoom value changes.
Namespace containing Qt-specific UI components for CaptureMoment.
Simple image display using QQuickPaintedItem and QPainter (Qt 6)
Represents a rectangular region of an image and its pixel data.
constexpr ImageDim height() const noexcept
constexpr ImageDim width() const noexcept
std::vector< float > m_data
Pixel data (row-major layout).
constexpr bool isValid() const noexcept
Validates the integrity of the ImageRegion (Overflow-Safe Version).