removing the imagefloat thing... and trying to solve the filter in integer only

main
Steffen Pohle 2 weeks ago
parent 7456f23aa8
commit d897822e9e

@ -46,9 +46,9 @@ Configuration::Configuration() {
web_imagerefresh = 250; web_imagerefresh = 250;
debug = 0; debug = 0;
filter_ratio = 0.5; filter_weight = 50;
auto_brightness = 0; auto_brightness = 0;
auto_brightness_target = 0.5; auto_brightness_target = 0.5f;
}; };
Configuration::~Configuration() { Configuration::~Configuration() {
@ -292,9 +292,9 @@ void Configuration::Help() {
void Configuration::SetValue(std::string name, std::string value) { void Configuration::SetValue(std::string name, std::string value) {
if (name.compare("filter_ratio") == 0) { if (name.compare("filter_weight") == 0) {
filter_ratio = atof(value.c_str()); filter_weight = atof(value.c_str());
debug ("Filter Ration set to : %g", filter_ratio); debug ("Filter Weight set to : %g", filter_weight);
} }
if (name.compare("auto_brightness") == 0) { if (name.compare("auto_brightness") == 0) {
auto_brightness = atol(value.c_str()); auto_brightness = atol(value.c_str());
@ -302,6 +302,8 @@ void Configuration::SetValue(std::string name, std::string value) {
} }
if (name.compare("auto_brightness_target") == 0) { if (name.compare("auto_brightness_target") == 0) {
auto_brightness_target = atof(value.c_str()); auto_brightness_target = atof(value.c_str());
if (auto_brightness_target < 0.1f) auto_brightness_target = 0.1f;
if (auto_brightness_target > 1.0f) auto_brightness_target = 1.0f;
debug ("Auto Brightness Target set to : %g", auto_brightness_target); debug ("Auto Brightness Target set to : %g", auto_brightness_target);
} }
}; };
@ -318,9 +320,9 @@ std::string Configuration::GetValues() {
// //
jpe.Clear(); jpe.Clear();
jpe.AddObject("name", "filter_ratio"); jpe.AddObject("name", "filter_weight");
jpe.AddObject("value", filter_ratio); jpe.AddObject("value", filter_weight);
jpe.AddObject("desc", "Ratio between new to old image (1.0 = new image)"); jpe.AddObject("desc", "Weight for the filtered image (0-100)");
je.SetAddArrayEscaped("variables", jpe.ToString()); je.SetAddArrayEscaped("variables", jpe.ToString());
// //

@ -50,7 +50,7 @@ public:
unsigned int auto_brightness; unsigned int auto_brightness;
float auto_brightness_target; float auto_brightness_target;
float filter_ratio; int filter_weight;
Configuration(); Configuration();
~Configuration(); ~Configuration();

@ -105,13 +105,12 @@ int ConvertStop(ConvertData *cdata, uint32_t pixelformat) {
/* /*
* converts the video from input type to RGB24 type - 24Bit * converts the video from input type to RGB24 type - 24Bit
*/ */
int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsigned char *ptrsrc, int srcsize, uint32_t pixelformat, int srcw, int srch) { int Convert (ConvertData *cdata, VideoFrame *dest, unsigned char *ptrsrc, int srcsize, uint32_t pixelformat, int srcw, int srch) {
int xs, ys; int xs, ys;
int xd, yd; int xd, yd;
unsigned char r,g,b; unsigned char r,g,b;
unsigned char cb, cr, y1; unsigned char cb, cr, y1;
unsigned char *ptrdst = NULL; unsigned char *ptrdst = NULL;
float *ptrdstf = NULL; // for float data scaled to 0...1.0
// debug ("srcsize:%d pixfmt:%s size: %dx%d", srcsize, convert_from_pixelformat(pixelformat).c_str(), srcw, srch); // debug ("srcsize:%d pixfmt:%s size: %dx%d", srcsize, convert_from_pixelformat(pixelformat).c_str(), srcw, srch);
if (config.vdev_dumppath.length() > 0) dumpframe(ptrsrc, srcsize, pixelformat, srcw, srch); if (config.vdev_dumppath.length() > 0) dumpframe(ptrsrc, srcsize, pixelformat, srcw, srch);
@ -121,17 +120,12 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig
// check if there is a destination and that the destination is large to keep // check if there is a destination and that the destination is large to keep
// the full image // the full image
if ((dest == NULL && destf == NULL) || ptrsrc == NULL) if (dest == NULL || ptrsrc == NULL) return 0;
return 0;
if (dest) { if (dest) {
dest->SetSize(srcw, srch); dest->SetSize(srcw, srch);
ptrdst = dest->GetPixBuf(); ptrdst = dest->GetPixBuf();
} }
if (destf) {
destf->SetSize(srcw, srch);
ptrdstf = destf->GetPixBuf();
}
switch (pixelformat) { switch (pixelformat) {
case (V4L2_PIX_FMT_RGB32): case (V4L2_PIX_FMT_RGB32):
@ -152,11 +146,6 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig
*(ptrdst++) = g; *(ptrdst++) = g;
*(ptrdst++) = b; *(ptrdst++) = b;
} }
if (ptrdstf) {
*(ptrdstf++) = (float)r/255.0;
*(ptrdstf++) = (float)g/255.0;
*(ptrdstf++) = (float)b/255.0;
}
xd++; xd++;
} }
} }
@ -164,7 +153,6 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig
/* if the source image is too small ignore the other places.. */ /* if the source image is too small ignore the other places.. */
if (xd < srcw) { if (xd < srcw) {
if (ptrdst) ptrdst += 3 * (srcw - xd); if (ptrdst) ptrdst += 3 * (srcw - xd);
if (ptrdstf) ptrdstf += 3 *(srcw - xd);
} }
yd++; yd++;
} }
@ -187,11 +175,6 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig
*(ptrdst++) = g; *(ptrdst++) = g;
*(ptrdst++) = b; *(ptrdst++) = b;
} }
if (ptrdstf) {
*(ptrdstf++) = (float)r/255.0;
*(ptrdstf++) = (float)g/255.0;
*(ptrdstf++) = (float)b/255.0;
}
xd++; xd++;
} }
} }
@ -199,7 +182,6 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig
/* if the source image is too small ignore the other places.. */ /* if the source image is too small ignore the other places.. */
if (xd < srcw) { if (xd < srcw) {
if (ptrdst) ptrdst += 3 * (srcw - xd); if (ptrdst) ptrdst += 3 * (srcw - xd);
if (ptrdstf) ptrdstf += 3 *(srcw - xd);
} }
yd++; yd++;
} }
@ -220,11 +202,6 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig
*(ptrdst++) = g; *(ptrdst++) = g;
*(ptrdst++) = b; *(ptrdst++) = b;
} }
if (ptrdstf) {
*(ptrdstf++) = (float)r/255.0;
*(ptrdstf++) = (float)g/255.0;
*(ptrdstf++) = (float)b/255.0;
}
xd++; xd++;
} }
} }
@ -232,7 +209,6 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig
/* if the source image is too small ignore the other places.. */ /* if the source image is too small ignore the other places.. */
if (xd < srcw) { if (xd < srcw) {
if (ptrdst) ptrdst += 3 * (srcw - xd); if (ptrdst) ptrdst += 3 * (srcw - xd);
if (ptrdstf) ptrdstf += 3 *(srcw - xd);
} }
yd++; yd++;
} }
@ -254,11 +230,6 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig
*(ptrdst++) = g; *(ptrdst++) = g;
*(ptrdst++) = b; *(ptrdst++) = b;
} }
if (ptrdstf) {
*(ptrdstf++) = (float)r/255.0;
*(ptrdstf++) = (float)g/255.0;
*(ptrdstf++) = (float)b/255.0;
}
xd++; xd++;
} }
} }
@ -266,34 +237,33 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig
/* if the source image is too small ignore the other places.. */ /* if the source image is too small ignore the other places.. */
if (xd < srcw) { if (xd < srcw) {
if (ptrdst) ptrdst += 3 * (srcw - xd); if (ptrdst) ptrdst += 3 * (srcw - xd);
if (ptrdstf) ptrdstf += 3 *(srcw - xd);
} }
yd++; yd++;
} }
break; break;
case (V4L2_PIX_FMT_SGRBG16): case (V4L2_PIX_FMT_SGRBG16):
debayer_grbg16 ((uint16_t *)ptrsrc, srcw, srch, ptrdst, ptrdstf, srcw, srch); debayer_grbg16 ((uint16_t *)ptrsrc, srcw, srch, ptrdst, srcw, srch);
break; break;
case (V4L2_PIX_FMT_SRGGB10P): case (V4L2_PIX_FMT_SRGGB10P):
debayer_rggb10packet ((uint8_t *)ptrsrc, srcw, srch, ptrdst, ptrdstf, srcw, srch); debayer_rggb10packet ((uint8_t *)ptrsrc, srcw, srch, ptrdst, srcw, srch);
break; break;
case (V4L2_PIX_FMT_SGBRG10): case (V4L2_PIX_FMT_SGBRG10):
debayer_gbrg10 ((uint8_t *)ptrsrc, srcw, srch, ptrdst, ptrdstf, srcw, srch); debayer_gbrg10 ((uint8_t *)ptrsrc, srcw, srch, ptrdst, srcw, srch);
break; break;
case (V4L2_PIX_FMT_SRGGB10): case (V4L2_PIX_FMT_SRGGB10):
debayer_rggb10 ((uint8_t *)ptrsrc, srcw, srch, ptrdst, ptrdstf, srcw, srch); debayer_rggb10 ((uint8_t *)ptrsrc, srcw, srch, ptrdst, srcw, srch);
break; break;
case (V4L2_PIX_FMT_SRGGB8): case (V4L2_PIX_FMT_SRGGB8):
debayer_rggb8 ((uint8_t *)ptrsrc, srcw, srch, ptrdst, ptrdstf, srcw, srch); debayer_rggb8 ((uint8_t *)ptrsrc, srcw, srch, ptrdst, srcw, srch);
break; break;
case (V4L2_PIX_FMT_SGRBG8): case (V4L2_PIX_FMT_SGRBG8):
debayer_grbg8 ((uint8_t *)ptrsrc, srcw, srch, ptrdst, ptrdstf, srcw, srch); debayer_grbg8 ((uint8_t *)ptrsrc, srcw, srch, ptrdst, srcw, srch);
break; break;
case (V4L2_PIX_FMT_UYVY): case (V4L2_PIX_FMT_UYVY):
@ -321,11 +291,6 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig
*(ptrdst++) = g; *(ptrdst++) = g;
*(ptrdst++) = b; *(ptrdst++) = b;
} }
if (ptrdstf) {
*(ptrdstf++) = (float)r/255.0;
*(ptrdstf++) = (float)g/255.0;
*(ptrdstf++) = (float)b/255.0;
}
xd++; xd++;
} }
} }
@ -333,7 +298,6 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig
/* if the source image is too small ignore the other places.. */ /* if the source image is too small ignore the other places.. */
if (xd < srcw) { if (xd < srcw) {
if (ptrdst) ptrdst += 3 * (srcw - xd); if (ptrdst) ptrdst += 3 * (srcw - xd);
if (ptrdstf) ptrdstf += 3 *(srcw - xd);
} }
yd++; yd++;
} }
@ -364,11 +328,6 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig
*(ptrdst++) = g; *(ptrdst++) = g;
*(ptrdst++) = b; *(ptrdst++) = b;
} }
if (ptrdstf) {
*(ptrdstf++) = (float)r/255.0;
*(ptrdstf++) = (float)g/255.0;
*(ptrdstf++) = (float)b/255.0;
}
xd++; xd++;
} }
} }
@ -376,7 +335,6 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig
/* if the source image is too small ignore the other places.. */ /* if the source image is too small ignore the other places.. */
if (xd < srcw) { if (xd < srcw) {
if (ptrdst) ptrdst += 3 * (srcw - xd); if (ptrdst) ptrdst += 3 * (srcw - xd);
if (ptrdstf) ptrdstf += 3 *(srcw - xd);
} }
yd++; yd++;
} }

