Skip to content

Commit

Permalink
feat: Add pixelFormat field (#559)
Browse files Browse the repository at this point in the history
* Add `mediaSubType` field to device formats

* Create FourCharCode `toString` extension

* Move pixelFormat -> `AVCaptureDevice.Format+toDictionary`

* `mediaSubType` -> `pixelFormat` + non-optional

* ts pixelFormat `string` -> specific formats

* Add default pixelFormat value of `420v` on Android

Co-authored-by: tcoldwell72 <31568400+tcoldwell72@users.noreply.github.com>
  • Loading branch information
thomas-coldwell and thomas-coldwell committed Dec 10, 2021
1 parent a54ff57 commit c3039c9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions android/src/main/java/com/mrousavy/camera/CameraViewModule.kt
Expand Up @@ -244,6 +244,9 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase
}
}

// TODO: Get the pixel format programatically rather than assuming a default of 420v
val pixelFormat = "420v"

val format = Arguments.createMap()
format.putDouble("photoHeight", size.height.toDouble())
format.putDouble("photoWidth", size.width.toDouble())
Expand All @@ -260,6 +263,7 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase
format.putArray("frameRateRanges", frameRateRanges)
format.putString("autoFocusSystem", "none") // TODO: Revisit getAvailableCameraDevices (autoFocusSystem) (CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES or CameraCharacteristics.LENS_INFO_FOCUS_DISTANCE_CALIBRATION)
format.putArray("videoStabilizationModes", videoStabilizationModes)
format.putString("pixelFormat", pixelFormat)
formats.pushMap(format)
}
}
Expand Down
3 changes: 2 additions & 1 deletion ios/Extensions/AVCaptureDevice.Format+toDictionary.swift
Expand Up @@ -42,12 +42,13 @@ extension AVCaptureDevice.Format {
"maxFrameRate": $0.maxFrameRate,
]
},
"pixelFormat": CMFormatDescriptionGetMediaSubType(formatDescription).toString()
]

if #available(iOS 13.0, *) {
dict["isHighestPhotoQualitySupported"] = self.isHighestPhotoQualitySupported
}

return dict
}
}
17 changes: 17 additions & 0 deletions ios/Extensions/FourCharCode+toString.swift
@@ -0,0 +1,17 @@
//
// FourCharCode+toString.swift
// VisionCamera
//
// Created by Thomas Coldwell on 28/10/2021.
// Based off this SO answer: https://stackoverflow.com/a/25625744
//

extension FourCharCode {
func toString() -> String {
var s: String = String (UnicodeScalar((self >> 24) & 255)!)
s.append(String(UnicodeScalar((self >> 16) & 255)!))
s.append(String(UnicodeScalar((self >> 8) & 255)!))
s.append(String(UnicodeScalar(self & 255)!))
return (s)
}
}
5 changes: 5 additions & 0 deletions src/CameraDevice.ts
@@ -1,4 +1,5 @@
import type { CameraPosition } from './CameraPosition';
import type { PixelFormat } from './PixelFormat';

/**
* Indentifiers for a physical camera (one that actually exists on the back/front of the device)
Expand Down Expand Up @@ -171,6 +172,10 @@ export interface CameraDeviceFormat {
* All supported video stabilization modes
*/
videoStabilizationModes: VideoStabilizationMode[];
/**
* Specifies the pixel format on iOS. e.g. 420v, 420f
*/
pixelFormat: PixelFormat;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/PixelFormat.ts
@@ -0,0 +1,7 @@
/**
* Represents the pixel format of a `Frame`.
* * `420v`: 420 YpCbCr 8 Bi-Planar Video Range
* * `420f`: 420 YpCbCr 8 Bi-Planar Full Range
* * `x420`: 420 YpCbCr 10 Bi-Planar Video Range
*/
export type PixelFormat = '420f' | '420v' | 'x420';

0 comments on commit c3039c9

Please sign in to comment.