def get_pixels_slow(self, ximage):
''' Retrieve all pixels from a monitor. Pixels have to be RGB.
(!) Insanely slow version, see doc/linux-slow-version. (!)
'''
# @TODO: this part takes most of the time. Need a better solution.
def pix(pixel, _resultats={}, p__=pack):
''' Apply shifts to a pixel to get the RGB values.
This method uses of memoization.
'''
# pylint: disable=dangerous-default-value
if pixel not in _resultats:
_resultats[pixel] = p__('<B', (pixel & rmask) >> 16) + \
p__('<B', (pixel & gmask) >> 8) + \
p__('<B', pixel & bmask)
return _resultats[pixel]
self.width = ximage.contents.width
self.height = ximage.contents.height
rmask = ximage.contents.red_mask
bmask = ximage.contents.blue_mask
gmask = ximage.contents.green_mask
get_pix = self.xlib.XGetPixel
pixels = [pix(get_pix(ximage, x, y))
for y in range(self.height) for x in range(self.width)]
self.image = b''.join(pixels)
return self.image
评论列表
文章目录