Your grey data does not seem to be 128*128 bytes long, which is probably
causing the problem. If you want to tile the data, you will need to make
multiple calls to draw_gray_image. Also, the rowstride value (the last
one should usually be >= width and for rgb data, >= 3*width.
The idea of rowstride is to allow you to display only a portion of the
image data. With the simple 6 bytes of image data I gave in my last
message, if you treat it as a 3x2 area and want to display the first
column, you would draw it with width 1, height 2 and rowstride 3. If you
have Numeric python installed, the draw_array function will handle setting
rowstride for you with sliced arrays (note that slicing numeric python
arrays does not involve a copy operation on the data).
James.
--
Email: [EMAIL PROTECTED]
WWW: http://www.daa.com.au/~james/
On Wed, 20 Oct 1999, Remi Delon wrote:
> I downloaded pygtk0.6.3 (because I only had 0.6.1 before, and it didn't do
> gdkrgb stuff).
> When I run the following program :
> from gtk import *
> from GDK import *
> def expose_event(da, event):
> grey_data="\000\177\377\377\177\000"
> gc=da.get_style().fg_gc[STATE_NORMAL]
> da.draw_gray_image(gc, 0, 0, 128, 128, RGB_DITHER_NORMAL, grey_data,3)
> return FALSE
> win=GtkWindow()
> da=GtkDrawingArea()
> da.size(3,2)
> da.connect("expose_event", expose_event)
> da.show()
> win.add(da)
> win.show()
> mainloop()
>
> I get the error : Illegal instruction (core dump)
> I froze my python program, ran it again and dumped the stack with dbx. Here
> is the result:
> (dbx) where
> warning: could not locate trace table from starting address 0x0
> gdk_draw_rgb_image_core(0x20165288, 0x20162618, 0x0, 0x0, 0x80, 0x80,
> 0x201251ac, 0x1), line 3008 in "gdkrgb.c"
> gdk_draw_gray_image(0x20165288, 0x20162618, 0x0, 0x0, 0x80, 0x80, 0x1,
> 0x201251ac), line 3120 in "gdkrgb.c"
> _wrap_gdk_draw_gray_image(0x0, 0x20145708) at 0x10039e84
> call_builtin(??, ??, ??) at 0x1001f04c
> PyEval_CallObjectWithKeywords(??, ??, ??) at 0x10022b94
> eval_code2(??, ??, ??, ??, ??, ??, ??, ??) at 0x10021cf8
> eval_code2(??, ??, ??, ??, ??, ??, ??, ??) at 0x10021bd0
> call_function(??, ??, ??) at 0x1001eec0
> PyEval_CallObjectWithKeywords(??, ??, ??) at 0x10022b80
> builtin_apply(??, ??) at 0x102a2e54
> call_builtin(??, ??, ??) at 0x1001f04c
> PyEval_CallObjectWithKeywords(??, ??, ??) at 0x10022b94
> eval_code2(??, ??, ??, ??, ??, ??, ??, ??) at 0x10021cf8
> call_function(??, ??, ??) at 0x1001eec0
> PyEval_CallObjectWithKeywords(??, ??, ??) at 0x10022b80
> PyObject_CallObject(??, ??) at 0x10026bb4
> PyGtk_CallbackMarshal(0x20160af8, 0x20142f38, 0x1, 0x2ff20a48) at 0x1007dbdc
> unnamed block $b499, line 1898 in "gtksignal.c"
> gtk_handlers_run(0x2025cb68, 0x2ff20990, 0x20160af8, 0x2ff20a48, 0x0), line
> 1898 in "gtksignal.c"
> unnamed block $b504, line 1469 in "gtksignal.c"
> gtk_signal_real_emit(0x20160af8, 0x19, 0x2ff20a48), line 1469 in
> "gtksignal.c"
> gtk_signal_emit(0x20160af8, 0x19, 0x2ff20e20, 0x2ff20da0, 0x20145798, 0x0,
> 0x2011582c, 0x0), line 552 in "gtksignal.c"
> gtk_widget_event(0x20160af8, 0x2ff20e20), line 2790 in "gtkwidget.c"
> gtk_widget_real_draw(0x20160af8, 0x2ff21364), line 4530 in "gtkwidget.c"
> gtk_marshal_NONE__POINTER(0x20160af8, 0x20115904, 0x0, 0x2ff20f98), line 225
> in "gtkmarshal.c"
> gtk_signal_real_emit(0x20160af8, 0x8, 0x2ff20f98), line 1432 in
> "gtksignal.c"
> gtk_signal_emit(0x20160af8, 0x8, 0x2ff21364, 0x0, 0x0, 0x8, 0x80000, 0x0),
> line 552 in "gtksignal.c"
> gtk_widget_draw(0x20160af8, 0x2ff21364), line 2312 in "gtkwidget.c"
> gtk_bin_draw(0x20145808, 0x202600dc), line 175 in "gtkbin.c"
> gtk_window_draw(0x20145808, 0x202600dc), line 1722 in "gtkwindow.c"
> gtk_marshal_NONE__POINTER(0x20145808, 0x20115214, 0x0, 0x2ff21528), line 225
> in "gtkmarshal.c"
> gtk_signal_real_emit(0x20145808, 0x8, 0x2ff21528), line 1432 in
> "gtksignal.c"
> gtk_signal_emit(0x20145808, 0x8, 0x202600dc, 0x0, 0x0, 0x10, 0x20167510,
> 0x2ff21918), line 552 in "gtksignal.c"
> gtk_widget_draw(0x20145808, 0x202600dc), line 2312 in "gtkwidget.c"
> unnamed block $b686, line 2235 in "gtkwidget.c"
> unnamed block $b685, line 2235 in "gtkwidget.c"
> gtk_widget_idle_draw(0x0), line 2235 in "gtkwidget.c"
> g_idle_dispatch(0x201157e4, 0x2ff21a88, 0x0), line 1348 in "gmain.c"
> unnamed block $b866, line 652 in "gmain.c"
> unnamed block $b865, line 652 in "gmain.c"
> g_main_dispatch(0x2ff21a88), line 652 in "gmain.c"
> g_main_iterate(0x1, 0x1), line 870 in "gmain.c"
> g_main_run(0x20162018), line 928 in "gmain.c"
> gtk_main(), line 475 in "gtkmain.c"
> _wrap_gtk_main(0x0, 0x2011ef08) at 0x10073cc0
> call_builtin(??, ??, ??) at 0x1001f04c
> PyEval_CallObjectWithKeywords(??, ??, ??) at 0x10022b94
> eval_code2(??, ??, ??, ??, ??, ??, ??, ??) at 0x10021cf8
> eval_code2(??, ??, ??, ??, ??, ??, ??, ??) at 0x10021bd0
> PyEval_EvalCode(??, ??, ??) at 0x10022524
> PyImport_ExecCodeModuleEx(??, ??, ??) at 0x10094134
> PyImport_ImportFrozenModule(??) at 0x100931cc
> Py_FrozenMain(??, ??) at 0x100003b4
> main(??, ??) at 0x1000026c
> (dbx)
>
> I'm starting to think there is something wrong with my gtk libraries.
> (Although everything
> I've used so far worked fine).
> I looked for a C example that uses gdkrgb, to validate that my gtk libraries
> are okay,
> but I could'nt find any.
>
> I'm on AIX4.2 and I'm using gtk 1.2.3
>
> Do you have any ideas ?
>
> Thanks
>
> Remi.
>
> PS : What's the last argument to draw_gray_image (rowstride) ?
> If I give a different width and height for the image than its original
> size, is
> it going to expand/shrink the image, or crop it ?
>
>
> > -----Original Message-----
> > From: James Henstridge [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, October 18, 1999 6:59 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: [pygtk] Greyscale images with imlib
> >
> >
> > I don't know if it does grey scale images (it may convert
> > them to 24 bit
> > RGB internally if you load one from a file). The
> > create_image_from_data()
> > routine expects 24-bit RGB image data as well. If all you
> > want to do is
> > display greyscale data to the screen, you could use the
> > gdkrgb code (which
> > does handle greyscale images -- it is the display code gimp uses).
> >
> > You use the draw_gray_image() function in gtk.py for this.
> > It can draw to
> > any GdkWindow. The GtkDrawingArea widget is probably the one
> > you would
> > want to draw on. The GtkDrawingArea also has all the
> > draw_*() functions
> > as methods to make things a bit easier. Here is a bit of
> > example code:
> >
> > grey_data = "\000\177\377\377\177\000"
> >
> > da = GtkDrawingArea()
> > da.size(3,2)
> >
> > def expose_event(da, event):
> > da.draw_gray_image(da.get_style[STATE_NORMAL].white_gc,
> > 0,0, 3,2, GDK.RGB_DITHER_NORMAL,
> > grey_data, 3)
> > return FALSE
> > da.connect("expose_event", expose_event)
> >
> > This code can probably be optimised by looking at the area
> > that should be
> > redrawn and only drawing it without much trouble. There is also a
> > draw_array() function that will render a Numeric Python array to a
> > drawable. It takes a nxm or nxmx1 array of unsigned bytes
> > (interpreted as
> > grey data) or a nxmx3 or nxmx4 array of unsigned bytes
> > (interpreted as RGB
> > data). It will also handle arrays that have been sliced
> > along the first
> > two axes, if you only want to display only part of the data.
> > This gives
> > you all the power of numpy for manipulating the data as well.
> > Note that
> > pygtk/gnome-python must have been compiled after numpy for
> > this code to be
> > enabled.
> >
> > James.
> >
> > --
> > Email: [EMAIL PROTECTED]
> > WWW: http://www.daa.com.au/~james/
> >
> >
> > On Mon, 18 Oct 1999, Remi Delon wrote:
> >
>
> To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]
>
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]