Commit 366b771b authored by Joel Collins's avatar Joel Collins
Browse files

Added size and position params to GPU preview route

parent 51cd7767
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
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)
+2 −2
Original line number Diff line number Diff line
@@ -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