ScreenMagnifier 1.11.0.post8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ScreenMagnifier might be problematic. Click here for more details.

Files changed (117) hide show
  1. ScreenMagnifier/__init__.py +68 -0
  2. ScreenMagnifier/__main__.py +17 -0
  3. ScreenMagnifier/advancedoverlay.py +593 -0
  4. ScreenMagnifier/advancedpanel.py +521 -0
  5. ScreenMagnifier/analysiscontroller.py +533 -0
  6. ScreenMagnifier/analysisserver.py +404 -0
  7. ScreenMagnifier/colordetector/__init__.py +28 -0
  8. ScreenMagnifier/colordetector/colordetector.py +570 -0
  9. ScreenMagnifier/colordetector/core.py +434 -0
  10. ScreenMagnifier/colordetector/main.py +23 -0
  11. ScreenMagnifier/colordetector/mainwindow.py +182 -0
  12. ScreenMagnifier/colorpanel.py +424 -0
  13. ScreenMagnifier/colorswatches/__init__.py +16 -0
  14. ScreenMagnifier/colorswatches/colorswatches.py +316 -0
  15. ScreenMagnifier/colorswatches/main.py +23 -0
  16. ScreenMagnifier/colorswatches/mainwindow.py +60 -0
  17. ScreenMagnifier/controlpanel.py +234 -0
  18. ScreenMagnifier/detectionpanel.py +790 -0
  19. ScreenMagnifier/facedetector/__init__.py +24 -0
  20. ScreenMagnifier/facedetector/core.py +314 -0
  21. ScreenMagnifier/facedetector/facedetector.py +288 -0
  22. ScreenMagnifier/facedetector/main.py +23 -0
  23. ScreenMagnifier/facedetector/mainwindow.py +122 -0
  24. ScreenMagnifier/facedetector/models/__init__.py +4 -0
  25. ScreenMagnifier/facepointer.py +1121 -0
  26. ScreenMagnifier/features.py +50 -0
  27. ScreenMagnifier/hotkeys/__init__.py +16 -0
  28. ScreenMagnifier/hotkeys/hotkeys.py +379 -0
  29. ScreenMagnifier/hotkeys/main.py +23 -0
  30. ScreenMagnifier/hotkeys/mainwindow.py +56 -0
  31. ScreenMagnifier/imagefilters/__init__.py +24 -0
  32. ScreenMagnifier/imagefilters/core.py +172 -0
  33. ScreenMagnifier/imagefilters/imagefilters.py +220 -0
  34. ScreenMagnifier/imagefilters/main.py +23 -0
  35. ScreenMagnifier/imagefilters/mainwindow.py +120 -0
  36. ScreenMagnifier/magnifierview/__init__.py +16 -0
  37. ScreenMagnifier/magnifierview/magnifierview.py +1249 -0
  38. ScreenMagnifier/magnifierview/main.py +23 -0
  39. ScreenMagnifier/magnifierview/mainwindow.py +91 -0
  40. ScreenMagnifier/main.py +157 -0
  41. ScreenMagnifier/mainwindow.py +1368 -0
  42. ScreenMagnifier/mousecatcher/__init__.py +16 -0
  43. ScreenMagnifier/mousecatcher/main.py +23 -0
  44. ScreenMagnifier/mousecatcher/mainwindow.py +78 -0
  45. ScreenMagnifier/mousecatcher/mousecatcher.py +251 -0
  46. ScreenMagnifier/mousemove.py +259 -0
  47. ScreenMagnifier/netprotocol/__init__.py +25 -0
  48. ScreenMagnifier/netprotocol/main.py +23 -0
  49. ScreenMagnifier/netprotocol/mainwindow.py +91 -0
  50. ScreenMagnifier/netprotocol/netprotocol.py +372 -0
  51. ScreenMagnifier/netprotocol/wire.py +189 -0
  52. ScreenMagnifier/regionselector/__init__.py +16 -0
  53. ScreenMagnifier/regionselector/main.py +23 -0
  54. ScreenMagnifier/regionselector/mainwindow.py +70 -0
  55. ScreenMagnifier/regionselector/regionselector.py +549 -0
  56. ScreenMagnifier/remoteclient.py +636 -0
  57. ScreenMagnifier/resources/icon-128.png +0 -0
  58. ScreenMagnifier/resources/icon-16.png +0 -0
  59. ScreenMagnifier/resources/icon-24.png +0 -0
  60. ScreenMagnifier/resources/icon-256.png +0 -0
  61. ScreenMagnifier/resources/icon-32.png +0 -0
  62. ScreenMagnifier/resources/icon-48.png +0 -0
  63. ScreenMagnifier/resources/icon-512.png +0 -0
  64. ScreenMagnifier/resources/icon-64.png +0 -0
  65. ScreenMagnifier/resources/icon.icns +0 -0
  66. ScreenMagnifier/resources/icon.ico +0 -0
  67. ScreenMagnifier/screengrabber/__init__.py +16 -0
  68. ScreenMagnifier/screengrabber/main.py +23 -0
  69. ScreenMagnifier/screengrabber/mainwindow.py +79 -0
  70. ScreenMagnifier/screengrabber/screengrabber.py +558 -0
  71. ScreenMagnifier/server.py +150 -0
  72. ScreenMagnifier/serverpanel.py +379 -0
  73. ScreenMagnifier/shortcuteditor/__init__.py +16 -0
  74. ScreenMagnifier/shortcuteditor/main.py +23 -0
  75. ScreenMagnifier/shortcuteditor/mainwindow.py +54 -0
  76. ScreenMagnifier/shortcuteditor/shortcuteditor.py +411 -0
  77. ScreenMagnifier/shortcuts.py +118 -0
  78. ScreenMagnifier/shortcutspanel.py +140 -0
  79. ScreenMagnifier/support.py +127 -0
  80. ScreenMagnifier/translations/ar.json +387 -0
  81. ScreenMagnifier/translations/de.json +387 -0
  82. ScreenMagnifier/translations/es.json +387 -0
  83. ScreenMagnifier/translations/fr.json +387 -0
  84. ScreenMagnifier/translations/it.json +387 -0
  85. ScreenMagnifier/translations/ja.json +387 -0
  86. ScreenMagnifier/translations/ko.json +387 -0
  87. ScreenMagnifier/translations/pt_BR.json +387 -0
  88. ScreenMagnifier/translations/ru.json +387 -0
  89. ScreenMagnifier/translations/tr.json +387 -0
  90. ScreenMagnifier/translations/zh_CN.json +387 -0
  91. ScreenMagnifier/translator/__init__.py +16 -0
  92. ScreenMagnifier/translator/main.py +23 -0
  93. ScreenMagnifier/translator/mainwindow.py +62 -0
  94. ScreenMagnifier/translator/translator.py +284 -0
  95. ScreenMagnifier/upscaler/__init__.py +24 -0
  96. ScreenMagnifier/upscaler/core.py +315 -0
  97. ScreenMagnifier/upscaler/main.py +23 -0
  98. ScreenMagnifier/upscaler/mainwindow.py +128 -0
  99. ScreenMagnifier/upscaler/models/FSRCNN-small_x2.pb +0 -0
  100. ScreenMagnifier/upscaler/models/FSRCNN-small_x3.pb +0 -0
  101. ScreenMagnifier/upscaler/models/FSRCNN-small_x4.pb +0 -0
  102. ScreenMagnifier/upscaler/models/FSRCNN_x2.pb +0 -0
  103. ScreenMagnifier/upscaler/models/FSRCNN_x3.pb +0 -0
  104. ScreenMagnifier/upscaler/models/FSRCNN_x4.pb +0 -0
  105. ScreenMagnifier/upscaler/models/LICENSE-FSRCNN +201 -0
  106. ScreenMagnifier/upscaler/models/__init__.py +4 -0
  107. ScreenMagnifier/upscaler/upscaler.py +285 -0
  108. ScreenMagnifier/wincheck.py +65 -0
  109. ScreenMagnifier/zoomoverlay/__init__.py +16 -0
  110. ScreenMagnifier/zoomoverlay/main.py +23 -0
  111. ScreenMagnifier/zoomoverlay/mainwindow.py +99 -0
  112. ScreenMagnifier/zoomoverlay/zoomoverlay.py +1779 -0
  113. screenmagnifier-1.11.0.post8.dist-info/METADATA +591 -0
  114. screenmagnifier-1.11.0.post8.dist-info/RECORD +117 -0
  115. screenmagnifier-1.11.0.post8.dist-info/WHEEL +5 -0
  116. screenmagnifier-1.11.0.post8.dist-info/entry_points.txt +5 -0
  117. screenmagnifier-1.11.0.post8.dist-info/top_level.txt +1 -0
