File indexing completed on 2024-07-21 06:28:26

0001 /*
0002     SPDX-FileCopyrightText: 2017 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "fitsviewer/bayer.h"
0010 
0011 #include <indidevapi.h>
0012 
0013 #include <QPixmap>
0014 #include <QVector>
0015 #include <QColor>
0016 #include <QLabel>
0017 #include <QSqlDatabase>
0018 #include <QPen>
0019 #include <QPainter>
0020 
0021 #include <memory>
0022 #include <mutex>
0023 
0024 class QImage;
0025 class QRubberBand;
0026 class QSqlTableModel;
0027 
0028 class VideoWG : public QLabel
0029 {
0030         Q_OBJECT
0031 
0032     public:
0033         explicit VideoWG(QWidget *parent = nullptr);
0034         virtual ~VideoWG() override;
0035 
0036         bool newFrame(IBLOB *bp);
0037         bool newBayerFrame(IBLOB *bp, const BayerParams &params);
0038 
0039         bool save(const QString &filename, const char *format);
0040 
0041         void setSize(uint16_t w, uint16_t h);
0042 
0043     protected:
0044         //virtual void resizeEvent(QResizeEvent *ev) override;
0045         void mousePressEvent(QMouseEvent *event) override;
0046         void mouseMoveEvent(QMouseEvent *event) override;
0047         void mouseReleaseEvent(QMouseEvent *event) override;
0048         void initOverlayModel();
0049 
0050     public slots:
0051         void modelChanged();
0052         void toggleOverlay();
0053 
0054     signals:
0055         void newSelection(QRect);
0056         void imageChanged(const QSharedPointer<QImage> &frame);
0057 
0058     private:
0059         bool debayer(const IBLOB *bp, const BayerParams &params);
0060 
0061         uint16_t streamW { 0 };
0062         uint16_t streamH { 0 };
0063         uint32_t totalBaseCount { 0 };
0064         QVector<QRgb> grayTable;
0065         QSharedPointer<QImage> streamImage;
0066         QPixmap kPix;
0067         QRubberBand *rubberBand { nullptr };
0068         QPoint origin;
0069         QString m_RawFormat;
0070         bool m_RawFormatSupported { false };
0071 
0072         // Collimation Overlay
0073         void setupOverlay();
0074         void paintOverlay(QPixmap &imagePix);
0075         bool overlayEnabled = false;
0076         QSqlTableModel *m_CollimationOverlayElementsModel = { nullptr };
0077         QList<QVariantMap> m_CollimationOverlayElements;
0078         QList<QVariantMap> m_EnabledOverlayElements;
0079         QVariantMap *m_CurrentElement = nullptr;
0080         QStringList *typeValues = nullptr;
0081         QPainter *painter = nullptr;
0082         float scale;
0083         void PaintOneItem (QString type, QPointF position, int sizeX, int sizeY, int thickness);
0084 };