File tree Expand file tree Collapse file tree 1 file changed +7
-16
lines changed Expand file tree Collapse file tree 1 file changed +7
-16
lines changed Original file line number Diff line number Diff line change @@ -530,23 +530,14 @@ def get_pixels(self, monitor):
530530 if image is None :
531531 raise ValueError ('MSSLinux: XGetImage() failed.' )
532532
533- # TODO: how to optimize this part? pixels[offset:offset+3] is too long.
534- '''
535- pixels = [b'0'] * (3 * width * height)
536- for x in range(width):
537- for y in range(height):
538- pixel = self.XGetPixel(image, x, y)
539- blue = pixel & 255
540- green = (pixel & 65280) >> 8
541- red = (pixel & 16711680) >> 16
542- offset = (x + width * y) * 3
543- pixels[offset:offset+3] = b(red), b(green), b(blue)
544- #'''
545-
546- # This code is a little bit better (19% faster)
533+ resultats = {}
547534 def pix (pixel ):
548- ''' Apply shifts to a pixel to get the RGB values. '''
549- return b ((pixel & 16711680 ) >> 16 ) + b ((pixel & 65280 ) >> 8 ) + b (pixel & 255 )
535+ ''' Apply shifts to a pixel to get the RGB values.
536+ This method uses of memoization, reducing time by a factor of 4.
537+ '''
538+ if not pixel in resultats :
539+ resultats [pixel ] = b ((pixel & 16711680 ) >> 16 ) + b ((pixel & 65280 ) >> 8 ) + b (pixel & 255 )
540+ return resultats [pixel ]
550541
551542 get_pix = self .XGetPixel
552543 pixels = [pix (get_pix (image , x , y )) for y in range (height ) for x in range (width )]
You can’t perform that action at this time.
0 commit comments