Almost ready image view OpenGL module

This commit is contained in:
Eddy
2015-03-01 14:37:23 +03:00
parent bf7a247678
commit 4e5d015e53
14 changed files with 806 additions and 335 deletions

View File

@@ -18,48 +18,28 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <sys/time.h>
#include <stdio.h>
#include <getopt.h>
#include <stdbool.h>
#include <X11/Xlib.h> // XInitThreads();
#include "main.h"
#include "macros.h"
#include "bmpview.h"
//GLubyte *BitmapBits = NULL;
/*
pthread_mutex_t m_ima = PTHREAD_MUTEX_INITIALIZER, m_wvlt = PTHREAD_MUTEX_INITIALIZER,
m_hist = PTHREAD_MUTEX_INITIALIZER;
*/
unsigned int bufsize;
void help(char *s){
fprintf(stderr, "\n\n%s, simple interface for LOMO's webcam \"microscope\"\n", s);
fprintf(stderr, "Usage: %s [-h] [-d videodev] [-c channel]\n\n", s);
fprintf(stderr,
"-h, --help:\tthis help\n"
"-d, --device:\tcapture from <videodev>\n"
"-c, --channel:\tset channel <channel> (0..3)\n"
);
fprintf(stderr, "\n\n");
}
#include "imageview.h"
void* change_image(void *data){
FNAME();
windowData *win = (windowData*) data;
int w = win->w, h = win->h, x,y, id = win->ID;
int w = win->image->w, h = win->image->h, x,y, id = win->ID;
GLubyte i;
DBG("w=%d, h=%d",w,h);
for(i = 1; ;i++){
// DBG("search to refresh %d", id);
if(!searchWindow(id)) pthread_exit(NULL);
// DBG("found, lock mutex");
pthread_mutex_lock(&win->mutex);
GLubyte *raw = win->rawdata;
// DBG("refresh");
GLubyte *raw = win->image->rawdata;
for(y = 0; y < h; y++){
if(y%20 == 19){
raw += w*3;
@@ -74,79 +54,49 @@ void* change_image(void *data){
raw += 3;
}
}
win->image->changed = 1;
pthread_mutex_unlock(&win->mutex);
usleep(10000);
//sleep(1);
}
}
/*
void *GLloop(void *data){
FNAME();
windowData *win = (windowData *)data;
createWindow(win);
void *main_thread(_U_ void *none){
// while(1){};
rawimage im;
windowData *mainwin, *win, *third;
int w = 640, h = 480;
im.protected = 1;
im.rawdata = MALLOC(GLubyte, w*h*3);
im.w = w; im.h = h;
mainwin = createGLwin("Sample window", w, h, &im);
DBG("ok");
if(!mainwin) ERRX("can't create main");
pthread_create(&mainwin->thread, NULL, &change_image, (void*)mainwin);
win = createGLwin("Second window", w/2, h/2, NULL);
if(!win) ERRX("can't create second");
pthread_create(&win->thread, NULL, &change_image, (void*)win);
pthread_join(mainwin->thread, NULL);
pthread_join(win->thread, NULL);
clear_GL_context();
WARNX("Two windows closed, create another one");
imageview_init(); // init after killing
third = createGLwin("third window", w*2, h, &im);
if(!third) ERRX("can't create third");
pthread_create(&third->thread, NULL, &change_image, (void*)third);
pthread_join(third->thread, NULL);
DBG("try to clear");
clear_GL_context();
DBG("cleared");
return NULL;
}
*/
/**
* create new window, run thread & return pointer to its structure or NULL
* @param title - header (copyed inside this function)
* @param w,h - image size
*/
windowData *createGLwin(char *title, int w, int h){
windowData *win = MALLOC(windowData, 1);
if(!addWindow(win)){
FREE(win);
return NULL;
}
GLubyte *raw = MALLOC(GLubyte, w*h*3);
win->title = strdup(title);
win->rawdata = raw;
if(pthread_mutex_init(&win->mutex, NULL)){
WARN(_("Can't init mutex!"));
removeWindow(win->ID);
return NULL;
}
win->w = w;
win->h = h;
// pthread_create(&win->glthread, NULL, GLloop, (void*)win);
createWindow(win);
return win;
}
/*
GLubyte *prepareImage(){
static GLubyte *imPtr = NULL;
//static int bufferSize;
//int readlines, linesize;
//GLubyte *ptr;
if(!imPtr) imPtr = calloc(100, sizeof(GLubyte));
return imPtr;
}
*/
int main(_U_ int argc, _U_ char** argv){
windowData *mainwin, _U_ *win, _U_ *third;
int w = 640, h = 480;
char *v[] = {PROJNAME, NULL};
int c = 1;
glutInit(&c, v);
int main(_U_ int argc, _U_ char **argv){
pthread_t mainthread;
initial_setup(); // locale & messages
XInitThreads(); // we need it for threaded windows
//BitmapBits = prepareImage();
mainwin = createGLwin("Sample window", w, h);
if(!mainwin) return 1;
pthread_create(&mainwin->thread, NULL, &change_image, (void*)mainwin);
win = createGLwin("Second window", w/2, h/2);
if(!win) return 1;
pthread_create(&win->thread, NULL, &change_image, (void*)win);
third = createGLwin("Second window", w/4, h/4);
if(!win) return 1;
pthread_create(&third->thread, NULL, &change_image, (void*)third);
// wait for end
glutMainLoop();
imageview_init();
DBG("init main thread");
pthread_create(&mainthread, NULL, &main_thread, NULL);
pthread_join(mainthread, NULL);
return 0;
}