00001 #include "mythgoom.h"
00002
00003 #ifdef SDL_SUPPORT
00004
00005 extern "C" {
00006 #include "goom_tools.h"
00007 #include "goom_core.h"
00008 }
00009
00010 #include <qpainter.h>
00011
00012 #include <math.h>
00013 #include <stdlib.h>
00014
00015 #include <mythtv/compat.h>
00016
00017 #include <iostream>
00018 using namespace std;
00019
00020 #include <mythtv/mythcontext.h>
00021
00022 Goom::Goom(long int winid)
00023 {
00024 fps = 20;
00025
00026 surface = NULL;
00027 buffer = NULL;
00028
00029 char SDL_windowhack[32];
00030
00031 sprintf(SDL_windowhack, "%ld", winid);
00032 setenv("SDL_WINDOWID", SDL_windowhack, 1);
00033
00034 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
00035 {
00036 cerr << "Unable to init SDL\n";
00037 return;
00038 }
00039
00040 SDL_ShowCursor(0);
00041
00042 goom_init(800, 600, 0);
00043
00044 scalew = gContext->GetNumSetting("VisualScaleWidth", 2);
00045 scaleh = gContext->GetNumSetting("VisualScaleHeight", 2);
00046
00047 if (scaleh > 2)
00048 scaleh = 2;
00049 if (scaleh < 1)
00050 scaleh = 1;
00051
00052 if (scalew > 2)
00053 scalew = 2;
00054 if (scalew < 1)
00055 scalew = 1;
00056 }
00057
00058 Goom::~Goom()
00059 {
00060 goom_close();
00061 SDL_Quit();
00062
00063 unsetenv("SDL_WINDOWID");
00064 }
00065
00066 void Goom::resize(const QSize &newsize)
00067 {
00068 size = newsize;
00069
00070 size.setHeight((size.height() / 2) * 2);
00071 size.setWidth((size.width() / 2) * 2);
00072
00073 surface = SDL_SetVideoMode(size.width(), size.height(), 32, 0 );
00074 goom_set_resolution(size.width() / scalew, size.height() / scaleh, 0);
00075 }
00076
00077 bool Goom::process(VisualNode *node)
00078 {
00079 if (!node || node->length == 0 || !surface)
00080 return true;
00081
00082 int numSamps = 512;
00083 if (node->length < 512)
00084 numSamps = node->length;
00085
00086 signed short int data[2][512];
00087
00088 int i = 0;
00089 for (i = 0; i < numSamps; i++)
00090 {
00091 data[0][i] = node->left[i];
00092 if (node->right)
00093 data[1][i] = node->right[i];
00094 else
00095 data[1][i] = data[0][i];
00096 }
00097
00098 for (; i < 512; i++)
00099 {
00100 data[0][i] = 0;
00101 data[1][i] = 0;
00102 }
00103
00104 buffer = goom_update(data, 0);
00105
00106 return false;
00107 }
00108
00109 bool Goom::draw(QPainter *p, const QColor &back)
00110 {
00111 (void)p;
00112 (void)back;
00113
00114 if (!surface)
00115 {
00116 cerr << "No sdl surface\n";
00117 return false;
00118 }
00119
00120 if (!buffer)
00121 return false;
00122
00123 if (scalew != 1 || scaleh != 1)
00124 {
00125 SDL_LockSurface(surface);
00126
00127 register int *d = (int*)surface->pixels;
00128 register int *s = (int*)buffer;
00129
00130 int sw = (size.width() / scalew) << 2;
00131 int sw2 = surface->pitch;
00132 int swd = sw2 - sw * scalew;
00133
00134 long fin = (long)s;
00135 long fd = (long)d + (sw2 * size.height());
00136
00137 while ((long)d < fd) {
00138 fin += sw;
00139 if (scalew == 2)
00140 {
00141 while ((long)s < fin) {
00142 register long col = *(s++);
00143 *(d++) = col; *(d++) = col;
00144 }
00145 }
00146 else
00147 {
00148 while ((long)s < fin) {
00149 register long col = *(s++);
00150 *(d++) = col;
00151 }
00152 }
00153 d = (int*)((char*)d + swd);
00154
00155 if (scaleh == 2)
00156 {
00157 memcpy(d, ((char*)d) - sw2, sw2);
00158 d = (int*)((char*)d + sw2);
00159 }
00160 }
00161 }
00162 else
00163 {
00164 SDL_Surface *tmpsurf = SDL_CreateRGBSurfaceFrom(buffer, size.width(),
00165 size.height(), 32,
00166 size.width() * 4,
00167 0x00ff0000, 0x0000ff00,
00168 0x000000ff, 0x00000000);
00169 SDL_BlitSurface(tmpsurf, NULL, surface, NULL);
00170 SDL_FreeSurface(tmpsurf);
00171 }
00172
00173 SDL_UnlockSurface(surface);
00174 SDL_Flip(surface);
00175
00176 return false;
00177 }
00178
00179 static class GoomFactory : public VisFactory
00180 {
00181 public:
00182 const QString &name(void) const
00183 {
00184 static QString name("Goom");
00185 return name;
00186 }
00187
00188 uint plugins(QStringList *list) const
00189 {
00190 *list << name();
00191 return 1;
00192 }
00193
00194 VisualBase *create(MainVisual *parent, long int winid, const QString &pluginName) const
00195 {
00196 (void)parent;
00197 (void)pluginName;
00198 return new Goom(winid);
00199 }
00200 }GoomFactory;
00201
00202
00203 #endif