pyqt  

[PyQt] Re: Efficiency under nested loop

Sergi Blanch i Torné
Fri, 25 Apr 2008 02:11:00 -0700

Hi,

On my stand alone conversation, the current solution of the looping is:
        def convertfrom(self,image,depth):
                if self._debug:
                        print "[PyImageViewer]convertfrom():"+str(int(bits*8))
                if depth == 1: # 8 bit grayscale
                        shift = 0
                elif depth == 1.5: # 12 bits non packet
                        shift = 4
                elif depth == 2: # 16 bits
                        shift = 8
                else:
                        raise "Not supported depth"
                return "".join(chr(i>>shift) for i in image )

The trapezoid problem continue here, but now at least I have a faster 
drawing...

/Sergi.
                        

On Thursday 24 April 2008 16:05:36 Sergi Blanch i Torné wrote:
> Hi,
>
> In the discussion about the QListWidget[1] I saw something that happens to
> me also with the QImage conversion from 12 bits to 8. Remember that I have
> a problem showing grayscaled images[2] I need to say that the data needs to
> be process and it means the solution cannot be simply acquire the pictures
> in 8 bits.
>
> Right now I write a loop for the list and then convert to the array of
> unsigned chars need by the QImage. It means touch each element two times.
> The code is:
>       #input: values list of the image
>       #output: array of unsigned chars for the QImage
>       def convertfrom(self,image,bits):
>               if self._debug:
>                       print "[PyImageViewer]convertfrom():"+str(int(bits*8))
>               if depth == 1: # 8 bit grayscale
>                       barfoo = image
>               elif depth == 1.5: # 12 bits unpacket
>                       bar,barfoo = image,[]
>                       for i in range(len(bar)):
>                               barfoo.append(bar[i].__lshift__(4))#shift to 
> loss 4 less significant
> bits #barfoo = bar
>               elif depth == 2: # 16 bits
>                       bar,barfoo = image,[]
>                       for i in range(len(bar)):
>                               barfoo.append(bar[i].__lshift__(8))#shift to 
> loss 4 less significant
> bits #barfoo = bar
>               else:
>                       raise "Not supported depth"
>               return array.array('B',barfoo).tostring()
>
> I am not sure but this tostring() call at the end, maybe means another
> third touch of all the elements to make it worst.
>
> Sano kaj liber!
>
> /Sergi.
>
> [1] http://www.riverbankcomputing.com/pipermail/pyqt/2008-April/019142.html
> [2] http://www.riverbankcomputing.com/pipermail/pyqt/2008-April/019130.html



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt