[gtk-list] Re: An image viewer on the Gnome::Canvas in perl

In his letter Etienne Grossman wrote:
>  Hello,
>#  I wrote the following image viewer with the perl Gnome::Canvas module.
>  A first question : What version of Gtk-Perl are you using? I have
>0.6.123, but I cannot do "use Gnome" with it (don't know why, never
>tried it before). I tried 0.7.000 this morning, but then I could not
>do "use Gtk::Gdk::ImlibImage". In fact, the test of Gtk::Gdk::-
>ImlibImage functionality provided with Gtk-Perl fails too, and
>couldn't put it to work (didn't try very hard).

Indeed I used Gtk 0.7000 which is the first that supports images on
the canvas (thanks Lupus!). Note that the Gtk library has a somewhat
unusual installation. You first do perl Makefile.PL; make; make install
in the top directory and then cd to GdkImlib and Gnome respectively
and redo the installation. This is described in the INSTALL file.

>#  In terms of functionality everything except scrolling works quite well.
>#  The main work of this pseudo widget is done in the sub view_changed()
>#  that does the following series of calls:
>#      $sim = $img->crop_and_clone($x0,$y0,$cw,$ch);
>#      $sim2 = $sim->clone_scaled_image($sw, $sh);
>#      $canv_img->get("image")->destroy_image;
>#      $canv_img->set("image",$sim2);
>#  Where:
>#      $img        is the original imlib image
>#      $x0, $y0    Are the coordinates in the orig image beeing zoomed in.
>#      $cw, $ch    Are the width and the height of the area beeing zoomed in.
>#      $sw, $sh    are the scaled width and height.
>#  Thus there is a lot of work being done for every scrolling and scaling
>                   ^^^^^^^^^^^
>                 I have a small image display program, using Gtk-Perl
>           (no Gnome). Scrolling is not slow at all (maybe it has to
>        do with image size (512x768 is ok) and/or machine (PII/350).
>        Zooming is ok too, but I only zoom on limited areas (selected
>     with crop_and_clone_image()), and once I have zoomed, I can't
>                       scroll out of the zoomed area. 

I'm trying to do something more memory saving, and that is *not* to
precompute the whole zoomed up image, but instead calculate it by
cropping and scaling as the image is moved with the mouse. For my applications
(contourization) I often need to zoom in up to 32 times so you can see the
individual pixels really big. For a reasonably sized (e.g. 256x256) the
memory to store a whole zoomed up image is prohibitive. That is why I
need to go through the contortions outlined above. In contrast to you
I don't have any problem zooming out as I never touch the original image,
but always cut out a piece, and then zoom the cut out piece. The reason
I want to use the canvas is that I want to draw different kinds of 
annotations on top of the image. E.g. countours, or the result of 
some feature detection. The canvas is really nice for this, but I need
some kind of interactive environment for zooming, panning etc. (Btw,
since it is easy to create an Imlib image from a piddle it should 
provide a nice environment for viewing images within PDL).

> #  I would also be very thankful if someone could make this pseudo widget
> #  into a real widget, or at least point me to documentation of how to
> #  do this in perl.
>   What do you mean by "real widget" ? (I have Havoc Pennington's
> book around, but I didn't get at it seriously). One possibility is to
> do a "class" (perl package) for an "image viewer" object which you can
> then add to GtkBox'es. Would you like to have a look at my code (which
> does this, in perl)? Warning : I am not sure if I did things right
> (but, in perl, there's more than one way to do it, of course). 

What I would like to do is to do a proper subclassing of the canvas
widget so that I can use get and set to extract parameters from the
widget. Currently in my code, I e.g. don't have a way of calling
zoom_reset() except through a callback function.

> I hope I can get "use Gnome" to work, so I can try your app.
So do I. 8-)

>  Cheers,
>  Etienne

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