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