From: Olivier Andrieu MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <17211.57896.40053.753344 at karryall.dnsalias.org> Date: Thu, 29 Sep 2005 14:46:32 +0200 To: Sebastien Ferre Cc: lablgtk at math.nagoya-u.ac.jp Subject: Re: GTree: delaying the computation of a pixbuf upon visibility In-Reply-To: <433A46AE.8000004 at irisa.fr> References: <43355ED4.5000004 at inria.fr> <433A46AE.8000004@irisa.fr> Sebastien Ferre [Wednesday 28 September 2005] : > > Hi, > > I'm working on a GUI in which there is a 'GTree.list_store' > of thumbnails (look at http://www.irisa.fr/lande/ferre/camelis > for screen captions). I use the library CamlImages for computing > these thumbnails from JPEG pictures. Why don't you use GdkPixbuf for this ? It can load JPEG pictures. > The problem is that computing these thumbnails is really slow. > For example it takes about 20s for 100 thumbnails, whereas only > a few are visible at one time. So I wonder if it is possible to > delay these computations upon the visibility of a row of the list > inside the scrolling window ? What I want is also to keep control on > the scrolling and selecting while thumbnails are being computed > and displayed. > > Here is the code I use to build a pixbuf from a JPEG file. Can it be > made more efficient ? > > let pixbuf_of_jpeg = > let ht = Hashtbl.create 100 in > fun ~maxside filename -> > try Hashtbl.find ht filename > with Not_found -> > let spec = { > spec_width = Scale 0.2; > spec_height = Scale 0.2; > spec_aspect = Keep_at_most; > spec_switch = Smaller_only; > spec_x = 0; > spec_y = 0} in > let _, _, img = OJpeg.load_thumbnail filename [] spec in > let img = OImages.rgb24 img in > let w = img#width in > let h = img#height in > let scale = max maxside (max w h) / maxside in > let width = w / scale in > let height = h / scale in > let newimage = img#resize None width height in > let pixmap = OXimage2.pixmap_of_image (Gdk.Window.root_parent ()) > None newimage#coerce in > let pixbuf = GdkPixbuf.create ~width ~height () in > GdkPixbuf.get_from_drawable ~dest:pixbuf pixmap#pixmap; > Hashtbl.add ht filename pixbuf; > pixbuf I see you're doing a pixmap_of_image, ie you're sending your image to the server, then you do a GdkPixbuf.get_from_drawable, ie you're asking the server to send the image data back. And GTK will send the data to the server again when displaying the pixbuf. This doesn't seem very efficient. > And now, here is the code I use for building the list. In the model > I put the filename of the source picture, and in the view I use a > 'cell_renderer_pixbuf' and redefine the cell_data_func. But why don't you have a pixbuf column in you model ? I'd do it this way: - have a string column and a pixbuf column in your model - setup the TreeViewColumn to display the pixbuf column with CellRendererPixbuf - compute a small, fixed number of thumbnails (say, 10) and store them in the pixbuf column of model - handle the rest of the thumbnailing in a Glib.Idle callback and update the model as more thumbnails are completed. -- Olivier