fix: raw hdr baseline exposure
This commit is contained in:
1 parent
5ba66f0498
commit
5c7408e2fa
2 files changed
+40
-3
No files matched your search
@@ -3797,10 +3797,16 @@ class Camera2Controller(private val context: Context) {
|
||||
private fun calculateHdrBracketExposureCompensation(state: CameraState, evOffset: Float): Int {
|
||||
val evStep = state.getExposureCompensationStep().takeIf { it > 0f } ?: return state.exposureCompensation
|
||||
val range = state.getExposureCompensationRange()
|
||||
val steps = (evOffset / evStep).roundToInt()
|
||||
val steps = roundHdrBracketCompensationSteps(evOffset, evStep)
|
||||
return (state.exposureCompensation + steps).coerceIn(range.lower, range.upper)
|
||||
}
|
||||
|
||||
private fun roundHdrBracketCompensationSteps(evOffset: Float, evStep: Float): Int {
|
||||
if (evOffset == 0f) return 0
|
||||
val magnitude = (abs(evOffset / evStep) + 0.0001f).roundToInt()
|
||||
return if (evOffset < 0f) -magnitude else magnitude
|
||||
}
|
||||
|
||||
private fun copyStillFocusSettingsFromPreview(builder: CaptureRequest.Builder) {
|
||||
previewRequestBuilder?.let { preview ->
|
||||
preview.get(CaptureRequest.CONTROL_AF_MODE)?.let {
|
||||
|
||||
@@ -58,6 +58,7 @@ import kotlin.io.extension
|
||||
import kotlin.io.inputStream
|
||||
import kotlin.io.readBytes
|
||||
import kotlin.io.walkBottomUp
|
||||
import kotlin.math.ln
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.system.measureTimeMillis
|
||||
import kotlin.use
|
||||
@@ -85,7 +86,7 @@ object GalleryManager {
|
||||
private const val DETAIL_HDR_FILE = "detail_hdr.jpg"
|
||||
private const val MULTIPLE_EXPOSURE_DIR = "multiple_exposure_sessions"
|
||||
private const val MULTIPLE_EXPOSURE_PREVIEW_FILE = "preview.jpg"
|
||||
private const val RAW_HDR_DNG_BASELINE_EXPOSURE_EV = 2.0f
|
||||
private const val RAW_HDR_DNG_BASELINE_EXPOSURE_EV_FALLBACK = 2.5f
|
||||
|
||||
data class VideoRecordInfo(
|
||||
val uri: Uri,
|
||||
@@ -2309,6 +2310,10 @@ object GalleryManager {
|
||||
rawHdrFusionResult = fusionResult
|
||||
|
||||
val fusedBayerBuffer = fusionResult.fusedBayerBuffer ?: return@withContext false
|
||||
val rawHdrBaselineExposureEv = calculateRawHdrDngBaselineExposureEv(
|
||||
referenceResult = zeroResult,
|
||||
captureResults = listOf(lowResult, zeroResult, highResult)
|
||||
)
|
||||
val dngWritten = try {
|
||||
trySaveStackedRawDng(
|
||||
context = context,
|
||||
@@ -2327,7 +2332,7 @@ object GalleryManager {
|
||||
metadata = metadata,
|
||||
shouldAutoSave = shouldAutoSave,
|
||||
exportDngWithRawExport = exportDngWithRawExport,
|
||||
baselineExposureEv = RAW_HDR_DNG_BASELINE_EXPOSURE_EV
|
||||
baselineExposureEv = rawHdrBaselineExposureEv
|
||||
)
|
||||
} finally {
|
||||
fusionResult.fusedBayerBuffer = null
|
||||
@@ -2397,6 +2402,32 @@ object GalleryManager {
|
||||
)
|
||||
}
|
||||
|
||||
private fun calculateRawHdrDngBaselineExposureEv(
|
||||
referenceResult: CaptureResult,
|
||||
captureResults: List<CaptureResult>,
|
||||
): Float {
|
||||
val referenceProduct = rawExposureProduct(referenceResult)
|
||||
.takeIf { it.isFinite() && it > 0.0 }
|
||||
?: return RAW_HDR_DNG_BASELINE_EXPOSURE_EV_FALLBACK
|
||||
val baseProduct = captureResults
|
||||
.mapNotNull { result ->
|
||||
rawExposureProduct(result).takeIf { it.isFinite() && it > 0.0 }
|
||||
}
|
||||
.minOrNull()
|
||||
?: return RAW_HDR_DNG_BASELINE_EXPOSURE_EV_FALLBACK
|
||||
val baselineExposureEv = if (baseProduct < referenceProduct) {
|
||||
(ln(referenceProduct / baseProduct) / ln(2.0)).toFloat()
|
||||
} else {
|
||||
0f
|
||||
}.coerceIn(0f, 8f)
|
||||
PLog.d(
|
||||
TAG,
|
||||
"RAW HDR DNG baseline exposure: ${baselineExposureEv}EV, " +
|
||||
"referenceProduct=$referenceProduct, baseProduct=$baseProduct"
|
||||
)
|
||||
return baselineExposureEv
|
||||
}
|
||||
|
||||
private fun rawExposureProduct(captureResult: CaptureResult): Double {
|
||||
val iso = captureResult.get(CaptureResult.SENSOR_SENSITIVITY)?.coerceAtLeast(1) ?: 1
|
||||
val exposureTime = captureResult.get(CaptureResult.SENSOR_EXPOSURE_TIME)?.coerceAtLeast(1L) ?: 1L
|
||||
|
||||
Reference in new issue
Block a user