diff options
Diffstat (limited to 'noatun-plugins/blurscope')
-rw-r--r-- | noatun-plugins/blurscope/Makefile.am | 10 | ||||
-rw-r--r-- | noatun-plugins/blurscope/blurscope.plugin | 74 | ||||
-rw-r--r-- | noatun-plugins/blurscope/scopedisplayer.cpp | 291 | ||||
-rw-r--r-- | noatun-plugins/blurscope/sdlscope.cpp | 78 | ||||
-rw-r--r-- | noatun-plugins/blurscope/sdlscope.h | 110 |
5 files changed, 563 insertions, 0 deletions
diff --git a/noatun-plugins/blurscope/Makefile.am b/noatun-plugins/blurscope/Makefile.am new file mode 100644 index 0000000..6ac86b3 --- /dev/null +++ b/noatun-plugins/blurscope/Makefile.am @@ -0,0 +1,10 @@ +INCLUDES= $(all_includes) $(SDL_CFLAGS) + +kde_module_LTLIBRARIES = noatunblurscope.la +noatunblurscope_la_SOURCES = sdlscope.cpp scopedisplayer.cpp +noatunblurscope_la_LDFLAGS = -module -avoid-version -no-undefined $(all_libraries) +noatunblurscope_la_LIBADD = $(LIB_KFILE) -lnoatun -lm $(SDL_LIBS) +noatunblurscope_la_METASOURCES = AUTO + +noatun_DATA = blurscope.plugin +noatundir = $(kde_datadir)/noatun diff --git a/noatun-plugins/blurscope/blurscope.plugin b/noatun-plugins/blurscope/blurscope.plugin new file mode 100644 index 0000000..9b50232 --- /dev/null +++ b/noatun-plugins/blurscope/blurscope.plugin @@ -0,0 +1,74 @@ +Filename=noatunblurscope.la +Author=Charles Samuels +Site=http://noatun.kde.org/ +Email=charles@kde.org +Type=visualization +License=BSD +Name=Blurscope +Name[da]=Blurskop +Name[de]=Blurskop +Name[eo]=Monoskopo +Name[hi]=ब्लरस्कोप +Name[ne]=ब्लरस्कोप +Name[nn]=Skoddeskop +Name[ru]=Зрительный образ Размытие +Name[sv]=Blurskop +Name[ta]=கறை செயற்பரப்பு +Name[tg]=Рахна кардан +Name[tr]=Buğulu Alan +Name[vi]=Xem mờ +Name[zh_CN]=模糊观测器 +Comment=A pretty, fading monoscope +Comment[af]='n redelik, uitdoof monoskoop +Comment[az]=Gözəl, feydləyən monoskop +Comment[bg]=Хубавичък и шарен визуализатор +Comment[bs]=Lijep fading monoscope +Comment[ca]=Un bonic monoscopi per a desdibuixar +Comment[cs]=Pěkný monoskop +Comment[cy]=Monosgop del, gwanllyd +Comment[da]=Et flot, henfaldende monoskop +Comment[de]=Ein schönes, ausblendendes Monoskop +Comment[el]=Ένα όμορφο, ομαλό καλειδοσκόπιο +Comment[eo]=Okulplaĉa, stompanta monoskopo +Comment[es]=Un bonito suavizado +Comment[et]=Kena ja hägune Monoscope'ile tuginev ostsilloskoop +Comment[eu]=Motelduz doan monoskopio polit bat +Comment[fa]=monoscope محوشوندۀ زیبای +Comment[fi]=Kaunis häviävä monoskooppi +Comment[fr]=Un joli scope de fondus +Comment[fy]=In fraaie, ferdizenjende monoskoop +Comment[gl]=Un osciloscópio bonito e que se desvanece +Comment[he]=מונוסקופ יפה שנמוג +Comment[hi]=एक सुन्दर, मन्द होता मोनोस्कोप +Comment[hr]=Lijep, pretapajući monoskop +Comment[hu]=Elhalványuló monoszkóp +Comment[is]=Falleg monoscope myndbrella +Comment[ja]=感じの良いフェードするモノスコープ +Comment[ka]=სიმპატიური ჩამოშლადი monoscope +Comment[kk]=Көркем эффект моноскопы +Comment[km]=ម៉ូណូស្កូបលិចបន្តិចម្ដងៗដ៏ស្អាតអាត +Comment[lt]=Gražus, lėtai išnykstantis monoskopas +Comment[mk]=Убав, избледувачки осцилоскоп +Comment[ms]=Monoskop luntur dan cantik +Comment[nb]=Et pent, hendøende monoskop +Comment[nds]=En smuck, utblennen Monoskop +Comment[ne]=एउटा राम्रो, फेडिङ मोनोस्कोप +Comment[nl]=Een fraaie, vervagende monoscoop +Comment[nn]=Eit pent, monoskop som tonar ut +Comment[pl]=Ładny, gasnący monoskop +Comment[pt]=Um osciloscópio bonito e que se desvanece +Comment[pt_BR]=Um monoscópio +Comment[ro]=Un monoscop cu estompare şi drăguţ +Comment[ru]=Зрительный образ с эффектом размытия +Comment[sk]=Pekný, blednucí monoskop +Comment[sl]=Prijeten, pojemajoč monoscope +Comment[sr]=Леп, бледећи моноскоп +Comment[sr@Latn]=Lep, bledeći monoskop +Comment[sv]=Snyggt, tonande monoskop +Comment[ta]=அழகான ஒரே வண்ண நிறமாற்றம் +Comment[tg]=Намуди тамошобин бо қувваи рахна +Comment[tr]=Güzel, yok olan Monoskop +Comment[uk]=Гарний, згасаючий моноскоп +Comment[vi]=Xem mờ dần đẹp +Comment[xh]=I monoscope ephelayo, entle +Comment[zh_CN]=一个美观的能够逐渐淡出的单管观测器 diff --git a/noatun-plugins/blurscope/scopedisplayer.cpp b/noatun-plugins/blurscope/scopedisplayer.cpp new file mode 100644 index 0000000..42b375a --- /dev/null +++ b/noatun-plugins/blurscope/scopedisplayer.cpp @@ -0,0 +1,291 @@ +/***************************************************************** + +Copyright (c) 2001 Charles Samuels <charles@kde.org> + 2001 Neil Stevens <multivac@fcmail.com> + With code stolen from Paul Harrison <pfh@yoyo.cc.monash.edu.au> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIAB\ILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +******************************************************************/ + +#include "sdlscope.h" + +#if 0 +#define TEST() cout << "At line " << __LINE__ << endl +#else +#define TEST() if(0) +#endif + +#define output ((unsigned char*)data) +template <class Type> +inline void Bitmap<Type>::addPixel(int x, int y, int br1, int br2) +{ + if (x < 0 || x >= width || y < 0 || y >= height) return; + + register unsigned char *p = output+x*2+y*width*2; + if (p[0] < 255-br1) p[0] += br1; else p[0] = 255; + if (p[1] < 255-br2) p[1] += br2; else p[1] = 255; +} + +template <class Type> +void Bitmap<Type>::addVertLine(int x, int y1, int y2, int br1, int br2) +{ + if(y1 < y2) + { + for(int y = y1; y <= y2; y++) + addPixel(x,y, br1, br2); + } + else if(y2 < y1) + { + for(int y = y2; y <= y1; y++) + addPixel(x, y, br1, br2); + } + else + { + addPixel(x, y1, br1, br2); + } +} + +template <class Type> +void Bitmap<Type>::fadeStar() +{ + register unsigned long *ptr = (unsigned long*)output; + int i = width*height*2/4; + do + { + if (*ptr) + *ptr -= ((*ptr & 0xf0f0f0f0ul) >> 4) + ((*ptr & 0xe0e0e0e0ul) >> 5); + ptr++; + } while(--i > 0); +} + +SDLView::SDLView(int in) : mFd(in), outputBmp(0), fullscreen(false) +{ + surface = 0; + width = 320; + height = width*6/8; + outputBmp.size(width, height); + TEST(); + + TEST(); + fcntl(mFd, F_SETFL, fcntl(mFd, F_GETFL) & ~O_NONBLOCK); + TEST(); + + + float *data = new float[width]; + TEST(); + + startVideo(); + setupPalette(); + TEST(); + + while(true) + { + checkInput(); + + if(!surface) exit(0); + + int bytestoread = width * sizeof(float); + int pos = 0; + while(pos < bytestoread) + { + char *d = (char *)data; + int r = read(mFd, d + pos, bytestoread - pos); + if(r > 0) pos += r; + else if (r==0) exit(0); + } + + outputBmp.fadeStar(); + outputBmp.fadeStar(); + + float *d = data; + float *end = data + width; + float heightHalf = height / 4.0; + int y = height / 2; + int x=0; + int oldy=(int)(*d * heightHalf); + while(d <= end) + { + int amp = (int)(*d * heightHalf); + amp+=y; + + outputBmp.addVertLine(x, oldy, amp, 255, 255); + oldy=amp; + + d++; + x++; + } + repaint(); + } +} + +static SDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags) +{ + SDL_Surface *screen; + + // Set the video mode + screen = SDL_SetVideoMode(w, h, bpp, flags); + return screen; +} + +void SDLView::startVideo() +{ + if(surface) + { + SDL_FreeSurface(surface); + surface = 0; + } + + Uint32 videoflags; + + /* Initialize SDL */ + if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) + exit(0); + + SDL_WM_SetCaption("BlurScope","blurscope"); + + /* See if we try to get a hardware colormap */ + videoflags = SDL_SWSURFACE | (fullscreen?SDL_FULLSCREEN:0); + + surface = CreateScreen(width, height, 8, videoflags); + if (!surface) + exit(0); + + SDL_ShowCursor(0); + + if(!surface) + SDL_Quit(); + + SDL_WM_SetCaption("BlurScope", 0); + SDL_ShowCursor(0); + +} + +void SDLView::setupPalette(double) +{ +#define BOUND(x) ((x) > 255 ? 255 : (x)) +#define PEAKIFY(x) int(BOUND((x) - (x)*(255-(x))/255/2)) +#define MAX(x,y) ((x) > (y) ? (x) : (y)) + + int redMax=136; + int greenMax=136; + int blueMax=255; + + SDL_Color sdlPalette[256]; + + for(int i=0;i<256;i++) + { + // i + // 255 136 + sdlPalette[i].r = i*redMax/255; + sdlPalette[i].g = i*greenMax/255; + sdlPalette[i].b = i*blueMax/255; + } + + SDL_SetColors(surface, sdlPalette, 0, 256); + +#undef BOUND +#undef PEAKIFY +#undef MAX +} + +void SDLView::checkInput() +{ + SDL_Event myEvent; + + while(SDL_PollEvent(&myEvent)) + { + switch(myEvent.type) + { + case SDL_KEYDOWN: + switch(myEvent.key.keysym.sym) + { + case SDLK_SPACE: +// fullscreen ^= true; +// startVideo(); + break; + default: + break; + } + break; + + case SDL_QUIT: + exit(0); + break; + } + } +} + +#define output2 ((unsigned char*)outputBmp.data) + +void SDLView::repaint() +{ + SDL_LockSurface(surface); + TEST(); + + register unsigned long *ptr2 = (unsigned long*)output2; + unsigned long *ptr1 = (unsigned long*)( surface->pixels ); + int i = width*height/4; + TEST(); + + do { + // Asger Alstrup Nielsen's (alstrup@diku.dk) + // optimized 32 bit screen loop + register unsigned int const r1 = *(ptr2++); + register unsigned int const r2 = *(ptr2++); + + //if (r1 || r2) { +#ifdef LITTLEENDIAN + register unsigned int const v = + ((r1 & 0x000000f0ul) >> 4) + | ((r1 & 0x0000f000ul) >> 8) + | ((r1 & 0x00f00000ul) >> 12) + | ((r1 & 0xf0000000ul) >> 16); + *(ptr1++) = v | + ( ((r2 & 0x000000f0ul) << 12) + | ((r2 & 0x0000f000ul) << 8) + | ((r2 & 0x00f00000ul) << 4) + | ((r2 & 0xf0000000ul))); +#else + register unsigned int const v = + ((r2 & 0x000000f0ul) >> 4) + | ((r2 & 0x0000f000ul) >> 8) + | ((r2 & 0x00f00000ul) >> 12) + | ((r2 & 0xf0000000ul) >> 16); + *(ptr1++) = v | + ( ((r1 & 0x000000f0ul) << 12) + | ((r1 & 0x0000f000ul) << 8) + | ((r1 & 0x00f00000ul) << 4) + | ((r1 & 0xf0000000ul))); +#endif + //} else ptr1++; + } while (--i); + TEST(); + + SDL_UnlockSurface(surface); + SDL_UpdateRect(surface, 0, 0, 0, 0); + TEST(); + +} + +SDLView::~SDLView() +{ + ::close(mFd); +} + + diff --git a/noatun-plugins/blurscope/sdlscope.cpp b/noatun-plugins/blurscope/sdlscope.cpp new file mode 100644 index 0000000..9485c1f --- /dev/null +++ b/noatun-plugins/blurscope/sdlscope.cpp @@ -0,0 +1,78 @@ +/***************************************************************** + +Copyright (c) 2001 Charles Samuels <charles@kde.org> + 2001 Neil Stevens <multivac@fcmail.com> + With code stolen from Paul Harrison <pfh@yoyo.cc.monash.edu.au> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIAB\ILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************/ + +#include <sys/wait.h> +#include <sys/types.h> + +#include "sdlscope.h" + +extern "C" +{ +Plugin *create_plugin() +{ + return new SDLScope(); +} +} + +SDLScope::SDLScope() + : MonoScope(50) + , Plugin() +{ + setSamples(320); +} + +SDLScope::~SDLScope() +{ + ::close(mOutFd); + wait(0); +} + +void SDLScope::init() +{ + int pipes[2]; + ::pipe(pipes); + mOutFd=pipes[1]; + if (!fork()) + { + ::close(pipes[1]); + new SDLView(pipes[0]); + exit(0); + } + else + { + fcntl(mOutFd, F_SETFL, fcntl(mOutFd, F_GETFL) & ~O_NONBLOCK); + ::close(pipes[0]); + MonoScope::start(); + } +} + +void SDLScope::scopeEvent(float *d, int size) +{ + if (::write(mOutFd, (char *)d, size * sizeof(float))==-1) + { + MonoScope::stop(); + unload(); + } +} + diff --git a/noatun-plugins/blurscope/sdlscope.h b/noatun-plugins/blurscope/sdlscope.h new file mode 100644 index 0000000..45c734c --- /dev/null +++ b/noatun-plugins/blurscope/sdlscope.h @@ -0,0 +1,110 @@ +/***************************************************************** + +Copyright (c) 2000-2001 the noatun authors. See file AUTHORS. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIAB\ILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +******************************************************************/ + +#ifndef SDLSCOPE_H +#define SDLSCOPE_H + +#include <noatun/plugin.h> +#include <string.h> + +extern "C" +{ +#include <SDL.h> +#include <fcntl.h> +#include <unistd.h> +} + +class SDLScope : public MonoScope, public Plugin +{ +NOATUNPLUGIND + +public: + SDLScope(); + virtual ~SDLScope(); + + void init(); + +protected: + virtual void scopeEvent(float *data, int bands); + +private: + int mOutFd; +}; + +struct SDL_Surface; + +template<class Pixel> class Bitmap +{ +public: + int width, height, extra; + Pixel *data; + + Bitmap(int e=0) : extra(e), data(0) { } + ~Bitmap() { delete[] data; } + + inline void addPixel(int x, int y, int bright1, int bright2); + void addVertLine(int x, int y, int y2, int br1, int br2); + + void fadeStar(); + + void size(int w,int h) + { + delete[] data; + width = w; + height = h; + data = new Pixel[w*h+extra]; + clear(); + } + + void clear() + { + memset(data,0,sizeof(Pixel)*(width*height+extra)); + } +}; + + +class SDLView +{ +public: + SDLView(int in); + ~SDLView(); + +protected: + void startVideo(); + void checkInput(); + void setupPalette(double dummy=0.0); + + void repaint(); + +private: + int mFd; + + SDL_Surface *surface; + Bitmap<unsigned short> outputBmp; + + bool fullscreen; + int width; + int height; +}; + +#endif |