image view works!

This commit is contained in:
eddyem
2015-03-02 14:00:26 +03:00
parent 4e5d015e53
commit da3cde5816
10 changed files with 313 additions and 193 deletions

View File

@@ -29,15 +29,24 @@
void* change_image(void *data){
FNAME();
//struct timeval tv;
windowData *win = (windowData*) data;
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);
if(!searchWindow(id)){
DBG("Window deleted");
pthread_exit(NULL);
}
// DBG("found, lock mutex");
pthread_mutex_lock(&win->mutex);
if(win->killthread){
pthread_mutex_unlock(&win->mutex);
DBG("got killthread");
pthread_exit(NULL);
}
// DBG("refresh");
GLubyte *raw = win->image->rawdata;
for(y = 0; y < h; y++){
@@ -57,7 +66,41 @@ void* change_image(void *data){
win->image->changed = 1;
pthread_mutex_unlock(&win->mutex);
usleep(10000);
//sleep(1);
/*tv.tv_sec = 0;
tv.tv_usec = 10000;
select(0, NULL, NULL, NULL, &tv);*/
}
}
void* another_change(void *data){
FNAME();
windowData *win = (windowData*) data;
int w = win->image->w, h = win->image->h, x,y, id = win->ID;
GLubyte i;
for(i = 1; ;i++){
if(!searchWindow(id)){
DBG("Window deleted");
pthread_exit(NULL);
}
pthread_mutex_lock(&win->mutex);
GLubyte *raw = win->image->rawdata;
for(y = 0; y < h; y++){
if(y%20 == 19){
raw += w*3;
continue;
}
for(x = 0; x < w; x++){
if(x%20 != 19){
if(i < 80) raw[0]--;
else if(i < 170) raw[1]--;
else raw[2]--;
}
raw += 3;
}
}
win->image->changed = 1;
pthread_mutex_unlock(&win->mutex);
usleep(10000);
}
}
@@ -65,6 +108,7 @@ void *main_thread(_U_ void *none){
// while(1){};
rawimage im;
windowData *mainwin, *win, *third;
pthread_t mainthread;
int w = 640, h = 480;
im.protected = 1;
im.rawdata = MALLOC(GLubyte, w*h*3);
@@ -72,11 +116,14 @@ void *main_thread(_U_ void *none){
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);
// pthread_create(&mainwin->thread, NULL, &change_image, (void*)mainwin);
pthread_create(&mainthread, NULL, &another_change, (void*)mainwin);
mainwin->killthread = 1; // say that there's no thread for manipulating
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(mainwin->thread, NULL);
pthread_join(mainthread, NULL);
pthread_join(win->thread, NULL);
clear_GL_context();
WARNX("Two windows closed, create another one");