From b7692c5bc08e8874a4a4520f1326d09086f7d1f5 Mon Sep 17 00:00:00 2001 From: buddsean Date: Mon, 2 Aug 2021 10:11:34 +1000 Subject: [PATCH] use screenBitmap --- .../screenCurtain.py | 37 +++++-------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/source/visionEnhancementProviders/screenCurtain.py b/source/visionEnhancementProviders/screenCurtain.py index 6942f26f3b3..bd94c1a45c8 100644 --- a/source/visionEnhancementProviders/screenCurtain.py +++ b/source/visionEnhancementProviders/screenCurtain.py @@ -1,7 +1,7 @@ # A part of NonVisual Desktop Access (NVDA) # This file is covered by the GNU General Public License. # See the file COPYING for more details. -# Copyright (C) 2018-2019 NV Access Limited, Babbage B.V., Leonard de Ruijter +# Copyright (C) 2018-2021 NV Access Limited, Babbage B.V., Leonard de Ruijter """Screen curtain implementation based on the windows magnification API. The Magnification API has been marked by MS as unsupported for WOW64 applications such as NVDA. (#12491) @@ -22,6 +22,8 @@ from typing import Optional, Type import nvwave import globalVars +from screenBitmap import ScreenBitmap +from itertools import chain class MAGCOLOREFFECT(Structure): @@ -302,35 +304,16 @@ def confirmInitWithUser(self) -> bool: def isScreenFullyBlack() -> bool: """ - Uses wx to check that the screen is currently fully black by taking a screen capture and checking: - - there is only one colour used in the image - - the first pixel of the screen capture is black + Uses ScreenBitmap to check that the screen is currently fully black by taking a screen capture and + checking the colour of each pixel. """ screen = wx.ScreenDC() screenSize = screen.GetSize() - bmp: wx.Bitmap = wx.Bitmap(screenSize[0], screenSize[1]) - mem = wx.MemoryDC(bmp) - mem.Blit(0, 0, screenSize[0], screenSize[1], screen, 0, 0) # copy screen over to bmp - del mem # Release bitmap - img: wx.Image = bmp.ConvertToImage() - # https://docs.wxwidgets.org/3.0/classwx_image.html#a7c9d557cd7ad577ed76e4337b1fd843a - hist = wx.ImageHistogram() - numberOfColours = img.ComputeHistogram(hist) - # Due to wxImageHistogram not fully supported in wxPython, the histogram is not subscriptable, - # and thus the key value cannot be accessed for colours. - # https://github.com/wxWidgets/Phoenix/issues/1991 - # This function could be improved in the future using the following logic: - # numberOfBlackPixelsKey = hist.MakeKey(255, 255, 255) - # numberOfBlackPixels = hist[numberOfBlackPixelsKey] - # numberOfDisplayPixels = screenSize[0] * screenSize[1] - # log.debug(f"""Screen Capture: - # - number of colours: {numberOfColours} - # - number of black pixels: {numberOfBlackPixels} - # - number of total pixels: {numberOfDisplayPixels} - # """) - # return numberOfColours == 1 and numberOfBlackPixels == numberOfDisplayPixels - firstPixelIsBlack = img.GetRed(0, 0) == 0 and img.GetBlue(0, 0) == 0 and img.GetGreen(0, 0) == 0 - return numberOfColours == 1 and firstPixelIsBlack + screenCapture = ScreenBitmap(screenSize[0], screenSize[1]).captureImage(0, 0, screenSize[0], screenSize[1]) + for pixel in chain.from_iterable(screenCapture): + if not (pixel.rgbRed == 0 and pixel.rgbGreen == 0 and pixel.rgbBlue == 0): + return False + return True class ScreenCurtainInitializationError(RuntimeError):