Re: [gtkmm] New to GTKmm; some beginner questions.



Amit BHATNAGAR schrieb:
#1 Does GTK provide an API that I can use to perform the above operations? Since GTK is closely connected with GIMP, is it possible to use GIMP to achieve this? (assuming that GIMP has an API). I have read the documentation
for GtkImage and even GdkPixmap, but nothing would suggest that image
manipulation is possible from these.

Concerning every piece of example code I have seen (even inside gtk+) I guess that accessing the pixel values one by one is the recommended API for a GdkPixbuf (look there, it is the base of Image). [e.g. graying out images is done this way internally] Code example below.

Since gimp does not operate on a GdkPixbuf (if I guess right, you should check this, I never looked inside gimp!), you can not use gimp filters inside gtkmm programs. You might either: - use a gimp buffer as the representation and use the same way as gimp(1.3) to put it onscreen. - write an abstraction/translation layer to apply gimp filters to pixbufs (if possible)
- do it yourself (pixel by pixel)

#2 Is my only other alternative to use a library like ImageMagick to perform these operations? Is there a GTK(mm) interface for this? I have
found GDKMagick but this seems to be very old (obsolete?). There is also
Magic++, but again I don't know how this integrates well within a GTK app.
Is there any better alternative than ImageMagick?

Any image manipulation library (or external program) should do it, but you will need to convert between pixbuf and library representation IIRC.

   Christof

----
blend an image from Load0 to Load1 (controlled by d)

static const unsigned steps=8;
static Gtk::Window *progresswin;
static Glib::RefPtr<Gdk::Pixbuf> Load0,Load1;
static unsigned current_n;
static Gtk::Image *imag;

static void progress(double d)
{  unsigned n=unsigned(steps*d+.5);
   if (n!=current_n)
   {  // von Load0 nach Load1 morphen
      double beta=(steps-n)/double(steps-current_n);
      double gamma=(n-beta*current_n)/double(steps);
      guchar *b_pixel,*dest_pixel;
      guchar *b_line,*dest_line;
      unsigned rowstride = Load0->get_rowstride ();
      unsigned bytes_per_pixel = Load0->get_has_alpha() ? 4 : 3;
      b_line=Load1->get_pixels();
      dest_line=Load0->get_pixels();
      for (unsigned y=0;y<Load1->get_height();++y)
      {  b_pixel=b_line;
         dest_pixel=dest_line;
         for (unsigned x=0;x<Load1->get_width();++x)
{ if (dest_pixel[0]!=b_pixel[0]) dest_pixel[0]= beta*dest_pixel[0]+ gamma*b_pixel[0]; if (dest_pixel[1]!=b_pixel[1]) dest_pixel[1]= beta*dest_pixel[1]+ gamma*b_pixel[1]; if (dest_pixel[2]!=b_pixel[2]) dest_pixel[2]= beta*dest_pixel[2]+ gamma*b_pixel[2];
            if (bytes_per_pixel==4 && dest_pixel[3]!=b_pixel[3])
               dest_pixel[3]= beta*dest_pixel[3]+ gamma*b_pixel[3];
            dest_pixel+=bytes_per_pixel;
            b_pixel+=bytes_per_pixel;
         }
         b_line+=rowstride;
         dest_line+=rowstride;
      }
      imag->set(Load0);
      while(Gtk::Main::events_pending()) Gtk::Main::iteration() ;
      current_n=n;
   }
}





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