Hello community,

here is the log from the commit of package python-PyScreeze for 
openSUSE:Factory checked in at 2019-06-18 14:59:32
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-PyScreeze (Old)
 and      /work/SRC/openSUSE:Factory/.python-PyScreeze.new.4811 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-PyScreeze"

Tue Jun 18 14:59:32 2019 rev:6 rq:710520 version:0.1.21

Changes:
--------
--- /work/SRC/openSUSE:Factory/python-PyScreeze/python-PyScreeze.changes        
2019-03-11 13:51:36.469258395 +0100
+++ 
/work/SRC/openSUSE:Factory/.python-PyScreeze.new.4811/python-PyScreeze.changes  
    2019-06-18 14:59:34.441291265 +0200
@@ -1,0 +2,6 @@
+Tue Jun 18 09:11:09 UTC 2019 - Tomáš Chvátal <[email protected]>
+
+- Update to 0.1.21:
+  * Fix memory leak at pixel().
+
+-------------------------------------------------------------------

Old:
----
  PyScreeze-0.1.20.tar.gz

New:
----
  PyScreeze-0.1.21.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-PyScreeze.spec ++++++
--- /var/tmp/diff_new_pack.Rs0NAH/_old  2019-06-18 14:59:35.473290754 +0200
+++ /var/tmp/diff_new_pack.Rs0NAH/_new  2019-06-18 14:59:35.497290742 +0200
@@ -18,7 +18,7 @@
 
 %{?!python_module:%define python_module() python-%{**} python3-%{**}}
 Name:           python-PyScreeze
-Version:        0.1.20
+Version:        0.1.21
 Release:        0
 Summary:        A screenshot Python module
 License:        BSD-3-Clause

