Re: [pygtk] converting an Numeric array to a Pixbuf

2003-08-02 Thread Anthony Joseph Seward
On Wed, 2003-07-30 at 11:45, Christian Reis wrote:
 On Tue, Jul 29, 2003 at 09:27:45AM +1200, Tim Evans wrote:
  Anthony Joseph Seward wrote:
  
  I am trying to figure out a simple way of converting a Numeric array to
  a gtk.gdk.Pixbuf without depending on PIL.
 
 [snip]
 
  Assuming that you have a (n,m,3) or (n,m,4) shape 'b' type array of RGB 
  or RGBA values called 'data', you would do this:
  
  w,h = data.shape[:2]
  hasalpha = shape.shape[3] == 4
  p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, hasalpha, 8, w, h)
  p.pixel_array[:] = data
 
 Added as FAQ 8.3, thanks:
 
 http://www.async.com.br/faq/pygtk/index.py?req=showfile=faq08.003.htp
 
 Take care,

The PyGTK reference at 
http://www.moeraki.com/pygtkreference/pygtk2reference/class-gdkpixbuf.html
says
  Attributes
pixel_array
Read
A numeric ...
So according to the reference pixel_array is a read only attribute.  Is
the reference in error?

Tony

-- 
Anthony Joseph Seward [EMAIL PROTECTED]

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


Re: [pygtk] converting an Numeric array to a Pixbuf

2003-07-31 Thread Anthony Joseph Seward
On Wed, 2003-07-30 at 11:45, Christian Reis wrote:
 On Tue, Jul 29, 2003 at 09:27:45AM +1200, Tim Evans wrote:
  Anthony Joseph Seward wrote:
  
  I am trying to figure out a simple way of converting a Numeric array to
  a gtk.gdk.Pixbuf without depending on PIL.
 
 [snip]
 
  Assuming that you have a (n,m,3) or (n,m,4) shape 'b' type array of RGB 
  or RGBA values called 'data', you would do this:
  
  w,h = data.shape[:2]
  hasalpha = shape.shape[3] == 4
  p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, hasalpha, 8, w, h)
  p.pixel_array[:] = data
 
 Added as FAQ 8.3, thanks:
 
 http://www.async.com.br/faq/pygtk/index.py?req=showfile=faq08.003.htp
 
 Take care,

The PyGTK reference at
http://www.moeraki.com/pygtkreference/pygtk2reference/class-gdkpixbuf.html
says
  Attributes

pixel_array   Read   A numeric ...

So according to the reference pixel_array is a read only attribute.  Is
the reference in error?

Tony

-- 
Anthony Joseph Seward [EMAIL PROTECTED]

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


Re: [pygtk] converting an Numeric array to a Pixbuf

2003-07-31 Thread Tim Evans
p.pixel_array[:] = data
The PyGTK reference at
http://www.moeraki.com/pygtkreference/pygtk2reference/class-gdkpixbuf.html
says
  Attributes
pixel_array   Read   A numeric ...

So according to the reference pixel_array is a read only attribute.  Is
the reference in error?
The 'pixel_array' attribute is read-only in that you can't do 
'p.pixel_array = data'.  But it's not immutable, so you can still change 
it's contents, which is what the [:] slice assignment does.  The 
reference could probably make this more clear.

--
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] converting an Numeric array to a Pixbuf

2003-07-31 Thread James Henstridge
On 1/08/2003 4:46 AM, Anthony Joseph Seward wrote:

On Wed, 2003-07-30 at 11:45, Christian Reis wrote:
 

On Tue, Jul 29, 2003 at 09:27:45AM +1200, Tim Evans wrote:
   

Anthony Joseph Seward wrote:

 

I am trying to figure out a simple way of converting a Numeric array to
a gtk.gdk.Pixbuf without depending on PIL.
   

[snip]

   

Assuming that you have a (n,m,3) or (n,m,4) shape 'b' type array of RGB 
or RGBA values called 'data', you would do this:

w,h = data.shape[:2]
hasalpha = shape.shape[3] == 4
p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, hasalpha, 8, w, h)
p.pixel_array[:] = data
 

Added as FAQ 8.3, thanks:

http://www.async.com.br/faq/pygtk/index.py?req=showfile=faq08.003.htp

Take care,
   

The PyGTK reference at
http://www.moeraki.com/pygtkreference/pygtk2reference/class-gdkpixbuf.html
says
 Attributes
   pixel_array   Read   A numeric ...

So according to the reference pixel_array is a read only attribute.  Is
the reference in error?
 

You can't set the pixel_array attribute, but you can modify the existing 
value.  Note however that modifying the pixel data of some GdkPixbufs 
will cause a segfault (ones that are backed by a const string, such as 
the stock icons).  Pixbufs you create yourself are safe to modify though.

James.

--
Email: [EMAIL PROTECTED]
WWW:   http://www.daa.com.au/~james/


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


Re: [pygtk] converting an Numeric array to a Pixbuf

2003-07-31 Thread Tim Evans
Tim Evans wrote:
 [snip]
I'm not sure about 1.99.14, but 1.99.16 can be compiled with Numeric 
support.  If it is you can create a Pixbuf by modifying the array 
returned be accessing the 'pixel_array' attribute of an existing pixbuf.

Assuming that you have a (n,m,3) or (n,m,4) shape 'b' type array of RGB 
or RGBA values called 'data', you would do this:

w,h = data.shape[:2]
hasalpha = shape.shape[3] == 4
p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, hasalpha, 8, w, h)
p.pixel_array[:] = data
I just noticed that the above is only working because of luck.  The 
width and height of the pixbuf were being put in the array dimensions in 
the wrong order.  In some cases this can even cause a segfault.

See http://bugzilla.gnome.org/show_bug.cgi?id=118839 for a patch.

--
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] converting an Numeric array to a Pixbuf

2003-07-30 Thread Christian Reis
On Tue, Jul 29, 2003 at 09:27:45AM +1200, Tim Evans wrote:
 Anthony Joseph Seward wrote:
 
 I am trying to figure out a simple way of converting a Numeric array to
 a gtk.gdk.Pixbuf without depending on PIL.

[snip]

 Assuming that you have a (n,m,3) or (n,m,4) shape 'b' type array of RGB 
 or RGBA values called 'data', you would do this:
 
 w,h = data.shape[:2]
 hasalpha = shape.shape[3] == 4
 p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, hasalpha, 8, w, h)
 p.pixel_array[:] = data

Added as FAQ 8.3, thanks:

http://www.async.com.br/faq/pygtk/index.py?req=showfile=faq08.003.htp

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] converting an Numeric array to a Pixbuf

2003-07-28 Thread Anthony Joseph Seward
I am trying to figure out a simple way of converting a Numeric array to
a gtk.gdk.Pixbuf without depending on PIL.

I am having a hard time finding documentation on how to make an RGB XPM
file or even if it is possible.

gdk_pixbuf_new_from_data seems like is what I want, but it does not
appear to be wrapped in pygtk 1.99.14.

Any suggestions?

Tony
-- 
Anthony Joseph Seward [EMAIL PROTECTED]

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


Re: [pygtk] converting an Numeric array to a Pixbuf

2003-07-28 Thread Christian Reis
On Mon, Jul 28, 2003 at 01:55:42PM -0600, Anthony Joseph Seward wrote:
 gdk_pixbuf_new_from_data seems like is what I want, but it does not
 appear to be wrapped in pygtk 1.99.14.
 
 Any suggestions?

IIRC it's wrapped in CVS HEAD. Give it a go.

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/