From 366b771b725012e74611c12b82ad1efdc5f90c3d Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Tue, 19 Feb 2019 11:04:12 +0000 Subject: [PATCH] Added size and position params to GPU preview route --- .../api/v1/blueprints/camera/preview.py | 22 ++++++++++++++++--- openflexure_microscope/camera/pi.py | 4 ++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/openflexure_microscope/api/v1/blueprints/camera/preview.py b/openflexure_microscope/api/v1/blueprints/camera/preview.py index 2150712f..11ea28f8 100644 --- a/openflexure_microscope/api/v1/blueprints/camera/preview.py +++ b/openflexure_microscope/api/v1/blueprints/camera/preview.py @@ -1,13 +1,16 @@ +from openflexure_microscope.api.utilities import JsonPayload from openflexure_microscope.api.v1.views import MicroscopeView -from flask import jsonify +from flask import jsonify, request class GPUPreviewAPI(MicroscopeView): def post(self, operation): """ - Create a new image capture. + Start or stop the onboard GPU preview. + Optional "window" parameter can be passed to control the position and size of the preview window, + in the format ``[x, y, width, height]``. .. :quickref: GPU Preview; Start/stop preview @@ -18,6 +21,10 @@ class GPUPreviewAPI(MicroscopeView): POST /camera/preview/start HTTP/1.1 Accept: application/json + { + "window": [0, 0, 480, 320], + } + .. sourcecode:: http POST /camera/preview/stop HTTP/1.1 @@ -29,7 +36,16 @@ class GPUPreviewAPI(MicroscopeView): :status 200: preview started/stopped """ if operation == "start": - self.microscope.camera.start_preview() + payload = JsonPayload(request) + + window = payload.param('window', default=[]) + fullscreen = False + + if len(window) != 4 or not all(isinstance(n, int) for n in window): + fullscreen = True + window = None + + self.microscope.camera.start_preview(fullscreen=fullscreen, window=window) elif operation == "stop": self.microscope.camera.stop_preview() return jsonify(self.microscope.state) diff --git a/openflexure_microscope/camera/pi.py b/openflexure_microscope/camera/pi.py index f39034e6..df49fc40 100644 --- a/openflexure_microscope/camera/pi.py +++ b/openflexure_microscope/camera/pi.py @@ -225,9 +225,9 @@ class StreamingCamera(BaseCamera): # LAUNCH ACTIONS - def start_preview(self) -> bool: + def start_preview(self, fullscreen=True, window=None) -> bool: """Start the on board GPU camera preview.""" - self.camera.start_preview() + self.camera.start_preview(fullscreen=fullscreen, window=window) self.state['preview_active'] = True return True