GdkPixbuf questions



Hi all:
       I have some questions when I using the drawable area with the gtk+2.0.
First, I'm building a data analyzer under thr Linux, so there is a process to generate the data and  my analyzer display the data.
My idea is to use a drawable area(I use the GtkDrawingArea) and get the pix buffer of it by the gdk_pixbuf_get_from_drawable(), then my background program can fill the pix buffer pix by pix.

Question 1: anytime I fill to the pixbuf, it will rendering the drawing area immediately?
Question 2: the following code segment is what I done until now...what should I do?

Thanks.
Dave.

this function put_pixel is referenced from the GDK Reference Manual
 34 void
 35 put_pixel (GdkPixbuf *pixbuf, int x, int y, guchar red, guchar green, guchar blue, guchar alpha)
 36 {
 37   int width, height, rowstride, n_channels;
 38   guchar *pixels, *p;
 39
 40   n_channels = gdk_pixbuf_get_n_channels (pixbuf);
 41   g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
 42   g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
 43   g_assert (gdk_pixbuf_get_has_alpha (pixbuf));
 44   g_assert (n_channels == 4);
 45
 46   width = gdk_pixbuf_get_width (pixbuf);
 47   height = gdk_pixbuf_get_height (pixbuf);
 48
 49   g_assert (x >= 0 && x < width);
 50   g_assert (y >= 0 && y < height);
 51
 52   rowstride = gdk_pixbuf_get_rowstride (pixbuf);
 53   pixels = gdk_pixbuf_get_pixels (pixbuf);
 54
 55   p = pixels + y * rowstride + x * n_channels;
 56   p[0] = red;
 57   p[1] = green;
 58   p[2] = blue;
 59   p[3] = alpha;
 60 }


In the callbacks.c
function on_drawingarea_virtual_LCD_configure_event() is the callback function of my drawing area.

151 gboolean
152 on_drawingarea_virtual_LCD_configure_event        (GtkWidget       *widget,
153                                         GdkEventConfigure *event)
154 {
155   gint x,y;
156   GdkPixbuf* virtual_LCD_buf;
157   GdkRectangle rect;
158
159
160   if(virtual_LCD_pixmap)
161         g_object_unref(virtual_LCD_pixmap);
162
163   virtual_LCD_pixmap    = gdk_pixmap_new(widget->window,
164                           widget-> allocation.width,
165                           widget->allocation.height,
166                           -1);
167
168   gdk_window_get_origin (widget->window, &x, &y);
169   rect.x = x;
170   rect.y = y;
171   gdk_drawable_get_size (GDK_DRAWABLE (widget->window), &rect.width,
172   &rect.height);
173
174   virtual_LCD_buf = gdk_pixbuf_get_from_drawable(NULL,
175                                                  virtual_LCD_pixmap,
176                                                  gdk_colormap_get_system(),
177                                                  rect.x-x,
178                                                  rect.y-y,
179                                                  0,
180                                                  0,
181                                                  rect.width,
182                                                  rect.height
183                                                  );
184 gint i=0;
185 // I want to test the put_pixel when the drawing are establish.
186 for(i=0;i<100;i++){
187         put_pixel (virtual_LCD_buf, i, i, 255-i,255-i,255-(2*i),0);
188
189
190 }

 




--
System  on Chip Design  Lab.
Dept. of Computer Science and Information Engineering,
National Chung Cheng University
E-mail : s88 tw acm org

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