@@ -0,0 +1,172 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Image filters on NumPy arrays - pure Python + NumPy, no Qt (usable by the application and the headless server).
4
+ applyFilters(arr, effect, brightness, contrast, saturation, strength) -> filtered copy
5
+ Adjustments (-100 .. 100, 0 = unchanged): brightness, contrast, saturation; applied first.
6
+ Effects (then blended with the adjusted image by strength 0 .. 100):
7
+ NONE, GRAYSCALE, SEPIA, INVERT, HIGH_CONTRAST (auto levels + steep curve), WARM (less blue light),
8
+ NIGHT_VISION, THERMAL (false colours by brightness), OUTLINE (edges over a dimmed image),
9
+ PROTAN / DEUTAN / TRITAN (colour-blindness help: colours a red-, green- or blue-weak viewer would confuse are
10
+ moved apart - see _CORRECTION for how the matrices were made and measured).
11
+ Arrays are (H, W, 3) uint8 RGB; every function returns a new uint8 array.
12
+ """
13
+ try:
14
+ from numpy import array, clip, dot, float32, uint8, empty, linspace, interp, percentile, sqrt, repeat, stack, \
15
+ zeros_like
16
+ numpy = True # type: bool
17
+ except:
18
+ numpy = False # type: bool
19
+
20
+ NONE, GRAYSCALE, SEPIA, INVERT, HIGH_CONTRAST, WARM, NIGHT_VISION, THERMAL, OUTLINE, PROTAN, DEUTAN, TRITAN = range(12)
21
+ EFFECT_NAMES = [
22
+ 'None', 'Grayscale', 'Sepia', 'Invert', 'High contrast', 'Warm (less blue light)', 'Night vision',
23
+ 'Thermal (false colors)', 'Outline (edges)', 'Color-blind help: red-weak', 'Color-blind help: green-weak',
24
+ 'Color-blind help: blue-weak'] # type: list[str] # index = effect
25
+
26
+ _LUMA = (0.2126, 0.7152, 0.0722) # type: tuple # Rec. 709
27
+ _SEPIA = ((0.393, 0.769, 0.189), (0.349, 0.686, 0.168), (0.272, 0.534, 0.131)) # type: tuple
28
+ _RGB_TO_LMS = ((17.8824, 43.5161, 4.11935), (3.45565, 27.1554, 3.86714), (0.0299566, 0.184309, 1.46709))
29
+ _LMS_TO_RGB = ((0.0809444479, -0.130504409, 0.116721066), (-0.0102485335, 0.0540193266, -0.113614708),
30
+ (-0.000365296938, -0.00412161469, 0.693511405))
31
+ _SIMULATE = { # Viénot / Brettel dichromacy in LMS space (what each viewer sees; used to measure _CORRECTION)
32
+ PROTAN: ((0.0, 2.02344, -2.52581), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)),
33
+ DEUTAN: ((1.0, 0.0, 0.0), (0.494207, 0.0, 1.24827), (0.0, 0.0, 1.0)),
34
+ TRITAN: ((1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (-0.395913, 0.801109, 0.0)),
35
+ } # type: dict
36
+ _CORRECTION = { # colour-blindness help: one 3 x 3 matrix each (rows = output R, G, B; each row sums to 1)
37
+ PROTAN: ((-0.021395, 1.013657, 0.007738), (-0.076196, 1.046547, 0.029649), (-0.047976, 0.006427, 1.041549)),
38
+ DEUTAN: ((-0.054579, 1.031042, 0.023537), (-0.079481, 1.050765, 0.028716), (-0.080570, 0.059028, 1.021542)),
39
+ TRITAN: ((0.650883, 0.525070, -0.175952), (0.361911, 0.811148, -0.173059), (0.360183, -0.029230, 0.669047)),
40
+ } # type: dict
41
+ # How the matrices were made: each one minimises, for 600 random colours, the pairs that typical vision sees as
42
+ # different (CIE76 delta E >= 20) but the simulated viewer (_SIMULATE) cannot tell apart - the sum of
43
+ # max(0, min(20, typical distance) - viewer distance) squared - plus a penalty for colours pushed outside 0 .. 255
44
+ # (which would posterise the picture). Each row sums to 1, so whites, greys and blacks never change. On 600 other
45
+ # random colours they cut the pairs the viewer confuses (delta E < 10) by 20 % (red-weak), 38 % (green-weak) and
46
+ # 67 % (blue-weak); the classic Fidaner daltonisation increases them. Red / green differences become lightness
47
+ # differences, which red- and green-weak viewers see. The Strength slider blends the correction with the original.
48
+ _THERMAL_STOPS = ((0, (0, 0, 0)), (40, (40, 10, 110)), (95, (150, 20, 140)), (150, (225, 60, 50)),
49
+ (200, (250, 160, 20)), (240, (255, 240, 90)), (255, (255, 255, 255))) # type: tuple
50
+ _THERMAL = [] # type: list # lazily built 256 x 3 palette
51
+
52
+
53
+ def isAvailable():
54
+ """
55
+ :return: (bool) NumPy is installed (every effect needs it).
56
+ """
57
+ return numpy
58
+
59
+
60
+ def _luma(a):
61
+ """
62
+ :param a: (ndarray) (H, W, 3) float32.
63
+ :return: (ndarray) (H, W) float32.
64
+ """
65
+ return a[..., 0] * _LUMA[0] + a[..., 1] * _LUMA[1] + a[..., 2] * _LUMA[2]
66
+
67
+
68
+ def _matrix(a, m):
69
+ """
70
+ :param a: (ndarray) (H, W, 3) float32.
71
+ :param m: 3 x 3 matrix (rows = output channels).
72
+ :return: ndarray
73
+ """
74
+ return dot(a, array(m, float32).T)
75
+
76
+
77
+ def _thermalPalette():
78
+ """
79
+ :return: (ndarray) 256 x 3 float32 palette, black -> purple -> red -> orange -> yellow -> white.
80
+ """
81
+ if not _THERMAL:
82
+ xs = [s[0] for s in _THERMAL_STOPS] # type: list
83
+ lut = empty((256, 3), float32)
84
+ for c in range(3):
85
+ lut[:, c] = interp(linspace(0, 255, 256), xs, [s[1][c] for s in _THERMAL_STOPS])
86
+ _THERMAL.append(lut)
87
+ return _THERMAL[0]
88
+
89
+
90
+ def adjust(a, brightness=0, contrast=0, saturation=0):
91
+ """
92
+ :param a: (ndarray) (H, W, 3) float32 0 .. 255.
93
+ :param brightness: (int) -100 .. 100.
94
+ :param contrast: (int) -100 .. 100.
95
+ :param saturation: (int) -100 .. 100 (-100 = gray).
96
+ :return: (ndarray) float32.
97
+ """
98
+ if brightness:
99
+ a += float(brightness) * 1.28
100
+ if contrast:
101
+ c = float(contrast) * 2.55 # type: float
102
+ factor = (259.0 * (c + 255.0)) / (255.0 * (259.0 - c)) # type: float
103
+ a = (a - 128.0) * factor + 128.0
104
+ if saturation:
105
+ gray = _luma(a)[..., None]
106
+ a = gray + (a - gray) * (1.0 + float(saturation) / 100.0)
107
+ return a
108
+
109
+
110
+ def effect(a, kind):
111
+ """
112
+ :param a: (ndarray) (H, W, 3) float32 0 .. 255 (already adjusted).
113
+ :param kind: (int) Effect number.
114
+ :return: (ndarray) float32.
115
+ """
116
+ if kind == GRAYSCALE:
117
+ return repeat(_luma(a)[..., None], 3, axis=2)
118
+ if kind == SEPIA:
119
+ return _matrix(a, _SEPIA)
120
+ if kind == INVERT:
121
+ return 255.0 - a
122
+ if kind == HIGH_CONTRAST:
123
+ y = _luma(a)
124
+ lo, hi = percentile(y, 2), percentile(y, 98)
125
+ span = max(1.0, float(hi - lo)) # type: float
126
+ b = (a - lo) * (255.0 / span) # auto levels, then a steep S-curve
127
+ b = clip(b, 0, 255) / 255.0
128
+ return (b * b * (3.0 - 2.0 * b)) * 255.0
129
+ if kind == WARM:
130
+ return a * array((1.0, 0.86, 0.62), float32)
131
+ if kind == NIGHT_VISION: # lift the shadows (gamma), keep the highlights apart, green phosphor
132
+ y = 255.0 * (clip(_luma(a), 0, 255) / 255.0) ** 0.55
133
+ return stack([y * 0.28, y, y * 0.26], axis=2)
134
+ if kind == THERMAL:
135
+ return _thermalPalette()[clip(_luma(a), 0, 255).astype(uint8)]
136
+ if kind == OUTLINE:
137
+ y = _luma(a)
138
+ gx = zeros_like(y)
139
+ gy = zeros_like(y)
140
+ gx[:, 1:-1] = y[:, 2:] - y[:, :-2]
141
+ gy[1:-1, :] = y[2:, :] - y[:-2, :]
142
+ edges = clip(sqrt(gx * gx + gy * gy) * 1.6, 0, 255)[..., None]
143
+ return a * 0.35 + edges
144
+ if kind in _CORRECTION:
145
+ return _matrix(a, _CORRECTION[kind])
146
+ return a
147
+
148
+
149
+ def applyFilters(arr, kind=NONE, brightness=0, contrast=0, saturation=0, strength=100):
150
+ """
151
+ :param arr: (ndarray) (H, W, 3) uint8 RGB.
152
+ :param kind: (int) Effect number (see EFFECT_NAMES).
153
+ :param brightness: (int) -100 .. 100.
154
+ :param contrast: (int) -100 .. 100.
155
+ :param saturation: (int) -100 .. 100.
156
+ :param strength: (int) 0 .. 100: how much of the effect (100 = all of it).
157
+ :return: (ndarray) Filtered (H, W, 3) uint8 copy.
158
+ """
159
+ a = arr.astype(float32)
160
+ a = adjust(a, brightness, contrast, saturation)
161
+ if kind != NONE and strength > 0:
162
+ e = effect(clip(a, 0, 255), int(kind))
163
+ k = min(1.0, max(0.0, float(strength) / 100.0)) # type: float
164
+ a = e if k >= 1.0 else a + (e - a) * k
165
+ return clip(a + 0.5, 0, 255).astype(uint8)
166
+
167
+
168
+ def isIdentity(kind=NONE, brightness=0, contrast=0, saturation=0, strength=100):
169
+ """
170
+ :return: (bool) These settings leave every image unchanged (skip the work).
171
+ """
172
+ return (kind == NONE or strength <= 0) and not brightness and not contrast and not saturation
@@ -0,0 +1,220 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ ImageFilters: colour filters for QImage - adjustments (brightness, contrast, saturation) and effects (grayscale,
4
+ sepia, invert, high contrast, warm, night vision, thermal, outline, color-blindness help), blended by strength.
5
+ The work is done by the Qt-free core (core.py, NumPy); without NumPy, Invert and Grayscale still work (Qt).
6
+ """
7
+ from ManyQt.QtCore import QObject, pyqtSignal, pyqtSlot, pyqtProperty
8
+ from ManyQt.QtGui import QImage
9
+ from os.path import dirname
10
+ from sys import path
11
+
12
+ if not __package__ and dirname(__file__) not in path:
13
+ path.append(dirname(__file__))
14
+
15
+ try:
16
+ from .core import applyFilters, isIdentity, isAvailable, EFFECT_NAMES, NONE, GRAYSCALE, INVERT
17
+ except:
18
+ from core import applyFilters, isIdentity, isAvailable, EFFECT_NAMES, NONE, GRAYSCALE, INVERT
19
+ if isAvailable():
20
+ from numpy import frombuffer, uint8, ascontiguousarray
21
+
22
+
23
+ def clamp(x, a, b):
24
+ """
25
+ :param x: float | int
26
+ :param a: float | int
27
+ :param b: float | int
28
+ :return: float | int
29
+ """
30
+ return a if x < a else b if x > b else x
31
+
32
+
33
+ def qimageToArray(image):
34
+ """
35
+ :param image: QImage
36
+ :return: (ndarray) Owned (H, W, 3) uint8 RGB array.
37
+ """
38
+ img = image.convertToFormat(QImage.Format_RGB888) # type: QImage
39
+ w, h, bpl = img.width(), img.height(), img.bytesPerLine() # type: int, int, int
40
+ nbytes = img.sizeInBytes() if hasattr(img, 'sizeInBytes') else img.byteCount() # type: int
41
+ ptr = img.constBits()
42
+ if hasattr(ptr, 'setsize'):
43
+ ptr.setsize(nbytes)
44
+ return frombuffer(ptr, uint8, count=nbytes).reshape(h, bpl)[:, :w * 3].reshape(h, w, 3).copy()
45
+
46
+
47
+ def arrayToQImage(arr):
48
+ """
49
+ :param arr: (ndarray) (H, W, 3) uint8 RGB.
50
+ :return: (QImage) Owned copy.
51
+ """
52
+ arr = ascontiguousarray(arr)
53
+ h, w = arr.shape[:2]
54
+ return QImage(arr.data, w, h, w * 3, QImage.Format_RGB888).copy()
55
+
56
+
57
+ class ImageFilters(QObject):
58
+ """
59
+ ImageFilters class.
60
+ """
61
+ changed = pyqtSignal() # type: pyqtSignal
62
+ EFFECT_NAMES = EFFECT_NAMES # type: list[str] # index = effect number (English; translate with tr())
63
+
64
+ def __init__(self, *args, **kwargs):
65
+ """
66
+ :param effect: (int) Effect number (see EFFECT_NAMES), 0 = none.
67
+ :param brightness: (int) -100 .. 100.
68
+ :param contrast: (int) -100 .. 100.
69
+ :param saturation: (int) -100 .. 100.
70
+ :param strength: (int) 0 .. 100: how much of the effect.
71
+ :param changed: (callable | None) Called after any setting changes.
72
+ :param args: any
73
+ :param kwargs: any
74
+ """
75
+ effect = kwargs.pop('effect', NONE) # type: int
76
+ brightness = kwargs.pop('brightness', 0) # type: int
77
+ contrast = kwargs.pop('contrast', 0) # type: int
78
+ saturation = kwargs.pop('saturation', 0) # type: int
79
+ strength = kwargs.pop('strength', 100) # type: int
80
+ changed = kwargs.pop('changed', None) # type: callable | None
81
+ super(ImageFilters, self).__init__(*args, **kwargs)
82
+ if callable(changed):
83
+ self.changed.connect(changed)
84
+ self.__m_effect = int(clamp(int(effect), 0, len(EFFECT_NAMES) - 1)) # type: int
85
+ self.__m_brightness = int(clamp(int(brightness), -100, 100)) # type: int
86
+ self.__m_contrast = int(clamp(int(contrast), -100, 100)) # type: int
87
+ self.__m_saturation = int(clamp(int(saturation), -100, 100)) # type: int
88
+ self.__m_strength = int(clamp(int(strength), 0, 100)) # type: int
89
+
90
+ # ---------- Helpers ----------
91
+ @staticmethod
92
+ def isAvailable():
93
+ """
94
+ :return: (bool) Every effect is available (NumPy installed); else only Invert and Grayscale.
95
+ """
96
+ return isAvailable()
97
+
98
+ def isActive(self):
99
+ """
100
+ :return: (bool) The settings change images.
101
+ """
102
+ return not isIdentity(self.__m_effect, self.__m_brightness, self.__m_contrast, self.__m_saturation,
103
+ self.__m_strength)
104
+
105
+ def _set(self, name, value):
106
+ """
107
+ :param name: str | unicode | QString
108
+ :param value: int
109
+ :return:
110
+ """
111
+ attribute = '_ImageFilters__m_' + name # type: str
112
+ if getattr(self, attribute) != value:
113
+ setattr(self, attribute, value)
114
+ self.changed.emit()
115
+
116
+ # ---------- Public API ----------
117
+ def apply(self, image):
118
+ """
119
+ :param image: QImage
120
+ :return: (QImage) The filtered image (the image itself when nothing changes it).
121
+ """
122
+ if image is None or image.isNull() or not self.isActive():
123
+ return image
124
+ if isAvailable():
125
+ return arrayToQImage(applyFilters(qimageToArray(image), self.__m_effect, self.__m_brightness,
126
+ self.__m_contrast, self.__m_saturation, self.__m_strength))
127
+ if self.__m_effect == INVERT: # without NumPy: what Qt does by itself
128
+ out = image.convertToFormat(QImage.Format_RGB32) # type: QImage
129
+ out.invertPixels()
130
+ return out
131
+ if self.__m_effect == GRAYSCALE:
132
+ return image.convertToFormat(QImage.Format_Grayscale8).convertToFormat(QImage.Format_RGB32)
133
+ return image
134
+
135
+ @pyqtSlot()
136
+ def reset(self):
137
+ """
138
+ No effect, no adjustment.
139
+ :return:
140
+ """
141
+ for name, value in (('effect', NONE), ('brightness', 0), ('contrast', 0), ('saturation', 0), ('strength', 100)):
142
+ setattr(self, '_ImageFilters__m_' + name, value)
143
+ self.changed.emit()
144
+
145
+ def getEffect(self):
146
+ """
147
+ :return: int
148
+ """
149
+ return self.__m_effect
150
+
151
+ @pyqtSlot(int)
152
+ def setEffect(self, effect):
153
+ """
154
+ :param effect: (int) See EFFECT_NAMES.
155
+ :return:
156
+ """
157
+ self._set('effect', int(clamp(int(effect), 0, len(EFFECT_NAMES) - 1)))
158
+
159
+ def getBrightness(self):
160
+ """
161
+ :return: int
162
+ """
163
+ return self.__m_brightness
164
+
165
+ @pyqtSlot(int)
166
+ def setBrightness(self, brightness):
167
+ """
168
+ :param brightness: (int) -100 .. 100.
169
+ :return:
170
+ """
171
+ self._set('brightness', int(clamp(int(brightness), -100, 100)))
172
+
173
+ def getContrast(self):
174
+ """
175
+ :return: int
176
+ """
177
+ return self.__m_contrast
178
+
179
+ @pyqtSlot(int)
180
+ def setContrast(self, contrast):
181
+ """
182
+ :param contrast: (int) -100 .. 100.
183
+ :return:
184
+ """
185
+ self._set('contrast', int(clamp(int(contrast), -100, 100)))
186
+
187
+ def getSaturation(self):
188
+ """
189
+ :return: int
190
+ """
191
+ return self.__m_saturation
192
+
193
+ @pyqtSlot(int)
194
+ def setSaturation(self, saturation):
195
+ """
196
+ :param saturation: (int) -100 .. 100.
197
+ :return:
198
+ """
199
+ self._set('saturation', int(clamp(int(saturation), -100, 100)))
200
+
201
+ def getStrength(self):
202
+ """
203
+ :return: int
204
+ """
205
+ return self.__m_strength
206
+
207
+ @pyqtSlot(int)
208
+ def setStrength(self, strength):
209
+ """
210
+ :param strength: (int) 0 .. 100.
211
+ :return:
212
+ """
213
+ self._set('strength', int(clamp(int(strength), 0, 100)))
214
+
215
+ # ---------- Properties ----------
216
+ effect = pyqtProperty(int, fget=getEffect, fset=setEffect, notify=changed) # type: pyqtProperty
217
+ brightness = pyqtProperty(int, fget=getBrightness, fset=setBrightness, notify=changed) # type: pyqtProperty
218
+ contrast = pyqtProperty(int, fget=getContrast, fset=setContrast, notify=changed) # type: pyqtProperty
219
+ saturation = pyqtProperty(int, fget=getSaturation, fset=setSaturation, notify=changed) # type: pyqtProperty
220
+ strength = pyqtProperty(int, fget=getStrength, fset=setStrength, notify=changed) # type: pyqtProperty
@@ -0,0 +1,23 @@
1
+ # coding=utf-8
2
+ """
3
+ Entry point for the ImageFilters demo.
4
+ """
5
+ from os.path import dirname
6
+ from sys import path
7
+
8
+ if not __package__ and dirname(__file__) not in path:
9
+ path.append(dirname(__file__))
10
+
11
+ try:
12
+ from .mainwindow import MainWindow
13
+ except:
14
+ from mainwindow import MainWindow
15
+
16
+ if __name__ == '__main__':
17
+ from ManyQt.QtWidgets import QApplication
18
+ from sys import argv, exit
19
+
20
+ a = QApplication(argv) # type: QApplication
21
+ w = MainWindow() # type: MainWindow
22
+ w.show()
23
+ exit(a.exec_())
@@ -0,0 +1,120 @@
1
+ # coding=utf-8
2
+ """
3
+ ImageFilters demo: a test picture before / after, with the effect and the adjustment sliders.
4
+ """
5
+ from ManyQt.QtWidgets import QMainWindow, QWidget, QGridLayout, QHBoxLayout, QVBoxLayout, QLabel, QSlider, QComboBox, \
6
+ QPushButton
7
+ from ManyQt.QtGui import QImage, QPainter, QColor, QFont, QPixmap, QLinearGradient, QConicalGradient
8
+ from ManyQt.QtCore import Qt, QPointF, QRectF, pyqtSlot
9
+ from os.path import dirname
10
+ from sys import path
11
+
12
+ if not __package__ and dirname(__file__) not in path:
13
+ path.append(dirname(__file__))
14
+
15
+ try:
16
+ from .imagefilters import ImageFilters
17
+ except:
18
+ from imagefilters import ImageFilters
19
+
20
+
21
+ def testPicture():
22
+ """
23
+ :return: (QImage) Colour wheel, grey ramp, red / green and blue / yellow patches, text.
24
+ """
25
+ img = QImage(360, 240, QImage.Format_RGB32) # type: QImage
26
+ img.fill(QColor(236, 238, 242))
27
+ p = QPainter(img) # type: QPainter
28
+ p.setRenderHint(QPainter.Antialiasing, True)
29
+ wheel = QConicalGradient(QPointF(80, 90), 0) # type: QConicalGradient
30
+ for i, c in enumerate(('#FF0000', '#FFFF00', '#00FF00', '#00FFFF', '#0000FF', '#FF00FF', '#FF0000')):
31
+ wheel.setColorAt(i / 6.0, QColor(c))
32
+ p.setBrush(wheel)
33
+ p.setPen(Qt.NoPen)
34
+ p.drawEllipse(QPointF(80, 90), 62, 62)
35
+ ramp = QLinearGradient(0, 0, 360, 0) # type: QLinearGradient
36
+ ramp.setColorAt(0, QColor('black'))
37
+ ramp.setColorAt(1, QColor('white'))
38
+ p.fillRect(QRectF(0, 200, 360, 40), ramp)
39
+ for i, c in enumerate(('#D03030', '#30A040', '#2E6BD8', '#E8C020')):
40
+ p.fillRect(QRectF(170 + (i % 2) * 90, 30 + (i // 2) * 70, 80, 60), QColor(c))
41
+ p.setPen(QColor(30, 32, 40))
42
+ p.setFont(QFont('Sans', 13, QFont.Bold))
43
+ p.drawText(QRectF(170, 172, 180, 24), Qt.AlignCenter, 'Screen Magnifier')
44
+ p.end()
45
+ return img
46
+
47
+
48
+ class MainWindow(QMainWindow):
49
+ """
50
+ MainWindow class.
51
+ """
52
+
53
+ def __init__(self, *args, **kwargs):
54
+ """
55
+ :param args: any
56
+ :param kwargs: any
57
+ """
58
+ super(MainWindow, self).__init__(*args, **kwargs)
59
+ self.setWindowTitle(u'ImageFilters demo')
60
+ self.__m_source = testPicture() # type: QImage
61
+ self.__m_filters = ImageFilters(changed=self._render) # type: ImageFilters
62
+ central = QWidget(self) # type: QWidget
63
+ layout = QVBoxLayout(central) # type: QVBoxLayout
64
+ images = QHBoxLayout() # type: QHBoxLayout
65
+ self.__m_before = QLabel() # type: QLabel
66
+ self.__m_after = QLabel() # type: QLabel
67
+ for title, label in ((u'Before', self.__m_before), (u'After', self.__m_after)):
68
+ box = QVBoxLayout() # type: QVBoxLayout
69
+ box.addWidget(QLabel(title))
70
+ box.addWidget(label)
71
+ images.addLayout(box)
72
+ layout.addLayout(images)
73
+ grid = QGridLayout() # type: QGridLayout
74
+ self.__m_effect = QComboBox() # type: QComboBox
75
+ self.__m_effect.addItems(ImageFilters.EFFECT_NAMES)
76
+ self.__m_effect.currentIndexChanged.connect(self.__m_filters.setEffect)
77
+ grid.addWidget(QLabel(u'Effect'), 0, 0)
78
+ grid.addWidget(self.__m_effect, 0, 1)
79
+ self.__m_sliders = [] # type: list[QSlider]
80
+ for row, (name, lo, value, slot) in enumerate(((u'Strength', 0, 100, self.__m_filters.setStrength),
81
+ (u'Brightness', -100, 0, self.__m_filters.setBrightness),
82
+ (u'Contrast', -100, 0, self.__m_filters.setContrast),
83
+ (u'Saturation', -100, 0, self.__m_filters.setSaturation))):
84
+ s = QSlider(Qt.Horizontal) # type: QSlider
85
+ s.setRange(lo, 100)
86
+ s.setValue(value)
87
+ s.valueChanged.connect(slot)
88
+ grid.addWidget(QLabel(name), row + 1, 0)
89
+ grid.addWidget(s, row + 1, 1)
90
+ self.__m_sliders.append(s)
91
+ reset = QPushButton(u'Reset') # type: QPushButton
92
+ reset.clicked.connect(self._reset)
93
+ grid.addWidget(reset, 5, 1)
94
+ layout.addLayout(grid)
95
+ self.setCentralWidget(central)
96
+ self.__m_before.setPixmap(QPixmap.fromImage(self.__m_source))
97
+ self._render()
98
+
99
+ @pyqtSlot()
100
+ def _render(self):
101
+ """
102
+ :return:
103
+ """
104
+ self.__m_after.setPixmap(QPixmap.fromImage(self.__m_filters.apply(self.__m_source)))
105
+
106
+ @pyqtSlot()
107
+ def _reset(self):
108
+ """
109
+ :return:
110
+ """
111
+ self.__m_filters.reset()
112
+ self.__m_effect.setCurrentIndex(0)
113
+ for s, value in zip(self.__m_sliders, (100, 0, 0, 0)):
114
+ s.setValue(value)
115
+
116
+ def getFilters(self):
117
+ """
118
+ :return: ImageFilters
119
+ """
120
+ return self.__m_filters
@@ -0,0 +1,16 @@
1
+ # coding=utf-8
2
+ """
3
+ magnifierview package.
4
+ """
5
+ from os.path import dirname
6
+ from sys import path
7
+
8
+ if not __package__ and dirname(__file__) not in path:
9
+ path.append(dirname(__file__))
10
+
11
+ try:
12
+ from .magnifierview import MagnifierViewWidget
13
+ except:
14
+ from magnifierview import MagnifierViewWidget
15
+
16
+ __all__ = ['MagnifierViewWidget'] # type: list[str]