00001 #include "mythgoom.h"
00002
00003 #include <cmath>
00004 #include <cstdlib>
00005
00006 #include <iostream>
00007 using namespace std;
00008
00009 #include <QCoreApplication>
00010 #include <QPainter>
00011
00012 #include <compat.h>
00013 #include <mythcontext.h>
00014 #include <mythlogging.h>
00015
00016 extern "C" {
00017 #include "goom_tools.h"
00018 #include "goom_core.h"
00019 }
00020
00021 Goom::Goom()
00022 {
00023 m_fps = 20;
00024
00025 m_buffer = NULL;
00026
00027 goom_init(800, 600, 0);
00028
00029 m_scalew = 1;
00030 m_scaleh = 1;
00031
00032 if (m_scaleh > 2)
00033 m_scaleh = 2;
00034 if (m_scaleh < 1)
00035 m_scaleh = 1;
00036
00037 if (m_scalew > 2)
00038 m_scalew = 2;
00039 if (m_scalew < 1)
00040 m_scalew = 1;
00041 }
00042
00043 Goom::~Goom()
00044 {
00045 goom_close();
00046 }
00047
00048 void Goom::resize(const QSize &newsize)
00049 {
00050 m_size = newsize;
00051
00052 m_size.setHeight((m_size.height() / 2) * 2);
00053 m_size.setWidth((m_size.width() / 2) * 2);
00054
00055 goom_set_resolution(m_size.width() / m_scalew, m_size.height() / m_scaleh, 0);
00056 }
00057
00058 bool Goom::process(VisualNode *node)
00059 {
00060 if (!node || node->length == 0)
00061 return false;
00062
00063 int numSamps = 512;
00064 if (node->length < 512)
00065 numSamps = node->length;
00066
00067 signed short int data[2][512];
00068
00069 int i = 0;
00070 for (i = 0; i < numSamps; i++)
00071 {
00072 data[0][i] = node->left[i];
00073 if (node->right)
00074 data[1][i] = node->right[i];
00075 else
00076 data[1][i] = data[0][i];
00077 }
00078
00079 for (; i < 512; i++)
00080 {
00081 data[0][i] = 0;
00082 data[1][i] = 0;
00083 }
00084
00085 m_buffer = goom_update(data, 0);
00086
00087 return false;
00088 }
00089
00090 bool Goom::draw(QPainter *p, const QColor &back)
00091 {
00092 p->fillRect(0, 0, m_size.width(), m_size.height(), back);
00093
00094 if (!m_buffer)
00095 return true;
00096
00097 QImage *image = new QImage((uchar*) m_buffer, m_size.width(), m_size.height(), m_size.width() * 4, QImage::Format_ARGB32);
00098
00099 p->drawImage(0, 0, *image);
00100
00101 delete image;
00102
00103 return true;
00104 }
00105
00106 static class GoomFactory : public VisFactory
00107 {
00108 public:
00109 const QString &name(void) const
00110 {
00111 static QString name = QCoreApplication::translate("Visualizers",
00112 "Goom");
00113 return name;
00114 }
00115
00116 uint plugins(QStringList *list) const
00117 {
00118 *list << name();
00119 return 1;
00120 }
00121
00122 VisualBase *create(MainVisual *parent, const QString &pluginName) const
00123 {
00124 (void)parent;
00125 (void)pluginName;
00126 return new Goom();
00127 }
00128 }GoomFactory;