pb using Gdk-Pixbuf with progressive loading



Hi all,

I am writing a small application using Gtk/GdkPixbuf librairies

It seems that the progressive loading of jpeg images which require
multiple passes - the first pass displays the whole image but 
blurred and subsequent passes bring details - does not work.

In fact the image shows up when all of the data has been received,
despite the fact that the signal "area-prepared" is issued
at the beginning of the loading.

I shall add the progressive loading of dumb single-pass jpeg images
works great.

I am using :
GTK+ 1.2.6,
GdkPixbuf 0.9.0,
gnome-libs-1.0.54,
libjpeg.so.0.62.0

Thank you for your help.

Here are some excerpts from my code:

Basically, whenever the expose event issued a 4096-byte chunk of data
is read in and fed into the loader.

main ()
{
 ...
 Image = gtk_drawing_area_new ();
 gtk_drawing_area_size (GTK_DRAWING_AREA (Image), 100, 100);
 
 Loader = gdk_pixbuf_loader_new ();
 gtk_signal_connect (GTK_OBJECT (Loader), "area-prepared",
GTK_SIGNAL_FUNC (cb_AreaPrepared), Image);
 gtk_signal_connect (GTK_OBJECT (Loader), "area-updated",
GTK_SIGNAL_FUNC (cb_AreaUpdated), Image);
 gtk_signal_connect (GTK_OBJECT (Image), "expose-event", GTK_SIGNAL_FUNC
(cb_DAreaExposeEvent), Loader);
 ...
}

/*
** callback for the expose event
*/
void cb_DAreaExposeEvent (GtkWidget *DArea, GdkEventExpose *Evt,
gpointer Data)
{
 static GdkPixbuf *Pixbuf = NULL;
 static FILE *f = NULL;
 static gboolean Done = FALSE;
 
 GdkPixbufLoader *Loader = (GdkPixbufLoader *)Data;
 guchar Buf [4096];
 int Read;
 
 if (!Done)
 {
  if (!f) f = fopen ("some_image.jpg", "r");
 
  Read = fread (Buf, 1, sizeof (Buf), f);
  g_print ("Feed %u data\n", Read);

  if (Read)
  {
   if (gdk_pixbuf_loader_write (Loader, Buf, Read) == FALSE)
   {
    g_print ("Error feeding image data\n");
    return;
   }

   Pixbuf = gdk_pixbuf_loader_get_pixbuf (Loader);
   if (!Pixbuf)
   {
    g_print ("Not enough data to show\n");
    return;
   }
  }
  else {
   gdk_pixbuf_loader_close (Loader);
   fclose (f);
   Done = TRUE;
  }
 }

 gdk_pixbuf_render_to_drawable (Pixbuf,
                                DArea->window,
                                DArea->style->fg_gc [GTK_STATE_NORMAL],
                                0, 0, 0, 0,
                                gdk_pixbuf_get_width (Pixbuf),
                                gdk_pixbuf_get_height (Pixbuf),
                                GDK_RGB_DITHER_NORMAL,
                                0,
                                0);
}









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