parent
5ac24490d3
commit
67e0d160af
@ -1,120 +0,0 @@
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "gui.h"
|
||||
#include "filter.h"
|
||||
|
||||
extern Filter filter;
|
||||
//gboolean cb_filtertemp_thread (gpointer data);
|
||||
//gboolean cb_filterout_thread (gpointer data);
|
||||
|
||||
//
|
||||
// C / C++ Wrapper for the thread function
|
||||
//
|
||||
gpointer _FilterThread (gpointer data) {
|
||||
filter.Thread ();
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Filter::Filter() { // @suppress("Class members should be properly initialized")
|
||||
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||
|
||||
g_mutex_init (&mutexin);
|
||||
g_mutex_init (&muteximage);
|
||||
g_mutex_init (&mutextmp);
|
||||
g_mutex_init (&mutex);
|
||||
running = 1;
|
||||
inFrame.SetSize(64, 64);
|
||||
image.SetSize(64, 64);
|
||||
imagegtk.SetSize(64, 64);
|
||||
thread = NULL;
|
||||
thread = g_thread_new("Filter", _FilterThread, NULL);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Filter::~Filter() {
|
||||
running = 0;
|
||||
if (thread) {
|
||||
g_thread_join (thread);
|
||||
thread = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
int Filter::NewFrame(VideoFrame *newframe, int posx, int posy) {
|
||||
if (newframe == NULL) return -1;
|
||||
LockInMutex();
|
||||
inFrame.CopyFrom(newframe);
|
||||
inFrameNew = 1;
|
||||
UnLockInMutex();
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
void Filter::NewImage() {
|
||||
newimage = 1;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// NewFrame: will set new frame
|
||||
// Thread: newFrame |------> Find Object --- not found ---> send gui information
|
||||
void Filter::Thread() {
|
||||
while (running) {
|
||||
// check for new frame
|
||||
LockInMutex();
|
||||
if (inFrameNew == 1) {
|
||||
inFrameNew = 0;
|
||||
|
||||
//
|
||||
// do some other stuff use if possible only the oldFrame data
|
||||
ComposeOutput();
|
||||
UnLockInMutex();
|
||||
|
||||
// copy output image for gtk
|
||||
LockImageMutex();
|
||||
imagegtk.CopyFrom(&image);
|
||||
UnLockImageMutex();
|
||||
gdk_threads_add_idle(cb_thread_filter , &imagegtk);
|
||||
}
|
||||
else
|
||||
UnLockInMutex();
|
||||
|
||||
usleep (10000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define FACTOR 25.0
|
||||
void Filter::ComposeOutput() {
|
||||
int x, y, idx, i;
|
||||
float *pixd = NULL; // destination
|
||||
unsigned char *pixs = NULL; // source
|
||||
|
||||
image.SetSize(inFrame.w, inFrame.h);
|
||||
pixd = image.data;
|
||||
pixs = inFrame.data;
|
||||
|
||||
if (pixd == NULL || pixs == NULL) return;
|
||||
if (newimage) {
|
||||
inFrame.CopyTo(&image);
|
||||
newimage = 0;
|
||||
}
|
||||
else {
|
||||
for (x = 0; x < inFrame.w; x++)
|
||||
for (y = 0; y < inFrame.h; y++) {
|
||||
idx = 3 * (inFrame.w * y + x);
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
pixd[idx+i] = ((FACTOR-1.0) * (float)pixd[idx+i]/FACTOR) + (float)(pixs[idx+i] / FACTOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,93 @@
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "gui.h"
|
||||
#include "output.h"
|
||||
|
||||
extern Output output;
|
||||
|
||||
//
|
||||
// C / C++ Wrapper for the thread function
|
||||
//
|
||||
gpointer _OutputThread (gpointer data) {
|
||||
output.Thread ();
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Output::Output() { // @suppress("Class members should be properly initialized")
|
||||
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||
|
||||
g_mutex_init (&mutexin);
|
||||
g_mutex_init (&muteximage);
|
||||
g_mutex_init (&mutextmp);
|
||||
g_mutex_init (&mutex);
|
||||
running = 1;
|
||||
inFrame.SetSize(64, 64);
|
||||
thread = NULL;
|
||||
thread = g_thread_new("Output", _OutputThread, NULL);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Output::~Output() {
|
||||
running = 0;
|
||||
if (thread) {
|
||||
g_thread_join (thread);
|
||||
thread = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
int Output::NewFrame(VideoFrame *newframe, int posx, int posy) {
|
||||
if (newframe == NULL || posx == -1 || posy == -1) return -1;
|
||||
|
||||
// printf ("%s:%d Output::NewFrame Frame w:%d h:%d posx:%d posy:%d\n", __FILE__, __LINE__, newframe->w, newframe->h, posx, posy);
|
||||
|
||||
LockInMutex();
|
||||
inFrame.CopyFrom(newframe);
|
||||
inFrameNew = 1;
|
||||
UnLockInMutex();
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
void Output::NewImage() {
|
||||
newimage = 1;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// NewFrame: will set new frame
|
||||
// Thread: newFrame |------> Find Object --- not found ---> send gui information
|
||||
void Output::Thread() {
|
||||
while (running) {
|
||||
// check for new frame
|
||||
LockInMutex();
|
||||
if (inFrameNew == 1) {
|
||||
inFrameNew = 0;
|
||||
|
||||
//
|
||||
// do some other stuff use if possible only the oldFrame data
|
||||
ComposeOutput();
|
||||
UnLockInMutex();
|
||||
|
||||
// copy output image for gtk
|
||||
}
|
||||
else
|
||||
UnLockInMutex();
|
||||
|
||||
usleep (10000); // sleep 10ms
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Output::ComposeOutput() {
|
||||
// printf ("%s:%d inFrame (w:%d h:%d)\n", __FILE__, __LINE__, inFrame.w, inFrame.h);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in new issue