@ -18,7 +18,7 @@ struct {
} typedef ConvertData; } typedef ConvertData;
int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsigned char *ptrsrc, int srcsize, uint32_t pixelformat, int srcw, int srch); int Convert (ConvertData *cdata, VideoFrame *dest, unsigned char *ptrsrc, int srcsize, uint32_t pixelformat, int srcw, int srch);
int ConvertStart(ConvertData *cdata, uint32_t pixelformat); int ConvertStart(ConvertData *cdata, uint32_t pixelformat);
int ConvertStop(ConvertData *cdata, uint32_t pixelformat); int ConvertStop(ConvertData *cdata, uint32_t pixelformat);

@ -24,8 +24,6 @@ std::string toBits(unsigned int i, int maxbits);
#define BITCONV(d) ((d>>8) & 0xff) #define BITCONV(d) ((d>>8) & 0xff)
#define STORE if (dst) { *(dst++) = BITCONV(r); *(dst++) = BITCONV(g); *(dst++) = BITCONV(b); src++; } #define STORE if (dst) { *(dst++) = BITCONV(r); *(dst++) = BITCONV(g); *(dst++) = BITCONV(b); src++; }
#define STORE8 if (dst) { *(dst++) = (r & 0xff); *(dst++) = (g & 0xff); *(dst++) = (b & 0xff); src++; } #define STORE8 if (dst) { *(dst++) = (r & 0xff); *(dst++) = (g & 0xff); *(dst++) = (b & 0xff); src++; }
#define STOREF16 if (dstf) { *(dstf++) = ((float)r/65535.0); *(dstf++) = ((float)g/65535.0); *(dstf++) = ((float)b/65535.0); }
#define STOREF8 if (dstf) { *(dstf++) = ((float)r/255.0); *(dstf++) = ((float)g/255.0); *(dstf++) = ((float)b/255.0); }
/* /*
@ -33,7 +31,7 @@ std::string toBits(unsigned int i, int maxbits);
RGB image by bilinear interpolation. RGB image by bilinear interpolation.
*/ */
void debayer_grbg16 (uint16_t * src, int src_w, int src_h, void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
uint8_t * dst, float * dstf, int dst_w, int dst_h) { uint8_t * dst, int dst_w, int dst_h) {
// GG RR GG RR // GG RR GG RR
// BB GG BB GG // BB GG BB GG
@ -47,7 +45,6 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
g = CE; g = CE;
b = DN; b = DN;
STORE; STORE;
STOREF16;
// upper first line, starts with RR GG RR ... // upper first line, starts with RR GG RR ...
for (xs = 1; xs < src_w - 1; xs+=2) { for (xs = 1; xs < src_w - 1; xs+=2) {
@ -56,13 +53,11 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
g = (LE + RI + DN) / 3; g = (LE + RI + DN) / 3;
b = (DNLE + DNRI) / 2; b = (DNLE + DNRI) / 2;
STORE; STORE;
STOREF16;
// green pixel // green pixel
r = (LE + RI) / 2; r = (LE + RI) / 2;
g = CE; g = CE;
b = DN; b = DN;
STORE; STORE;
STOREF16;
} }
// upper right pixel (red) // upper right pixel (red)
@ -70,7 +65,6 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
g = (DN + LE) / 2; g = (DN + LE) / 2;
b = DNLE; b = DNLE;
STORE; STORE;
STOREF16;
// go through the "body" of the image // go through the "body" of the image
for (ys = 1; ys < src_h - 1; ys+=2) { for (ys = 1; ys < src_h - 1; ys+=2) {
@ -82,27 +76,23 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
g = (UP + DN + RI) / 3; g = (UP + DN + RI) / 3;
b = CE; b = CE;
STORE; STORE;
STOREF16;
for (xs = 1; xs < src_w - 1; xs+=2) { for (xs = 1; xs < src_w - 1; xs+=2) {
// green pixel // green pixel
r = (UP + DN) / 2; r = (UP + DN) / 2;
g = CE; g = CE;
b = (LE + RI) / 2; b = (LE + RI) / 2;
STORE; STORE;
STOREF16;
// blue pixel // blue pixel
r = (UPLE + UPRI + DNLE + DNRI) / 4; r = (UPLE + UPRI + DNLE + DNRI) / 4;
g = (LE + RI + UP + DN) / 4; g = (LE + RI + UP + DN) / 4;
b = CE; b = CE;
STORE; STORE;
STOREF16;
} }
// last pixel in line (green) // last pixel in line (green)
r = (UP + DN) / 2; r = (UP + DN) / 2;
g = CE; g = CE;
b = LE; b = LE;
STORE; STORE;
STOREF16;
// every second line with GG RR GG RR ... (start at 3rd line) // every second line with GG RR GG RR ... (start at 3rd line)
@ -111,27 +101,23 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
g = CE; g = CE;
b = (UP + DN) / 2; b = (UP + DN) / 2;
STORE; STORE;
STOREF16;
for (xs = 1; xs < src_w - 1; xs+=2) { for (xs = 1; xs < src_w - 1; xs+=2) {
// red pixel // red pixel
r = CE; r = CE;
g = (LE + RI + UP + DN) / 4; g = (LE + RI + UP + DN) / 4;
b = (UPLE + UPRI + DNLE + DNRI) / 4; b = (UPLE + UPRI + DNLE + DNRI) / 4;
STORE; STORE;
STOREF16;
// green pixel // green pixel
r = (LE + RI) / 2; r = (LE + RI) / 2;
g = CE; g = CE;
b = (UP + DN) / 2; b = (UP + DN) / 2;
STORE; STORE;
STOREF16;
} }
// last pixel in line (red) // last pixel in line (red)
r = CE; r = CE;
g = (UP + DN + LE) / 3; g = (UP + DN + LE) / 3;
b = (UPLE + DNLE) / 2; b = (UPLE + DNLE) / 2;
STORE; STORE;
STOREF16;
} }
// bottom left pixel // bottom left pixel
@ -139,7 +125,6 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
g = (UP + RI) / 2; g = (UP + RI) / 2;
b = CE; b = CE;
STORE; STORE;
STOREF16;
// last line starting with GG BB GG ... // last line starting with GG BB GG ...
for (xs = 1; xs < src_w - 1; xs+=2) { for (xs = 1; xs < src_w - 1; xs+=2) {
@ -148,13 +133,11 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
g = CE; g = CE;
b = (LE + RI) / 2; b = (LE + RI) / 2;
STORE; STORE;
STOREF16;
// blue pixel // blue pixel
r = (UPLE + UPRI) / 2; r = (UPLE + UPRI) / 2;
g = (LE + UP + RI) / 2; g = (LE + UP + RI) / 2;
b = CE; b = CE;
STORE; STORE;
STOREF16;
} }
// bottom right pixel (green) // bottom right pixel (green)
@ -162,22 +145,21 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
g = CE; g = CE;
b = LE; b = LE;
STORE; STORE;
STOREF16;
} }
/* /*
The function converts a 8bit GRBG 2x2 CFA coded image into an 8bit The function converts a 8bit GRBG 2x2 CFA coded image into an 8bit
RGB image by bilinear interpolation. RGB image by bilinear interpolation.
*/ */
void debayer_gbrg8 (uint8_t * src, int src_w, int src_h, uint8_t *dst, float *dstf, int dst_w, int dst_h) { void debayer_gbrg8 (uint8_t * src, int src_w, int src_h, uint8_t *dst, int dst_w, int dst_h) {
debayer_grbg8 (src, src_w, src_h, dst, dstf, dst_w, dst_h); debayer_grbg8 (src, src_w, src_h, dst, dst_w, dst_h);
}; };
void debayer_rggb8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *dstf, int dst_w, int dst_h) { void debayer_rggb8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_w, int dst_h) {
debayer_grbg8 (src, src_w, src_h, dst, dstf, dst_w, dst_h); debayer_grbg8 (src, src_w, src_h, dst, dst_w, dst_h);
}; };
void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *dstf, int dst_w, int dst_h) { void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_w, int dst_h) {
// GG RR GG RR // GG RR GG RR
// BB GG BB GG // BB GG BB GG
@ -191,7 +173,6 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
g = CE; g = CE;
b = DN; b = DN;
STORE8; STORE8;
STOREF8;
// upper first line, starts with RR GG RR ... // upper first line, starts with RR GG RR ...
for (xs = 1; xs < src_w - 1; xs+=2) { for (xs = 1; xs < src_w - 1; xs+=2) {
@ -200,13 +181,11 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
g = (LE + RI + DN) / 3; g = (LE + RI + DN) / 3;
b = (DNLE + DNRI) / 2; b = (DNLE + DNRI) / 2;
STORE8; STORE8;
STOREF8;
// green pixel // green pixel
r = (LE + RI) / 2; r = (LE + RI) / 2;
g = CE; g = CE;
b = DN; b = DN;
STORE8; STORE8;
STOREF8;
} }
// upper right pixel (red) // upper right pixel (red)
@ -214,7 +193,6 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
g = (DN + LE) / 2; g = (DN + LE) / 2;
b = DNLE; b = DNLE;
STORE8; STORE8;
STOREF8;
// go through the "body" of the image // go through the "body" of the image
for (ys = 1; ys < src_h - 1; ys+=2) { for (ys = 1; ys < src_h - 1; ys+=2) {
@ -226,27 +204,23 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
g = (UP + DN + RI) / 3; g = (UP + DN + RI) / 3;
b = CE; b = CE;
STORE8; STORE8;
STOREF8;
for (xs = 1; xs < src_w - 1; xs+=2) { for (xs = 1; xs < src_w - 1; xs+=2) {
// green pixel // green pixel
r = (UP + DN) / 2; r = (UP + DN) / 2;
g = CE; g = CE;
b = (LE + RI) / 2; b = (LE + RI) / 2;
STORE8; STORE8;
STOREF8;
// blue pixel // blue pixel
r = (UPLE + UPRI + DNLE + DNRI) / 4; r = (UPLE + UPRI + DNLE + DNRI) / 4;
g = (LE + RI + UP + DN) / 4; g = (LE + RI + UP + DN) / 4;
b = CE; b = CE;
STORE8; STORE8;
STOREF8;
} }
// last pixel in line (green) // last pixel in line (green)
r = (UP + DN) / 2; r = (UP + DN) / 2;
g = CE; g = CE;
b = LE; b = LE;
STORE8; STORE8;
STOREF8;
// every second line with GG RR GG RR ... (start at 3rd line) // every second line with GG RR GG RR ... (start at 3rd line)
@ -255,27 +229,23 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
g = CE; g = CE;
b = (UP + DN) / 2; b = (UP + DN) / 2;
STORE8; STORE8;
STOREF8;
for (xs = 1; xs < src_w - 1; xs+=2) { for (xs = 1; xs < src_w - 1; xs+=2) {
// red pixel // red pixel
r = CE; r = CE;
g = (LE + RI + UP + DN) / 4; g = (LE + RI + UP + DN) / 4;
b = (UPLE + UPRI + DNLE + DNRI) / 4; b = (UPLE + UPRI + DNLE + DNRI) / 4;
STORE8; STORE8;
STOREF8;
// green pixel // green pixel
r = (LE + RI) / 2; r = (LE + RI) / 2;
g = CE; g = CE;
b = (UP + DN) / 2; b = (UP + DN) / 2;
STORE8; STORE8;
STOREF8;
} }
// last pixel in line (red) // last pixel in line (red)
r = CE; r = CE;
g = (UP + DN + LE) / 3; g = (UP + DN + LE) / 3;
b = (UPLE + DNLE) / 2; b = (UPLE + DNLE) / 2;
STORE8; STORE8;
STOREF8;
} }
// bottom left pixel // bottom left pixel
@ -283,7 +253,6 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
g = (UP + RI) / 2; g = (UP + RI) / 2;
b = CE; b = CE;
STORE8; STORE8;
STOREF8;
// last line starting with GG BB GG ... // last line starting with GG BB GG ...
for (xs = 1; xs < src_w - 1; xs+=2) { for (xs = 1; xs < src_w - 1; xs+=2) {
@ -292,13 +261,11 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
g = CE; g = CE;
b = (LE + RI) / 2; b = (LE + RI) / 2;
STORE8; STORE8;
STOREF8;
// blue pixel // blue pixel
r = (UPLE + UPRI) / 2; r = (UPLE + UPRI) / 2;
g = (LE + UP + RI) / 2; g = (LE + UP + RI) / 2;
b = CE; b = CE;
STORE8; STORE8;
STOREF8;
} }
// bottom right pixel (green) // bottom right pixel (green)
@ -306,7 +273,6 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
g = CE; g = CE;
b = LE; b = LE;
STORE8; STORE8;
STOREF8;
} }
#define MAX(_a_,_m_) ( _a_ > _m_ ? _m_ : _a_) #define MAX(_a_,_m_) ( _a_ > _m_ ? _m_ : _a_)
@ -319,7 +285,7 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
#define PRGGB10P_DL ((uint16_t)(*(psrc-2-src_w*2*10/8))) #define PRGGB10P_DL ((uint16_t)(*(psrc-2-src_w*2*10/8)))
#define PRGGB10P_DR ((uint16_t)(*(psrc+2+src_w*2*10/8))) #define PRGGB10P_DR ((uint16_t)(*(psrc+2+src_w*2*10/8)))
void debayer_rggb10packet (uint8_t *src, int src_w, int src_h, void debayer_rggb10packet (uint8_t *src, int src_w, int src_h,
uint8_t *dst, float *dstf, int dst_w, int dst_h) { uint8_t *dst, int dst_w, int dst_h) {
debug ("not yep implemented"); debug ("not yep implemented");
debug ("src size:%dx%d dst size:%dx%d", src_w, src_h, dst_w, dst_h); debug ("src size:%dx%d dst size:%dx%d", src_w, src_h, dst_w, dst_h);
@ -355,7 +321,7 @@ inline int swap16(uint16_t i) {
#define PRGGB10_UR (unsigned int)(*(psrc+1-src_w)) #define PRGGB10_UR (unsigned int)(*(psrc+1-src_w))
#define PRGGB10_DL (unsigned int)(*(psrc-1+src_w)) #define PRGGB10_DL (unsigned int)(*(psrc-1+src_w))
#define PRGGB10_DR (unsigned int)(*(psrc+1+src_w)) #define PRGGB10_DR (unsigned int)(*(psrc+1+src_w))
void debayer_gbrg10 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float * dstf, int dst_w, int dst_h) { void debayer_gbrg10 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_w, int dst_h) {
// GG BB GG BB // GG BB GG BB
// RR GG RR GG // RR GG RR GG
// GG BB GG BB // GG BB GG BB
@ -371,7 +337,6 @@ void debayer_gbrg10 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float
int max_b = 0; int max_b = 0;
pdst = dst; pdst = dst;
pdstf = dstf;
for (ys = 0, yd = 0, psrc = (uint16_t*)src; ys < dst_h; ys++, yd++) { for (ys = 0, yd = 0, psrc = (uint16_t*)src; ys < dst_h; ys++, yd++) {
r = 0; r = 0;
g = 0; g = 0;
@ -413,19 +378,12 @@ void debayer_gbrg10 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float
pdst += 3; pdst += 3;
} }
// copy pixel to destination float
if (pdstf) {
pdstf[0] = ((float)r / 1023.0);
pdstf[1] = ((float)g / 1023.0);
pdstf[2] = ((float)b / 1023.0);
pdstf += 3;
}
psrc += 1; psrc += 1;
} }
} }
}; };
void debayer_rggb10 (uint8_t *src, int src_w, int src_h, uint8_t *dst, float *dstf, int dst_w, int dst_h) { void debayer_rggb10 (uint8_t *src, int src_w, int src_h, uint8_t *dst, int dst_w, int dst_h) {
// RR GG RR GG // RR GG RR GG
// GG BB GG BB // GG BB GG BB
// RR GG RR GG // RR GG RR GG
@ -441,7 +399,6 @@ void debayer_rggb10 (uint8_t *src, int src_w, int src_h, uint8_t *dst, float *ds
int max_b = 0; int max_b = 0;
pdst = dst; pdst = dst;
pdstf = dstf;
for (ys = 0, yd = 0, psrc = (uint16_t*)src; ys < dst_h; ys++, yd++) { for (ys = 0, yd = 0, psrc = (uint16_t*)src; ys < dst_h; ys++, yd++) {
r = 0; r = 0;
g = 0; g = 0;
@ -482,13 +439,6 @@ void debayer_rggb10 (uint8_t *src, int src_w, int src_h, uint8_t *dst, float *ds
pdst += 3; pdst += 3;
} }
// copy pixel to destination float
if (pdstf) {
pdstf[0] = ((float)r / 1023.0);
pdstf[1] = ((float)g / 1023.0);
pdstf[2] = ((float)b / 1023.0);
pdstf += 3;
}
psrc += 1; psrc += 1;
} }
} }

@ -3,14 +3,14 @@
#include <stdint.h> #include <stdint.h>
void debayer_grbg16 (uint16_t *src, int src_w, int src_h, uint8_t *dst, float*dstf, int dst_w, int dst_h); void debayer_grbg16 (uint16_t *src, int src_w, int src_h, uint8_t *dst, int dst_w, int dst_h);
void debayer_grbg8 (uint8_t *src, int src_w, int src_h, uint8_t *dst, float*dstf, int dst_w, int dst_h); void debayer_grbg8 (uint8_t *src, int src_w, int src_h, uint8_t *dst, int dst_w, int dst_h);
void debayer_gbrg8 (uint8_t *src, int src_w, int src_h, uint8_t *dst, float*dstf, int dst_w, int dst_h); void debayer_gbrg8 (uint8_t *src, int src_w, int src_h, uint8_t *dst, int dst_w, int dst_h);
void debayer_rggb8 (uint8_t *src, int src_w, int src_h, uint8_t *dst, float*dstf, int dst_w, int dst_h); void debayer_rggb8 (uint8_t *src, int src_w, int src_h, uint8_t *dst, int dst_w, int dst_h);
void debayer_rggb10packet (uint8_t *src, int src_w, int src_h, uint8_t *dst, float *dstf, int dst_w, int dst_h); void debayer_rggb10packet (uint8_t *src, int src_w, int src_h, uint8_t *dst, int dst_w, int dst_h);
void debayer_gbrg10 (uint8_t *src, int src_w, int src_h, uint8_t *dst, float *dstf, int dst_w, int dst_h); void debayer_gbrg10 (uint8_t *src, int src_w, int src_h, uint8_t *dst, int dst_w, int dst_h);
void debayer_rggb10 (uint8_t *src, int src_w, int src_h, uint8_t *dst, float *dstf, int dst_w, int dst_h); void debayer_rggb10 (uint8_t *src, int src_w, int src_h, uint8_t *dst, int dst_w, int dst_h);
#endif #endif

