diff options
author | horchi <vdr@jwendel.de> | 2012-11-30 07:45:15 +0100 |
---|---|---|
committer | horchi <vdr@jwendel.de> | 2012-11-30 07:45:15 +0100 |
commit | 68fca5fc8c2fcb462e294ede7379f9bfc0350e29 (patch) | |
tree | 370f6ebfa301903dd4873dd1d645c9a5ebf48afa | |
parent | 98b8637fa506ff8d56d68fd38883e151e05d85bf (diff) | |
parent | 58250a33a5f60aa415c3b4548096ab3b37368b0a (diff) | |
download | vdr-plugin-seduatmo-68fca5fc8c2fcb462e294ede7379f9bfc0350e29.tar.gz vdr-plugin-seduatmo-68fca5fc8c2fcb462e294ede7379f9bfc0350e29.tar.bz2 |
Merge branch 'develop' of projects.vdr-developer.org:vdr-plugin-seduatmo into develop
-rw-r--r-- | common.c | 17 | ||||
-rw-r--r-- | common.h | 3 | ||||
-rw-r--r-- | seduatmo.c | 16 | ||||
-rw-r--r-- | seduservice.c | 109 | ||||
-rw-r--r-- | seduservice.h | 17 | ||||
-rw-r--r-- | seduthread.c | 117 | ||||
-rw-r--r-- | seduthread.h | 14 |
7 files changed, 210 insertions, 83 deletions
@@ -80,7 +80,7 @@ MsTime msNow() } //*************************************************************************** -// +// Misc. Functions //*************************************************************************** int minMax(int x, int min, int max) @@ -94,3 +94,18 @@ int minMax(int x, int min, int max) return x; } +double min(double a, double b) +{ + return a < b ? a : b; +} + +double max(double a, double b) +{ + return a >= b ? a : b; +} + +int getrand(int min, int max) +{ + srand(time(0)); + return rand() % (max-min) + min; +} @@ -31,6 +31,9 @@ enum Misc //*************************************************************************** int minMax(int x, int min, int max); +int getrand(int min, int max); +float min(float a, float b); +float max(float a, float b); //*************************************************************************** // Time @@ -331,6 +331,20 @@ cString cPluginSeduatmo::SVDRPCommand(const char* Command, const char* Option, i ReplyCode = 550; return "rainbow effect activated"; } + else if (Option && strcasecmp(Option, "wheel") == 0) + { + cfg.viewMode = cSeduService::vmColorWheel; + startAtmo(); + ReplyCode = 550; + return "color wheel effect activated"; + } + else if (Option && strcasecmp(Option, "wheelstatic") == 0) + { + cfg.viewMode = cSeduService::vmColorWheelStatic; + startAtmo(); + ReplyCode = 550; + return "static color wheel activated"; + } else if (Option && strcasecmp(Option, "black") == 0) { cfg.viewMode = cSeduService::vmBlack; @@ -362,7 +376,7 @@ const char** cPluginSeduatmo::SVDRPHelpPages(void) static const char* HelpPages[] = { "MODE <mode>\n" - " Set mode {atmo|fixed|rainbow|black|detach}\n", + " Set mode {atmo|fixed|rainbow|wheel|wheelstatic|black|detach}\n", 0 }; diff --git a/seduservice.c b/seduservice.c index d82f86e..d55e5ff 100644 --- a/seduservice.c +++ b/seduservice.c @@ -6,7 +6,9 @@ * $Id: seduservice.c,v 1.3 2012/11/22 18:02:59 wendel Exp $ */ +#include <math.h> #include "seduservice.h" +#include "common.h" //*************************************************************************** // View Modes @@ -17,6 +19,8 @@ const char* cSeduService::viewModes[] = "atmo", "fixed color", "rainbow", + "moving color wheel", + "static color wheel", "black", "detached", @@ -27,3 +31,108 @@ const char* cSeduService::toName(ViewMode vm) { return viewModes[vm]; } +//*************************************************************************** +// Color conversion functions +//*************************************************************************** + +void cSeduService::rgb2hsv(int r, int g, int b, double* h, double* s, double* v) +{ + double minC, maxC, delta, rc, gc, bc; + rc = (double)r / 255.0; + gc = (double)g / 255.0; + bc = (double)b / 255.0; + maxC = max(rc, max(gc, bc)); + minC = min(rc, min(gc, bc)); + delta = maxC - minC; + *v = maxC; + + if (maxC != 0) + *s = delta / maxC; + else + *s = 0; + + if (*s == 0) + { + *h = 0; + } + else + { + if (rc == maxC) + *h = (gc - bc) / delta; + else if (gc == maxC) + *h = 2 + (bc - rc) / delta; + else if (bc == maxC) + *h = 4 + (rc - gc) / delta; + + *h *= 60.0; + + if (*h < 0) + *h += 360.0; + } +} + +//*************************************************************************** +// +//*************************************************************************** + +Pixel cSeduService::hsv2rgb(int h, double s, double v) +{ + Pixel p; + + double rr = 0; + double gg = 0; + double bb = 0; + + int i = floor(h/60.0); + double f = h/60.0 - i; + double pv = v * (1 - s); + double qv = v * (1 - s * f); + double tv = v * (1 - s * (1-f)); + + switch (i) + { + case 0: // rojo dominante + rr = v; + gg = tv; + bb = pv; + break; + + case 1: // verde + rr = qv; + gg = v; + bb = pv; + break; + + case 2: + rr = pv; + gg = v; + bb = tv; + break; + + case 3: // azul + rr = pv; + gg = qv; + bb = v; + break; + + case 4: + rr = tv; + gg = pv; + bb = v; + break; + + case 5: // rojo + rr = v; + gg = pv; + bb = qv; + break; + } + + // set each component to a integer value between 0 and 255 + + p.r = minMax(255*rr, 0, 255); + p.g = minMax(255*gg, 0, 255); + p.b = minMax(255*bb, 0, 255); + + return p; +} diff --git a/seduservice.h b/seduservice.h index 9612331..7079041 100644 --- a/seduservice.h +++ b/seduservice.h @@ -10,6 +10,18 @@ #define __SEDU_SERVICE_H //*************************************************************************** +// Pixel - format as provided by softhddevice +//*************************************************************************** + +struct Pixel +{ + unsigned char b; + unsigned char g; + unsigned char r; + unsigned char a; +}; + +//*************************************************************************** // Sedu Service //*************************************************************************** @@ -37,6 +49,8 @@ class cSeduService vmAtmo, vmFixedCol, vmRainbow, + vmColorWheel, + vmColorWheelStatic, vmBlack, vmDetached, vmCount @@ -61,6 +75,9 @@ class cSeduService // static + void rgb2hsv(int r, int g, int b, double* h, double* s, double* v); + Pixel hsv2rgb(int h, double s, double v); + static const char* toName(ViewMode vm); static const char* viewModes[]; }; diff --git a/seduthread.c b/seduthread.c index b3910cf..ae9b1ec 100644 --- a/seduthread.c +++ b/seduthread.c @@ -101,10 +101,10 @@ void cSeduThread::Action() { putData(); - if (cfg.viewMode != vmRainbow) - wait = 500; // less load on fixed color or black + if (cfg.viewMode != vmRainbow && cfg.viewMode != vmColorWheel) + wait = 500; // less load on fixed color or black else - wait = 100; // for Rainbow sleep always 100ms + wait = 100; // for Rainbow sleep always 100ms } waitCondition.TimedWait(mutex, wait); // wait time in ms @@ -294,12 +294,10 @@ int cSeduThread::putData() case vmRainbow: { pFixedCol = getRainbowColor(); - break; } - default: - break; + default: break; } sedu.writeStartSeq(); @@ -323,13 +321,24 @@ int cSeduThread::putData() whiteAdj(p); } else - { - p = &pFixedCol; - } - + if (cfg.viewMode == vmColorWheel) + { + pixel = getColorWheel(1, led); + p = &pixel; + } + else if (cfg.viewMode == vmColorWheelStatic) + { + pixel = getColorWheel(0, led); + p = &pixel; + } + else + { + p = &pFixedCol; + } + sedu.writePix(p); } - + sedu.writeEndSeq(); sedu.read(); @@ -480,10 +489,10 @@ Pixel cSeduThread::getRainbowColor() static int rainbowColorTone = 0; static int callCount = 0; - Pixel p = hsv2Rgb(rainbowColorTone, 1, 1); + Pixel p = hsv2rgb(rainbowColorTone, 1, 1); if (!(callCount++ % (cfg.effectSpeed / 100))) - { + { if (++rainbowColorTone >= 360) rainbowColorTone = 0; } @@ -494,69 +503,41 @@ Pixel cSeduThread::getRainbowColor() return p; } -//*************************************************************************** -// Convert from HSV to RGB -//*************************************************************************** - -Pixel cSeduThread::hsv2Rgb(int h, double s, double v) +Pixel cSeduThread::getColorWheel(int moving, int led) { - Pixel pix = {0,0,0,0}; - double r = 0; - double g = 0; - double b = 0; - - int i = floor(h/60.0); - double f = h/60.0 - i; - double pv = v * (1 - s); - double qv = v * (1 - s * f); - double tv = v * (1 - s * (1-f)); + static int degrees = 0; + static int callCount = 0; + int steps = 360 / cfg.ledCount; + int color = 0; - switch (i) + if (moving && !(callCount++ % (cfg.effectSpeed / 100))) { - case 0: // rojo dominante - r = v; - g = tv; - b = pv; - break; + // calculate spinng wheel with given effect speed - case 1: // verde - r = qv; - g = v; - b = pv; - break; + if (led == 0) + degrees += steps; - case 2: - r = pv; - g = v; - b = tv; - break; + if (degrees >= 360) + degrees = 0; + } - case 3: // azul - r = pv; - g = qv; - b = v; - break; + // calculate color degrees - case 4: - r = tv; - g = pv; - b = v; - break; + color = led * steps + degrees; - case 5: // rojo - r = v; - g = pv; - b = qv; - break; - } - - // set each component to a integer value between 0 and 255 - - pix.r = minMax(255*r, 0, 255); - pix.g = minMax(255*g, 0, 255); - pix.b = minMax(255*b, 0, 255); - - return pix; + if (color >= 360) + color -= 360; + + // convert color from HSV to RGB + + Pixel p = hsv2rgb(color, 1, 1); + + // create a single Pixel + + gammaAdj(&p); + whiteAdj(&p); + + return p; } //*************************************************************************** diff --git a/seduthread.h b/seduthread.h index 38ca6cc..23688c4 100644 --- a/seduthread.h +++ b/seduthread.h @@ -14,18 +14,6 @@ #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: @@ -200,5 +188,5 @@ class cSeduThread : public cThread, public cSeduService int imageHeight; Pixel getRainbowColor(); - Pixel hsv2Rgb(int h, double s, double v); + Pixel getColorWheel(int moving = 0, int led = 0); }; |