Re: Drawing an image from a slow-scan transmission
- From: Havoc Pennington <hp redhat com>
- To: Neoklis <neok spidernet com cy>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Drawing an image from a slow-scan transmission
- Date: Mon, 11 Nov 2002 22:18:46 -0500
On Sun, Nov 10, 2002 at 03:40:25PM +0200, Neoklis wrote:
I already have a console app (tool) written, that decodes weather
images from satellites transmitting in the APT format. At the
moment this app produces PGM image files after finishing with the
satellite pass. I intend to port this to GTK+ and arrange it to
display the incoming image line-by-line as it is decoded. So what
I need is a suitable way to plot the line of pixels on the screen
(in 8-bit gray levels) so that the image can be seen to form, one
line at a time. Pixel rate is quite slow (2 lines of 696 8-bit
pixels per second) with an average of about 800-900 lines per
image. So I think the recommendation of the FAQ not to use
gdk_draw_point() may not apply here.
If so, I would appreciate some general pointers on how to proceed
with this objective.
Indeed, gdk_draw_point() doesn't sound likely to be your bottleneck.
Still (assuming GTK 2.0), what I would do is just create a GdkPixbuf
at the expected size, gdk_pixbuf_fill() to your background color,
then as the lines come in set those pixels in the pixbuf. A pixbuf
is a block of RGB or RGBA data, one byte for each channel (R, G, B, A
being channels):
unsigned char *pixels;
unsigned char *p;
int rowstride;
int n_channels;
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
FALSE, 8, width, height);
if (pixbuf == NULL)
/* error, not enough memory */;
/* fill with opaque white */
gdk_pixbuf_fill (pixbuf, 0xffffffff);
/* get details of pixbuf */
pixels = gdk_pixbuf_get_pixels (pixbuf);
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
n_channels = gdk_pixbuf_get_n_channels (pixbuf);
/* Find the pixel (3 or 4 bytes depending on n_channels) at x,y */
p = (y * rowstride) + x * n_channels;
/* Assign R,G,B to our grayscale value and leave alpha as-is */
p[0] = gray_value; /* r */
p[1] = gray_value; /* g */
p[2] = gray_value; /* b */
p[3] = gray_value; /* a */
/* create a widget to display the pixbuf */
image = gtk_image_new_from_pixbuf (pixbuf);
/* put it in a window and display */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_container_add (GTK_CONTAINER (window), image);
gtk_widget_show_all (window);
Each time you modify the pixbuf to add new data,
gtk_widget_queue_draw() on the image (or for bonus points,
gtk_widget_queue_draw_area() only the changed pixels).
gtk-demo has lots of example code that probably applies.
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]