scaling seem to work

main
Steffen Pohle 3 months ago
parent 168c5a831f
commit 8fc696ee7e

@ -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)

@ -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");
}

@ -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

@ -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(&currentimage) == 0) {
if (vdev.GetFrame(&inputimage) == 0) {
vdev.Stop();
vdev.Start();
}
}
inputimage.CopyTo(&currentimage, config.web_width, config.web_height);
webserver.Loop();
usleep (1000);

@ -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;
};
/*********************************************************************/

@ -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);
};

Loading…
Cancel
Save