unpack() exploration!

Marlin Rowley marlin_rowley at hotmail.com
Thu May 15 11:59:59 EDT 2008


All:

I've got a script that runs really slow because I'm reading from a stream a byte at a time:

// TERRIBLE
for y in range( height ):
        for color in range(4):
            for x in range( width ):
                    pixelComponent = fileIO.read(4)
                    buffer = unpack("!f",pixelComponent)  << unpacks ONE float, but we now can do something with that pixel component.


I can speed this up dramatically if I did this:

// MUCH FASTER
for y in range( height ):
    for color in range(4):
        pixelComponent = fileIO.read(4*width) <<<<<<<<<  GET a LOT more data from the stream into memory FIRST!!
        for x in range( width ):
           buffer = unpack( ?????? ) <<<< how do I get each float from the pixelComponent???


-M



_________________________________________________________________
Windows Live SkyDrive lets you share files with faraway friends.
http://www.windowslive.com/skydrive/overview.html?ocid=TXT_TAGLM_WL_Refresh_skydrive_052008
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080515/1530540d/attachment.html>


More information about the Python-list mailing list