From 906428b4e03a371911fe2109e0c470a7e60daa3c Mon Sep 17 00:00:00 2001 From: Steffen Date: Fri, 6 Feb 2026 18:14:44 +0000 Subject: [PATCH 1/6] seems to work --- configuration.cc | 37 ++++++++++++++++++++++ configuration.h | 5 +++ main.cc | 2 +- videoframe.cc | 4 +-- videoframe.h | 2 +- webserver.cc | 67 +++++++++++++++++++++++++++++++++++++--- www/default.css | 11 +++++++ www/index.html | 80 +++++++++++++++++++++++++++++++++++++++++++++--- 8 files changed, 194 insertions(+), 14 deletions(-) diff --git a/configuration.cc b/configuration.cc index b19b476..0a3e948 100644 --- a/configuration.cc +++ b/configuration.cc @@ -44,6 +44,8 @@ Configuration::Configuration() { web_height = -1; web_width = -1; web_imagerefresh = 250; + + filter_ratio = 0.5; }; Configuration::~Configuration() { @@ -276,3 +278,38 @@ void Configuration::Help() { printf (" ./miniwebcam -sslkey ./ssl-key.pem -sslcert ./ssl-cert.pem -websize 800x600\n"); } + + + +void Configuration::SetValue(std::string name, std::string value) { + if (name.compare("filter_ratio") == 0) { + filter_ratio = atof(value.c_str()); + debug ("Filter Ration set to : %g", filter_ratio); + } +}; + + +std::string Configuration::GetValues() { + JSONParse jp; + JSONElement je; + + je.Clear(); + jp.Clear(); + + JSONParse jpe; + + // + jpe.Clear(); + jpe.AddObject("name", "filter_ratio"); + jpe.AddObject("value", filter_ratio); + jpe.AddObject("desc", "Ratio between new to old image (1.0 = new image)"); + + je.SetAddArray("variables", jpe.ToString()); + + // + + + jp.AddObject(je); + return jp.ToString(); +}; + diff --git a/configuration.h b/configuration.h index 7dc070f..38f84a6 100644 --- a/configuration.h +++ b/configuration.h @@ -47,12 +47,17 @@ public: std::string vdev_dumpfile; std::string vdev_dumppath; + float filter_ratio; + Configuration(); ~Configuration(); int LoadArgs(int argc, char **argv); int LoadFile(std::string fn); + void SetValue(std::string name, std::string value); + std::string GetValues(); + int GetInitFlags() { return initflags; }; std::string GetFilename() { return filename; }; diff --git a/main.cc b/main.cc index 1236689..9566f74 100644 --- a/main.cc +++ b/main.cc @@ -73,7 +73,7 @@ static void *thread_video(void *ignored_argument) { } Lock(); inputimage.CopyTo(¤timage, config.web_width, config.web_height); - if (inputfloatfilter.AddScaledImage(&inputfloat, 0.6, 0.4) == 0) + if (inputfloatfilter.AddScaledImage(&inputfloat, config.filter_ratio) == 0) inputfloat.CopyTo(&inputfloatfilter); inputfloatfilter.CopyTo(¤timagefloat); UnLock(); diff --git a/videoframe.cc b/videoframe.cc index 72557b9..5e78be4 100644 --- a/videoframe.cc +++ b/videoframe.cc @@ -277,7 +277,7 @@ int VideoFrameFloat::CopyTo(VideoFrameFloat *dest) { }; -int VideoFrameFloat::AddScaledImage(VideoFrameFloat *vf, float f1, float f2) { +int VideoFrameFloat::AddScaledImage(VideoFrameFloat *vf, float ratio) { float *sptr, *dptr; int x, y; @@ -285,7 +285,7 @@ int VideoFrameFloat::AddScaledImage(VideoFrameFloat *vf, float f1, float f2) { for (dptr = memf, sptr = vf->GetPixBuf(), y = 0; y < height; y++) for (x = 0; x < width*3; x++) { - *dptr = f1 * (*dptr) + f2 * (*sptr); + *dptr = (1.0-ratio) * (*dptr) + ratio * (*sptr); dptr++; sptr++; } diff --git a/videoframe.h b/videoframe.h index 2fdfd21..75fd4b6 100644 --- a/videoframe.h +++ b/videoframe.h @@ -49,7 +49,7 @@ class VideoFrameFloat { int CopyTo(VideoFrame *dest); int CopyTo(VideoFrameFloat *dest); - int AddScaledImage(VideoFrameFloat *vf, float f1, float f2); + int AddScaledImage(VideoFrameFloat *vf, float ratio); }; diff --git a/webserver.cc b/webserver.cc index 02f0a02..f1e4a00 100644 --- a/webserver.cc +++ b/webserver.cc @@ -10,6 +10,9 @@ extern VideoDevice *vdev; std::string API_Get_Ctrls(); std::string API_Set_Ctrl(std::string request); +std::string API_Get_Values(); +std::string API_Set_Value(std::string request); + // InMemoryFile GenerateJpgFile(VideoFrame *vf); InMemoryTar assets; @@ -44,9 +47,20 @@ int WebCamServer::HandleRequest (WebRequestBuffer *requestbuffer, WebServerClien if (webclient->SendResponseData(requestbuffer, API_Get_Ctrls(), "") != 1) return 0; } else if (request.find("/set/ctrl") != std::string::npos) { - debug ("set controls"); + debug ("set control"); if (webclient->SendResponseData(requestbuffer, API_Set_Ctrl(request), "") != 1) return 0; } + + else if (request.compare("/get/variables") == 0) { + debug ("get values"); + if (webclient->SendResponseData(requestbuffer, API_Get_Values(), "") != 1) return 0; + } + else if (request.find("/set/var") != std::string::npos) { + debug ("set value"); + if (webclient->SendResponseData(requestbuffer, API_Set_Value(request), "") != 1) return 0; + } + + else if (isfile("www"+request)) { if (webclient->SendResponseFile(requestbuffer, request, "") != 1) return 0; } @@ -102,14 +116,57 @@ std::string API_Set_Ctrl(std::string request) { while ((t = strchr (t, '/'))) { i++; t++; - if (i == 3) id = atol (t); - if (i == 4) value = atoi (t); + printf ("%d %s\n", i, t); + if (i == 3) { + char *v = strchr (t, '='); + id = atol (t); + if (v == NULL) break; + value = atoi(++v); + debug ("id:%d value:%d", id, value); + vdev->SetDevCtrl(id, value); + break; + } + if (i > 4) break; + } + + + JSONParse jp; + jp.Clear(); + return jp.ToString(); +} + + +std::string API_Get_Values() { + return config.GetValues(); +} + + + +std::string API_Set_Value(std::string request) { + std::string name; + std::string value; + char *t = (char*) request.c_str(); + + int i = 0; + while ((t = strchr (t, '/'))) { + i++; + t++; + printf ("%d %s\n", i, t); + if (i == 3) { + char *v = strchr (t, '='); + if (v == NULL) break; + name = ((std::string) t).substr(0, (v-t)); + value = (++v); + debug ("name:%s value:%s", name.c_str(), value.c_str()); + config.SetValue(name, value); + break; + } if (i > 4) break; } - vdev->SetDevCtrl(id, value); JSONParse jp; jp.Clear(); return jp.ToString(); -} \ No newline at end of file +} + diff --git a/www/default.css b/www/default.css index 810e7ef..34b824d 100644 --- a/www/default.css +++ b/www/default.css @@ -2,3 +2,14 @@ body { background-color: #444; color: #BBB; } + +table, th, td { + border: thin solid; + border-collapse: collapse; +} + +.float { + float: left; + padding: 10px; + border: thin solid; +} diff --git a/www/index.html b/www/index.html index 1ab02af..785a038 100644 --- a/www/index.html +++ b/www/index.html @@ -19,7 +19,14 @@
-
+
+

Controls


+
+
+
+

Infos


+
+

@@ -32,7 +39,8 @@ \ No newline at end of file From e67d6f8d507e9b532080b2f0d3dc3550ba9dc662 Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Fri, 6 Feb 2026 20:57:07 +0100 Subject: [PATCH 2/6] fixed float images in convert --- convert.cc | 12 ++++++------ webserver.cc | 1 - www/index.html | 6 ++++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/convert.cc b/convert.cc index 950e071..62c2eb2 100644 --- a/convert.cc +++ b/convert.cc @@ -153,7 +153,7 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig *(ptrdst++) = g; *(ptrdst++) = b; } - else { + if (ptrdstf) { *(ptrdstf++) = (float)r/255.0; *(ptrdstf++) = (float)g/255.0; *(ptrdstf++) = (float)b/255.0; @@ -188,7 +188,7 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig *(ptrdst++) = g; *(ptrdst++) = b; } - else { + if (ptrdstf) { *(ptrdstf++) = (float)r/255.0; *(ptrdstf++) = (float)g/255.0; *(ptrdstf++) = (float)b/255.0; @@ -221,7 +221,7 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig *(ptrdst++) = g; *(ptrdst++) = b; } - else { + if (ptrdstf) { *(ptrdstf++) = (float)r/255.0; *(ptrdstf++) = (float)g/255.0; *(ptrdstf++) = (float)b/255.0; @@ -255,7 +255,7 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig *(ptrdst++) = g; *(ptrdst++) = b; } - else { + if (ptrdstf) { *(ptrdstf++) = (float)r/255.0; *(ptrdstf++) = (float)g/255.0; *(ptrdstf++) = (float)b/255.0; @@ -322,7 +322,7 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig *(ptrdst++) = g; *(ptrdst++) = b; } - else { + if (ptrdstf) { *(ptrdstf++) = (float)r/255.0; *(ptrdstf++) = (float)g/255.0; *(ptrdstf++) = (float)b/255.0; @@ -365,7 +365,7 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig *(ptrdst++) = g; *(ptrdst++) = b; } - else { + if (ptrdstf) { *(ptrdstf++) = (float)r/255.0; *(ptrdstf++) = (float)g/255.0; *(ptrdstf++) = (float)b/255.0; diff --git a/webserver.cc b/webserver.cc index f1e4a00..a883979 100644 --- a/webserver.cc +++ b/webserver.cc @@ -116,7 +116,6 @@ std::string API_Set_Ctrl(std::string request) { while ((t = strchr (t, '/'))) { i++; t++; - printf ("%d %s\n", i, t); if (i == 3) { char *v = strchr (t, '='); id = atol (t); diff --git a/www/index.html b/www/index.html index 785a038..f6f860d 100644 --- a/www/index.html +++ b/www/index.html @@ -92,9 +92,11 @@ function refreshVariables() { variables = JSON.parse(response); let table = document.getElementById("variables"); - let t = ""; + let t = "NameValueDescription"; variables.variables.forEach(function (elm, idx) { - t += ""+elm.name+""; + t += ""+elm.name+""+ + ""+ + ""+elm.desc+""; }); t += ""; table.innerHTML = t; From 4484af81fa614b55a90ea6dcb914b663d4fb4d0e Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Fri, 6 Feb 2026 21:10:55 +0100 Subject: [PATCH 3/6] working on outo brightness --- www/index.html | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/www/index.html b/www/index.html index f6f860d..a5d7a61 100644 --- a/www/index.html +++ b/www/index.html @@ -7,8 +7,11 @@ -
- +
+ +
+
+

@@ -52,7 +55,8 @@ function reloadImage() { function refreshCtrls() { let debug = document.getElementById("debug"); - + let datalist = document.getElementById("autobrightlist"); + datalist.innerHTML = ""; $.ajax({ type: "POST", url: 'get/ctrls', @@ -68,6 +72,7 @@ function refreshCtrls() { t += ""+elm.name+""+elm.min+""+ ""+elm.max+"" + ""; + datalist.innerHTML += "