Update camera API to use defined capture modes

Switching to defined capture modes

Closes #424 (closed) #436 (closed) #786 (closed) #405 (closed) #593 (closed)

This MR contains the following

  • Introduce defined modes for captures which are set by the camera, use these for captureing functions rather than picamera style stream names.
  • Create ImageFormatInfo class for defining information about capture formats
  • Rename capture_array to capture_as_array to match grab_as_array
  • Remove capture_jpeg and capture_png to just capture
  • Consolidate capture methods, including moving the robust capture logic into save from memory
  • Change actions that were accepting full paths (which is a security issue as anywhere on the Pi could be written to from the web API) to instead take a RelativeDataPath object RootModel` which
    • Is created automatically if a string is passed to actions or models that need this class.
    • Validates that the path is relative and doesn't contain ..s
    • Adds a method for Things to be added as the saving Thing (so the data is saved in the Thing's data dir)
    • Adds a way to set temporary directories rather than a Thing for the saving
    • Adds a way to set a fallback for if the Thing wasn't set
    • For camera actions if no saving Thing is set (such as if a method is called over the HTTP API) then the camera sets itself as a fall back.
  • Change webapp to use new capture method but only provide one option. This will need to be extended by reading the capture modes of the available camera. This should be a separate MR
  • Better testing of captures.

Before merge:

  • Finish refactor
  • Better docstrings.
    • Be clear that setting raw=True ignores some settings
  • Add better tests including
    • Checking that the jpeg quality is always set for
    • Checking the image format correct

Screenshots

Before:
image

After:
image

Merge checklist:

  • All new/changed functions have up to date typehints and docstrings
  • Any UI updates have a before and after screenshot in the MR description
  • Unit testing of new functionality has similar or better coverage than similar existing code
  • This code has been tested on a microscope
    • Webapp has been recompiled, with aesthetic changes checked in light and dark mode (if changed)
    • With updated settings JSON (if changed)
    • SmartScan and live stitching work
Edited by Julian Stirling

Merge request reports

Loading