First working GTK+ window with pretty fast update of the IR cam frames
This commit is contained in:
parent
39f9bf67a2
commit
cfcb290322
17 changed files with 896 additions and 53 deletions
226
flirgtk.c
226
flirgtk.c
|
@ -3,9 +3,30 @@
|
|||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "palettes/15.h"
|
||||
#include "palettes/17.h"
|
||||
#include "palettes/7.h"
|
||||
#include "palettes/85.h"
|
||||
#include "palettes/92.h"
|
||||
#include "palettes/Grayscale.h"
|
||||
#include "palettes/Grey.h"
|
||||
#include "palettes/Iron2.h"
|
||||
#include "palettes/Iron_Black.h"
|
||||
#include "palettes/Rainbow.h"
|
||||
|
||||
static GtkWidget *window = NULL;
|
||||
static GtkWidget *image_darea = NULL;
|
||||
static cairo_surface_t *surface = NULL;
|
||||
|
||||
// internal frame buffer with 640x480 pixels of 4 byte each,
|
||||
// first byte unused, R, G, B 0x00RRGGBB
|
||||
unsigned char fbuffer[640*480*4];
|
||||
unsigned char *fbdata;
|
||||
unsigned char *color_palette;
|
||||
gboolean flir_run = FALSE;
|
||||
|
||||
gpointer cam_thread_main(gpointer user_data);
|
||||
|
||||
|
||||
static gboolean
|
||||
configure_event (GtkWidget *widget,
|
||||
|
@ -13,87 +34,192 @@ configure_event (GtkWidget *widget,
|
|||
gpointer data)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
cairo_t *cr;
|
||||
int stride;
|
||||
|
||||
if (surface)
|
||||
cairo_surface_destroy (surface);
|
||||
if (surface)
|
||||
cairo_surface_destroy (surface);
|
||||
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
|
||||
CAIRO_CONTENT_COLOR,
|
||||
allocation.width,
|
||||
allocation.height);
|
||||
// cr = cairo_create (surface);
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, 640);
|
||||
// g_printerr("stride %d\n", stride);
|
||||
surface = cairo_image_surface_create_for_data (fbuffer,
|
||||
CAIRO_FORMAT_RGB24,
|
||||
640,
|
||||
480,
|
||||
stride);
|
||||
fbdata = cairo_image_surface_get_data(surface);
|
||||
|
||||
g_printerr("configure event %d x %d\n", allocation.width, allocation.height);
|
||||
g_printerr("configure event %d x %d\n", allocation.width, allocation.height);
|
||||
|
||||
/* We've handled the configure event, no need for further processing. */
|
||||
return TRUE;
|
||||
/* We've handled the configure event, no need for further processing. */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int stride;
|
||||
unsigned char *data;
|
||||
cairo_surface_t *surface;
|
||||
|
||||
stride = cairo_format_stride_for_width (format, width);
|
||||
data = malloc (stride * height);
|
||||
surface = cairo_image_surface_create_for_data (data, format,
|
||||
width, height,
|
||||
stride);
|
||||
#endif
|
||||
|
||||
static gboolean
|
||||
draw_event (GtkWidget *widget,
|
||||
cairo_t *cr,
|
||||
gpointer data)
|
||||
{
|
||||
g_printerr("draw event\n");
|
||||
// g_printerr("draw event\n");
|
||||
|
||||
cairo_set_source_surface (cr, surface, 0, 0);
|
||||
cairo_paint (cr);
|
||||
cairo_set_source_surface (cr, surface, 0, 0);
|
||||
cairo_paint (cr);
|
||||
|
||||
return FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
update_fb(void)
|
||||
{
|
||||
#if 0
|
||||
unsigned int x,y;
|
||||
unsigned int *pdata;
|
||||
static unsigned char cnt=0;
|
||||
|
||||
cnt+=0x0f;
|
||||
// g_printerr("cnt=%d\n", cnt);
|
||||
for (y=0; y<480; y++) {
|
||||
for (x=0; x<640; x++) {
|
||||
pdata = (unsigned int *)&fbdata[(y*640*4)+(x*4)];
|
||||
*pdata = (cnt << 16) | (x << 9) | y;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
gtk_widget_queue_draw(image_darea);
|
||||
}
|
||||
|
||||
void
|
||||
start_clicked(GtkWidget *button, gpointer user_data)
|
||||
{
|
||||
flir_run = TRUE;
|
||||
g_thread_new ("CAM thread", cam_thread_main, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
stop_clicked(GtkWidget *button, gpointer user_data)
|
||||
{
|
||||
flir_run = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
close_window (void)
|
||||
{
|
||||
window = NULL;
|
||||
// clean up and quit
|
||||
window = NULL;
|
||||
gtk_main_quit();
|
||||
}
|
||||
|
||||
gboolean
|
||||
handle_timeout (gpointer user_data)
|
||||
{
|
||||
update_fb();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
palette_changed (GtkComboBox *widget, gpointer user_data)
|
||||
{
|
||||
int act;
|
||||
|
||||
act = gtk_combo_box_get_active(widget);
|
||||
if (act < 0) {
|
||||
g_printerr("oops, palette selection = %d\n", act);
|
||||
} else {
|
||||
if (act == 0) color_palette = palette_7;
|
||||
if (act == 1) color_palette = palette_15;
|
||||
if (act == 2) color_palette = palette_17;
|
||||
if (act == 3) color_palette = palette_85;
|
||||
if (act == 4) color_palette = palette_92;
|
||||
if (act == 5) color_palette = palette_Grayscale;
|
||||
if (act == 6) color_palette = palette_Grey;
|
||||
if (act == 7) color_palette = palette_Iron2;
|
||||
if (act == 8) color_palette = palette_Iron_Black;
|
||||
if (act == 9) color_palette = palette_Rainbow;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
GtkWidget *
|
||||
do_drawingarea ()
|
||||
create_main_window ()
|
||||
{
|
||||
GtkWidget *da;
|
||||
GtkWidget *box;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *w;
|
||||
// GtkWidget *da;
|
||||
|
||||
if (!window) {
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_title (GTK_WINDOW (window), "FLIR One");
|
||||
if (!window) {
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_title (GTK_WINDOW (window), "FLIR One");
|
||||
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (close_window), NULL);
|
||||
da = gtk_drawing_area_new ();
|
||||
/* set a minimum size */
|
||||
gtk_widget_set_size_request (da, 160, 120);
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (close_window), NULL);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (window), da);
|
||||
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
|
||||
gtk_container_add (GTK_CONTAINER (window), box);
|
||||
|
||||
g_signal_connect (da, "draw",
|
||||
G_CALLBACK (draw_event), NULL);
|
||||
g_signal_connect (da,"configure-event",
|
||||
G_CALLBACK (configure_event), NULL);
|
||||
gtk_widget_show_all(window);
|
||||
}
|
||||
return window;
|
||||
hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
|
||||
gtk_container_add (GTK_CONTAINER (box), hbox);
|
||||
|
||||
w = gtk_button_new_with_label("Start");
|
||||
gtk_container_add (GTK_CONTAINER (hbox), w);
|
||||
|
||||
g_signal_connect (w, "clicked",
|
||||
G_CALLBACK (start_clicked), NULL);
|
||||
|
||||
w = gtk_button_new_with_label("Stop");
|
||||
gtk_container_add (GTK_CONTAINER (hbox), w);
|
||||
|
||||
g_signal_connect (w, "clicked",
|
||||
G_CALLBACK (stop_clicked), NULL);
|
||||
|
||||
// drop down for color palettes
|
||||
w = gtk_combo_box_text_new();
|
||||
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(w), NULL, "7");
|
||||
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(w), NULL, "15");
|
||||
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(w), NULL, "17");
|
||||
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(w), NULL, "85");
|
||||
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(w), NULL, "92");
|
||||
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(w), NULL, "Grayscale");
|
||||
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(w), NULL, "Grey");
|
||||
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(w), NULL, "Iron 2");
|
||||
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(w), NULL, "Iron Black");
|
||||
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(w), NULL, "Rainbow");
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX(w), 9);
|
||||
gtk_container_add (GTK_CONTAINER (hbox), w);
|
||||
color_palette = palette_Rainbow;
|
||||
g_signal_connect (w, "changed",
|
||||
G_CALLBACK (palette_changed), NULL);
|
||||
|
||||
image_darea = gtk_drawing_area_new ();
|
||||
/* set a minimum size */
|
||||
gtk_widget_set_size_request (image_darea, 640, 480);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (box), image_darea);
|
||||
|
||||
g_signal_connect (image_darea, "draw",
|
||||
G_CALLBACK (draw_event), NULL);
|
||||
g_signal_connect (image_darea,"configure-event",
|
||||
G_CALLBACK (configure_event), NULL);
|
||||
|
||||
// g_timeout_add_seconds(1, handle_timeout, NULL);
|
||||
|
||||
gtk_widget_show_all(window);
|
||||
}
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
gtk_init(&argc, &argv);
|
||||
do_drawingarea();
|
||||
gtk_main();
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
create_main_window();
|
||||
|
||||
gtk_main();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue