Hi all,
i want to display images on the Freerunner with a rate of at least 10
frames per second.
I make some tests with pygame and pygtk. With pygtk i got maximal 2-3
frames per second. So i developed a gtk c application to show an image
but it is not smooth and do not reach a higher rate.
I use GtkImage to display the image.
Is there another lib to draw images at a high rate directly to the
framebuffer for openmoko? Anyone a hint how to display images?
I attached the code to this mail do anyone have an optimization?
compile:
gcc small.c -o small $(pkg-config --cflags --libs gtk+-2.0 gthread-2.0)
best regards
Timo
#include <gtk/gtk.h>
#include <pthread.h>
#include <glib.h>
static gboolean delete_event( GtkWidget *widget, GdkEvent *event,
gpointer data ) {
return FALSE;
}
static void destroy( GtkWidget *widget,gpointer data ) {
gtk_main_quit ();
}
double x_position = 0;
double y_position = 50;
GdkPixbuf *buffer;
GtkImage *image;
GdkPixbuf *scaled;
int width=450;
int height=600;
/* Multithreading test*/
void *motionThread(){
printf("Motion thread startet.\n");
while(1) {
x_position+=5;
scaled = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
double pos_y = 50;
double scale_factor = 2.0;
gdk_pixbuf_scale(buffer, scaled, 0, 0, width, height,
x_position , y_position,
scale_factor, scale_factor, GDK_INTERP_BILINEAR);
gdk_threads_enter();
gtk_image_set_from_pixbuf(image,scaled);
gdk_threads_leave();
}
pthread_exit(NULL);
}
/* Event based test. Do not work well. If the timeout is to low no image will be displayed */
static gboolean time_handler (GtkWidget *widget)
{
if (widget->window == NULL) return FALSE;
x_position+=5;
double scale_factor = 2.0;
gdk_pixbuf_scale(buffer, scaled, 0, 0, width, height,
x_position , y_position,
scale_factor, scale_factor, GDK_INTERP_BILINEAR);
gtk_image_set_from_pixbuf(image,scaled);
return TRUE;
}
int main( int argc,
char *argv[] )
{
GtkWidget *window;
GtkWidget *button;
g_thread_init (NULL);
gdk_threads_init ();
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (window), "delete_event",
G_CALLBACK (delete_event), NULL);
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (destroy), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 5);
buffer = gdk_pixbuf_new_from_file("brave-gnu-world-logo.jpg",NULL);
scaled = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
gdk_pixbuf_scale(buffer, scaled, 0, 0, width, height,-100, 50,
2.0, 2.0 , GDK_INTERP_BILINEAR);
image = gtk_image_new_from_pixbuf(scaled);
/* This packs the button into the window (a gtk container). */
gtk_container_add (GTK_CONTAINER (window), image);
gtk_widget_show_all (window);
// Start thread for image movement.
pthread_t tid;
pthread_attr_t * thAttr = NULL;
printf("Create thread...\n");
pthread_create(&tid, thAttr, motionThread, NULL);
gtk_main ();
return 0;
}