From 8fc696ee7ea5c45b608d94e79053e6081912bea1 Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Wed, 7 Jan 2026 00:35:10 +0100 Subject: [PATCH] scaling seem to work --- Makefile | 6 +++++- configuration.cc | 2 ++ configuration.h | 4 ++-- main.cc | 8 +++++--- videoframe.cc | 33 +++++++++++++++++++++++++++++++++ videoframe.h | 1 + 6 files changed, 48 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index d5b30aa..656403d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# .SILENT: +.SILENT: DEPENDFILE=.depend VERSION=0.1 @@ -65,4 +65,8 @@ cleanall: clean source: cleanall +help: + echo " config to create a new config.h file" + echo " keygen generate a key and a self-signed certificate" + -include $(DEPENDFILE) diff --git a/configuration.cc b/configuration.cc index 7db2cb5..d908ee6 100644 --- a/configuration.cc +++ b/configuration.cc @@ -204,5 +204,7 @@ void Configuration::Help() { printf (" -dump_config print the config file\n"); printf ("\n"); printf (" -H print this help\n"); + printf ("\n\nSample:\n"); + printf (" ./miniwebcam -sslkey ./ssl-key.pem -sslcert ./ssl-cert.pem -websize 800x600\n"); } diff --git a/configuration.h b/configuration.h index c08e5f7..95b0ecb 100644 --- a/configuration.h +++ b/configuration.h @@ -17,8 +17,8 @@ #define DEFAULT_VDEV_DEVICE "/dev/video0" #define DEFAULT_VDEV_HEIGHT -1 #define DEFAULT_VDEV_WIDTH -1 -#define DEFAULT_WEB_HEIGHT 1024 -#define DEFAULT_WEB_WIDTH 786 +#define DEFAULT_WEB_WIDTH 1024 +#define DEFAULT_WEB_HEIGHT 768 #define CONF_INITFLAGS_PRINT 0x0001 #define CONF_INITFLAGS_HELP 0x0002 diff --git a/main.cc b/main.cc index a7721eb..5710185 100644 --- a/main.cc +++ b/main.cc @@ -13,6 +13,7 @@ int running = 1; static void sig_int(int); int SetupSignals(); +VideoFrame inputimage; VideoFrame currentimage; void ErrorExit(std::string text, int errorcode) { @@ -60,13 +61,14 @@ int main(int argc, char **argv) { return 0; } - + currentimage.SetSize (config.web_width, config.web_height); while (running) { - if (vdev.GetFrame(¤timage) == 0) { + if (vdev.GetFrame(&inputimage) == 0) { vdev.Stop(); vdev.Start(); - } + } + inputimage.CopyTo(¤timage, config.web_width, config.web_height); webserver.Loop(); usleep (1000); diff --git a/videoframe.cc b/videoframe.cc index 83bff74..6cb2961 100644 --- a/videoframe.cc +++ b/videoframe.cc @@ -121,6 +121,39 @@ int VideoFrame::TestScreen(int w, int h) { } +int VideoFrame::CopyTo(VideoFrame *dest, int destw, int desth) { + unsigned char *destptr; + if (dest == NULL) return 0; + + dest->SetSize(destw, desth); + destptr = dest->GetPixBuf(); + if (destptr == NULL) return 0; + + float scale_x = (float)width / destw; + float scale_y = (float)height / desth; + + for (int dy = 0; dy < dest->height; ++dy) { + for (int dx = 0; dx < dest->width; ++dx) { + // Map destination coordinates back to source coordinates + int sx = (int)(dx * scale_x); + int sy = (int)(dy * scale_y); + + // Bounds checking (should be unnecessary with correct scale calculation) + if (sx >= width) sx = width - 1; + if (sy >= height) sy = height - 1; + + // Calculate byte index in the source and destination buffers + int src_idx = 3*((sy * width) + sx); + int dest_idx = 3*((dy * destw) + dx); + + // Copy the pixel data (e.g., all 3 RGB bytes) + memcpy(&destptr[dest_idx], &mem[src_idx], 3); + } + } + + return 1; +}; + /*********************************************************************/ diff --git a/videoframe.h b/videoframe.h index c2fdb94..ff87d80 100644 --- a/videoframe.h +++ b/videoframe.h @@ -24,6 +24,7 @@ class VideoFrame { int SetSize(int w, int h); int ConvertToJpeg(InMemoryFile *imf, int quality); int TestScreen(int w, int h); + int CopyTo(VideoFrame *dest, int destw, int desth); };