Skip to content

Commit 5d3ab7c

Browse files
authored
MSS: Add PNG compression level control
1 parent ea45c61 commit 5d3ab7c

16 files changed

Lines changed: 109 additions & 22 deletions

CHANGELOG

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ History:
33
<see Git checking messages for history>
44

55
dev 2018/xx/xx
6-
6+
- add PNG compression level control
77

88
3.1.2 2018/01/05
99
- removed support for Python 3.3

CHANGES.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
3.1.2 (2018-01-xx)
1+
3.1.3 (2018-xx-xx)
2+
==================
3+
4+
base.py
5+
-------
6+
- Added ``MSSBase.compression_level`` to control the PNG compression level
7+
8+
tools.py
9+
--------
10+
- Changed signature of ``to_png(data, size, output=None)`` to ``to_png(data, size, level=6, output=None)``. ``level`` is the Zlib compression level.
11+
12+
13+
3.1.2 (2018-01-05)
214
==================
315

416
tools.py
@@ -19,9 +31,9 @@ base.py
1931

2032
darwin.py
2133
---------
22-
- Add ``CGPoint.__repr__()``
23-
- Add ``CGRect.__repr__()``
24-
- Add ``CGSize.__repr__()``
34+
- Added ``CGPoint.__repr__()``
35+
- Added ``CGRect.__repr__()``
36+
- Added ``CGSize.__repr__()``
2537
- Removed ``get_infinity()`` function
2638

2739
windows.py
@@ -36,7 +48,7 @@ windows.py
3648
base.py
3749
-------
3850
- Added the ``ScreenShot`` class containing data for a given screen shot (support the Numpy array interface [``ScreenShot.__array_interface__``])
39-
- Add ``shot()`` method to ``MSSBase``. It takes the same arguments as the ``save()`` method.
51+
- Added ``shot()`` method to ``MSSBase``. It takes the same arguments as the ``save()`` method.
4052
- Renamed ``get_pixels`` to ``grab``. It now returns a ``ScreenShot`` object.
4153
- Moved ``to_png`` method to ``tools.py``. It is now a simple function.
4254
- Removed ``enum_display_monitors()`` method. Use ``monitors`` property instead.

docs/source/api.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,24 @@ Methods
110110

111111
.. module:: mss.tools
112112

113-
.. method:: to_png(data, size, output=None)
113+
.. method:: to_png(data, size, level=6, output=None)
114114

115115
:param bytes data: RGBRGB...RGB data.
116116
:param tuple size: The (width, height) pair.
117+
:param int level: PNG compression level.
117118
:param str output: output's file name.
118119
:raises ScreenShotError: On error when writing ``data`` to ``output``.
120+
:raises zlib.error: On bad compression ``level``.
119121

120122
Dump data to the image file. Pure Python PNG implementation.
121123
If ``output`` is ``None``, create no file but return the whole PNG data.
122124

123125
.. versionadded:: 3.0.0
124126

127+
.. versionadded:: 3.1.3
128+
129+
Added the ``level`` keyword argument to control the PNG compression level.
130+
125131

126132
Properties
127133
==========

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# built documents.
3232
#
3333
# The short X.Y version.
34-
version = '3.1.2'
34+
version = '3.1.3'
3535

3636
# The full version, including alpha/beta/rc tags.
3737
release = 'latest'

docs/source/examples.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ This is an example that uses it, but also using percentage values:
5656

5757
.. versionadded:: 3.1.0
5858

59+
PNG Compression
60+
---------------
61+
62+
You can tweak the PNG compression level (see :py:func:`zlib.compress()` for details)::
63+
64+
sct.compression_level = 2
65+
66+
.. versionadded:: 3.1.3
67+
5968
Advanced
6069
========
6170

docs/source/examples/from_pil_tuple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
im = sct.grab(bbox)
2828

2929
# Save it!
30-
mss.tools.to_png(im.rgb, im.size, 'screenshot.png')
30+
mss.tools.to_png(im.rgb, im.size, output='screenshot.png')

docs/source/examples/part_of_screen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
sct_img = sct.grab(monitor)
2020

2121
# Save to the picture file
22-
mss.tools.to_png(sct_img.rgb, sct_img.size, output)
22+
mss.tools.to_png(sct_img.rgb, sct_img.size, output=output)
2323
print(output)

docs/source/support.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Tested successfully on Pypy 5.1.0 on Windows, but speed is terrible.
2323
Abandoned
2424
=========
2525

26-
- Support for Python 2.6 was dropped on 2016-10-08: too old and introduced optimizations broke it.
27-
- Support for Python 3.0, 3.1, and 3.2 was dropped on 2016-10-08: there is no more tests facilities.
28-
- Support for Python 3.3 was dropped on 2017-12-05: there is no more tests facilities for the documentation.
26+
- 2016-10-08 Support for Python 2.6 was dropped: too old and introduced optimizations broke it.
27+
- 2016-10-08 Support for Python 3.0, 3.1, and 3.2 was dropped: there is no more tests facilities.
28+
- 2017-12-05 Support for Python 3.3 was dropped: there is no more tests facilities for the documentation.
2929

3030
By the way, if you find the *force*, give it a try and tell us if you managed to make one of these versions working (a patch should be quite easy).

docs/source/where.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ AI, Computer Vison
1313
- `Europilot <https://github.com/jsistla/eu-pilot>`_, a self-driving algorithm using Euro Truck Simulator (ETS2);
1414
- `gym-mupen64plus <https://github.com/bzier/gym-mupen64plus>`_, an OpenAI Gym environment wrapper for the Mupen64Plus N64 emulator;
1515
- `Open Source Self Driving Car Initiative <https://github.com/OSSDC/OSSDC-VisionBasedACC>`_;
16+
- `PUBGIS <https://github.com/andrewzwicky/PUBGIS>`_, a map generator of your position throughout PUBG gameplay;
1617
- `Self-Driving-Car-3D-Simulator-With-CNN <https://github.com/sagar448/Self-Driving-Car-3D-Simulator-With-CNN>`_;
1718

1819
Games

mss/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .exception import ScreenShotError
1414
from .factory import mss
1515

16-
__version__ = '3.1.2'
16+
__version__ = '3.1.3'
1717
__author__ = "Mickaël 'Tiger-222' Schoentgen"
1818
__copyright__ = """
1919
Copyright (c) 2013-2018, Mickaël 'Tiger-222' Schoentgen

0 commit comments

Comments
 (0)