Marc Rousavy 0b7b4d50b5
Automatically build API documentation (#11)
* Automatically build API documentation using Typedoc and Docusaurus
* Move MD and move to MDX for Docusaurus Guides
2021-03-03 12:37:43 +01:00

14 KiB

id title sidebar_label custom_edit_url hide_title
utils_formatfilter Module: utils/FormatFilter utils/FormatFilter null true

Module: utils/FormatFilter

Type aliases

Size

Ƭ Size: object

Represents a Size in any unit.

Type declaration:

Name Type Description
height number Points in height.
width number Points in width.

Defined in: src/utils/FormatFilter.ts:36

Functions

filterFormatsByAspectRatio

ConstfilterFormatsByAspectRatio(formats: Readonly<{ autoFocusSystem: AutoFocusSystem ; colorSpaces: ColorSpace[] ; fieldOfView: number ; frameRateRanges: Readonly<{ maxFrameRate: number ; minFrameRate: number }>[] ; isHighestPhotoQualitySupported?: undefined | boolean ; maxISO: number ; maxZoom: number ; minISO: number ; photoHeight: number ; photoWidth: number ; supportsPhotoHDR: boolean ; supportsVideoHDR: boolean ; videoHeight?: undefined | number ; videoStabilizationModes: VideoStabilizationMode[] ; videoWidth?: undefined | number }>[], viewSize?: Size): Readonly<{ autoFocusSystem: AutoFocusSystem ; colorSpaces: ColorSpace[] ; fieldOfView: number ; frameRateRanges: Readonly<{ maxFrameRate: number ; minFrameRate: number }>[] ; isHighestPhotoQualitySupported?: undefined | boolean ; maxISO: number ; maxZoom: number ; minISO: number ; photoHeight: number ; photoWidth: number ; supportsPhotoHDR: boolean ; supportsVideoHDR: boolean ; videoHeight?: undefined | number ; videoStabilizationModes: VideoStabilizationMode[] ; videoWidth?: undefined | number }>[]

Filters Camera Device Formats by the best matching aspect ratio for the given viewSize.

example

const formats = useMemo(() => filterFormatsByAspectRatio(device.formats, CAMERA_VIEW_SIZE), [device.formats])

method

Parameters:

Name Type Description
formats Readonly<{ autoFocusSystem: AutoFocusSystem ; colorSpaces: ColorSpace[] ; fieldOfView: number ; frameRateRanges: Readonly<{ maxFrameRate: number ; minFrameRate: number }>[] ; isHighestPhotoQualitySupported?: undefined | boolean ; maxISO: number ; maxZoom: number ; minISO: number ; photoHeight: number ; photoWidth: number ; supportsPhotoHDR: boolean ; supportsVideoHDR: boolean ; videoHeight?: undefined | number ; videoStabilizationModes: VideoStabilizationMode[] ; videoWidth?: undefined | number }>[] A list of formats the current device has (see {@link CameraDevice.formats})
viewSize Size The size of the camera view which will be used to find the best aspect ratio. Defaults to the screen size.

Returns: Readonly<{ autoFocusSystem: AutoFocusSystem ; colorSpaces: ColorSpace[] ; fieldOfView: number ; frameRateRanges: Readonly<{ maxFrameRate: number ; minFrameRate: number }>[] ; isHighestPhotoQualitySupported?: undefined | boolean ; maxISO: number ; maxZoom: number ; minISO: number ; photoHeight: number ; photoWidth: number ; supportsPhotoHDR: boolean ; supportsVideoHDR: boolean ; videoHeight?: undefined | number ; videoStabilizationModes: VideoStabilizationMode[] ; videoWidth?: undefined | number }>[]

A list of Camera Device Formats that match the given viewSize' aspect ratio as close as possible.

Defined in: src/utils/FormatFilter.ts:92


frameRateIncluded

ConstframeRateIncluded(range: Readonly<{ maxFrameRate: number ; minFrameRate: number }>, fps: number): boolean

Returns true if the given Frame Rate Range (range) contains the given frame rate (fps)

example

// get all formats that support 60 FPS
const formatsWithHighFps = useMemo(() => device.formats.filter((f) => f.frameRateRanges.some((r) => frameRateIncluded(r, 60))), [device.formats])

method

Parameters:

Name Type Description
range Readonly<{ maxFrameRate: number ; minFrameRate: number }> The range to check if the given fps are included in
fps number The FPS to check if the given range supports.

Returns: boolean

Defined in: src/utils/FormatFilter.ts:137


sortDevices

ConstsortDevices(left: Readonly<{ devices: PhysicalCameraDeviceType[] ; formats: Readonly<{ autoFocusSystem: AutoFocusSystem ; colorSpaces: ColorSpace[] ; fieldOfView: number ; frameRateRanges: Readonly<{ maxFrameRate: number ; minFrameRate: number }>[] ; isHighestPhotoQualitySupported?: undefined | boolean ; maxISO: number ; maxZoom: number ; minISO: number ; photoHeight: number ; photoWidth: number ; supportsPhotoHDR: boolean ; supportsVideoHDR: boolean ; videoHeight?: undefined | number ; videoStabilizationModes: VideoStabilizationMode[] ; videoWidth?: undefined | number }>[] ; hasFlash: boolean ; hasTorch: boolean ; id: string ; isMultiCam: boolean ; maxZoom: number ; minZoom: number ; name: string ; neutralZoom: number ; position: CameraPosition ; supportsLowLightBoost: boolean }>, right: Readonly<{ devices: PhysicalCameraDeviceType[] ; formats: Readonly<{ autoFocusSystem: AutoFocusSystem ; colorSpaces: ColorSpace[] ; fieldOfView: number ; frameRateRanges: Readonly<{ maxFrameRate: number ; minFrameRate: number }>[] ; isHighestPhotoQualitySupported?: undefined | boolean ; maxISO: number ; maxZoom: number ; minISO: number ; photoHeight: number ; photoWidth: number ; supportsPhotoHDR: boolean ; supportsVideoHDR: boolean ; videoHeight?: undefined | number ; videoStabilizationModes: VideoStabilizationMode[] ; videoWidth?: undefined | number }>[] ; hasFlash: boolean ; hasTorch: boolean ; id: string ; isMultiCam: boolean ; maxZoom: number ; minZoom: number ; name: string ; neutralZoom: number ; position: CameraPosition ; supportsLowLightBoost: boolean }>): number

Compares two devices by the following criteria:

  • wide-angle-cameras are ranked higher than others
  • Devices with more physical cameras are ranked higher than ones with less. (e.g. "Triple Camera" > "Wide-Angle Camera")

Note that this makes the sort() function descending, so the first element ([0]) is the "best" device.

example

const devices = camera.devices.sort(sortDevices)
const bestDevice = devices[0]

method

Parameters:

Name Type
left Readonly<{ devices: PhysicalCameraDeviceType[] ; formats: Readonly<{ autoFocusSystem: AutoFocusSystem ; colorSpaces: ColorSpace[] ; fieldOfView: number ; frameRateRanges: Readonly<{ maxFrameRate: number ; minFrameRate: number }>[] ; isHighestPhotoQualitySupported?: undefined | boolean ; maxISO: number ; maxZoom: number ; minISO: number ; photoHeight: number ; photoWidth: number ; supportsPhotoHDR: boolean ; supportsVideoHDR: boolean ; videoHeight?: undefined | number ; videoStabilizationModes: VideoStabilizationMode[] ; videoWidth?: undefined | number }>[] ; hasFlash: boolean ; hasTorch: boolean ; id: string ; isMultiCam: boolean ; maxZoom: number ; minZoom: number ; name: string ; neutralZoom: number ; position: CameraPosition ; supportsLowLightBoost: boolean }>
right Readonly<{ devices: PhysicalCameraDeviceType[] ; formats: Readonly<{ autoFocusSystem: AutoFocusSystem ; colorSpaces: ColorSpace[] ; fieldOfView: number ; frameRateRanges: Readonly<{ maxFrameRate: number ; minFrameRate: number }>[] ; isHighestPhotoQualitySupported?: undefined | boolean ; maxISO: number ; maxZoom: number ; minISO: number ; photoHeight: number ; photoWidth: number ; supportsPhotoHDR: boolean ; supportsVideoHDR: boolean ; videoHeight?: undefined | number ; videoStabilizationModes: VideoStabilizationMode[] ; videoWidth?: undefined | number }>[] ; hasFlash: boolean ; hasTorch: boolean ; id: string ; isMultiCam: boolean ; maxZoom: number ; minZoom: number ; name: string ; neutralZoom: number ; position: CameraPosition ; supportsLowLightBoost: boolean }>

Returns: number

Defined in: src/utils/FormatFilter.ts:18


sortFormatsByResolution

ConstsortFormatsByResolution(left: Readonly<{ autoFocusSystem: AutoFocusSystem ; colorSpaces: ColorSpace[] ; fieldOfView: number ; frameRateRanges: Readonly<{ maxFrameRate: number ; minFrameRate: number }>[] ; isHighestPhotoQualitySupported?: undefined | boolean ; maxISO: number ; maxZoom: number ; minISO: number ; photoHeight: number ; photoWidth: number ; supportsPhotoHDR: boolean ; supportsVideoHDR: boolean ; videoHeight?: undefined | number ; videoStabilizationModes: VideoStabilizationMode[] ; videoWidth?: undefined | number }>, right: Readonly<{ autoFocusSystem: AutoFocusSystem ; colorSpaces: ColorSpace[] ; fieldOfView: number ; frameRateRanges: Readonly<{ maxFrameRate: number ; minFrameRate: number }>[] ; isHighestPhotoQualitySupported?: undefined | boolean ; maxISO: number ; maxZoom: number ; minISO: number ; photoHeight: number ; photoWidth: number ; supportsPhotoHDR: boolean ; supportsVideoHDR: boolean ; videoHeight?: undefined | number ; videoStabilizationModes: VideoStabilizationMode[] ; videoWidth?: undefined | number }>): number

Sorts Camera Device Formats by highest photo-capture resolution, descending. Use this in a .sort function.

example

const formats = useMemo(() => device.formats.sort(sortFormatsByResolution), [device.formats])
const bestFormat = formats[0]

method

Parameters:

Name Type
left Readonly<{ autoFocusSystem: AutoFocusSystem ; colorSpaces: ColorSpace[] ; fieldOfView: number ; frameRateRanges: Readonly<{ maxFrameRate: number ; minFrameRate: number }>[] ; isHighestPhotoQualitySupported?: undefined | boolean ; maxISO: number ; maxZoom: number ; minISO: number ; photoHeight: number ; photoWidth: number ; supportsPhotoHDR: boolean ; supportsVideoHDR: boolean ; videoHeight?: undefined | number ; videoStabilizationModes: VideoStabilizationMode[] ; videoWidth?: undefined | number }>
right Readonly<{ autoFocusSystem: AutoFocusSystem ; colorSpaces: ColorSpace[] ; fieldOfView: number ; frameRateRanges: Readonly<{ maxFrameRate: number ; minFrameRate: number }>[] ; isHighestPhotoQualitySupported?: undefined | boolean ; maxISO: number ; maxZoom: number ; minISO: number ; photoHeight: number ; photoWidth: number ; supportsPhotoHDR: boolean ; supportsVideoHDR: boolean ; videoHeight?: undefined | number ; videoStabilizationModes: VideoStabilizationMode[] ; videoWidth?: undefined | number }>

Returns: number

Defined in: src/utils/FormatFilter.ts:112