feat: Implement exposure (#2173)

* feat: Implement `exposure` (iOS)

* Update Podfile.lock

* Format

* Expose exposure in format

* Set exposure in Camera2

* fix: Fix exposure calculation

* Add exposure docs
This commit is contained in:
Marc Rousavy
2023-11-19 15:26:43 +01:00
committed by GitHub
parent a7e706150e
commit ef58d13b87
19 changed files with 156 additions and 8 deletions

View File

@@ -78,6 +78,7 @@ class CameraView(context: Context) :
var isActive = false
var torch: Torch = Torch.OFF
var zoom: Float = 1f // in "factor"
var exposure: Float = 1f // TODO: Implement exposure bias
var orientation: Orientation = Orientation.PORTRAIT
var enableZoomGesture: Boolean = false
set(value) {
@@ -198,6 +199,7 @@ class CameraView(context: Context) :
config.fps = fps
config.enableLowLightBoost = lowLightBoost ?: false
config.torch = torch
config.exposure = exposure
// Zoom
config.zoom = zoom

View File

@@ -140,8 +140,12 @@ class CameraViewManager : ViewGroupManager<CameraView>() {
@ReactProp(name = "zoom")
fun setZoom(view: CameraView, zoom: Double) {
val zoomFloat = zoom.toFloat()
view.zoom = zoomFloat
view.zoom = zoom.toFloat()
}
@ReactProp(name = "exposure")
fun setExposure(view: CameraView, exposure: Double) {
view.exposure = exposure.toFloat()
}
@ReactProp(name = "orientation")

View File

@@ -33,6 +33,7 @@ data class CameraConfiguration(
var enableLowLightBoost: Boolean = false,
var torch: Torch = Torch.OFF,
var videoStabilizationMode: VideoStabilizationMode = VideoStabilizationMode.OFF,
var exposure: Float? = null,
// Zoom
var zoom: Float = 1f,
@@ -94,7 +95,8 @@ data class CameraConfiguration(
val sidePropsChanged = outputsChanged || // depend on outputs
left?.torch != right.torch || left.enableLowLightBoost != right.enableLowLightBoost || left.fps != right.fps ||
left.zoom != right.zoom || left.videoStabilizationMode != right.videoStabilizationMode || left.isActive != right.isActive
left.zoom != right.zoom || left.videoStabilizationMode != right.videoStabilizationMode || left.isActive != right.isActive ||
left.exposure != right.exposure
return Difference(
deviceChanged,

View File

@@ -6,6 +6,7 @@ import android.hardware.camera2.CameraManager
import android.hardware.camera2.CameraMetadata
import android.os.Build
import android.util.Range
import android.util.Rational
import android.util.Size
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReadableArray
@@ -68,6 +69,8 @@ class CameraDeviceDetails(private val cameraManager: CameraManager, private val
private val cameraConfig = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)!!
private val isoRange = characteristics.get(CameraCharacteristics.SENSOR_INFO_SENSITIVITY_RANGE) ?: Range(0, 0)
private val exposureRange = characteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE) ?: Range(0, 0)
private val exposureStep = characteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP) ?: Rational(1, 1)
private val digitalStabilizationModes =
characteristics.get(CameraCharacteristics.CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES) ?: IntArray(0)
private val opticalStabilizationModes =
@@ -174,6 +177,9 @@ class CameraDeviceDetails(private val cameraManager: CameraManager, private val
map.putInt("videoWidth", videoSize.width)
map.putInt("minISO", isoRange.lower)
map.putInt("maxISO", isoRange.upper)
// TODO: Implement minExposureBias
map.putDouble("minExposure", exposureRange.lower.toDouble() / exposureStep.toDouble())
map.putDouble("maxExposure", exposureRange.upper.toDouble() / exposureStep.toDouble())
map.putInt("minFps", fpsRange.lower)
map.putInt("maxFps", fpsRange.upper)
map.putDouble("maxZoom", maxZoom)

View File

@@ -434,6 +434,12 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
captureRequest.set(CaptureRequest.CONTROL_SCENE_MODE, CaptureRequest.CONTROL_SCENE_MODE_NIGHT)
}
// Set Exposure Bias
val exposure = config.exposure?.toInt()
if (exposure != null) {
captureRequest.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, exposure)
}
// Set Zoom
// TODO: Check if that zoom value is even supported
captureRequest.setZoom(config.zoom, cameraCharacteristics)

View File

@@ -13,6 +13,8 @@ data class CameraDeviceFormat(
val maxFps: Double,
val minISO: Double,
val maxISO: Double,
val minExposure: Double,
val maxExposure: Double,
val fieldOfView: Double,
val maxZoom: Double,
val videoStabilizationModes: List<VideoStabilizationMode>,
@@ -46,6 +48,8 @@ data class CameraDeviceFormat(
value.getDouble("maxFps"),
value.getDouble("minISO"),
value.getDouble("maxISO"),
value.getDouble("minExposure"),
value.getDouble("maxExposure"),
value.getDouble("fieldOfView"),
value.getDouble("maxZoom"),
videoStabilizationModes,