Skip to content

Commit

Permalink
fix: Disable precapture sequence by default (#2629)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy authored Mar 4, 2024
1 parent e8dd1e0 commit 3f1a7c9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ suspend fun CameraView.takePhoto(optionsMap: ReadableMap): WritableMap {
val flash = options["flash"] as? String ?: "off"
val enableAutoStabilization = options["enableAutoStabilization"] == true
val enableShutterSound = options["enableShutterSound"] as? Boolean ?: true
val enablePrecapture = options["enablePrecapture"] as? Boolean ?: false

// TODO: Implement Red Eye Reduction
options["enableAutoRedEyeReduction"]
Expand All @@ -44,6 +45,7 @@ suspend fun CameraView.takePhoto(optionsMap: ReadableMap): WritableMap {
flashMode,
enableShutterSound,
enableAutoStabilization,
enablePrecapture,
orientation
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
flash: Flash,
enableShutterSound: Boolean,
enableAutoStabilization: Boolean,
enablePrecapture: Boolean,
outputOrientation: Orientation
): CapturedPhoto {
val photoOutput = photoOutput ?: throw PhotoNotEnabledError()
Expand All @@ -380,7 +381,8 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
enableAutoStabilization,
photoOutput.enableHdr,
outputOrientation,
enableShutterSound
enableShutterSound,
enablePrecapture
)

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ class PersistentCameraCaptureSession(private val cameraManager: CameraManager, p
enableAutoStabilization: Boolean,
enablePhotoHdr: Boolean,
orientation: Orientation,
enableShutterSound: Boolean
enableShutterSound: Boolean,
enablePrecapture: Boolean
): TotalCaptureResult {
// Cancel any ongoing focus jobs
focusJob?.cancel()
Expand All @@ -169,7 +170,8 @@ class PersistentCameraCaptureSession(private val cameraManager: CameraManager, p
val outputs = outputs
val repeatingOutputs = outputs.filter { it.isRepeating }

if (qualityPrioritization == QualityPrioritization.SPEED && flash == Flash.OFF) {
val skipPrecapture = !enablePrecapture || qualityPrioritization == QualityPrioritization.SPEED
if (skipPrecapture && flash == Flash.OFF) {
// 0. We want to take a picture as fast as possible, so skip any precapture sequence and just capture one Frame.
Log.i(TAG, "Using fast capture path without pre-capture sequence...")
val singleRequest = photoRequest.createCaptureRequest(device, deviceDetails, outputs)
Expand Down
8 changes: 8 additions & 0 deletions package/src/PhotoFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ export interface TakePhotoOptions {
* @default true
*/
enableShutterSound?: boolean
/**
* Whether to run the pre-capture sequence to properly lock AF, AE and AWB values.
* Enabling this results in greater photos, but might not work on some devices.
*
* @platform Android
* @default false
*/
enablePrecapture?: boolean
}

/**
Expand Down

0 comments on commit 3f1a7c9

Please sign in to comment.