diff options
author | horchi <vdr@jwendel.de> | 2012-11-28 09:17:32 +0100 |
---|---|---|
committer | horchi <vdr@jwendel.de> | 2012-11-28 09:17:32 +0100 |
commit | 0197b5c98cdeec3740644655963e1f100d73998e (patch) | |
tree | 029168cfc6a31cb3bb6309f2b8ae577302307d8d /seduthread.h | |
download | vdr-plugin-seduatmo-0197b5c98cdeec3740644655963e1f100d73998e.tar.gz vdr-plugin-seduatmo-0197b5c98cdeec3740644655963e1f100d73998e.tar.bz2 |
initial Release of vdr-plugin-seduatmo
Diffstat (limited to 'seduthread.h')
-rw-r--r-- | seduthread.h | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/seduthread.h b/seduthread.h new file mode 100644 index 0000000..038a2ec --- /dev/null +++ b/seduthread.h @@ -0,0 +1,194 @@ + +#include <termios.h> +#include <queue> + +#include <vdr/thread.h> + +#include "common.h" +#include "config.h" + +//*************************************************************************** +// Pixel - format as provided by softhddevice +//*************************************************************************** + +struct Pixel +{ + unsigned char b; + unsigned char g; + unsigned char r; + unsigned char a; +}; + +class PixQueue +{ + public: + + PixQueue() { clear(); } + virtual ~PixQueue() { clear(); } + void clear() { while (!pQueue.empty()) pQueue.pop(); r=g=b=0; } + int getCount() { return pQueue.size(); } + + void push(Pixel* p) + { + pQueue.push(*p); + + r += p->r; + g += p->g; + b += p->b; + + // remove old entrys from queue and sum + + while (pQueue.size() > cfg.average) + { + r -= pQueue.front().r; + g -= pQueue.front().g; + b -= pQueue.front().b; + + pQueue.pop(); + } + } + + void getPixel(Pixel* p) + { + p->r = r / pQueue.size(); + p->g = g / pQueue.size(); + p->b = b / pQueue.size(); + } + + protected: + + std::queue <Pixel> pQueue; + unsigned int r; + unsigned int g; + unsigned int b; +}; + +class PixSum +{ + public: + + PixSum() { clear(); } + + void clear() { r=g=b=count=0; } + int getCount() { return count; } + + void add(Pixel* p) + { + r += p->r; + g += p->g; + b += p->b; + count++; + } + + void getAvg(Pixel* p) + { + p->r = r / count; + p->g = g / count; + p->b = b / count; + } + + protected: + + unsigned int r; + unsigned int g; + unsigned int b; + int count; +}; + +//*************************************************************************** +// cSeduLine - Serial Communication +//*************************************************************************** + +class cSeduLine : public cSeduService +{ + public: + + cSeduLine(); + ~cSeduLine() { close(); } + + int open(); + int close(); + int isOpen() { return fd != na; } + + int checkLine(); + int read(); + + int write(unsigned char b); + + int writeStartSeq(); + int writeEndSeq(); + int writePix(Pixel* p); + int writeColor(Pixel* p, int index); + + // set .. + + void setMode(SeduMode aMode, int channels = 0); + + private: + + int detect(); + + // data + + int dataBytesSend; + + int mode; + int dataBytes; + int byteMode; + int byteStart; + int byteEnd; + + char* deviceName; + int fd; + struct termios oldtio; +}; + +//*************************************************************************** +// SEDU Thread +//*************************************************************************** + +class cSeduThread : public cThread, public cSeduService +{ + public: + + cSeduThread(); + ~cSeduThread(); + + int isRunning() { return Running(); } + + // interface + + void Stop(); + + private: + + void Action(void); + + int grabImage(); + int detectCineBars(); + int putData(); + + void threshold(Pixel* p); + void whiteAdj(Pixel* p); + void gammaAdj(Pixel* p); + void merge(Pixel* p1, Pixel* p2, int level = 100); + + int getPixel(int ledIdx, Pixel* pixel); + int isBlack(Pixel* p) { return p->r < cfg.threshold && p->g < cfg.threshold && p->b < cfg.threshold; } + + // data + + cSeduLine sedu; + + cMutex mutex; + cCondVar waitCondition; + int loopActive; + + Pixel* image; + PixQueue* pixAverage; + int cineBarsHor; + int cineBarsVer; + int imageSize; + int imageWidth; + int imageHeight; +}; |