MythTV master
mythgoom.cpp
Go to the documentation of this file.
1#include "mythgoom.h"
2
3// C++
4#include <algorithm>
5#include <cmath>
6#include <cstdlib>
7#include <iostream>
8
9// Qt
10#include <QCoreApplication>
11#include <QPainter>
12
13// MythTV
14#include <libmythbase/compat.h>
16
17// Goom
20
22{
23 m_fps = 20;
24
25 goom_init(800, 600, 0);
26
27 m_scalew = gCoreContext->GetNumSetting("VisualScaleWidth", 2);
28 m_scaleh = gCoreContext->GetNumSetting("VisualScaleHeight", 2);
29
30 // we allow 1, 2 or 4 for the scale since goom likes its resolution to be a multiple of 2
31 if (m_scaleh == 3 || m_scaleh > 4)
32 m_scaleh = 4;
33 m_scaleh = std::max(m_scaleh, 1);
34
35 if (m_scalew == 3 || m_scalew > 4)
36 m_scalew = 4;
37 m_scalew = std::max(m_scalew, 1);
38}
39
41{
42 goom_close();
43}
44
45void Goom::resize(const QSize &newsize)
46{
47 m_size = newsize;
48
49 m_size.setHeight((m_size.height() / 2) * 2);
50 m_size.setWidth((m_size.width() / 2) * 2);
51
52 // only scale the resolution if it is > 256
53 // this ensures the small visualisers don't look too blocky
54 if (m_size.width() > 256)
55 goom_set_resolution(m_size.width() / m_scalew, m_size.height() / m_scaleh, 0);
56 else
57 goom_set_resolution(m_size.width(), m_size.height(), 0);
58}
59
61{
62 if (!node || node->m_length == 0)
63 return false;
64
65 int numSamps = 512;
66 if (node->m_length < 512)
67 numSamps = node->m_length;
68
69 GoomDualData data;
70
71 int i = 0;
72 for (i = 0; i < numSamps; i++)
73 {
74 data[0][i] = node->m_left[i];
75 if (node->m_right)
76 data[1][i] = node->m_right[i];
77 else
78 data[1][i] = data[0][i];
79 }
80
81 m_buffer = goom_update(data, 0);
82
83 return false;
84}
85
86bool Goom::draw(QPainter *p, const QColor &back)
87{
88 p->fillRect(0, 0, m_size.width(), m_size.height(), back);
89
90 if (!m_buffer)
91 return true;
92
93 int width = m_size.width();
94 int height = m_size.height();
95
96 if (m_size.width() > 256)
97 {
98 width /= m_scalew;
99 height /= m_scaleh;
100 }
101
102 auto *image = new QImage((uchar*) m_buffer, width, height, width * 4, QImage::Format_RGB32);
103
104 p->drawImage(QRect(0, 0, m_size.width(), m_size.height()), *image);
105
106 delete image;
107
108 return true;
109}
110
111static class GoomFactory : public VisFactory
112{
113 public:
114 const QString &name(void) const override // VisFactory
115 {
116 static QString s_name = QCoreApplication::translate("Visualizers",
117 "Goom");
118 return s_name;
119 }
120
121 uint plugins(QStringList *list) const override // VisFactory
122 {
123 *list << name();
124 return 1;
125 }
126
127 VisualBase *create([[maybe_unused]] MainVisual *parent,
128 [[maybe_unused]] const QString &pluginName) const override // VisFactory
129 {
130 return new Goom();
131 }
VisualBase * create(MainVisual *parent, const QString &pluginName) const override
Definition: mythgoom.cpp:127
uint plugins(QStringList *list) const override
Definition: mythgoom.cpp:121
const QString & name(void) const override
Definition: mythgoom.cpp:114
Definition: mythgoom.h:7
unsigned int * m_buffer
Definition: mythgoom.h:20
int m_scalew
Definition: mythgoom.h:21
bool draw(QPainter *p, const QColor &back) override
Definition: mythgoom.cpp:86
~Goom() override
Definition: mythgoom.cpp:40
Goom(void)
Definition: mythgoom.cpp:21
bool process(VisualNode *node) override
Definition: mythgoom.cpp:60
int m_scaleh
Definition: mythgoom.h:22
void resize(const QSize &size) override
Definition: mythgoom.cpp:45
QSize m_size
Definition: mythgoom.h:18
int GetNumSetting(const QString &key, int defaultval=0)
int m_fps
Definition: visualize.h:87
long m_length
Definition: videovisual.h:38
short * m_left
Definition: videovisual.h:36
short * m_right
Definition: videovisual.h:37
unsigned int uint
Definition: freesurround.h:24
static guint32 * back
Definition: goom_core.cpp:25
void goom_init(guint32 resx, guint32 resy, int cinemascope)
Definition: goom_core.cpp:64
void goom_set_resolution(guint32 resx, guint32 resy, int cinemascope)
Definition: goom_core.cpp:104
void goom_close()
Definition: goom_core.cpp:846
guint32 * goom_update(GoomDualData &data, int forceMode)
Definition: goom_core.cpp:133
std::array< GoomSingleData, 2 > GoomDualData
Definition: goom_core.h:13
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
GoomFactory GoomFactory