Re: Images in GTK over DirectFB - delay in image transitions




Hi All,
 
I used g_object_unref on GdkPixbuf but still I'm seeing memory leak. It constantly increases and the program is killed. I've reproduced part of the code here. Please mail me if I'm doing something wrong. I'm also not able to get gtk_widget_queue_draw()  to refresh the screen after creating new image and had to use gtk_window_move to get that effect.
 
 
GtkWidget*
create_window1 (char *filename)
{
  GtkWidget *window1;
  GtkWidget *image1;
  GdkPixbuf *pixbuf;
  GdkPixbuf *pixbuf_scaled;
 
  window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_size_request (window1, 640, 480);
  gtk_window_set_title (GTK_WINDOW (window1), _("window1"));
  
  pixbuf = gdk_pixbuf_new_from_file( filename,NULL );
  pixbuf_scaled = gdk_pixbuf_scale_simple(pixbuf,640,480,GDK_INTERP_BILINEAR);
  image1 = gtk_image_new_from_pixbuf(pixbuf_scaled);
  gtk_widget_show (image1);
  gtk_container_add (GTK_CONTAINER (window1), image1);
 
  g_timeout_add(1000, (GSourceFunc) on_Next_clicked, (gpointer)image1);
 
/* Store pointers to all widgets, for use by lookup_widget(). */
  GLADE_HOOKUP_OBJECT_NO_REF (window1, window1, "window1");
  GLADE_HOOKUP_OBJECT (window1, image1, "image1");
  return window1;
}
int on_Next_clicked(GtkWidget *image)
{
 
 char filename[50];
 GdkPixbuf *pixbuf;
 GdkPixbuf *pixbuf_scaled;
 GtkWidget *image1;
 
 window1 = lookup_widget(image,"window1");

 static int i =0;
  
 sprintf(filename,"Slide%d.JPG",i);
 
 gtk_container_remove (GTK_CONTAINER(window1),image);
 gtk_widget_destroy(slide);
 
 pixbuf = gdk_pixbuf_new_from_file(filename,NULL );
 pixbuf_scaled = gdk_pixbuf_scale_simple(pixbuf,640,480,GDK_INTERP_BILINEAR);
 image = gtk_image_new_from_pixbuf(pixbuf_scaled);
 gtk_widget_show (image1);
 gtk_container_add (GTK_CONTAINER (window1), image);
  
  if((i%2) == 0)
  {
         gtk_window_move(window1,0,1);
   }
  else
  {
        gtk_window_move(window1,0,0);
  }
   
 
 g_object_unref(pixbuf);
 g_object_unref(pixbuf_scaled);
 
return TRUE;
}
 
On Thu, Aug 28, 2008 at 7:50 PM, richard boaz <ivor boaz gmail com> wrote:

you destroy them by releasing the reference, once this is 0, gtk frees it automatically.  you do this after your image has been created:

g_object_unref(pixbufb

g_object_unref(pixbuf_scaled);


2008/8/28 Harinandan S <harinandans gmail com>

Hi All,
 
I made the transition smooth by destroying only the image and recreating a new one. I now have another problem - memory leak. I first create a pixbuf, scale it and then create an image widget from the scaled pixbuf. I see a memory leak here. I feel that its because i am not freeing pixbuf at all. My code is like this
 
pixbuf = gdk_pixbuf_new_from_file(filename,NULL );
pixbuf_scaled = gdk_pixbuf_scale_simple(pixbuf,640,480,GDK_INTERP_BILINEAR);
image = gtk_image_new_from_pixbuf(pixbuf_scaled);
 
I destroy image whenever i need a new image later. How can i free pixbuf and pixbuf_scaled after image widget is created?

 
On Wed, Aug 27, 2008 at 8:28 PM, richard boaz <ivor boaz gmail com> wrote:
I guess I don't understand why you have to create new windows.  Why can you not use the same window and GtkImage widget to display all images?  thus avoiding having to create them every time?


On Wed, Aug 27, 2008 at 4:50 PM, Harinandan S <harinandans gmail com> wrote:
Hi,
 
I also tried a sequence in which i create next frame before hand. ie
 
on startup:
create window1
show window 1
create window2
 
on next
show window2
create window3
 
Similarly on subsequent next clicks. I see no improvement. In the above sequence only show window was the work, which made me think that show may be taking most of the time in transition.
I am not able to use the sequence you mentioned since I use GtkImage and not GtkDrawingArea.
On Wed, Aug 27, 2008 at 7:53 PM, richard boaz <ivor boaz gmail com> wrote:
Hi,

Try a different sequence, if possible:
  1. at startup, create window and drawing area to display image
  2. never destroy window and drawing area, except on application exit
  3. on next:
    3.1  destroy previous image
    3.2 create next image for display
  4. invoke the expose callback on the drawing area to display image from 3.2
With this sequence, you are guaranteed that the only work required is to create the next image and display it, i.e., the absolute minimum of work required.

richard

2008/8/27 Harinandan S <harinandans gmail com>
Hi All,
 
I am implementing a image viewer using GTK on DirectFB on an embedded ARM. When i press next i should get a new image. At present i am putting an image(VGA size) in a window and destroying the window and creating a new window with next image. I see that its taking a lot of time in transition.
 
At present my sequence is :
 
 when next button is pressed -
          1. Create new window with new image.
          2. Show new window
          3. Destroy old window
 
I thought old window will still be shown until new window is created so transition will be smooth. But still transition is taking time.
 
Is there any better way to do this so that the transition is smooth?

--
Regards,
Harinandan S

_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list





--
Regards,
Harinandan S




--
Regards,
Harinandan S

_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list





--
Regards,
Harinandan S


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]