From b77a3d75093d2b03293815acbeadab9dfdd6b431 Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Tue, 15 Nov 2022 21:46:35 +0100 Subject: [PATCH] VideoFrame added methode ToPixbuf. --- gui.cc | 4 ++-- video.cc | 21 +-------------------- videodev-dumpfile.cc | 4 ++++ videoframe.cc | 23 +++++++++++++++++++++++ videoframe.h | 2 ++ 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/gui.cc b/gui.cc index 8dcdfc9..01a95c2 100644 --- a/gui.cc +++ b/gui.cc @@ -124,7 +124,7 @@ gboolean cb_thread_filter (gpointer data) { pix_w = vf->w; pix_h = vf->h; } - videoframe_to_pixbuf(image_pixbuf, vf); + vf->ToPixbuf(image_pixbuf); gdk_window_invalidate_rect(gtk_widget_get_window(image_da), NULL, true); filter.UnLockImageMutex(); @@ -170,7 +170,7 @@ gboolean cb_thread_detect (gpointer data) { pix_w = dout->image->w; pix_h = dout->image->h; } - videoframe_to_pixbuf(detect_pixbuf, dout->image); + dout->image->ToPixbuf(detect_pixbuf); gdk_window_invalidate_rect(gtk_widget_get_window(detect_da), NULL, true); filter.NewFrame(dout->image, dout->posx, dout->posy); diff --git a/video.cc b/video.cc index 68fd798..ba39db0 100644 --- a/video.cc +++ b/video.cc @@ -111,25 +111,6 @@ gboolean videoctrl_update(gpointer data) { } -void videoframe_to_pixbuf(GdkPixbuf* dest, VideoFrame *src) { - int destw, desth; - unsigned char *destpixel; - - if (dest == NULL || src == NULL) return; - - desth = gdk_pixbuf_get_height(dest); - destw = gdk_pixbuf_get_width(dest); - destpixel = gdk_pixbuf_get_pixels(dest); - - if (destw * desth < src->h * src->w) { - destw = src->w; - desth = src->h; - } - - memcpy (destpixel, src->data, 3*destw*desth); -} - - #define S_X(_x_) (((_x_) * clientw / pixbufw)) #define S_Y(_y_) (((_y_) * clienth / pixbufh)) void cb_videoda_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer data) { @@ -545,7 +526,7 @@ gboolean cb_thread_video (gpointer data) { pix_w = vf->w; pix_h = vf->h; } - videoframe_to_pixbuf(video_pixbuf, vf); + vf->ToPixbuf(video_pixbuf); detect.NewFrame(vf); videodev->UnLockMutex(); gdk_window_invalidate_rect(gtk_widget_get_window(video_da), NULL, true); diff --git a/videodev-dumpfile.cc b/videodev-dumpfile.cc index 3a8f97a..3a940b1 100644 --- a/videodev-dumpfile.cc +++ b/videodev-dumpfile.cc @@ -197,6 +197,10 @@ int VideoDev_Dumpfile::Grab(VideoFrame *vf) { usleep ((inframe_nexttime-diff)*1000); } while (diff < inframe_nexttime); + if (diff - inframe_nexttime > 1000) + printf ("%s:%d time difference to bit. (%dms) Maybe to slow hard drive?\n", + __FILE__, __LINE__, (diff - inframe_nexttime)); + LockMutex(); Convert(&cdata, vf, inframe, inframe_size, pixformat, w, h); UnLockMutex(); diff --git a/videoframe.cc b/videoframe.cc index 21e57e5..26fc97e 100644 --- a/videoframe.cc +++ b/videoframe.cc @@ -106,6 +106,29 @@ void VideoFrame::CopyTo(FloatImage *dest) { +void VideoFrame::ToPixbuf(GdkPixbuf* dest) { + int destw, desth; + unsigned char *destpixel; + + if (dest == NULL) return; + + desth = gdk_pixbuf_get_height(dest); + destw = gdk_pixbuf_get_width(dest); + destpixel = gdk_pixbuf_get_pixels(dest); + + if (destw * desth < h * w) { + destw = w; + desth = h; + } + + memcpy (destpixel, data, 3*destw*desth); +} + + + + + + FloatImage::FloatImage() { data = NULL; w = 0; diff --git a/videoframe.h b/videoframe.h index 3ac6741..7e46673 100644 --- a/videoframe.h +++ b/videoframe.h @@ -25,6 +25,7 @@ public: class VideoFrame { +private: public: int w; int h; @@ -42,6 +43,7 @@ public: void CopyFrom(VideoFrame *source); void CopyFrom(FloatImage *source); void CopyTo(FloatImage *dest); + void ToPixbuf(GdkPixbuf* dest); };