Something like?

>>> a=numpy.array([1,2,3,4,5,6,7,8])
>>> b=a.reshape(2,4).copy()
>>> b
array([[1, 2, 3, 4],
       [5, 6, 7, 8]])
>>> b[:,0]=a.reshape(2,4)[:,2].copy()
>>> b[:,2]=a.reshape(2,4)[:,0].copy()
>>> b
array([[3, 2, 1, 4],
       [7, 6, 5, 8]])
See also http://www.mail-archive.com/numpy-discussion@scipy.org/msg18651.html
Ray

At 11:53 AM 5/31/2011, Tim Roberts wrote:
Greg Ewing wrote:
> Can anyone think of an efficient way to convert a string
> full of RGBA image data to BGRA, using only what's available
> in the standard library?
>
> I'm trying to add a function to PyGUI for creating an Image
> object from arbitrary data. The problem I'm having is that
> GDI+ on Windows expects BGRA, whereas most other platforms
> deal with RGBA. I don't want to require the user to supply
> the data in different formats on different platforms, so
> PyGUI needs to be able to convert where necessary.
>
> I know the conversion can be done easily using something
> like PIL or numpy, but I'm after a solution that doesn't
> depend on any third-party libraries.

Nothing other than brute force.

  bout = []
  for i in range(0,len(bin),4):
    bout.extend( [bin[i+2], bin[i+1], bin[i], bin[i+3]) )

It ain't gonna be quick.  If it were me, I'd rather ship PIL.

--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to