numpy.frombuffer != unpack() ??

Marlin Rowley marlin_rowley at hotmail.com
Fri May 16 20:36:44 EDT 2008


Ok.  Here's the deal.. 
 
I've gathered a string of bytes that are turned into floats and stored in an array of floats.
 
The stream gives me color channels represented in bytes.
 
stream = 'rrrrrrrrggggggggggbbbbbbbbbaaaaaaaaarrrrrrrrrrrggggggggggbbbbbbbbbbaaaaaaaa......' etc.. 
 
the number of r's,g's,b's in one consecutive pattern represent the width of a bitmap.  The number of times the pattern (rgba) is repeated gives the height of the bitmap.  I must first convert these bytes into floats.  The rgba represents floating point values for each of the pixel components.  I've gotten that far.
 
Now I have an array of individual floats with that pattern.  I need to:
 
1) pull out the alphas from this float list.
2) reshape this float list so that I have an array that seperates the repeated pattern into a height of this bitmap: 
 
rrrrrrrrrrrgggggggggggbbbbbbbbb [0] - first pattern
...
rrrrrrrrrrrgggggggggggbbbbbbbbb [height-1] - last pattern
 
3) then I need to reverse this array so that height-1 is the first element in my new array:
 
rrrrrrrrrrrgggggggggggbbbbbbbbb [height-1]
...
rrrrrrrrrrrgggggggggggbbbbbbbbb [0]
 
since wx.Python reverses the y-axis in a bitmap
 
4) Then I need to make the pattern another pattern:
rrrrrrrrrrrgggggggggggbbbbbbbbb ---> needs to become ---> rgbrgbrgb.... starting at [height-1] (my first pattern in my new array).
 
5) Then I need to flatten the array to one continuous array of floats:
 
rgbrgbrgbrgb[from height-1]............rgbrgbrgb[height = 0]
 
this is my final array to be drawn on the screen!
 
 
 
 



> To: python-list at python.org> From: robert.kern at gmail.com> Subject: Re: numpy.frombuffer != unpack() ??> Date: Fri, 16 May 2008 18:50:38 -0500> > Marlin Rowley wrote:> > All:> > > > Say I have an array:> > > > a = (['rrrrggggbbbbaaaa'],['rrrrggggbbbbaaaa'])> > I'm sorry, you are going to have to be less elliptical. Exactly what do you have > there? It's certainly not an array, but a tuple of single-element lists each > containing a single string which can be interpreted as a group of 4 IEEE-754 > single-precision floats. Is this correct? Do you really have single-element > lists? Some more context would be nice (can the tuple be longer? can the lists > be longer? can the strings be longer? etc.).> > But basically, I would concatenate all of the strings together in the correct > order and use numpy.fromstring() on the resulting string.> > And please, just respond to the list. I read this through GMane, and I don't > like getting duplicates in my in-box.> > -- > Robert Kern> > "I have come to believe that the whole world is an enigma, a harmless enigma> that is made terrible by our own mad attempt to interpret it as though it had> an underlying truth."> -- Umberto Eco> > --> http://mail.python.org/mailman/listinfo/python-list
_________________________________________________________________
Keep your kids safer online with Windows Live Family Safety.
http://www.windowslive.com/family_safety/overview.html?ocid=TXT_TAGLM_WL_Refresh_family_safety_052008
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080516/a0316eb8/attachment-0001.html>


More information about the Python-list mailing list