summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Pixel.h18
-rw-r--r--ambithread.c147
-rw-r--r--ambithread.h4
-rw-r--r--config.c1
-rw-r--r--config.h1
-rw-r--r--setup_menu.c3
-rw-r--r--vdrboblight.c2
7 files changed, 80 insertions, 96 deletions
diff --git a/Pixel.h b/Pixel.h
index 9d9adf6..55a684f 100644
--- a/Pixel.h
+++ b/Pixel.h
@@ -26,9 +26,19 @@
struct Pixel
{
- unsigned char b;
- unsigned char g;
- unsigned char r;
- unsigned char a;
+ unsigned char b;
+ unsigned char g;
+ unsigned char r;
+ unsigned char a;
+
+ int isBlack(int threshold = 3) {
+
+ if (r > threshold || g > threshold || b > threshold) {
+ return false;
+ }
+ return true;
+ }
+
};
+
#endif \ No newline at end of file
diff --git a/ambithread.c b/ambithread.c
index 8a2f2e2..1f71968 100644
--- a/ambithread.c
+++ b/ambithread.c
@@ -37,8 +37,8 @@ cAmbiThread::cAmbiThread()
imageSize = 0;
imageWidth = 0;
imageHeight = 0;
- cineBarsHor = 0;
- cineBarsVer = 0;
+ xBarHeight = 0;
+ yBarWidth = 0;
}
cAmbiThread::~cAmbiThread()
@@ -66,6 +66,7 @@ void cAmbiThread::Action()
{
MsTime wait = 0;
MsTime lastPing = 0;
+ MsTime lastBoarderDetect = 0;
int lastPingResult = na;
cMutexLock lock(&mutex);
@@ -104,7 +105,11 @@ void cAmbiThread::Action()
case vmAtmo:
if (grabImage() == success)
{
- detectCineBars();
+ if(start - lastBoarderDetect > 5000) {
+ lastBoarderDetect = start;
+ detectCineBars();
+ }
+
putData();
MsTime elapsed = msNow() - start;
@@ -222,101 +227,67 @@ int cAmbiThread::grabImage()
int cAmbiThread::detectCineBars()
{
- const int threshold = 3; // threshold for black level of cine bars
+ /*
+ Annahme: Wenn im mittleren oberen und unterem Drittel des Bildes alle aufeinander folgenden Pixel schwarz sind
+ haben wir einen Horizontalen Balken.
+
+ |0|x x|0|
+ |y|0 0|y|
+ |y|0 0|y|
+ |0|x x|0|
+
+ */
Pixel* p;
- int off;
- // check horizontal bars
+ const int xOffset = imageWidth / 4;
+ const int yOffset = imageHeight / 4;
- if (cfg.detectCineBars == cbHorizontal || cfg.detectCineBars == cbBoth)
- {
- for (off = 0; off < imageHeight/5; off++) // cinebar height max 1/5 of the screen height
- {
- int above = 0;
-
- for (int x = 0; x < imageWidth; x++)
- {
- p = &image[off*imageWidth + x];
-
- if (p->r > threshold || p->g > threshold || p->b > threshold)
- above++;
-
- p = &image[((imageHeight-1)-off)*imageWidth + x];
-
- if (p->r > threshold || p->g > threshold || p->b > threshold)
- above++;
- }
-
- if (above > imageWidth/8) // max 1/8 failed pixel
- break;
- }
-
- if (cineBarsHor != off)
- {
- static int last = 0;
- static int count = 0;
+ xBarHeight = 0;
+ yBarWidth = 0;
+
- if (off != last)
- {
- last = off;
- count = 0;
+ if (cfg.detectCineBars == cbHorizontal || cfg.detectCineBars == cbBoth) {
+ // check for xBar
+ for (int y = 0; y < yOffset; y++) {
+ int row = imageWidth * y;
+ int xBarCount = 0;
+ for (int x = xOffset; x < imageWidth - xOffset; x++) {
+
+ p = &image[row + x];
+ if(p->isBlack(cfg.cineBarsThreshold)) {
+ xBarCount++;
+ }
}
-
- if (count++ >= cfg.frequence)
- {
- count = 0;
- cineBarsHor = off;
- tell(0, "Switch horizontal cine bars to %d", cineBarsHor);
+ if(xBarCount == imageWidth - (2*xOffset)){
+ xBarHeight++;
+ }
+ else {
+ break;
}
}
}
- // check vertical bars
-
- if (cfg.detectCineBars == cbVertical || cfg.detectCineBars == cbBoth)
- {
- for (off = 0; off < imageWidth/5; off++) // cinebar height max 1/5 of the screen width
- {
- int above = 0;
-
- for (int y = 0; y < imageHeight; y++)
- {
- p = &image[y*imageWidth + off];
-
- if (p->r > threshold || p->g > threshold || p->b > threshold)
- above++;
-
- p = &image[y*imageWidth + ((imageWidth-1)-off)];
-
- if (p->r > threshold || p->g > threshold || p->b > threshold)
- above++;
+ if (cfg.detectCineBars == cbVertical || cfg.detectCineBars == cbBoth) {
+ // check for yBar
+ for (int x = 0; x < xOffset; x++) {
+ int yBarCount = 0;
+ for (int y = yOffset; y < imageHeight - yOffset; y++) {
+ int row = imageWidth * y;
+ p = &image[row + x];
+ if(p->isBlack(cfg.cineBarsThreshold)) {
+ yBarCount++;
+ }
}
-
- if (above > imageHeight/6) // max 1/6 failed pixel
- break;
- }
-
- if (cineBarsVer != off)
- {
- static int last = 0;
- static int count = 0;
-
- if (off != last)
- {
- last = off;
- count = 0;
+ if(yBarCount == imageHeight - (2*yOffset) ){
+ yBarWidth++;
}
-
- if (count++ >= cfg.frequence)
- {
- count = 0;
-
- cineBarsVer = off;
- tell(0, "Switch vertical cine bars to %d", cineBarsVer);
+ else {
+ break;
}
}
}
+ tell(1, "Black border detection horBar: %d verBar: %d", xBarHeight, yBarWidth);
return done;
}
@@ -344,24 +315,22 @@ int cAmbiThread::putData()
for (int y = 0; y < imageHeight; y++) {
// skip horizontal cinebars
- if(y < cineBarsHor) continue;
- if(y > imageHeight - cineBarsHor) continue;
+ if(y < xBarHeight || y > imageHeight - xBarHeight) continue;
int rgb[3];
row = imageWidth * y;
for (int x = 0; x < imageWidth; x++) {
// skip vertical cinebars
- if(x < cineBarsVer) continue;
- if(x > imageWidth - cineBarsVer) continue;
+ if(x < yBarWidth || x > imageWidth - yBarWidth) continue;
p = &image[row + x];
rgb[0] = p->r;
rgb[1] = p->g;
rgb[2] = p->b;
- bob.writeColor(rgb, x - cineBarsVer, y - cineBarsHor);
+ bob.writeColor(rgb, x - yBarWidth, y - xBarHeight);
}
}
- bob.setScanRange(imageWidth - (2*cineBarsVer), imageHeight - (2*cineBarsHor));
+ bob.setScanRange(imageWidth - (2*yBarWidth), imageHeight - (2*xBarHeight));
}
bob.send();
diff --git a/ambithread.h b/ambithread.h
index 3558aea..2bf739d 100644
--- a/ambithread.h
+++ b/ambithread.h
@@ -61,8 +61,8 @@ class cAmbiThread : public cThread, public cAmbiService
int loopActive;
Pixel* image;
- int cineBarsHor;
- int cineBarsVer;
+ int xBarHeight;
+ int yBarWidth;
int imageSize;
int imageWidth;
int imageHeight;
diff --git a/config.c b/config.c
index 02e33ad..6f197a6 100644
--- a/config.c
+++ b/config.c
@@ -47,6 +47,7 @@ cBobConfig::cBobConfig()
priority = 128;
detectCineBars = cbBoth;
+ cineBarsThreshold = 20;
loglevel = 0;
diff --git a/config.h b/config.h
index 344a6e2..f9c2892 100644
--- a/config.h
+++ b/config.h
@@ -56,6 +56,7 @@ class cBobConfig : public cAmbiService
int showMainmenu; //bool
int detectCineBars;
+ int cineBarsThreshold;
int loglevel;
diff --git a/setup_menu.c b/setup_menu.c
index 6098ca8..7c8cf5a 100644
--- a/setup_menu.c
+++ b/setup_menu.c
@@ -30,7 +30,8 @@ void cAmbiSetup::Setup()
Add(new cMenuEditIntItem(tr("Updaterate [Hz]"), &cfg.frequence, 1, 100));
- Add(new cMenuEditStraItem(tr("Detect cinema bars"), &cfg.detectCineBars, 3, cineBars));
+ Add(new cMenuEditStraItem(tr("Detect black borders"), &cfg.detectCineBars, 3, cineBars));
+ Add(new cMenuEditIntItem(tr("Black border detection Threshold (0-255)"), &cfg.cineBarsThreshold, 0, 255));
Add(new cMenuEditIntItem(tr("Threshold (0-255)"), &cfg.threshold, 0, 255));
Add(new cMenuEditIntItem(tr("Gamma (0-10.0)"), &cfg.gamma, 0, 100));
diff --git a/vdrboblight.c b/vdrboblight.c
index d48fe99..5a90b77 100644
--- a/vdrboblight.c
+++ b/vdrboblight.c
@@ -85,6 +85,7 @@ void cPluginBoblight::Save() {
SetupStore("StartupViewMode", cfg.startupViewMode);
SetupStore("DetectCineBars", cfg.detectCineBars);
+ SetupStore("CineBarsThreshold", cfg.cineBarsThreshold);
SetupStore("Updaterate", cfg.frequence);
SetupStore("Threshold", cfg.threshold);
@@ -135,6 +136,7 @@ bool cPluginBoblight::SetupParse(const char* Name, const char* Value)
}
else if (!strcasecmp(Name, "DetectCineBars")) cfg.detectCineBars = (cAmbiService::Cinebars)atoi(Value);
+ else if (!strcasecmp(Name, "CineBarsThreshold")) cfg.cineBarsThreshold = atoi(Value);
else if (!strcasecmp(Name, "Frequence")) cfg.frequence = atoi(Value);
else if (!strcasecmp(Name, "Threshold")) cfg.threshold = atoi(Value);