Re: gdk_draw_gray_image.
- From: Patrice St-Gelais <patrice st-gelais oricom ca>
- To: "Klein, Lisa L." <Lisa Klein jhuapl edu>, "gtk-app-devel-list gnome org" <gtk-app-devel-list gnome org>
- Subject: Re: gdk_draw_gray_image.
- Date: Tue, 05 Feb 2002 21:04:41 -0500
Hi,
I don't think your can write directly into a GdkWindow.
I coded something similar some time ago. I wrote the data in a GdkPixmap *,
which was created with
gdk_pixmap_new (image_area->window,
image_area->allocation.width,
image_area->allocation.height, -1);
... in a "configure_event" connected to "image_area". "image_area" is created
with gtk_image_area_new();
Here is the example, if it can help - it was intended to draw continuously a
scanned image coming from a "popened" FILE *:
typedef struct {
guchar *image_buf;
gint image_depth; /* 1, 8, 24 bits */
gint x;
gint y;
} rgbbuftype;
void read_image_in_pixmap(FILE *pipeline, rgbbuftype *rgbbuf,
GtkWidget *image_area, int ifdisplay, GdkPixmap *pixmap)
{
// Draws continuously the image in the backup pixmap,line by line
int i,j,k,x,y,linesize,charread;
char c;
// We round linesize for bitmaps
linesize = (int) (rgbbuf->x+(rgbbuf->image_depth==1?7:0)) *
rgbbuf->image_depth / 8;
for (y=0; y<rgbbuf->y; y++) {
switch (rgbbuf->image_depth) {
case 1:
k=0;
for (i=0; i < linesize; i++) {
c = fgetc(pipeline);
// Expand each bit - image_buf is initialised with 0x00's
for (j=0; j<8 ; j++) {
if (! (c & (guchar) (0x80 >> j)))
*(rgbbuf->image_buf+(y*rgbbuf->x)+k) = '\377';
if (k++ == rgbbuf->x) break;
}
}
if (ifdisplay)
gdk_draw_gray_image(pixmap, image_area->style->black_gc,
0, y, rgbbuf->x, 1, GDK_RGB_DITHER_NONE,
rgbbuf->image_buf+(y*rgbbuf->x), rgbbuf->x);
break;
case 8 :
charread=fread(rgbbuf->image_buf+(y*linesize),1,linesize,pipeline);
if (ifdisplay)
gdk_draw_gray_image(pixmap, image_area->style->black_gc,
0, y, rgbbuf->x, 1, GDK_RGB_DITHER_NONE,
rgbbuf->image_buf+(y*linesize), linesize);
break;
case 24 :
charread=fread(rgbbuf->image_buf+(y*linesize),1,linesize,pipeline);
if (ifdisplay)
gdk_draw_rgb_image(pixmap, image_area->style->black_gc,
0, y, rgbbuf->x, 1, GDK_RGB_DITHER_NONE,
rgbbuf->image_buf+(y*linesize), linesize);
} // switch
if (ifdisplay) Repaint(0,y,rgbbuf->x,1);
} // for
if (ifdisplay) {
draw_selection(pixmap, invert_gc);
Repaint(0,0,image_area->allocation.width,image_area->allocation.height);
}
return;
}
Regards,
Patrice St-Gelais
_____________________________________
"Klein, Lisa L." a écrit :
I am attempting to draw an image line-by-line from data received one row at
a time. Currently, I am reading the data from a file, one line at a time,
and I either get an empty window that hangs, or a "BadMatch (invalid
parameter attributes)" error: "serial 119 error_code 8 request _code 72
minor_code 0". I know that the error has something to do with the
combination of the imagewidth, imageheight, and stride parameters to
gdk_draw_gray_image(). I used GLADE to create a window and a drawing_area
with an expose_event signal callback (code follows).
gboolean on_drawingarea1_expose_event (GtkWidget *widget, GdkEventExpose
*event, gpointer user_data)
{
FILE *fd;
int count=0, i;
unsigned char inbuf[43];
guchar *pixbuf;
/* Data file which is 43 columns wide and very long */
fd = fopen("datafile.dat", "r");
/* Read fifty lines of data from file as a test */
for(i=0; i<50; i++)
{
/* Each element in file is an 8-bit grayscale value */
count = fread(inbuf, sizeof(unsigned char), 43, fd);
pixbuf = inbuf;
gdk_draw_gray_image(widget->window,
widget->style->fg_gc[GTK_STATE_NORMAL],
0, i, 43, 1,GDK_RGB_DITHER_NORMAL,
pixbuf, 43);
}
return FALSE;
}
I think the problem might be that the function is meant to draw an entire
image at once and fill the drawable space. I have exhausted my resources, so
any insight anyone might provide would be helpful. Thanks.
Lisa
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]