MythTV  master
mythgoom.cpp
Go to the documentation of this file.
1 #include "mythgoom.h"
2 
3 #include <cmath>
4 #include <cstdlib>
5 
6 #include <iostream>
7 using namespace std;
8 
9 #include <QCoreApplication>
10 #include <QPainter>
11 
12 #include <compat.h>
13 #include <mythcontext.h>
14 #include <mythlogging.h>
15 
16 extern "C" {
17 #include "goom_tools.h"
18 #include "goom_core.h"
19 }
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  if (m_scaleh < 1)
34  m_scaleh = 1;
35 
36  if (m_scalew == 3 || m_scalew > 4)
37  m_scalew = 4;
38  if (m_scalew < 1)
39  m_scalew = 1;
40 }
41 
43 {
44  goom_close();
45 }
46 
47 void Goom::resize(const QSize &newsize)
48 {
49  m_size = newsize;
50 
51  m_size.setHeight((m_size.height() / 2) * 2);
52  m_size.setWidth((m_size.width() / 2) * 2);
53 
54  // only scale the resolution if it is > 256
55  // this ensures the small visualisers don't look too blocky
56  if (m_size.width() > 256)
57  goom_set_resolution(m_size.width() / m_scalew, m_size.height() / m_scaleh, 0);
58  else
59  goom_set_resolution(m_size.width(), m_size.height(), 0);
60 }
61 
63 {
64  if (!node || node->m_length == 0)
65  return false;
66 
67  int numSamps = 512;
68  if (node->m_length < 512)
69  numSamps = node->m_length;
70 
71  signed short int data[2][512];
72 
73  int i = 0;
74  for (i = 0; i < numSamps; i++)
75  {
76  data[0][i] = node->m_left[i];
77  if (node->m_right)
78  data[1][i] = node->m_right[i];
79  else
80  data[1][i] = data[0][i];
81  }
82 
83  for (; i < 512; i++)
84  {
85  data[0][i] = 0;
86  data[1][i] = 0;
87  }
88 
89  m_buffer = goom_update(data, 0);
90 
91  return false;
92 }
93 
94 bool Goom::draw(QPainter *p, const QColor &back)
95 {
96  p->fillRect(0, 0, m_size.width(), m_size.height(), back);
97 
98  if (!m_buffer)
99  return true;
100 
101  int width = m_size.width();
102  int height = m_size.height();
103 
104  if (m_size.width() > 256)
105  {
106  width /= m_scalew;
107  height /= m_scaleh;
108  }
109 
110  QImage *image = new QImage((uchar*) m_buffer, width, height, width * 4, QImage::Format_RGB32);
111 
112  p->drawImage(QRect(0, 0, m_size.width(), m_size.height()), *image);
113 
114  delete image;
115 
116  return true;
117 }
118 
119 static class GoomFactory : public VisFactory
120 {
121  public:
122  const QString &name(void) const override // VisFactory
123  {
124  static QString name = QCoreApplication::translate("Visualizers",
125  "Goom");
126  return name;
127  }
128 
129  uint plugins(QStringList *list) const override // VisFactory
130  {
131  *list << name();
132  return 1;
133  }
134 
135  VisualBase *create(MainVisual *parent, const QString &pluginName) const override // VisFactory
136  {
137  (void)parent;
138  (void)pluginName;
139  return new Goom();
140  }
141 }GoomFactory;
Goom(void)
Definition: mythgoom.cpp:21
void goom_init(guint32 resx, guint32 resy, int cinemascope)
Definition: goom_core.c:73
unsigned int uint
Definition: compat.h:140
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
guint32 * goom_update(gint16 data[2][512], int forceMode)
Definition: goom_core.c:141
short * m_right
Definition: videovisual.h:34
void goom_set_resolution(guint32 resx, guint32 resy, int cinemascope)
Definition: goom_core.c:112
GoomFactory GoomFactory
const char * name
Definition: ParseText.cpp:328
VisualBase * create(MainVisual *parent, const QString &pluginName) const override
Definition: mythgoom.cpp:135
int GetNumSetting(const QString &key, int defaultval=0)
void resize(const QSize &size) override
Definition: mythgoom.cpp:47
long m_length
Definition: videovisual.h:35
bool draw(QPainter *p, const QColor &back) override
Definition: mythgoom.cpp:94
bool process(VisualNode *node) override
Definition: mythgoom.cpp:62
Definition: mythgoom.h:9
virtual ~Goom()
Definition: mythgoom.cpp:42
uint plugins(QStringList *list) const override
Definition: mythgoom.cpp:129
const QString & name(void) const override
Definition: mythgoom.cpp:122
void goom_close()
Definition: goom_core.c:830
static guint32 * back
Definition: goom_core.c:34
short * m_left
Definition: videovisual.h:33