#include "cc_interface.h" #include <Carbon/Carbon.h> /* temporarily including for development testing */ /* hard coding the webcam dimensions: BAD, but we're not probing hardware yet */ #define WEBCAM_X 644 /* webcam's x dim */ #define WEBCAM_Y 480 /* webcam's y dim */ /* default webcam timer callback delay */ #define WEBCAM_CALLBACK_DELAY 40 /* in ms */ struct input_instance input_data; /* move this to input_instance eventually */ UInt32 colorBuf[WEBCAM_Y][WEBCAM_X]; unsigned int (*colorBuf)[640]; int draw_mode=0; //0=pixels, 1=face static void *kickstart(void *data); static void *facefind(void *data); * Resets the OpenGL viewport stuff on widget reconfiguration (resize, * @param widget widget that got reconfigured * @param event the configuration event * @return TRUE ( i don't know what FALSE would do ) static gboolean config_wrapper(GtkWidget *widget, GdkEventConfigure *event, * Debug features test. Draws pixels directly to the frame buffer. * @param widget widget that we're drawing * @param event the draw event * @param data array of pixels static gboolean mydraw(GtkWidget *widget, GdkEventExpose *event, * Periodically querys the webcam for more data. * @param instance webcam input instance data * @return TRUE to stop other handler, FALSE to continue static gboolean webcam_cb(struct input_instance *instance); * Init window code, adding our click callback. * @param widget the window we clicked in * @param instance webcam input instance data static void init_cb(GtkWidget *widget, struct input_instance *instance); * @param widget the window we clicked in * @param event the button click event structure * @param instance input instance data * @return TRUE to stop other handler, FALSE to continue static gboolean click_cb(GtkWidget *widget, GdkEventButton *event, struct input_instance *instance); * @param button the button we clicked on * @param instance input instance data static void button_cb(GtkWidget *button, struct input_instance *instance); * Destroy callback. Called when the input processing window is destroyed. * @param widget the window we clicked in * @param cc crazychat global data structure static void destroy_cb(GtkWidget *widget, struct crazychat *cc); * @param entry model selector combo box entry * @param material pointer to material we're setting static void material_set(GtkWidget *entry, guint8 *material); struct input_instance *init_input(struct crazychat *cc) /*pthread_t userinput_t; // should we put this in a nicer wrapper?*/ struct input_instance *instance; info = (struct draw_info*)malloc(sizeof(*info)); memset(info, 0, sizeof(*info)); info->delay_ms = DEFAULT_FRAME_DELAY; info->data = &input_data; instance = (struct input_instance*)info->data; memset(instance, 0, sizeof(*instance)); instance->output.features = &instance->face; bank = Filter_Initialize(); assert(CamProc(instance, bank) == noErr); // change this prototype-> no windows instance->timer_id = g_timeout_add(WEBCAM_CALLBACK_DELAY, (GSourceFunc)webcam_cb, instance); /* THREAD_CREATE(&userinput_t, facefind, instance); // is this being created correctly?*/ cc_new_gl_window(init_cb, config_wrapper, mydraw, instance->widget = ret.window; gtk_window_set_title(GTK_WINDOW(ret.window), "Local User"); instance->box = ret.vbox; GtkWidget *label = gtk_label_new("Click your face"); gtk_box_pack_start(GTK_BOX(ret.vbox), label, FALSE, FALSE, 0); gtk_box_reorder_child(GTK_BOX(ret.vbox), label, 0); GtkWidget *button = gtk_button_new_with_label("Confirm"); gtk_box_pack_start(GTK_BOX(ret.vbox), button, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(button_cb), instance->button = button; GtkWidget *hbox = gtk_hbox_new(TRUE, 0); gtk_box_pack_start(GTK_BOX(ret.vbox), hbox, FALSE, FALSE, 0); GtkWidget *model_combo = gtk_combo_new(); glist = g_list_append(glist, "Dog"); glist = g_list_append(glist, "Shark"); gtk_combo_set_popdown_strings(GTK_COMBO(model_combo), glist); //gtk_combo_box_set_column_span_column(GTK_COMBO(model_combo), gtk_box_pack_start(GTK_BOX(hbox), model_combo, TRUE, TRUE, 0); gtk_widget_show(model_combo); instance->model = model_combo; GtkWidget *head_material_combo = gtk_combo_new(); glist = g_list_append(glist, "Red"); glist = g_list_append(glist, "Dark Brown"); glist = g_list_append(glist, "Light Brown"); glist = g_list_append(glist, "White"); glist = g_list_append(glist, "Green"); glist = g_list_append(glist, "Black"); gtk_combo_set_popdown_strings(GTK_COMBO(head_material_combo), glist); //gtk_combo_box_set_column_span_column(GTK_COMBO(head_material_combo), gtk_box_pack_start(GTK_BOX(hbox), head_material_combo, TRUE, TRUE, 0); gtk_widget_show(head_material_combo); instance->head = head_material_combo; GtkWidget *appendage_material_combo = gtk_combo_new(); glist = g_list_append(glist, "Red"); glist = g_list_append(glist, "Dark Brown"); glist = g_list_append(glist, "Light Brown"); glist = g_list_append(glist, "White"); glist = g_list_append(glist, "Green"); glist = g_list_append(glist, "Black"); gtk_combo_set_popdown_strings(GTK_COMBO(appendage_material_combo), //gtk_combo_box_set_column_span_column(GTK_COMBO(appendage_material_combo), 10); gtk_box_pack_start(GTK_BOX(hbox), appendage_material_combo, gtk_widget_show(appendage_material_combo); instance->appendage = appendage_material_combo; hbox = gtk_hbox_new(TRUE, 0); gtk_box_pack_start(GTK_BOX(ret.vbox), hbox, FALSE, FALSE, 0); GtkWidget *lids_material_combo = gtk_combo_new(); glist = g_list_append(glist, "Red"); glist = g_list_append(glist, "Dark Brown"); glist = g_list_append(glist, "Light Brown"); glist = g_list_append(glist, "White"); glist = g_list_append(glist, "Green"); glist = g_list_append(glist, "Black"); gtk_combo_set_popdown_strings(GTK_COMBO(lids_material_combo), glist); //gtk_combo_box_set_column_span_column(GTK_COMBO(lids_material_combo), 10); gtk_box_pack_start(GTK_BOX(hbox), lids_material_combo, TRUE, TRUE, 0); gtk_widget_show(lids_material_combo); instance->lid = lids_material_combo; GtkWidget *left_iris_material_combo = gtk_combo_new(); glist = g_list_append(glist, "Red"); glist = g_list_append(glist, "Dark Brown"); glist = g_list_append(glist, "Light Brown"); glist = g_list_append(glist, "White"); glist = g_list_append(glist, "Green"); glist = g_list_append(glist, "Black"); gtk_combo_set_popdown_strings(GTK_COMBO(left_iris_material_combo), //gtk_combo_box_set_column_span_column(GTK_COMBO(left_iris_material_combo), 10); gtk_box_pack_start(GTK_BOX(hbox), left_iris_material_combo, gtk_widget_show(left_iris_material_combo); instance->left_iris = left_iris_material_combo; GtkWidget *right_iris_material_combo = gtk_combo_new(); glist = g_list_append(glist, "Red"); glist = g_list_append(glist, "Dark Brown"); glist = g_list_append(glist, "Light Brown"); glist = g_list_append(glist, "White"); glist = g_list_append(glist, "Green"); glist = g_list_append(glist, "Black"); gtk_combo_set_popdown_strings(GTK_COMBO(right_iris_material_combo), //gtk_combo_box_set_column_span_column(GTK_COMBO(right_iris_material_combo), 10); gtk_box_pack_start(GTK_BOX(hbox), right_iris_material_combo, gtk_widget_show(right_iris_material_combo); instance->right_iris = right_iris_material_combo; gtk_widget_add_events(ret.draw_area, GDK_BUTTON_PRESS_MASK); g_signal_connect(G_OBJECT(ret.draw_area), "button_press_event", G_CALLBACK(click_cb), instance); g_signal_connect(G_OBJECT(ret.window), "destroy", G_CALLBACK(destroy_cb), cc); // gtk_widget_set_size_request(window, 640, 480); gtk_window_set_default_size(GTK_WINDOW(ret.window),320,300); gtk_window_set_geometry_hints (GTK_WINDOW(ret.window), gtk_widget_show(ret.window); static gboolean webcam_cb(struct input_instance *instance) static void *facefind(void *data) fprintf(stderr, "waiting\n"); fprintf(stderr,"got you"); void destroy_input(struct input_instance *instance) extern filter_bank *bank; g_source_remove(instance->timer_id); static gboolean config_wrapper(GtkWidget *widget, GdkEventConfigure *event, GdkGLContext *glcontext = gtk_widget_get_gl_context(widget); GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget); GLfloat w = widget->allocation.width; GLfloat h = widget->allocation.height; // fprintf(stderr,"Homicide %f %f %d\n", w,h,draw_mode); // fprintf(stderr, "Bad place to be- actually not so bad\n"); return configure(widget, event, data); if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext)) /* Undo all of the Model lighting here*/ // glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); // glDisable(GL_CULL_FACE); // glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glViewport(0,-(h/14),w*2,h*2); glMatrixMode(GL_PROJECTION); glPixelZoom(-w/(1*640),(-h/(1*480))); glMatrixMode(GL_MODELVIEW); gdk_gl_drawable_gl_end(gldrawable); static gboolean mydraw(GtkWidget *widget, GdkEventExpose *event, GdkGLContext *glcontext = gtk_widget_get_gl_context (widget); GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget); struct input_instance *instance = (struct input_instance*)data; struct cc_features *features = &instance->face; char *string = gtk_entry_get_text(GTK_COMBO(instance->model)->entry); if (!strcmp(string, "Dog")) { } else if (!strcmp(string, "Shark")) { material_set(GTK_ENTRY(GTK_COMBO(instance->head)->entry), material_set(GTK_ENTRY(GTK_COMBO(instance->appendage)->entry), &features->appendage_color); material_set(GTK_ENTRY(GTK_COMBO(instance->lid)->entry), material_set(GTK_ENTRY(GTK_COMBO(instance->left_iris)->entry), &features->left_iris_color); material_set(GTK_ENTRY(GTK_COMBO(instance->left_iris)->entry), &features->right_iris_color); config_wrapper(widget, event, data); instance->output.my_output=LOCAL; return draw(widget,event,&instance->output); boo = (unsigned int*)colorBuf; assert(gtk_widget_is_gl_capable(widget)); if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext)) { // fprintf(stderr, "We're fucked this time.\n"); glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glDrawPixels(WEBCAM_X, WEBCAM_Y-70, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, boo); if (gdk_gl_drawable_is_double_buffered(gldrawable)) gdk_gl_drawable_swap_buffers(gldrawable); gdk_gl_drawable_gl_end(gldrawable); static void init_cb(GtkWidget *widget, struct input_instance *instance) // setupDrawlists(LOCAL); // fprintf(stderr,"init_cb\n"); static gboolean click_cb(GtkWidget *widget, GdkEventButton *event, struct input_instance *instance) GLfloat w = widget->allocation.width; GLfloat h = widget->allocation.height; Debug("should never get here\n"); x_click=(event->x*(640/w)); y_click=(event->y-(h/14))*(480/(h-(h/14))); //Debug("@@@ x:%d y:%d\n", x_click, y_click); gtk_label_set_text(instance->label, "Put on the box, then press confirm."); if (x_click <= 10) x_click=10; if (x_click >= WEBCAM_X-10) x_click=WEBCAM_X-60; if (y_click <= 10) y_click=10; if (y_click >= WEBCAM_Y-10) y_click=WEBCAM_Y-60; static void button_cb(GtkWidget *button, struct input_instance *instance) if (!draw_mode) { /* transition to face mode */ if (detection_mode == 0) { /* ignore confirm if no calibrate */ setupLighting(instance->widget); gtk_button_set_label(GTK_BUTTON(button), "Calibrate"); gtk_label_set_label(instance->label, "If things get too crazy, click Calibrate."); } else { /* transition to calibration mode */ gtk_label_set_label(instance->label, "Click your face"); gtk_button_set_label(GTK_BUTTON(button), "Confirm"); static void destroy_cb(GtkWidget *widget, struct crazychat *cc) destroy_input(cc->input_data); static void material_set(GtkWidget *entry, guint8 *material) char *string = gtk_entry_get_text(GTK_ENTRY(entry)); if (!strcmp(string, "Red")) { } else if (!strcmp(string, "Dark Brown")) { } else if (!strcmp(string, "Light Brown")) { } else if (!strcmp(string, "White")) { } else if (!strcmp(string, "Green")) { } else if (!strcmp(string, "Black")) {