2021-02-20 23:20:28 +01:00
|
|
|
import { useMemo } from 'react';
|
2021-02-23 08:50:51 +01:00
|
|
|
import type { CameraDevice, CameraDeviceFormat } from '../CameraDevice';
|
2021-05-14 11:52:28 +02:00
|
|
|
import { sortFormats } from '../utils/FormatFilter';
|
2021-02-20 23:20:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the best format for the given camera device.
|
|
|
|
*
|
|
|
|
* This function tries to choose a format with the highest possible photo-capture resolution and best matching aspect ratio.
|
|
|
|
*
|
2021-03-03 12:37:43 +01:00
|
|
|
* @param {CameraDevice} device The Camera Device
|
2021-02-20 23:20:28 +01:00
|
|
|
*
|
|
|
|
* @returns The best matching format for the given camera device, or `undefined` if the camera device is `undefined`.
|
|
|
|
*/
|
2021-05-14 11:52:28 +02:00
|
|
|
export function useCameraFormat(device?: CameraDevice): CameraDeviceFormat | undefined {
|
|
|
|
return useMemo(() => device?.formats.sort(sortFormats)[0], [device?.formats]);
|
2021-02-20 23:20:28 +01:00
|
|
|
}
|