++++++ PyScreeze-0.1.20.tar.gz -> PyScreeze-0.1.21.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/PyScreeze-0.1.20/PKG-INFO 
new/PyScreeze-0.1.21/PKG-INFO
--- old/PyScreeze-0.1.20/PKG-INFO       2019-03-08 06:14:58.000000000 +0100
+++ new/PyScreeze-0.1.21/PKG-INFO       2019-05-17 19:19:10.000000000 +0200
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: PyScreeze
-Version: 0.1.20
+Version: 0.1.21
 Summary: A simple, cross-platform screenshot module for Python 2 and 3.
 Home-page: https://github.com/asweigart/pyscreeze
 Author: Al Sweigart
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/PyScreeze-0.1.20/PyScreeze.egg-info/PKG-INFO 
new/PyScreeze-0.1.21/PyScreeze.egg-info/PKG-INFO
--- old/PyScreeze-0.1.20/PyScreeze.egg-info/PKG-INFO    2019-03-08 
06:14:57.000000000 +0100
+++ new/PyScreeze-0.1.21/PyScreeze.egg-info/PKG-INFO    2019-05-17 
19:19:09.000000000 +0200
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: PyScreeze
-Version: 0.1.20
+Version: 0.1.21
 Summary: A simple, cross-platform screenshot module for Python 2 and 3.
 Home-page: https://github.com/asweigart/pyscreeze
 Author: Al Sweigart
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/PyScreeze-0.1.20/pyscreeze/__init__.py 
new/PyScreeze-0.1.21/pyscreeze/__init__.py
--- old/PyScreeze-0.1.20/pyscreeze/__init__.py  2019-03-08 05:57:59.000000000 
+0100
+++ new/PyScreeze-0.1.21/pyscreeze/__init__.py  2019-05-17 19:17:56.000000000 
+0200
@@ -10,7 +10,7 @@
 http://ubuntuforums.org/showthread.php?t=1751455
 """
 
-__version__ = '0.1.20'
+__version__ = '0.1.21'
 
 import collections
 import datetime
@@ -24,6 +24,7 @@
     from PIL import ImageOps
 except ImportError:
     pass
+from contextlib import contextmanager
 
 try:
     import cv2, numpy
@@ -68,6 +69,17 @@
 if sys.platform == 'win32':
     from ctypes import windll
 
+    # win32 DC(DeviceContext) Manager
+    @contextmanager
+    def __win32_openDC(hWnd):
+        hDC = windll.user32.GetDC(hWnd)
+        if hDC == 0: #NULL
+            raise WindowsError("windll.user32.GetDC failed : return NULL")
+        try:
+            yield hDC
+        finally:
+            if windll.user32.ReleaseDC(hWnd, hDC) == 0:
+                raise WindowsError("windll.user32.ReleaseDC failed : return 0")
 
 Box = collections.namedtuple('Box', 'left top width height')
 Point = collections.namedtuple('Point', 'x y')
@@ -103,6 +115,8 @@
         # don't try to convert an already-gray image to gray
         if grayscale and len(img.shape) == 3:  # and img.shape[2] == 3:
             img_cv = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
+        else:
+            img_cv = img
     elif hasattr(img, 'convert'):
         # assume its a PIL.Image, convert to cv format
         img_array = numpy.array(img.convert('RGB'))
@@ -159,7 +173,7 @@
         if USE_IMAGE_NOT_FOUND_EXCEPTION:
             raise ImageNotFoundException('Could not locate the image (highest 
confidence = %.3f)' % result.max())
         else:
-            return None
+            return
 
     # use a generator for API consistency:
     matchx = matches[1] * step + region[0]  # vectorized
@@ -258,7 +272,7 @@
         if USE_IMAGE_NOT_FOUND_EXCEPTION:
             raise ImageNotFoundException('Could not locate the image.')
         else:
-            return None
+            return
 
 
 def locate(needleImage, haystackImage, **kwargs):
@@ -354,6 +368,8 @@
         assert len(region) == 4, 'region argument must be a tuple of four ints'
         region = [int(x) for x in region]
         im = im.crop((region[0], region[1], region[2] + region[0], region[3] + 
region[1]))
+        os.unlink(tmpFilename) # delete image of entire screen to save cropped 
version
+        im.save(tmpFilename)
     else:
         # force loading before unlinking, Image.open() is lazy
         im.load()
@@ -378,6 +394,8 @@
             assert len(region) == 4, 'region argument must be a tuple of four 
ints'
             region = [int(x) for x in region]
             im = im.crop((region[0], region[1], region[2] + region[0], 
region[3] + region[1]))
+            os.unlink(tmpFilename) # delete image of entire screen to save 
cropped version
+            im.save(tmpFilename)
         else:
             # force loading before unlinking, Image.open() is lazy
             im.load()
@@ -443,15 +461,18 @@
 def pixel(x, y):
     if sys.platform == 'win32':
         # On Windows, calling GetDC() and GetPixel() is twice as fast as using 
our screenshot() function.
-        hdc = windll.user32.GetDC(0)
-        color = windll.gdi32.GetPixel(hdc, x, y)
-        # color is in the format 0xbbggrr 
https://msdn.microsoft.com/en-us/library/windows/desktop/dd183449(v=vs.85).aspx
-        r = color % 256
-        g = (color // 256) % 256
-        b = color // (256 ** 2)
-        return (r, g, b)
-    else:
-        return RGB(*screenshot().getpixel((x, y)))
+        with __win32_openDC(0) as hdc: # handle will be released automatically
+            color = windll.gdi32.GetPixel(hdc, x, y)
+            if color < 0:
+                raise WindowsError("windll.gdi32.GetPixel faild : return 
{}".format(color))
+            # color is in the format 0xbbggrr 
https://msdn.microsoft.com/en-us/library/windows/desktop/dd183449(v=vs.85).aspx
+            bbggrr = "{:0>6x}".format(color) # bbggrr => 'bbggrr' (hex)
+            b, g, r = (int(bbggrr[i:i+2], 16) for i in range(0, 6, 2))
+            return (r, g, b)
+    else:
+        # Need to select only the first three values of the color in
+        # case the returned pixel has an alpha channel
+        return RGB(*(screenshot().getpixel((x, y))[:3]))
 
 
 # set the screenshot() function based on the platform running this module


Reply via email to