@ -23,10 +23,9 @@ std::string GetDefaultConfig(std::string name);
int timedeiff_ms(timeval *t1); int timedeiff_ms(timeval *t1);
VideoFrame inputimage; VideoFrame inputimage;
VideoFrameFloat inputfloat;
VideoFrameFloat inputfloatfilter;
VideoFrame currentimage; VideoFrame currentimage;
VideoFrame currentimagefloat; VideoFrame filteredimage;
VideoFrame currentfilteredimage;
VideoDevice *vdev= NULL; VideoDevice *vdev= NULL;
double framespersecond = -1; // 60secs average frames per second double framespersecond = -1; // 60secs average frames per second
@ -36,6 +35,7 @@ static void *thread_webserver(void *ignored_argument) {
WebCamServer webserver; WebCamServer webserver;
webserver.SetupPorts(config.http_port, config.https_port); webserver.SetupPorts(config.http_port, config.https_port);
webserver.SetupSSL(config.ssl_key, config.ssl_cert); webserver.SetupSSL(config.ssl_key, config.ssl_cert);
webserver.SetupMaxClients(16);
webserver.Start(); webserver.Start();
while (running) { while (running) {
@ -57,7 +57,7 @@ static void *thread_video(void *ignored_argument) {
float brightness_error_sum = 0.0f; float brightness_error_sum = 0.0f;
float brightness_error_integral = 0.0f; float brightness_error_integral = 0.0f;
int brightness_sample_count = 0; int brightness_sample_count = 0;
const int brightness_settle_frames = 5; const int brightness_settle_frames = VDEV_INBUFFERS;
const float brightness_deadband = 0.01f; const float brightness_deadband = 0.01f;
const float brightness_kp = 0.10f; const float brightness_kp = 0.10f;
const float brightness_ki = 0.01f; const float brightness_ki = 0.01f;
@ -91,8 +91,7 @@ static void *thread_video(void *ignored_argument) {
currentimage.SetSize (config.web_width, config.web_height); currentimage.SetSize (config.web_width, config.web_height);
while (running) { while (running) {
// if (vdev->GetFrame(&inputimage, &inputfloat) == 0) { if (vdev->GetFrame(&inputimage) == 0) {
if (vdev->GetFrame(&inputimage, NULL) == 0) {
vdev->Stop(); vdev->Stop();
vdev->Start(); vdev->Start();
} }
@ -109,9 +108,8 @@ static void *thread_video(void *ignored_argument) {
Lock(); Lock();
current_brightness = 0.0f; current_brightness = 0.0f;
inputimage.CopyTo(&currentimage, config.web_width, config.web_height, &current_brightness); inputimage.CopyTo(&currentimage, config.web_width, config.web_height, &current_brightness);
if (inputfloatfilter.AddScaledImage(&inputfloat, config.filter_ratio) == 0) inputimage.CopyToFiltered(&filteredimage, config.filter_weight);
inputfloat.CopyTo(&inputfloatfilter); filteredimage.CopyTo(&currentfilteredimage);
inputfloatfilter.CopyTo(&currentimagefloat);
UnLock(); UnLock();
// calculate and set new brightness value if auto_brightness is enabled // calculate and set new brightness value if auto_brightness is enabled
@ -131,7 +129,7 @@ static void *thread_video(void *ignored_argument) {
config.auto_brightness = 0; // disable auto brightness if control not found config.auto_brightness = 0; // disable auto brightness if control not found
} }
if (found) { if (found) {
if (config.auto_brightness_target < 0.0f) config.auto_brightness_target = 0.0f; if (config.auto_brightness_target < 0.1f) config.auto_brightness_target = 0.1f;
if (config.auto_brightness_target > 1.0f) config.auto_brightness_target = 1.0f; if (config.auto_brightness_target > 1.0f) config.auto_brightness_target = 1.0f;
brightness_error_sum += config.auto_brightness_target - current_brightness; brightness_error_sum += config.auto_brightness_target - current_brightness;

@ -29,9 +29,8 @@ int isfile(std::string fname);
extern VideoFrame inputimage; extern VideoFrame inputimage;
extern VideoFrame currentimage; extern VideoFrame currentimage;
extern VideoFrame filteredimage;
extern VideoFrameFloat inputfloat; extern VideoFrame currentfilteredimage;
extern VideoFrame currentimagefloat;
extern int running; extern int running;
#endif #endif

@ -84,7 +84,7 @@ class VideoDevice {
virtual int SetIOMode(int newiomode) { debug (""); return 0; }; virtual int SetIOMode(int newiomode) { debug (""); return 0; };
virtual int Start() { debug (""); return 0; }; virtual int Start() { debug (""); return 0; };
virtual int Stop() { debug (""); return 0; }; virtual int Stop() { debug (""); return 0; };
virtual int GetFrame (VideoFrame *destframe, VideoFrameFloat *destfloat) { debug (""); return 0; }; virtual int GetFrame (VideoFrame *destframe) { debug (""); return 0; };
virtual int SetDevCtrl(unsigned int id, int value) { debug (""); return 0; }; virtual int SetDevCtrl(unsigned int id, int value) { debug (""); return 0; };
virtual int GetDevCtrl(unsigned int id, int *value) { debug (""); return 0; }; virtual int GetDevCtrl(unsigned int id, int *value) { debug (""); return 0; };
virtual std::list<VideoDevCtrl> GetDevCtrls() { return vidctrls; }; virtual std::list<VideoDevCtrl> GetDevCtrls() { return vidctrls; };

@ -248,7 +248,7 @@ int VideoDevice_Dump::Stop() {
// //
#define SIZE_FRAMEHEADER 8 #define SIZE_FRAMEHEADER 8
#define SIZE_DUMPHEADER 12 #define SIZE_DUMPHEADER 12
int VideoDevice_Dump::GetFrame(VideoFrame *destframe, VideoFrameFloat *destfloat) { int VideoDevice_Dump::GetFrame(VideoFrame *destframe) {
struct timeval curtv; struct timeval curtv;
unsigned int diff = 0; unsigned int diff = 0;
std::list<VideoDevCtrl>::iterator ctrl; std::list<VideoDevCtrl>::iterator ctrl;
@ -267,7 +267,7 @@ int VideoDevice_Dump::GetFrame(VideoFrame *destframe, VideoFrameFloat *destfloat
} while (diff < inframe_nexttime); } while (diff < inframe_nexttime);
ReadFrame(); ReadFrame();
Convert(&cdata, destframe, destfloat, inframe, inframe_size, Convert(&cdata, destframe, inframe, inframe_size,
conf_videofmt, w, h); conf_videofmt, w, h);
ctrl = vidctrls.begin(); ctrl = vidctrls.begin();

@ -34,7 +34,7 @@ class VideoDevice_Dump : public VideoDevice {
int SetIOMode(int newiomode) { return 1; }; int SetIOMode(int newiomode) { return 1; };
int Start(); int Start();
int Stop(); int Stop();
int GetFrame (VideoFrame *destframe, VideoFrameFloat *destfloat); int GetFrame (VideoFrame *destframe);
int SetDevCtrl(unsigned int id, int value); int SetDevCtrl(unsigned int id, int value);
int GetDevCtrl(unsigned int id, int *value); int GetDevCtrl(unsigned int id, int *value);
}; };

@ -401,11 +401,11 @@ int VideoDevice_V4L2::Stop() {
}; };
int VideoDevice_V4L2::GetFrame(VideoFrame *destframe, VideoFrameFloat *destfloat) { int VideoDevice_V4L2::GetFrame(VideoFrame *destframe) {
struct v4l2_buffer buf; struct v4l2_buffer buf;
int len, ret; int len, ret;
if (destframe == NULL && destfloat == NULL) return 0; if (destframe == NULL) return 0;
switch (conf_iomode) { switch (conf_iomode) {
case IOMODE_READ: case IOMODE_READ:
@ -424,8 +424,10 @@ int VideoDevice_V4L2::GetFrame(VideoFrame *destframe, VideoFrameFloat *destfloat
} }
} }
else { else {
Convert(&cdata, destframe, destfloat, inbuffer[0].data, len, if (Convert(&cdata, destframe, inbuffer[0].data, len,
fmt.fmt.pix.pixelformat, fmt.fmt.pix.width, fmt.fmt.pix.height); fmt.fmt.pix.pixelformat, fmt.fmt.pix.width, fmt.fmt.pix.height) == 0) {
return 0;
}
} }
break; break;
@ -452,8 +454,10 @@ int VideoDevice_V4L2::GetFrame(VideoFrame *destframe, VideoFrameFloat *destfloat
} }
if (buf.index >= 0 && buf.index < VDEV_INBUFFERS) { if (buf.index >= 0 && buf.index < VDEV_INBUFFERS) {
Convert(&cdata, destframe, destfloat, inbuffer[buf.index].data, buf.bytesused, if (Convert(&cdata, destframe, inbuffer[buf.index].data, buf.bytesused,
fmt.fmt.pix.pixelformat, fmt.fmt.pix.width, fmt.fmt.pix.height); fmt.fmt.pix.pixelformat, fmt.fmt.pix.width, fmt.fmt.pix.height) == 0) {
return 0;
}
} }
ret = xioctl(fd, VIDIOC_QBUF, &buf); ret = xioctl(fd, VIDIOC_QBUF, &buf);

@ -30,7 +30,7 @@ class VideoDevice_V4L2 : public VideoDevice {
int SetIOMode(int newiomode); int SetIOMode(int newiomode);
int Start(); int Start();
int Stop(); int Stop();
int GetFrame (VideoFrame *destframe, VideoFrameFloat *destfloat); int GetFrame (VideoFrame *destframe);
int SetDevCtrl(unsigned int id, int value); int SetDevCtrl(unsigned int id, int value);
int GetDevCtrl(unsigned int id, int *value); int GetDevCtrl(unsigned int id, int *value);
void RefreshCtrls(); void RefreshCtrls();

@ -177,139 +177,36 @@ int VideoFrame::CopyTo(VideoFrame *dest, int destw, int desth, float *brightness
return 1; return 1;
}; };
/*********************************************************************/
VideoFrameFloat::VideoFrameFloat() { int VideoFrame::CopyTo(VideoFrame *dest) {
memf = NULL; if (dest == NULL) return 0;
memf_allocated = 0; if (dest->GetWidth() != width || dest->GetHeight() != height)
width = 0;
height = 0;
};
VideoFrameFloat::~VideoFrameFloat() {
FreeFrame();
};
void VideoFrameFloat::FreeFrame() {
if (memf != NULL) free(memf);
memf = NULL;
memf_allocated = 0;
};
void VideoFrameFloat::AllocateFrame() {
int memnewsize = width * height * 3 * sizeof(float);
if (memnewsize <= memf_allocated) return;
else if (memnewsize == 0) {
FreeFrame();
return;
}
memf = (float *) realloc (memf, memnewsize);
memf_allocated = memnewsize;
if (memf == NULL) {
debug ("Error on allocation new frame\n");
exit (1);
}
};
int VideoFrameFloat::TestScreen(int w, int h) {
int x, y;
float r, g, b;
SetSize (w, h);
r = g = b = 0.0;
for (x = 0; x < w; x++) {
for (g = 0, y = 0; y < h; y++) {
if (g )
b = 0.5*(r + g);
memf[3*(x + y * width) + 0] = r;
memf[3*(x + y * width) + 1] = g;
memf[3*(x + y * width) + 2] = b;
g += 0.01;
}
r += 0.01;
}
return 1;
}
int VideoFrameFloat::SetSize(int w, int h) {
if (w < 0 || h < 0) return 0;
if (width == w && height == h) return 1;
width = w;
height = h;
AllocateFrame();
return 1;
};
int VideoFrameFloat::ConvertToJpeg(InMemoryFile *imf, int quality) {
VideoFrame vf;
if (CopyTo (&vf) == 0) return 0;
return vf.ConvertToJpeg(imf, quality);
};
int VideoFrameFloat::CopyTo(VideoFrame *dest) {
int x, y;
unsigned char *dptr;
float *sptr;
if (dest == NULL || memf == NULL || width == 0 || height == 0) return 0;
dest->SetSize(width, height); dest->SetSize(width, height);
memcpy(dest->GetPixBuf(), mem, width * height * 3);
for (sptr = memf, dptr = dest->GetPixBuf(), y = 0; y < height; y++)
for (x = 0; x < width*3; x++) {
*dptr = (unsigned char) (sqrtf(*sptr) * 255.0);
dptr++;
sptr++;
}
return 1; return 1;
}; };
int VideoFrameFloat::CopyTo(VideoFrameFloat *dest) { int VideoFrame::CopyToFiltered(VideoFrame *dest, int filter_weight) {
if (memf == NULL || height == 0 || width == 0) return 0; // check if destination is equal to source size, if not resize destination and blindly copy image data
if (dest == NULL) return 0;
if (dest->SetSize(width, height) == 0) return 0; if (dest->GetWidth() != width || dest->GetHeight() != height) {
memcpy (dest->memf, memf, 3 * height * width * sizeof(float)); dest->SetSize(width, height);
memcpy(dest->GetPixBuf(), mem, width * height * 3);
return 1; return 1;
};
int VideoFrameFloat::AddScaledImage(VideoFrameFloat *vf, float ratio, float *brightness) {
float *sptr, *dptr;
int x, y;
if (vf->height != height || vf->width != width || memf == NULL || vf->memf == NULL) return 0;
for (dptr = memf, sptr = vf->GetPixBuf(), y = 0; y < height; y++)
for (x = 0; x < width*3; x++) {
*dptr = (1.0-ratio) * (*dptr) + ratio * (*sptr);
if (brightness != NULL) *brightness += *dptr;
dptr++;
sptr++;
} }
if (brightness != NULL) { // merge the destination image with the source image using the old and the new pixel values averaging them out with the filter_weight
*brightness /= (width * height * 3); unsigned char *destptr = dest->GetPixBuf();
*brightness = sqrtf(*brightness); for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int idx = 3 * (y * width + x);
destptr[idx + 0] = (destptr[idx + 0] * (100 - filter_weight) + mem[idx + 0] * filter_weight) / 100;
destptr[idx + 1] = (destptr[idx + 1] * (100 - filter_weight) + mem[idx + 1] * filter_weight) / 100;
destptr[idx + 2] = (destptr[idx + 2] * (100 - filter_weight) + mem[idx + 2] * filter_weight) / 100;
}
} }
return 1; return 1;
}; };

@ -25,31 +25,9 @@ class VideoFrame {
int ConvertToJpeg(InMemoryFile *imf, int quality); int ConvertToJpeg(InMemoryFile *imf, int quality);
int TestScreen(int w, int h); int TestScreen(int w, int h);
int CopyTo(VideoFrame *dest, int destw, int desth, float *brightness = NULL); int CopyTo(VideoFrame *dest, int destw, int desth, float *brightness = NULL);
int CopyFrom(int sw, int sh, int ssize, unsigned char *sdata);
};
class VideoFrameFloat {
private:
protected:
void AllocateFrame();
void FreeFrame();
int height;
int width;
int memf_allocated;
float *memf;
public:
VideoFrameFloat();
~VideoFrameFloat();
int SetSize(int w, int h);
int TestScreen(int w, int h);
float *GetPixBuf() { return memf; };
int ConvertToJpeg(InMemoryFile *imf, int quality);
int CopyTo(VideoFrame *dest); int CopyTo(VideoFrame *dest);
int CopyTo(VideoFrameFloat *dest); int CopyToFiltered(VideoFrame *dest, int filter_weight);
int CopyFrom(int sw, int sh, int ssize, unsigned char *sdata);
int AddScaledImage(VideoFrameFloat *vf, float ratio, float *brightness = NULL);
}; };

@ -33,10 +33,10 @@ int WebCamServer::HandleRequest (WebRequestBuffer *requestbuffer, WebServerClien
(void*) jpgfile.mem, (void*) jpgfile.mem,
jpgfile.memsize) != 1) return 0; jpgfile.memsize) != 1) return 0;
} }
else if (request.find("/snapshot-float.jpg") != std::string::npos) { else if (request.find("/snapshot-filtered.jpg") != std::string::npos) {
InMemoryFile jpgfile; InMemoryFile jpgfile;
Lock(); Lock();
currentimagefloat.ConvertToJpeg(&jpgfile, 99); currentfilteredimage.ConvertToJpeg(&jpgfile, 99);
UnLock(); UnLock();
if (webclient->SendResponseFileFromMemory(requestbuffer, request, "", if (webclient->SendResponseFileFromMemory(requestbuffer, request, "",
(void*) jpgfile.mem, (void*) jpgfile.mem,

@ -109,6 +109,7 @@
const notice = document.getElementById("notice"); const notice = document.getElementById("notice");
const statusText = document.getElementById("status-text"); const statusText = document.getElementById("status-text");
const connectionStatus = document.getElementById("connection-status"); const connectionStatus = document.getElementById("connection-status");
let imageLoading = !image.complete;
let controls = []; let controls = [];
let filterEnabled = false; let filterEnabled = false;
let refreshCount = 0; let refreshCount = 0;
@ -141,13 +142,16 @@
} }
function reloadImage() { function reloadImage() {
const imageName = filterEnabled ? "snapshot-float.jpg" : "snapshot.jpg"; const imageName = filterEnabled ? "snapshot-filtered.jpg" : "snapshot.jpg";
image.src = imageName + "?" + Date.now();
document.getElementById("preview-label").textContent = document.getElementById("preview-label").textContent =
filterEnabled ? "Processed image" : "Standard image"; filterEnabled ? "Processed image" : "Standard image";
if (imageLoading) return;
imageLoading = true;
image.src = imageName + "?" + Date.now();
} }
image.addEventListener("load", function() { image.addEventListener("load", function() {
imageLoading = false;
setPreviewAspectRatio(); setPreviewAspectRatio();
document.getElementById("preview-error").hidden = true; document.getElementById("preview-error").hidden = true;
document.getElementById("last-updated").textContent = document.getElementById("last-updated").textContent =
@ -155,6 +159,7 @@
}); });
image.addEventListener("error", function() { image.addEventListener("error", function() {
imageLoading = false;
document.getElementById("preview-error").hidden = false; document.getElementById("preview-error").hidden = false;
}); });
@ -327,8 +332,8 @@
const editor = document.createElement("div"); const editor = document.createElement("div");
editor.className = "setting-editor"; editor.className = "setting-editor";
const isControlId = variable.name === "auto_brightness"; const isControlId = variable.name === "auto_brightness";
const isRatio = variable.name === "filter_ratio" || const isWeight = variable.name === "filter_weight";
variable.name === "auto_brightness_target"; const isBrightnessTarget = variable.name === "auto_brightness_target";
const input = document.createElement(isControlId ? "select" : "input"); const input = document.createElement(isControlId ? "select" : "input");
input.className = "variable-value"; input.className = "variable-value";
input.dataset.name = variable.name; input.dataset.name = variable.name;
@ -355,21 +360,24 @@
input.appendChild(option); input.appendChild(option);
}); });
input.value = currentId; input.value = currentId;
} else if (isRatio) { } else if (isWeight || isBrightnessTarget) {
const min = isBrightnessTarget ? "0.1" : "0";
const max = isBrightnessTarget ? "1" : "100";
const step = isBrightnessTarget ? "0.01" : "1";
const slider = document.createElement("input"); const slider = document.createElement("input");
slider.className = "control-slider variable-slider"; slider.className = "control-slider variable-slider";
slider.type = "range"; slider.type = "range";
slider.min = "0"; slider.min = min;
slider.max = "1"; slider.max = max;
slider.step = "0.01"; slider.step = step;
slider.value = variable.value; slider.value = variable.value;
slider.dataset.name = variable.name; slider.dataset.name = variable.name;
slider.setAttribute("aria-label", variable.name + " slider"); slider.setAttribute("aria-label", variable.name + " slider");
input.type = "number"; input.type = "number";
input.min = "0"; input.min = min;
input.max = "1"; input.max = max;
input.step = "0.01"; input.step = step;
input.value = variable.value; input.value = variable.value;
input.setAttribute("aria-label", variable.name + " value"); input.setAttribute("aria-label", variable.name + " value");

Loading…
Cancel
Save