You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
2.2 KiB
121 lines
2.2 KiB
|
|
|
|
#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);
|
|
}
|
|
}
|
|
}
|
|
|
|
|