[pygtk] Per pixel access to a pixbuf

2006-06-25 Thread BJörn Lindqvist

I need to do lots of per-pixel manipulation of gdk.Pixbufs. First i
started with pure Python because it was the simplest:

pixels = pixbuf.get_pixels()
for y in range(pixbuf.get_height()):
   for x in range(pixbuf.get_width()):
   [do some manipulation with the pixel at (x, y)]
[return a new pixbuf]

But that was to slow so I tried doing the same thing with Numeric:

pixelarr = pixbuf.get_pixels_array()
for y in range(pixbuf.get_heihgt()):
   for x in range(pixbuf.get_width()):
   pixel = pixelarr[y, x]
   [do something with pixel]
   pixelarr[y, x] = pixel

But that was even slower. Element access in Numeric is really freaking
dirt slow. So now I'm trying to create a Pyrex extension module
instead to do it. Problem is that pixbuf.get_pixels() return a Python
string and therefore is immutable. In pure C, I could have written
something like:

char *pixels = gdk_pixbuf_get_pixels(pixbuf);
int width = gdk_pixbuf_get_width(pixbuf);
for (int y = 0; y < gdk_pixbuf_get_height(pixbuf); y++)
   for (int x = 0; x < width; x++)
   {
   char *pixel = &pixels[(y * width + x) * 4];
   [ do something with pixel]
   }

I somehow need to get to the mutable char pointer array of pixel data
so that I can manipulate my pixbuf efficiently. gdk.Pixbuf doesn't
have a method for that. So I think that I need to somehow "cast" my
Python reference to the gdk.Pixbuf to a C reference to GdkPixbuf so
that I then can call gdk_pixbuf_get_pixels() on it. How do I do it?

Thanks in advance.

--
mvh Björn
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] faq 23.34 How can I use gtk.binding_entry_add

2006-06-25 Thread Paul Malherbe
Gustavo J. A. M. Carneiro wrote:
> Sex, 2006-06-23 às 09:25 +0200, Paul Malherbe escreveu:
>   
>> Hi all
>>
>> Please could someone help me with this problem.
>>
>> Why does the following script, as per the faq, work under linux but not
>> under windows.
>>
>> --
>> import sys
>> import pygtk
>> if sys.platform != "win32": pygtk.require("2.0")
>> import gtk, gobject
>>
>> class MyWindow(gtk.Window):
>> __gsignals__ = dict(\
>> mywindo=(gobject.SIGNAL_RUN_LAST|gobject.SIGNAL_ACTION,None,(str,)))
>> 
>
> put here:
>   gobject.type_register(MyWindow)
>
>   Regards,
>
>   
Thanks, that works great!

Paul
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] faq 23.34 How can I use gtk.binding_entry_add

2006-06-25 Thread Gustavo J. A. M. Carneiro
Sex, 2006-06-23 às 09:25 +0200, Paul Malherbe escreveu:
> Hi all
> 
> Please could someone help me with this problem.
> 
> Why does the following script, as per the faq, work under linux but not
> under windows.
> 
> --
> import sys
> import pygtk
> if sys.platform != "win32": pygtk.require("2.0")
> import gtk, gobject
> 
> class MyWindow(gtk.Window):
> __gsignals__ = dict(\
> mywindo=(gobject.SIGNAL_RUN_LAST|gobject.SIGNAL_ACTION,None,(str,)))

put here:
  gobject.type_register(MyWindow)

  Regards,

-- 
Gustavo J. A. M. Carneiro
<[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
The universe is always one step beyond logic

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/