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,128 @@
1
+ # coding=utf-8
2
+ """
3
+ Demo window for Upscaler: the same tiny crop upscaled with every available method.
4
+ """
5
+ from ManyQt.QtWidgets import QMainWindow, QGridLayout, QVBoxLayout, QHBoxLayout, QWidget, QLabel, QSlider, QScrollArea
6
+ from ManyQt.QtGui import QImage, QPainter, QColor, QFont, QPixmap, QPen, QLinearGradient
7
+ from ManyQt.QtCore import Qt, QSize, QRectF, pyqtSlot
8
+ from os.path import dirname
9
+ from sys import path
10
+
11
+ if not __package__ and dirname(__file__) not in path:
12
+ path.append(dirname(__file__))
13
+
14
+ try:
15
+ from .upscaler import Upscaler
16
+ except:
17
+ from upscaler import Upscaler
18
+
19
+
20
+ def makeSample():
21
+ """
22
+ Build a small UI-like sample: text, thin lines, a gradient and an icon-ish circle.
23
+ :return: QImage
24
+ """
25
+ img = QImage(96, 64, QImage.Format_RGB32) # type: QImage
26
+ img.fill(QColor('#F4F5F8'))
27
+ p = QPainter(img) # type: QPainter
28
+ p.setRenderHint(QPainter.Antialiasing, True)
29
+ g = QLinearGradient(0, 0, 96, 0) # type: QLinearGradient
30
+ g.setColorAt(0, QColor('#5227FF'))
31
+ g.setColorAt(1, QColor('#FF3B6B'))
32
+ p.fillRect(QRectF(0, 0, 96, 14), g)
33
+ p.setPen(Qt.white)
34
+ p.setFont(QFont('Sans Serif', 7, QFont.Bold))
35
+ p.drawText(QRectF(4, 0, 90, 14), Qt.AlignVCenter, u'Magnify me')
36
+ p.setPen(QColor('#22252E'))
37
+ p.setFont(QFont('Sans Serif', 7))
38
+ p.drawText(QRectF(4, 16, 90, 24), Qt.AlignLeft, u'Small text 123\nfine detail')
39
+ p.setPen(QPen(QColor('#1E88E5'), 1))
40
+ p.drawLine(4, 60, 60, 42)
41
+ p.setBrush(QColor('#43A047'))
42
+ p.drawEllipse(QRectF(70, 40, 18, 18))
43
+ p.end()
44
+ return img
45
+
46
+
47
+ class MainWindow(QMainWindow):
48
+ """
49
+ MainWindow class.
50
+ """
51
+
52
+ def __init__(self, *args, **kwargs):
53
+ """
54
+ :param args: any
55
+ :param kwargs: any
56
+ """
57
+ super(MainWindow, self).__init__(*args, **kwargs)
58
+ self.setWindowTitle(self.tr(u'Upscaler demo'))
59
+ self.resize(1180, 760)
60
+ self.__m_sample = makeSample() # type: QImage
61
+ self.__m_upscaler = Upscaler(sharpness=0.3, errorOccurred=self.onError) # type: Upscaler
62
+ self.__m_cells = [] # type: list
63
+ grid = QWidget() # type: QWidget
64
+ layout = QGridLayout(grid) # type: QGridLayout
65
+ for i, (method, name) in enumerate(self.__m_upscaler.availableMethods()):
66
+ title = QLabel(name) # type: QLabel
67
+ title.setStyleSheet('font-weight: bold;')
68
+ image = QLabel() # type: QLabel
69
+ image.setAlignment(Qt.AlignCenter)
70
+ layout.addWidget(title, (i // 3) * 2, i % 3)
71
+ layout.addWidget(image, (i // 3) * 2 + 1, i % 3)
72
+ self.__m_cells.append((method, title, image))
73
+ scroll = QScrollArea() # type: QScrollArea
74
+ scroll.setWidget(grid)
75
+ scroll.setWidgetResizable(True)
76
+ self.__m_scaleLabel = QLabel() # type: QLabel
77
+ scale = QSlider(Qt.Horizontal) # type: QSlider
78
+ scale.setRange(2, 6)
79
+ scale.setValue(4)
80
+ scale.valueChanged.connect(self.setScale)
81
+ sharp = QSlider(Qt.Horizontal) # type: QSlider
82
+ sharp.setRange(0, 200)
83
+ sharp.setValue(30)
84
+ sharp.valueChanged.connect(lambda v: (self.__m_upscaler.setSharpness(v / 100.0), self.render()))
85
+ bar = QHBoxLayout() # type: QHBoxLayout
86
+ bar.addWidget(self.__m_scaleLabel)
87
+ bar.addWidget(scale)
88
+ bar.addWidget(QLabel(self.tr(u'Sharpness')))
89
+ bar.addWidget(sharp)
90
+ wdg = QWidget() # type: QWidget
91
+ v = QVBoxLayout(wdg) # type: QVBoxLayout
92
+ v.addLayout(bar)
93
+ v.addWidget(scroll)
94
+ self.setCentralWidget(wdg)
95
+ self.__m_scale = 4 # type: int
96
+ self.render()
97
+
98
+ @pyqtSlot()
99
+ def render(self):
100
+ """
101
+ :return:
102
+ """
103
+ self.__m_scaleLabel.setText(self.tr(u'Scale x{}').format(self.__m_scale))
104
+ size = self.__m_sample.size() * self.__m_scale # type: QSize
105
+ for method, title, image in self.__m_cells:
106
+ self.__m_upscaler.setMethod(method)
107
+ out = self.__m_upscaler.process(self.__m_sample, size) # type: QImage
108
+ title.setText(
109
+ u'{} - {:.1f} ms'.format(Upscaler.METHOD_NAMES[method], self.__m_upscaler.getLastProcessTime()))
110
+ image.setPixmap(QPixmap.fromImage(out))
111
+
112
+ @pyqtSlot(int)
113
+ def setScale(self, scale):
114
+ """
115
+ :param scale: int
116
+ :return:
117
+ """
118
+ self.__m_scale = int(scale) # type: int
119
+ self.render()
120
+
121
+ @pyqtSlot('QString')
122
+ @pyqtSlot(str)
123
+ def onError(self, message):
124
+ """
125
+ :param message: str | unicode | QString
126
+ :return:
127
+ """
128
+ print(message)
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,4 @@
1
+ # coding=utf-8
2
+ """
3
+ Bundled FSRCNN super-resolution models (Apache-2.0, see LICENSE-FSRCNN).
4
+ """
@@ -0,0 +1,285 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Upscaler: real-time upscaling engine for QImage frames.
4
+ Methods (each degrades gracefully when its optional dependency is missing):
5
+ - Nearest : Qt only. Pixel-perfect blocks, best for inspecting pixels.
6
+ - Bilinear : Qt only. Smooth, cheap.
7
+ - Bicubic : OpenCV. Sharper than bilinear.
8
+ - Lanczos : OpenCV. Sharpest classic interpolation (Lanczos-4).
9
+ - PixelArt : NumPy. Edge-aware Scale2x (EPX) passes, keeps lines and text edges crisp.
10
+ - AIFast : OpenCV-contrib dnn_superres + FSRCNN-small (bundled), ~10 ms for 200x150 -> x4.
11
+ - AIQuality : OpenCV-contrib dnn_superres + FSRCNN (bundled), better detail, ~2.5x slower.
12
+ An optional unsharp mask ("sharpness") can be applied after any smooth method (needs OpenCV).
13
+ """
14
+ from ManyQt.QtCore import Qt, QObject, QElapsedTimer, pyqtSignal, pyqtSlot, pyqtProperty, Q_ENUMS, qVersion
15
+ from ManyQt.QtGui import QImage
16
+ from os.path import dirname, join
17
+ from enum import IntEnum
18
+ from sys import path
19
+
20
+ if not __package__ and dirname(__file__) not in path:
21
+ path.append(dirname(__file__))
22
+
23
+ try: # The algorithms are Qt-free (core.py), shared with the headless server.
24
+ from .core import UpscaleEngine, METHOD_NAMES as CORE_NAMES, MODEL_FILES as CORE_MODELS, nearestResize, scale2x, \
25
+ hasNumpy, hasCV2
26
+ except:
27
+ from core import UpscaleEngine, METHOD_NAMES as CORE_NAMES, MODEL_FILES as CORE_MODELS, nearestResize, scale2x, \
28
+ hasNumpy, hasCV2
29
+ if hasNumpy:
30
+ from numpy import frombuffer, ascontiguousarray, ndarray, uint8
31
+ MODELS_DIR = join(dirname(__file__), 'models') # type: str
32
+
33
+
34
+ def clamp(x, a, b):
35
+ """
36
+ :param x: float | int
37
+ :param a: float | int
38
+ :param b: float | int
39
+ :return: float | int
40
+ """
41
+ return a if x < a else b if x > b else x
42
+
43
+
44
+ def qimageToArray(image):
45
+ """
46
+ Convert a QImage into an owned (H, W, 3) uint8 RGB NumPy array.
47
+ :param image: QImage
48
+ :return: ndarray
49
+ """
50
+ img = image.convertToFormat(QImage.Format_RGB888) # type: QImage
51
+ w, h, bpl = img.width(), img.height(), img.bytesPerLine() # type: int, int, int
52
+ nBytes = img.sizeInBytes() if hasattr(img, 'sizeInBytes') else img.byteCount() # type: int
53
+ ptr = img.constBits()
54
+ if hasattr(ptr, 'setsize'): # PyQt (sip.voidptr). PySide returns a memoryview.
55
+ ptr.setsize(nBytes)
56
+ arr = frombuffer(ptr, uint8, count=nBytes).reshape(h, bpl)[:, :w * 3] # type: ndarray
57
+ return arr.reshape(h, w, 3).copy()
58
+
59
+
60
+ def arrayToQImage(arr):
61
+ """
62
+ Convert an (H, W, 3) uint8 RGB NumPy array into a QImage that owns its memory.
63
+ :param arr: ndarray
64
+ :return: QImage
65
+ """
66
+ arr = ascontiguousarray(arr, dtype=uint8) # type: ndarray
67
+ h, w = arr.shape[:2] # type: int, int
68
+ return QImage(arr.data, w, h, 3 * w, QImage.Format_RGB888).copy()
69
+
70
+
71
+ class Upscaler(QObject):
72
+ """
73
+ Upscaler class: converts a QImage crop into a QImage of the requested size with the selected method.
74
+ """
75
+
76
+ class Method(IntEnum):
77
+ """
78
+ Method enumeration class.
79
+ """
80
+ Nearest = 0 # type: int
81
+ Bilinear = 1 # type: int
82
+ Bicubic = 2 # type: int
83
+ Lanczos = 3 # type: int
84
+ PixelArt = 4 # type: int
85
+ AIFast = 5 # type: int
86
+ AIQuality = 6 # type: int
87
+
88
+ Nearest = Method.Nearest # type: int
89
+ Bilinear = Method.Bilinear # type: int
90
+ Bicubic = Method.Bicubic # type: int
91
+ Lanczos = Method.Lanczos # type: int
92
+ PixelArt = Method.PixelArt # type: int
93
+ AIFast = Method.AIFast # type: int
94
+ AIQuality = Method.AIQuality # type: int
95
+ METHOD_NAMES = dict(zip(map(Method, CORE_NAMES), CORE_NAMES.values())) # type: dict # names: core.py
96
+ MODEL_FILES = dict(zip(map(Method, CORE_MODELS), CORE_MODELS.values())) # type: dict
97
+ methodChanged = pyqtSignal(int) # type: pyqtSignal
98
+ sharpnessChanged = pyqtSignal(float) # type: pyqtSignal
99
+ errorOccurred = pyqtSignal('QString') # type: pyqtSignal
100
+
101
+ def __init__(self, *args, **kwargs):
102
+ """
103
+ :param method: (Upscaler.Method | int) Upscaling method, falls back to the best available one.
104
+ :param sharpness: (float | int) Unsharp-mask amount 0.0 .. 2.0 applied after smooth methods.
105
+ :param aiMinScale: (float | int) Below this scale factor the AI methods use Lanczos instead.
106
+ :param modelsDir: (str | unicode | QString)Folder containing FSRCNN*_x{2,3,4}.pb files.
107
+ :param errorOccurred: callable | None
108
+ :param args: any
109
+ :param kwargs: any
110
+ """
111
+ method = kwargs.pop('method', Upscaler.Lanczos) # type: int
112
+ sharpness = kwargs.pop('sharpness', 0.3) # type: float
113
+ aiMinScale = kwargs.pop('aiMinScale', 1.5) # type: float
114
+ modelsDir = kwargs.pop('modelsDir', MODELS_DIR) # type: str
115
+ errorOccurred = kwargs.pop('errorOccurred', None) # type: callable | None
116
+ super(Upscaler, self).__init__(*args, **kwargs)
117
+ if callable(errorOccurred):
118
+ self.errorOccurred.connect(errorOccurred)
119
+ # Options.
120
+ self.__m_modelsDir = u'{}'.format(modelsDir) # type: str
121
+ self.__m_sharpness = clamp(float(sharpness), 0.0, 2.0) # type: float
122
+ self.__m_aiMinScale = max(1.0, float(aiMinScale)) # type: float
123
+ self.__m_engine = UpscaleEngine(modelsDir=self.__m_modelsDir, aiMinScale=self.__m_aiMinScale,
124
+ onError=self.errorOccurred.emit) # type: UpscaleEngine
125
+ self.__m_method = self._resolve(method) # type: Upscaler.Method
126
+ # State.
127
+ self.__m_lastTimeMs = 0.0 # type: float
128
+ self.__m_clock = QElapsedTimer() # type: QElapsedTimer
129
+
130
+ # ---------- Helpers ----------
131
+ @staticmethod
132
+ def hasNumpy():
133
+ """
134
+ :return: bool
135
+ """
136
+ return hasNumpy
137
+
138
+ @staticmethod
139
+ def hasOpenCV():
140
+ """
141
+ :return: bool
142
+ """
143
+ return hasCV2 and hasNumpy
144
+
145
+ @staticmethod
146
+ def hasSuperRes():
147
+ """
148
+ :return: bool
149
+ """
150
+ return UpscaleEngine.hasSuperRes()
151
+
152
+ def isMethodAvailable(self, method):
153
+ """
154
+ :param method: Upscaler.Method | int
155
+ :return: bool
156
+ """
157
+ return self.__m_engine.isMethodAvailable(int(method))
158
+
159
+ def availableMethods(self):
160
+ """
161
+ :return: (list[tuple[Upscaler.Method, str]]) Available methods with display names.
162
+ """
163
+ return [(Upscaler.Method(m), n) for m, n in self.__m_engine.availableMethods()]
164
+
165
+ def _resolve(self, method):
166
+ """
167
+ Return the method itself if available, else the closest available fallback.
168
+ :param method: Upscaler.Method | int
169
+ :return: Upscaler.Method
170
+ """
171
+ return Upscaler.Method(self.__m_engine.resolve(int(method)))
172
+
173
+ # ---------- Public API ----------
174
+ def process(self, image, size):
175
+ """
176
+ Upscale (or downscale) image to exactly size using the current method.
177
+ :param image: QImage
178
+ :param size: QSize
179
+ :return: QImage
180
+ """
181
+ if image is None or image.isNull() or size.isEmpty():
182
+ return QImage()
183
+ self.__m_clock.start()
184
+ w, h = size.width(), size.height() # type: int, int
185
+ scale = max(w / float(image.width()), h / float(image.height())) # type: float
186
+ m = self.__m_method # type: Upscaler.Method
187
+ sharpen = self.__m_sharpness > 0.0 and scale > 1.0 and Upscaler.hasOpenCV() and m not in (
188
+ Upscaler.Nearest, Upscaler.PixelArt) # type: bool
189
+ if m == Upscaler.Nearest or (m == Upscaler.Bilinear and not sharpen):
190
+ mode = Qt.FastTransformation if m == Upscaler.Nearest else Qt.SmoothTransformation # type: int
191
+ out = image.scaled(size, Qt.IgnoreAspectRatio, mode) # type: QImage
192
+ else:
193
+ up = self.__m_engine.upscale(qimageToArray(image), w, h, int(m),
194
+ self.__m_sharpness if sharpen else 0.0) # type: ndarray
195
+ out = arrayToQImage(up) # type: QImage
196
+ self.__m_lastTimeMs = float(self.__m_clock.nsecsElapsed()) / 1e6 # type: float
197
+ return out
198
+
199
+ def getLastProcessTime(self):
200
+ """
201
+ :return: (float | int) Duration of the last process() call in ms.
202
+ """
203
+ return self.__m_lastTimeMs
204
+
205
+ def getMethod(self):
206
+ """
207
+ :return: Upscaler.Method
208
+ """
209
+ return self.__m_method
210
+
211
+ @pyqtSlot(Method)
212
+ @pyqtSlot(int)
213
+ def setMethod(self, method):
214
+ """
215
+ :param method: Upscaler.Method | int
216
+ :return:
217
+ """
218
+ method = self._resolve(method) # type: Upscaler.Method
219
+ if method != self.__m_method:
220
+ self.__m_method = method # type: Upscaler.Method
221
+ self.methodChanged.emit(int(method))
222
+
223
+ def getMethodName(self):
224
+ """
225
+ :return: str | unicode | QString
226
+ """
227
+ return Upscaler.METHOD_NAMES[self.__m_method]
228
+
229
+ def getSharpness(self):
230
+ """
231
+ :return: float | int
232
+ """
233
+ return self.__m_sharpness
234
+
235
+ @pyqtSlot(float)
236
+ @pyqtSlot(int)
237
+ def setSharpness(self, sharpness):
238
+ """
239
+ :param sharpness: (float | int) 0.0 .. 2.0
240
+ :return:
241
+ """
242
+ sharpness = clamp(float(sharpness), 0.0, 2.0) # type: float
243
+ if sharpness != self.__m_sharpness:
244
+ self.__m_sharpness = sharpness # type: float
245
+ self.sharpnessChanged.emit(sharpness)
246
+
247
+ def getAiMinScale(self):
248
+ """
249
+ :return: float | int
250
+ """
251
+ return self.__m_aiMinScale
252
+
253
+ @pyqtSlot(float)
254
+ @pyqtSlot(int)
255
+ def setAiMinScale(self, aiMinScale):
256
+ """
257
+ :param aiMinScale: float | int
258
+ :return:
259
+ """
260
+ self.__m_aiMinScale = max(1.0, float(aiMinScale)) # type: float
261
+ self.__m_engine.setAiMinScale(self.__m_aiMinScale)
262
+
263
+ def getModelsDir(self):
264
+ """
265
+ :return: str | unicode | QString
266
+ """
267
+ return self.__m_modelsDir
268
+
269
+ @pyqtSlot('QString')
270
+ @pyqtSlot(str)
271
+ def setModelsDir(self, modelsDir):
272
+ """
273
+ :param modelsDir: str | unicode | QString
274
+ :return:
275
+ """
276
+ self.__m_modelsDir = u'{}'.format(modelsDir) # type: str
277
+ self.__m_engine.setModelsDir(self.__m_modelsDir)
278
+ self.setMethod(self.__m_method)
279
+
280
+ # ---------- Properties ----------
281
+ Q_ENUMS('Method' if qVersion()[0] == '4' else Method)
282
+ method = pyqtProperty(int, fget=getMethod, fset=setMethod, notify=methodChanged) # type: pyqtProperty
283
+ sharpness = pyqtProperty(float, fget=getSharpness, fset=setSharpness, notify=sharpnessChanged) # type: pyqtProperty
284
+ aiMinScale = pyqtProperty(float, fget=getAiMinScale, fset=setAiMinScale) # type: pyqtProperty
285
+ modelsDir = pyqtProperty('QString', fget=getModelsDir, fset=setModelsDir) # type: pyqtProperty