Add auto detection of orientation

This commit is contained in:
Emanuele 2020-05-31 00:24:13 +01:00
parent 8db6189bd1
commit 62cd969826
3 changed files with 47 additions and 4 deletions

View file

@ -39,7 +39,7 @@ The supported configuration settings are:
// alternatively to key, "password": "****" is supported
"timeout": 1 // in seconds
},
"orientation": "portrait", // default: landscape
"orientation": "portrait", // auto for auto-detect, default: landscape
"pen_size": 10, // set to 0 to disable
"pen_color": "red",
"background_color": "black", // default: white

View file

@ -65,11 +65,17 @@ class rMViewApp(QApplication):
self.viewer.menu.addAction(act)
self.viewer.setWindowTitle("rMview")
self.viewer.show()
if self.config.get('orientation', 'landscape') == 'landscape':
self.orient = None
orient = self.config.get('orientation', 'landscape')
if orient == 'landscape':
self.viewer.rotateCW()
self.autoResize(WIDTH / HEIGHT)
else:
elif orient == 'portrait':
self.autoResize(HEIGHT / WIDTH)
else: # orient
self.autoResize(HEIGHT / WIDTH)
self.orient = True
# bar = QMenuBar()
# menu = bar.addMenu('&View')
@ -93,6 +99,25 @@ class rMViewApp(QApplication):
self.aboutToQuit.connect(self.joinWorkers)
self.requestConnect()
def detectOrientation(self, image):
c = image.pixel
portrait = False
# print(c(48, 47) , c(72, 72) , c(55, 55) , c(64, 65))
if c(48, 47) == 4278190080 and c(72, 72) == 4278190080 and \
(c(55, 55) == 4294967295 or c(64, 65) == 4294967295):
if c(61, 1812) != 4278190080 or c(5,5) == 4278190080:
portrait = True
elif c(1356, 47) == 4278190080 and c(1329, 72) == 4278190080 and \
(c(1348, 54) == 4294967295 or c(1336, 65) == 4294967295):
portrait = True
elif c(5,5) == 4278190080:
portrait = True
if portrait:
self.viewer.portrait()
self.autoResize(HEIGHT / WIDTH)
else:
self.viewer.landscape()
self.autoResize(WIDTH / HEIGHT)
def autoResize(self, ratio):
dg = self.desktop().availableGeometry(self.viewer)
@ -144,7 +169,7 @@ class rMViewApp(QApplication):
self.ssh = ssh
self.viewer.setWindowTitle("rMview - " + self.config.get('ssh').get('address'))
self.fbworker = FrameBufferWorker(ssh, delay=self.config.get('fetch_frame_delay'), lz4_path=self.config.get('lz4_path_on_remarkable'))
self.fbworker.signals.onNewFrame.connect(lambda image: self.viewer.setImage(image))
self.fbworker.signals.onNewFrame.connect(self.onNewFrame)
self.fbworker.signals.onFatalError.connect(self.frameError)
self.threadpool.start(self.fbworker)
@ -162,6 +187,13 @@ class rMViewApp(QApplication):
self.penworker.signals.onPenFar.connect(self.pen.hide)
@pyqtSlot(QImage)
def onNewFrame(self, image):
if self.orient:
self.detectOrientation(image)
self.orient = False
self.viewer.setImage(image)
@pyqtSlot(int, int)
def movePen(self, x, y):
y = 20951 - y

View file

@ -151,6 +151,17 @@ class QtImageViewer(QGraphicsView):
img = img.transformed(QTransform().rotate(self._rotation))
img.save(fileName)
def landscape(self):
self.resetTransform()
self.rotate(90)
self._rotation = 90
self.updateViewer()
def portrait(self):
self.resetTransform()
self._rotation = 0
self.updateViewer()
def rotateCW(self):
self.rotate(90)
self._rotation += 90