PonyPlayer
fireworks.hpp
浏览该文件的文档.
1#pragma once
2#include <QQuickItem>
3#include <QObject>
4#include <QQuickWindow>
5#include <QOpenGLShaderProgram>
6#include "renderer.hpp"
7#include "platform.hpp"
8
9
10class Fireworks : public QQuickItem {
11 Q_OBJECT
12 QML_ELEMENT
13 Q_PROPERTY(bool keepFrameRate READ isKeepFrameRate WRITE setKeepFrameRate NOTIFY keepFrameRateChanged)
14 Q_PROPERTY(int frameHeight READ getHeight NOTIFY frameSizeChanged)
15 Q_PROPERTY(int frameWidth READ getWidth NOTIFY frameSizeChanged)
16 Q_PROPERTY(double frameRate READ getFrameRate NOTIFY frameSizeChanged)
17 Q_PROPERTY(GLfloat brightness READ getBrightness WRITE setBrightness NOTIFY brightnessChanged)
18 Q_PROPERTY(GLfloat contrast READ getContrast WRITE setContrast NOTIFY contrastChanged)
19 Q_PROPERTY(GLfloat saturation READ getSaturation WRITE setSaturation NOTIFY saturationChanged)
20 Q_PROPERTY(QString filterPrefix READ getFilterPrefix)
21 Q_PROPERTY(QStringList filterJsons READ getFilterJsons)
22private:
23 FireworksRenderer *m_renderer;
24 QString m_filterPrefix;
25 QStringList m_filterJsons;
26 int m_frameHeight = 1;
27 int m_frameWidth = 1;
28 double m_frameRate = 1.0;
29protected:
30 QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *data) override {
31 return m_renderer;
32 }
33
34public:
35 explicit Fireworks(QQuickItem *parent = nullptr): QQuickItem(parent), m_renderer(new FireworksRenderer),
36 m_filterPrefix(PonyPlayer::getAssetsDir() + u"/filters"_qs), m_filterJsons() {
37 QDir filterDir(m_filterPrefix);
38 for(auto && filename : filterDir.entryList({"*.json"})) {
39 QFile file = filterDir.filePath(filename);
40 file.open(QIODevice::OpenModeFlag::ReadOnly);
41 m_filterJsons.append(file.readAll());
42 file.close();
43 }
44 this->setFlag(QQuickItem::ItemHasContents);
45 connect(this, &QQuickItem::windowChanged, this, [this](QQuickWindow *win){
46 qDebug() << "Window Size Changed:" << static_cast<void *>(win) << ".";
47 if (win) {
48 connect(this->window(), &QQuickWindow::beforeSynchronizing, m_renderer, &FireworksRenderer::sync, Qt::DirectConnection);
49 connect(this->window(), &QQuickWindow::beforeRendering, m_renderer, &FireworksRenderer::init, Qt::DirectConnection);
50 win->setColor(Qt::black);
51 } else {
52 qWarning() << "Window destroy.";
53 }
54
55 });
56 qDebug() << "Create Hurricane QuickItem.";
57 }
58 ~Fireworks() override {
59 m_renderer = nullptr;
60 }
61
63 [[nodiscard]] QString getFilterPrefix() const { return m_filterPrefix; }
64
65 [[nodiscard]] bool isKeepFrameRate() const { return m_renderer->isKeepFrameRate(); }
66
67 [[nodiscard]] QStringList getFilterJsons() const { return m_filterJsons; }
68
69 [[nodiscard]] GLfloat getBrightness() const { return m_renderer->getBrightness(); }
70
71 void setKeepFrameRate(bool keep) {
72 m_renderer->setKeepFrameRate(keep);
74 }
75
76 void setBrightness(GLfloat b) {
77 m_renderer->setBrightness(b);
78 emit brightnessChanged();
79 }
80
81 [[nodiscard]] GLfloat getContrast() const {
82 return m_renderer->getContrast();
83 }
84
85 void setContrast(GLfloat c) {
86 m_renderer->setContrast(c);
87 emit contrastChanged();
88 };
89
90 [[nodiscard]] GLfloat getSaturation() const { return m_renderer->getSaturation(); };
91
92 void setSaturation(GLfloat s) {
93 m_renderer->setSaturation(s);
94 emit saturationChanged();
95 };
96
97 [[nodiscard]] int getHeight() const {
98 return m_frameHeight;
99 }
100
101 [[nodiscard]] int getWidth() const {
102 return m_frameWidth;
103 }
104
105 [[nodiscard]] double getFrameRate() const {
106 return m_frameRate;
107 }
108
109
110public slots:
111
112 void setVideoFrame(const VideoFrameRef &pic) {
113 // this function must be called on GUI thread
114 // setImage -> sync -> render
115 // since picture may use on renderer thread, we CANNOT free now
116 // no change, return immediately
117 if (m_renderer->setVideoFrame(pic)) {
118 // make dirty
119 this->update();
120 if (!pic.isSameSize(m_frameWidth, m_frameHeight)) {
121 m_frameWidth = pic.getWidth();
122 m_frameHeight = pic.getHeight();
123 m_frameRate = static_cast<double>(m_frameHeight) / static_cast<double>(m_frameWidth);
124 emit frameSizeChanged();
125 }
126 }
127 }
128
133 Q_INVOKABLE void setLUTFilter(const QString& path) {
134 QImage image;
135 if (!path.isEmpty()) {
136 image.load(QDir(m_filterPrefix).filePath(path));
137 image.convertTo(QImage::Format_RGB888);
138 }
139
140 m_renderer->setLUTFilter(image);
141 }
142
143
144
145signals:
147
149
151
153
155};
156
157
158
159
160
Definition: fireworks.hpp:10
int getWidth() const
Definition: fireworks.hpp:101
PONY_GUARD_BY(MAIN) private
Definition: fireworks.hpp:62
QStringList filterJsons
Definition: fireworks.hpp:21
GLfloat saturation
Definition: fireworks.hpp:19
void contrastChanged()
double frameRate
Definition: fireworks.hpp:16
QML_ELEMENTbool keepFrameRate
Definition: fireworks.hpp:13
GLfloat getContrast() const
Definition: fireworks.hpp:81
void brightnessChanged()
int getHeight() const
Definition: fireworks.hpp:97
QSGNode * updatePaintNode(QSGNode *node, UpdatePaintNodeData *data) override
Definition: fireworks.hpp:30
Fireworks(QQuickItem *parent=nullptr)
Definition: fireworks.hpp:35
int frameHeight
Definition: fireworks.hpp:14
Q_INVOKABLE void setLUTFilter(const QString &path)
Definition: fireworks.hpp:133
void setBrightness(GLfloat b)
Definition: fireworks.hpp:76
void setSaturation(GLfloat s)
Definition: fireworks.hpp:92
double getFrameRate() const
Definition: fireworks.hpp:105
GLfloat contrast
Definition: fireworks.hpp:18
GLfloat getSaturation() const
Definition: fireworks.hpp:90
void setVideoFrame(const VideoFrameRef &pic)
Definition: fireworks.hpp:112
void setContrast(GLfloat c)
Definition: fireworks.hpp:85
void saturationChanged()
GLfloat brightness
Definition: fireworks.hpp:17
void frameSizeChanged()
int frameWidth
Definition: fireworks.hpp:15
~Fireworks() override
Definition: fireworks.hpp:58
QString filterPrefix
Definition: fireworks.hpp:20
void keepFrameRateChanged()
Definition: renderer.hpp:67
void sync()
Definition: renderer.hpp:173
void init()
Definition: renderer.hpp:117
Definition: frame.hpp:47
bool isSameSize(const VideoFrameRef &frame) const
Definition: frame.hpp:130
int getWidth() const
Definition: frame.hpp:122
int getHeight() const
Definition: frame.hpp:126
Definition: audioformat.hpp:155
constexpr PonyThread MAIN
Definition: ponyplayer.h:47
QString getAssetsDir()
Definition: platform.hpp:20