Re: [gtk-list] Re: Question: Displaying Images (TIM Files)




On Tue, 27 Apr 1999, Geoff Finger wrote:
> 
> That sounds like a good alternative, however GdkRGB doesn't seem to be

It will be orders of magnitude faster than gdk_draw_point(), I assure you!
:-)

> covered in the GTK tutorial, can you suggest someplace to find some
> documentation on it? (Or a piece of (hopefully commented) sample code?)
> 

Some widgets use it; such as GnomeCanvas and (I think) color selector.

> Preferably somepalce that also says what the format of an RGB is, though
> it sounds pretty simple =)
> 

Here is all you really need to know though: 

RGB buffer is a flat array of guchar. Every guchar triplet is a pixel;
they are in R,G, B order. You have to specify a width, height, and
rowstride; the rowstride is the number of guchar to jump to move one row.
It is not necessarily the same as the width, for efficiency reasons. Raph
can tell you which magic rowstrides are fast, and which aren't.

There will be height rows, one after another in the array of guchar.

You might look at guppi2/src/libguppi/rgbdraw.h for code that draws to one
of these buffers. (libart_lgpl and testrgb.c have some code too; they are
in gdk and gnome-libs respectively)

Here is an instructive function or two from Guppi:

 void set_pixel(const guint col, const guint row, // x, y
                 const guchar r, const guchar g, const guchar b)
    {
      guchar* pixel = buf_ + rowstride_*row + col*3;
      *pixel++ = r;
      *pixel++ = g;
      *pixel++ = b;
    }

  void set_pixel(const guint col, const guint row,  // x, y 
                 const guchar r, const guchar g, const guchar b,
                 const int alpha)
    {
      int v;
      guchar* pixel = buf_ + rowstride_*row + col*3;
      v = *pixel;
      *pixel++ = v + (((r - v) * alpha + 0x80) >> 8);
      v = *pixel;
      *pixel++ =  v + (((g - v) * alpha + 0x80) >> 8);
      v = *pixel;
      *pixel++ =  v + (((b - v) * alpha + 0x80) >> 8);
    }

The second variant includes an alpha channel. 

HTH, 
Havoc





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