feat: implement multi-level DRO support with automatic exposure adjustment
This commit is contained in:
1 parent
a4ba452a9f
commit
7f26c4959b
26 files changed
+326
-144
No files matched your search
@@ -29,6 +29,7 @@ import kotlinx.coroutines.flow.asStateFlow
|
||||
import com.hinnka.mycamera.livephoto.LivePhotoRecorder
|
||||
import com.hinnka.mycamera.model.SafeImage
|
||||
import com.hinnka.mycamera.processor.MultiFrameStacker
|
||||
import com.hinnka.mycamera.raw.RawProcessingPreferences.DROMode
|
||||
import com.hinnka.mycamera.utils.DeviceUtil
|
||||
import com.hinnka.mycamera.utils.OrientationObserver
|
||||
import com.hinnka.mycamera.video.CaptureMode
|
||||
@@ -1489,6 +1490,70 @@ class Camera2Controller(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun resolveCaptureExposureCompensation(state: CameraState, droExposureReductionEv: Float): Int {
|
||||
if (droExposureReductionEv <= 0f) return state.exposureCompensation
|
||||
val evStep = state.getExposureCompensationStep().takeIf { it > 0f } ?: return state.exposureCompensation
|
||||
val droSteps = (droExposureReductionEv / evStep).roundToInt()
|
||||
val range = state.getExposureCompensationRange()
|
||||
val adjusted = (state.exposureCompensation - droSteps).coerceIn(range.lower, range.upper)
|
||||
PLog.d(TAG, "RAW DRO ${state.droMode} AE compensation adjusted: ${state.exposureCompensation} -> $adjusted")
|
||||
return adjusted
|
||||
}
|
||||
|
||||
private fun calculateDroAdjustedExposure(state: CameraState): Pair<Int, Long> {
|
||||
val droExposureReductionEv = if (state.useRaw && state.captureMode == CaptureMode.PHOTO) {
|
||||
DROMode.fromPersistedName(state.droMode).captureExposureReductionEv
|
||||
} else {
|
||||
0f
|
||||
}
|
||||
|
||||
if (droExposureReductionEv <= 0f) return Pair(state.iso, state.shutterSpeed)
|
||||
|
||||
var remainingEv = droExposureReductionEv.toDouble()
|
||||
var targetIso = state.iso
|
||||
var targetShutter = state.shutterSpeed
|
||||
|
||||
val isoRange = state.getIsoRange()
|
||||
val shutterRange = state.getShutterSpeedRange()
|
||||
|
||||
if (state.iso > 200) {
|
||||
// Prioritize ISO reduction
|
||||
val maxIsoReductionEv = ln(targetIso.toDouble() / isoRange.lower.toDouble()) / ln(2.0)
|
||||
val isoReductionEv = remainingEv.coerceAtMost(maxIsoReductionEv)
|
||||
if (isoReductionEv > 0) {
|
||||
targetIso = (targetIso / 2.0.pow(isoReductionEv)).roundToInt().coerceIn(isoRange.lower, isoRange.upper)
|
||||
remainingEv -= isoReductionEv
|
||||
}
|
||||
|
||||
if (remainingEv > 0.01) {
|
||||
val maxShutterReductionEv = ln(targetShutter.toDouble() / shutterRange.lower.toDouble()) / ln(2.0)
|
||||
val shutterReductionEv = remainingEv.coerceAtMost(maxShutterReductionEv)
|
||||
if (shutterReductionEv > 0) {
|
||||
targetShutter = (targetShutter / 2.0.pow(shutterReductionEv)).toLong().coerceIn(shutterRange.lower, shutterRange.upper)
|
||||
remainingEv -= shutterReductionEv
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Prioritize Shutter reduction
|
||||
val maxShutterReductionEv = ln(targetShutter.toDouble() / shutterRange.lower.toDouble()) / ln(2.0)
|
||||
val shutterReductionEv = remainingEv.coerceAtMost(maxShutterReductionEv)
|
||||
if (shutterReductionEv > 0) {
|
||||
targetShutter = (targetShutter / 2.0.pow(shutterReductionEv)).toLong().coerceIn(shutterRange.lower, shutterRange.upper)
|
||||
remainingEv -= shutterReductionEv
|
||||
}
|
||||
|
||||
if (remainingEv > 0.01) {
|
||||
val maxIsoReductionEv = ln(targetIso.toDouble() / isoRange.lower.toDouble()) / ln(2.0)
|
||||
val isoReductionEv = remainingEv.coerceAtMost(maxIsoReductionEv)
|
||||
if (isoReductionEv > 0) {
|
||||
targetIso = (targetIso / 2.0.pow(isoReductionEv)).roundToInt().coerceIn(isoRange.lower, isoRange.upper)
|
||||
remainingEv -= isoReductionEv
|
||||
}
|
||||
}
|
||||
}
|
||||
return Pair(targetIso, targetShutter)
|
||||
}
|
||||
|
||||
private fun applyVideoFpsRange(builder: CaptureRequest.Builder, targetFps: Int) {
|
||||
val characteristics = cachedCharacteristics ?: return
|
||||
val availableRanges =
|
||||
@@ -1873,6 +1938,12 @@ class Camera2Controller(private val context: Context) {
|
||||
PLog.d(TAG, "RAW 格式拍照: $enabled")
|
||||
}
|
||||
|
||||
fun setDroMode(mode: String) {
|
||||
val resolvedMode = DROMode.fromPersistedName(mode).name
|
||||
_state.value = _state.value.copy(droMode = resolvedMode)
|
||||
PLog.d(TAG, "RAW DRO mode: $resolvedMode")
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置虚化模拟光圈大小
|
||||
*/
|
||||
@@ -3075,6 +3146,7 @@ class Camera2Controller(private val context: Context) {
|
||||
private fun performCapture(device: CameraDevice, reader: ImageReader) {
|
||||
try {
|
||||
val isRawCapture = isRawCaptureReader(reader)
|
||||
|
||||
val captureBuilder = device.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE).apply {
|
||||
addTarget(reader.surface)
|
||||
|
||||
@@ -3086,6 +3158,30 @@ class Camera2Controller(private val context: Context) {
|
||||
// isCapture = true 确保使用完整的曝光时间(不限制长曝光)
|
||||
applyBaseCameraSettings(this, isCapture = true, isRawCapture = isRawCapture)
|
||||
|
||||
// 强制手动控制 DRO 曝光调整 (覆盖 applyBaseCameraSettings 中的 AE 设置)
|
||||
if (state.value.useRaw && state.value.captureMode == CaptureMode.PHOTO) {
|
||||
val droExposureReductionEv = DROMode.fromPersistedName(state.value.droMode).captureExposureReductionEv
|
||||
if (droExposureReductionEv > 0f) {
|
||||
if (isManualSensorSupported) {
|
||||
val (adjustedIso, adjustedShutter) = calculateDroAdjustedExposure(_state.value)
|
||||
set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF)
|
||||
set(CaptureRequest.SENSOR_SENSITIVITY, adjustedIso)
|
||||
set(CaptureRequest.SENSOR_EXPOSURE_TIME, adjustedShutter)
|
||||
PLog.d(
|
||||
TAG,
|
||||
"Capture DRO ${state.value.droMode} override (Manual): ISO=$adjustedIso, shutter=$adjustedShutter"
|
||||
)
|
||||
} else if (state.value.isIsoAuto && state.value.isShutterSpeedAuto) {
|
||||
val adjustedCompensation = resolveCaptureExposureCompensation(state.value, droExposureReductionEv)
|
||||
set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, adjustedCompensation)
|
||||
PLog.d(
|
||||
TAG,
|
||||
"Capture DRO ${state.value.droMode} override (AE Compensation): $adjustedCompensation"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 强制将此请求的触发器设为 IDLE,防止携带预览中的触发状态
|
||||
set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_IDLE)
|
||||
|
||||
|
||||
@@ -207,6 +207,7 @@ data class CameraState(
|
||||
val useMFSR: Boolean = false,
|
||||
val useRaw: Boolean = false,
|
||||
val useLivePhoto: Boolean = false,
|
||||
val droMode: String = "OFF",
|
||||
// 是否正在拍摄 Live Photo (用于 UI 动画)
|
||||
val isCapturingLivePhoto: Boolean = false,
|
||||
val applyUltraHDR: Boolean = true,
|
||||
|
||||
@@ -312,7 +312,7 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
enableDevelopAnimation = preferences[ENABLE_DEVELOP_ANIMATION] ?: false,
|
||||
backgroundImage = preferences[BACKGROUND_IMAGE] ?: "camera_bg",
|
||||
useGpuAcceleration = preferences[USE_GPU_ACCELERATION] ?: DeviceUtil.defaultGpuAcceleration,
|
||||
droMode = preferences[DRO_MODE] ?: "OFF",
|
||||
droMode = preferences[DRO_MODE] ?: if (preferences[RAW_DRO_ENABLED_KEY] == true) "DR100" else "OFF",
|
||||
applyUltraHDR = preferences[APPLY_ULTRA_HDR] ?: false,
|
||||
colorSpace = ColorSpace.valueOf(preferences[COLOR_SPACE] ?: ColorSpace.SRGB.name),
|
||||
logCurve = TransferCurve.fromPersistedName(preferences[LOG_CURVE] ?: TransferCurve.SRGB.name),
|
||||
|
||||
@@ -53,13 +53,10 @@ import kotlin.io.deleteRecursively
|
||||
import kotlin.io.extension
|
||||
import kotlin.io.inputStream
|
||||
import kotlin.io.readBytes
|
||||
import kotlin.io.readText
|
||||
import kotlin.io.walkBottomUp
|
||||
import kotlin.io.writeText
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.system.measureTimeMillis
|
||||
import kotlin.use
|
||||
import androidx.core.net.toUri
|
||||
|
||||
/**
|
||||
* 照片管理器
|
||||
@@ -1179,7 +1176,7 @@ object GalleryManager {
|
||||
rawBlackPointCorrection = metadata.rawBlackPointCorrection ?: 0f,
|
||||
rawWhitePointCorrection = metadata.rawWhitePointCorrection ?: 0f,
|
||||
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(context, metadata),
|
||||
rawDROEnabled = metadata.rawDROEnabled ?: false,
|
||||
rawDROMode = droMode,
|
||||
sharpeningValue = 0.4f,
|
||||
denoiseValue = metadata.rawDenoiseValue,
|
||||
rawDcpId = metadata.rawDcpId
|
||||
@@ -1739,7 +1736,9 @@ object GalleryManager {
|
||||
rawBlackPointCorrection = metadata.rawBlackPointCorrection ?: 0f,
|
||||
rawWhitePointCorrection = metadata.rawWhitePointCorrection ?: 0f,
|
||||
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(context, metadata),
|
||||
rawDROEnabled = metadata.rawDROEnabled ?: false,
|
||||
rawDROMode = RawProcessingPreferences.DROMode.fromPersistedName(
|
||||
metadata.droMode
|
||||
),
|
||||
sharpeningValue = 0.4f,
|
||||
denoiseValue = metadata.rawDenoiseValue,
|
||||
rawDcpId = metadata.rawDcpId
|
||||
@@ -1935,7 +1934,6 @@ object GalleryManager {
|
||||
superResolutionScale: Float = 1.0f,
|
||||
useGpuAcceleration: Boolean = true,
|
||||
exposureBias: Float? = null,
|
||||
droMode: RawProcessingPreferences.DROMode = RawProcessingPreferences.DROMode.OFF,
|
||||
exportDngWithRawExport: Boolean = false
|
||||
) = withContext(Dispatchers.IO) {
|
||||
when (val format = images[0].format) {
|
||||
@@ -2654,7 +2652,9 @@ object GalleryManager {
|
||||
rawBlackPointCorrection = updatedMetadata.rawBlackPointCorrection ?: 0f,
|
||||
rawWhitePointCorrection = updatedMetadata.rawWhitePointCorrection ?: 0f,
|
||||
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(context, updatedMetadata),
|
||||
rawDROEnabled = updatedMetadata.rawDROEnabled ?: false,
|
||||
rawDROMode = RawProcessingPreferences.DROMode.fromPersistedName(
|
||||
updatedMetadata.droMode
|
||||
),
|
||||
sharpeningValue = 0.4f,
|
||||
denoiseValue = updatedMetadata.rawDenoiseValue,
|
||||
rawDcpId = updatedMetadata.rawDcpId,
|
||||
@@ -2744,7 +2744,6 @@ object GalleryManager {
|
||||
suspend fun refreshRawPreview(
|
||||
context: Context,
|
||||
photoId: String,
|
||||
droMode: RawProcessingPreferences.DROMode
|
||||
): Bitmap? {
|
||||
return withContext(Dispatchers.IO) {
|
||||
try {
|
||||
@@ -2769,8 +2768,9 @@ object GalleryManager {
|
||||
rawBlackPointCorrection = updatedMetadata?.rawBlackPointCorrection ?: 0f,
|
||||
rawWhitePointCorrection = updatedMetadata?.rawWhitePointCorrection ?: 0f,
|
||||
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(context, updatedMetadata),
|
||||
rawDROEnabled = (updatedMetadata ?: metadata)?.rawDROEnabled ?: false,
|
||||
sharpeningValue = 0.4f,
|
||||
rawDROMode = updatedMetadata?.droMode?.let { RawProcessingPreferences.DROMode.fromPersistedName(it) }
|
||||
?: RawProcessingPreferences.DROMode.OFF,
|
||||
sharpeningValue = updatedMetadata?.sharpening ?: 0.4f,
|
||||
denoiseValue = (updatedMetadata ?: MediaMetadata()).rawDenoiseValue,
|
||||
rawDcpId = updatedMetadata?.rawDcpId,
|
||||
onMetadata = { raw ->
|
||||
|
||||
@@ -43,7 +43,6 @@ data class MediaMetadata(
|
||||
val rawBlackPointCorrection: Float? = null,
|
||||
val rawWhitePointCorrection: Float? = null,
|
||||
val rawAutoWhiteBalanceEstimate: Boolean? = null,
|
||||
val rawDROEnabled: Boolean? = null,
|
||||
val rawDcpId: String? = null,
|
||||
// 边框水印配置
|
||||
val frameId: String? = null,
|
||||
@@ -170,7 +169,6 @@ data class MediaMetadata(
|
||||
shutterSpeed = formatShutterSpeed(raw.shutterSpeed).takeIf { it.isNotEmpty() } ?: shutterSpeed,
|
||||
aperture = formatAperture(raw.aperture).takeIf { it.isNotEmpty() } ?: aperture,
|
||||
exposureBias = raw.exposureBias,
|
||||
droMode = null,
|
||||
width = raw.width.takeIf { it > 0 } ?: width,
|
||||
height = raw.height.takeIf { it > 0 } ?: height
|
||||
)
|
||||
@@ -252,7 +250,6 @@ data class MediaMetadata(
|
||||
rawBlackPointCorrection = if (obj.isNull("rawBlackPointCorrection")) null else obj.optDouble("rawBlackPointCorrection").toFloat(),
|
||||
rawWhitePointCorrection = if (obj.isNull("rawWhitePointCorrection")) null else obj.optDouble("rawWhitePointCorrection").toFloat(),
|
||||
rawAutoWhiteBalanceEstimate = if (obj.isNull("rawAutoWhiteBalanceEstimate")) null else obj.optBoolean("rawAutoWhiteBalanceEstimate"),
|
||||
rawDROEnabled = if (obj.isNull("rawDROEnabled")) null else obj.optBoolean("rawDROEnabled"),
|
||||
rawDcpId = if (obj.isNull("rawDcpId")) null else obj.optString("rawDcpId"),
|
||||
rawBlackLevelMode = if (obj.isNull("rawBlackLevelMode")) null else obj.optString("rawBlackLevelMode"),
|
||||
rawCustomBlackLevel = if (obj.isNull("rawCustomBlackLevel")) null else obj.optDouble("rawCustomBlackLevel").toFloat(),
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.hinnka.mycamera.lut.LutManager
|
||||
import com.hinnka.mycamera.processor.DepthBokehProcessor
|
||||
import com.hinnka.mycamera.raw.RawDemosaicProcessor
|
||||
import com.hinnka.mycamera.raw.RawHdrRenderResult
|
||||
import com.hinnka.mycamera.raw.RawProcessingPreferences
|
||||
import com.hinnka.mycamera.utils.BitmapUtils
|
||||
import com.hinnka.mycamera.utils.PLog
|
||||
import com.hinnka.mycamera.utils.YuvProcessor
|
||||
@@ -63,11 +64,6 @@ class PhotoProcessor(
|
||||
?: (userPreferencesRepository.userPreferences.firstOrNull()?.rawAutoExposure ?: true)
|
||||
}
|
||||
|
||||
private suspend fun resolveRawDROEnabled(metadata: MediaMetadata): Boolean {
|
||||
return metadata.rawDROEnabled
|
||||
?: (userPreferencesRepository.userPreferences.firstOrNull()?.rawDROEnabled ?: false)
|
||||
}
|
||||
|
||||
suspend fun prepareUltraHdrSource(
|
||||
context: Context,
|
||||
photoId: String,
|
||||
@@ -450,7 +446,9 @@ class PhotoProcessor(
|
||||
rawBlackPointCorrection = metadata.rawBlackPointCorrection ?: 0f,
|
||||
rawWhitePointCorrection = metadata.rawWhitePointCorrection ?: 0f,
|
||||
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(metadata),
|
||||
rawDROEnabled = resolveRawDROEnabled(metadata),
|
||||
rawDROMode = RawProcessingPreferences.DROMode.fromPersistedName(
|
||||
metadata.droMode
|
||||
),
|
||||
sharpeningValue = 0.4f,
|
||||
denoiseValue = metadata.rawDenoiseValue,
|
||||
rawDcpId = metadata.rawDcpId
|
||||
@@ -512,7 +510,9 @@ class PhotoProcessor(
|
||||
rawBlackPointCorrection = metadata.rawBlackPointCorrection ?: 0f,
|
||||
rawWhitePointCorrection = metadata.rawWhitePointCorrection ?: 0f,
|
||||
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(metadata),
|
||||
rawDROEnabled = resolveRawDROEnabled(metadata),
|
||||
rawDROMode = RawProcessingPreferences.DROMode.fromPersistedName(
|
||||
metadata.droMode
|
||||
),
|
||||
denoiseValue = metadata.rawDenoiseValue,
|
||||
rawDcpId = metadata.rawDcpId
|
||||
)
|
||||
|
||||
@@ -258,7 +258,7 @@ object GalleryMediaStore {
|
||||
aiDenoiseStrength = metadata.aiDenoiseStrength,
|
||||
rawBlackLevelMode = metadata.rawBlackLevelMode,
|
||||
rawCustomBlackLevel = metadata.rawCustomBlackLevel,
|
||||
rawDROEnabled = metadata.rawDROEnabled,
|
||||
rawDROEnabled = false,
|
||||
cameraId = metadata.cameraId
|
||||
)
|
||||
}
|
||||
@@ -384,7 +384,6 @@ object GalleryMediaStore {
|
||||
aiDenoiseStrength = aiDenoiseStrength,
|
||||
rawBlackLevelMode = rawBlackLevelMode,
|
||||
rawCustomBlackLevel = rawCustomBlackLevel,
|
||||
rawDROEnabled = rawDROEnabled,
|
||||
cameraId = cameraId
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import androidx.core.graphics.createBitmap
|
||||
import com.hinnka.mycamera.camera.AspectRatio
|
||||
import com.hinnka.mycamera.data.ContentRepository
|
||||
import com.hinnka.mycamera.ml.SharedDepthEstimator
|
||||
import com.hinnka.mycamera.raw.RawProcessingPreferences.DROMode
|
||||
import com.hinnka.mycamera.utils.BitmapUtils
|
||||
import com.hinnka.mycamera.utils.PLog
|
||||
import com.hinnka.mycamera.utils.RawProcessor
|
||||
@@ -275,7 +276,7 @@ class RawDemosaicProcessor {
|
||||
rawBlackPointCorrection: Float = 0f,
|
||||
rawWhitePointCorrection: Float = 0f,
|
||||
rawAutoWhiteBalanceEstimate: Boolean = false,
|
||||
rawDROEnabled: Boolean = false,
|
||||
rawDROMode: DROMode = DROMode.fromPersistedName(null),
|
||||
sharpeningValue: Float = 0f,
|
||||
denoiseValue: Float? = null,
|
||||
rawDcpId: String? = null,
|
||||
@@ -300,7 +301,7 @@ class RawDemosaicProcessor {
|
||||
rawBlackPointCorrection = rawBlackPointCorrection,
|
||||
rawWhitePointCorrection = rawWhitePointCorrection,
|
||||
rawAutoWhiteBalanceEstimate = rawAutoWhiteBalanceEstimate,
|
||||
rawDROEnabled = rawDROEnabled,
|
||||
rawDROMode = rawDROMode,
|
||||
sharpeningValue = sharpeningValue,
|
||||
denoiseValue = denoiseValue,
|
||||
rawDcpId = rawDcpId,
|
||||
@@ -329,11 +330,10 @@ class RawDemosaicProcessor {
|
||||
rotation: Int,
|
||||
rawExposureCompensation: Float = 0f,
|
||||
rawAutoExposure: Boolean = true,
|
||||
rawMeteringCenterWeight: Float = 0f,
|
||||
rawBlackPointCorrection: Float = 0f,
|
||||
rawWhitePointCorrection: Float = 0f,
|
||||
rawAutoWhiteBalanceEstimate: Boolean = false,
|
||||
rawDROEnabled: Boolean = false,
|
||||
rawDROMode: DROMode = DROMode.fromPersistedName(null),
|
||||
sharpeningValue: Float = 0f,
|
||||
denoiseValue: Float? = null,
|
||||
chromaDenoiseValue: Float? = null,
|
||||
@@ -363,7 +363,7 @@ class RawDemosaicProcessor {
|
||||
rawBlackPointCorrection = rawBlackPointCorrection,
|
||||
rawWhitePointCorrection = rawWhitePointCorrection,
|
||||
rawAutoWhiteBalanceEstimate = rawAutoWhiteBalanceEstimate,
|
||||
rawDROEnabled = rawDROEnabled,
|
||||
rawDROMode = rawDROMode,
|
||||
sharpeningValue = sharpeningValue,
|
||||
denoiseValue = denoiseValue,
|
||||
chromaDenoiseValue = chromaDenoiseValue,
|
||||
@@ -388,7 +388,7 @@ class RawDemosaicProcessor {
|
||||
rawBlackPointCorrection: Float = 0f,
|
||||
rawWhitePointCorrection: Float = 0f,
|
||||
rawAutoWhiteBalanceEstimate: Boolean = false,
|
||||
rawDROEnabled: Boolean = false,
|
||||
rawDROMode: DROMode = DROMode.fromPersistedName(null),
|
||||
sharpeningValue: Float = 0f,
|
||||
denoiseValue: Float? = null,
|
||||
rawDcpId: String? = null,
|
||||
@@ -413,7 +413,7 @@ class RawDemosaicProcessor {
|
||||
rawBlackPointCorrection = rawBlackPointCorrection,
|
||||
rawWhitePointCorrection = rawWhitePointCorrection,
|
||||
rawAutoWhiteBalanceEstimate = rawAutoWhiteBalanceEstimate,
|
||||
rawDROEnabled = rawDROEnabled,
|
||||
rawDROMode = rawDROMode,
|
||||
sharpeningValue = sharpeningValue,
|
||||
denoiseValue = denoiseValue,
|
||||
rawDcpId = rawDcpId,
|
||||
@@ -447,7 +447,7 @@ class RawDemosaicProcessor {
|
||||
rawBlackPointCorrection: Float = 0f,
|
||||
rawWhitePointCorrection: Float = 0f,
|
||||
rawAutoWhiteBalanceEstimate: Boolean = false,
|
||||
rawDROEnabled: Boolean = false,
|
||||
rawDROMode: DROMode = DROMode.fromPersistedName(null),
|
||||
sharpeningValue: Float = 0f,
|
||||
denoiseValue: Float? = null,
|
||||
chromaDenoiseValue: Float? = null,
|
||||
@@ -621,13 +621,13 @@ class RawDemosaicProcessor {
|
||||
dcpRenderPlan = resolvedDcpRenderPlan
|
||||
)
|
||||
val autoExposureEv = meteringResult.meteredEv
|
||||
if (rawDROEnabled && autoExposureEv > 0f && meteringResult.dynamicRangeGap > 1.2f) {
|
||||
if (rawDROMode.isEnabled && autoExposureEv > 0f && meteringResult.dynamicRangeGap > 1.2f) {
|
||||
val maxLinearGainEv = ln(1.0f / meteringResult.p998.coerceAtLeast(0.01f)) / ln(2.0f)
|
||||
val linearEv = autoExposureEv.coerceAtMost(maxLinearGainEv).coerceAtLeast(0f)
|
||||
val remainingEv = autoExposureEv - linearEv
|
||||
shadowLift = ((2.0f.pow(remainingEv) - 1.0f) / 0.67f).coerceIn(0f, 1.0f)
|
||||
shadowLift = ((2.0f.pow(remainingEv) - 1.0f) / 0.67f).coerceIn(0f, 5.0f)
|
||||
|
||||
PLog.d(TAG, "Raw DRO enabled linearEv = $linearEv shadowLift=$shadowLift")
|
||||
PLog.d(TAG, "Raw DRO ${rawDROMode.name} linearEv=$linearEv shadowLift=$shadowLift")
|
||||
|
||||
effectiveExposureCompensation += linearEv
|
||||
} else {
|
||||
@@ -635,6 +635,7 @@ class RawDemosaicProcessor {
|
||||
}
|
||||
|
||||
if (effectiveExposureCompensation != rawExposureCompensation) {
|
||||
PLog.d(TAG, "final auto exposure compensation = $effectiveExposureCompensation")
|
||||
renderLinearPass(
|
||||
metadata = actualMetadata,
|
||||
rawExposureCompensation = effectiveExposureCompensation,
|
||||
@@ -1870,15 +1871,17 @@ class RawDemosaicProcessor {
|
||||
val combinedLut = if (shadowLift > 0f) {
|
||||
FloatArray(baseCurve.size) { i ->
|
||||
val v = baseCurve[i]
|
||||
val gammaPower = 0.75f
|
||||
val shadowRangeEnd = 0.6f
|
||||
val x = shadowLift.coerceIn(0f, 5f)
|
||||
val boost = smoothstep(1f, 5f, x)
|
||||
val gammaPower = 0.75f + 0.13f * boost
|
||||
val shadowRangeEnd = 0.6f + 0.25f * boost
|
||||
val liftStrength = 1.35f - 0.25f * boost
|
||||
val blackProtectStart = 0.02f
|
||||
val black = 0.004f
|
||||
val liftBase = (v.pow(gammaPower) - v).coerceAtLeast(0f)
|
||||
val shadowMask = smoothstep(shadowRangeEnd, 0.02f, v)
|
||||
val blackProtect = smoothstep(black, blackProtectStart, v)
|
||||
val liftStrength = 1.35f
|
||||
val lift = shadowLift * liftBase * liftStrength * shadowMask * blackProtect
|
||||
val lift = x * liftBase * liftStrength * shadowMask * blackProtect
|
||||
(v + lift - black).coerceIn(0f, 1f)
|
||||
}
|
||||
} else {
|
||||
@@ -2239,10 +2242,6 @@ class RawDemosaicProcessor {
|
||||
if (!bitmap.isRecycled) {
|
||||
bitmap.recycle()
|
||||
}
|
||||
PLog.d(
|
||||
TAG,
|
||||
"RAW auto exposure: renderedEv=${meteringResult.meteredEv} gap=${meteringResult.dynamicRangeGap}"
|
||||
)
|
||||
meteringResult
|
||||
} catch (e: Exception) {
|
||||
PLog.e(TAG, "Failed to resolve RAW auto exposure", e)
|
||||
|
||||
@@ -6,7 +6,25 @@ package com.hinnka.mycamera.raw
|
||||
* is removed from the processing pipeline.
|
||||
*/
|
||||
object RawProcessingPreferences {
|
||||
enum class DROMode {
|
||||
OFF, LOW, HIGH
|
||||
enum class DROMode(val captureExposureReductionEv: Float) {
|
||||
OFF(0f),
|
||||
DR100(0f),
|
||||
DR200(1f),
|
||||
DR400(2f);
|
||||
|
||||
val isEnabled: Boolean
|
||||
get() = this != OFF
|
||||
|
||||
companion object {
|
||||
fun fromPersistedName(name: String?): DROMode {
|
||||
return when (name) {
|
||||
DR100.name -> DR100
|
||||
DR200.name -> DR200
|
||||
DR400.name -> DR400
|
||||
OFF.name -> OFF
|
||||
else -> OFF
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ fun CameraScreen(
|
||||
val rawAutoExposure by viewModel.rawAutoExposure.collectAsState()
|
||||
val rawBlackPointCorrection by viewModel.rawBlackPointCorrection.collectAsState()
|
||||
val rawWhitePointCorrection by viewModel.rawWhitePointCorrection.collectAsState()
|
||||
val rawDROEnabled by viewModel.rawDROEnabled.collectAsState()
|
||||
val droMode by viewModel.droMode.collectAsState()
|
||||
val multipleExposureState = viewModel.multipleExposureState
|
||||
val canStartShutterAnimation by viewModel.canStartShutterAnimation.collectAsState()
|
||||
var previewRecipeParamsOverride by remember(currentLutId) { mutableStateOf<ColorRecipeParams?>(null) }
|
||||
@@ -1185,7 +1185,7 @@ fun CameraScreen(
|
||||
rawNlmNoiseFactor = rawNlmNoiseFactor,
|
||||
rawExposureCompensation = rawExposureCompensation,
|
||||
rawAutoExposure = rawAutoExposure,
|
||||
rawDROEnabled = rawDROEnabled,
|
||||
rawDROMode = droMode,
|
||||
rawBlackPointCorrection = rawBlackPointCorrection,
|
||||
rawWhitePointCorrection = rawWhitePointCorrection,
|
||||
onSelectDcp = { viewModel.setRawDcpId(it) },
|
||||
@@ -1194,7 +1194,7 @@ fun CameraScreen(
|
||||
onRawNlmNoiseFactorChange = { viewModel.setRawNlmNoiseFactor(it) },
|
||||
onRawExposureCompensationChange = { viewModel.setRawExposureCompensation(it) },
|
||||
onRawAutoExposureChange = { viewModel.setRawAutoExposure(it) },
|
||||
onRawDROEnabledChange = { viewModel.setRawDROEnabled(it) },
|
||||
onRawDROModeChange = { viewModel.setDroMode(it) },
|
||||
onRawBlackPointCorrectionChange = { viewModel.setRawBlackPointCorrection(it) },
|
||||
onRawWhitePointCorrectionChange = { viewModel.setRawWhitePointCorrection(it) },
|
||||
onAdjustmentStart = { },
|
||||
|
||||
@@ -87,7 +87,7 @@ fun CameraTopSheet(
|
||||
rawNlmNoiseFactor: Float,
|
||||
rawExposureCompensation: Float,
|
||||
rawAutoExposure: Boolean,
|
||||
rawDROEnabled: Boolean,
|
||||
rawDROMode: String,
|
||||
rawBlackPointCorrection: Float,
|
||||
rawWhitePointCorrection: Float,
|
||||
onSelectDcp: (String?) -> Unit,
|
||||
@@ -96,7 +96,7 @@ fun CameraTopSheet(
|
||||
onRawNlmNoiseFactorChange: (Float) -> Unit,
|
||||
onRawExposureCompensationChange: (Float) -> Unit,
|
||||
onRawAutoExposureChange: (Boolean) -> Unit,
|
||||
onRawDROEnabledChange: (Boolean) -> Unit,
|
||||
onRawDROModeChange: (String) -> Unit,
|
||||
onRawBlackPointCorrectionChange: (Float) -> Unit,
|
||||
onRawWhitePointCorrectionChange: (Float) -> Unit,
|
||||
onAdjustmentStart: () -> Unit,
|
||||
@@ -478,6 +478,7 @@ fun CameraTopSheet(
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(horizontal = 24.dp)
|
||||
.padding(bottom = 32.dp)
|
||||
) {
|
||||
@@ -522,7 +523,7 @@ fun CameraTopSheet(
|
||||
rawNlmNoiseFactor = rawNlmNoiseFactor,
|
||||
rawExposureCompensation = rawExposureCompensation,
|
||||
rawAutoExposure = rawAutoExposure,
|
||||
rawDROEnabled = rawDROEnabled,
|
||||
rawDROMode = rawDROMode,
|
||||
rawBlackPointCorrection = rawBlackPointCorrection,
|
||||
rawWhitePointCorrection = rawWhitePointCorrection,
|
||||
onSelectDcp = onSelectDcp,
|
||||
@@ -531,7 +532,7 @@ fun CameraTopSheet(
|
||||
onRawNlmNoiseFactorChange = onRawNlmNoiseFactorChange,
|
||||
onRawExposureCompensationChange = onRawExposureCompensationChange,
|
||||
onRawAutoExposureChange = onRawAutoExposureChange,
|
||||
onRawDROEnabledChange = onRawDROEnabledChange,
|
||||
onRawDROModeChange = onRawDROModeChange,
|
||||
onRawBlackPointCorrectionChange = onRawBlackPointCorrectionChange,
|
||||
onRawWhitePointCorrectionChange = onRawWhitePointCorrectionChange,
|
||||
onAdjustmentStart = onAdjustmentStart,
|
||||
|
||||
@@ -18,6 +18,7 @@ import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
@@ -26,6 +27,7 @@ import com.hinnka.mycamera.R
|
||||
import com.hinnka.mycamera.lut.LutInfo
|
||||
import com.hinnka.mycamera.ui.components.LutSelector
|
||||
import com.hinnka.mycamera.raw.DcpInfo
|
||||
import com.hinnka.mycamera.raw.RawProcessingPreferences.DROMode
|
||||
|
||||
@Composable
|
||||
fun RawEditPanel(
|
||||
@@ -39,7 +41,7 @@ fun RawEditPanel(
|
||||
rawNlmNoiseFactor: Float,
|
||||
rawExposureCompensation: Float,
|
||||
rawAutoExposure: Boolean,
|
||||
rawDROEnabled: Boolean,
|
||||
rawDROMode: String,
|
||||
rawBlackPointCorrection: Float,
|
||||
rawWhitePointCorrection: Float,
|
||||
onSelectDcp: (String?) -> Unit,
|
||||
@@ -48,7 +50,7 @@ fun RawEditPanel(
|
||||
onRawNlmNoiseFactorChange: (Float) -> Unit,
|
||||
onRawExposureCompensationChange: (Float) -> Unit,
|
||||
onRawAutoExposureChange: (Boolean) -> Unit,
|
||||
onRawDROEnabledChange: (Boolean) -> Unit,
|
||||
onRawDROModeChange: (String) -> Unit,
|
||||
onRawBlackPointCorrectionChange: (Float) -> Unit,
|
||||
onRawWhitePointCorrectionChange: (Float) -> Unit,
|
||||
onAdjustmentStart: () -> Unit,
|
||||
@@ -83,11 +85,11 @@ fun RawEditPanel(
|
||||
checked = rawAutoExposure,
|
||||
onCheckedChange = onRawAutoExposureChange
|
||||
)
|
||||
RawSwitchSettingItem(
|
||||
RawDROModeSettingItem(
|
||||
title = stringResource(R.string.settings_raw_dro),
|
||||
description = stringResource(R.string.settings_raw_dro_description),
|
||||
checked = rawDROEnabled,
|
||||
onCheckedChange = onRawDROEnabledChange
|
||||
currentMode = DROMode.fromPersistedName(rawDROMode),
|
||||
onModeSelected = { onRawDROModeChange(it.name) }
|
||||
)
|
||||
SliderSettingItem(
|
||||
title = stringResource(R.string.settings_raw_exposure_compensation),
|
||||
@@ -136,6 +138,73 @@ fun RawEditPanel(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RawDROModeSettingItem(
|
||||
title: String,
|
||||
description: String,
|
||||
currentMode: DROMode,
|
||||
onModeSelected: (DROMode) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val levels = listOf(
|
||||
DROMode.OFF to stringResource(R.string.settings_dro_off),
|
||||
DROMode.DR100 to stringResource(R.string.settings_dro_dr100),
|
||||
DROMode.DR200 to stringResource(R.string.settings_dro_dr200),
|
||||
DROMode.DR400 to stringResource(R.string.settings_dro_dr400)
|
||||
)
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 8.dp)
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
color = Color.White,
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Normal
|
||||
)
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Text(
|
||||
text = description,
|
||||
color = Color.White.copy(alpha = 0.6f),
|
||||
fontSize = 13.sp,
|
||||
lineHeight = 18.sp
|
||||
)
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
FlowRow(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
levels.forEach { (mode, label) ->
|
||||
val isSelected = currentMode == mode
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.height(36.dp)
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.background(
|
||||
if (isSelected) Color(0xFFFF6B35) else Color.White.copy(alpha = 0.1f)
|
||||
)
|
||||
.clickable { onModeSelected(mode) },
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
color = Color.White,
|
||||
fontSize = 12.sp,
|
||||
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 8.dp)
|
||||
.widthIn(min = 48.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RawSwitchSettingItem(
|
||||
title: String,
|
||||
|
||||
@@ -91,7 +91,7 @@ private data class PreviewRenderSignature(
|
||||
val editRawAutoExposure: Boolean,
|
||||
val editRawBlackPointCorrection: Float,
|
||||
val editRawWhitePointCorrection: Float,
|
||||
val editRawDROEnabled: Boolean,
|
||||
val editRawDROMode: String,
|
||||
val editRawDcpId: String?,
|
||||
val editRawBaselineLutId: String?,
|
||||
val editComputationalAperture: Float?,
|
||||
@@ -157,7 +157,7 @@ fun PhotoEditScreen(
|
||||
val editRawAutoExposure by viewModel.editRawAutoExposure.collectAsState()
|
||||
val editRawBlackPointCorrection by viewModel.editRawBlackPointCorrection.collectAsState()
|
||||
val editRawWhitePointCorrection by viewModel.editRawWhitePointCorrection.collectAsState()
|
||||
val editRawDROEnabled by viewModel.editRawDROEnabled.collectAsState()
|
||||
val editRawDROMode by viewModel.editRawDROMode.collectAsState()
|
||||
val editRawDcpId by viewModel.editRawDcpId.collectAsState()
|
||||
val editRawBaselineLutId by viewModel.editRawBaselineLutId.collectAsState()
|
||||
val availableDcps = viewModel.availableDcps
|
||||
@@ -207,7 +207,7 @@ fun PhotoEditScreen(
|
||||
editRawAutoExposure = editRawAutoExposure,
|
||||
editRawBlackPointCorrection = editRawBlackPointCorrection,
|
||||
editRawWhitePointCorrection = editRawWhitePointCorrection,
|
||||
editRawDROEnabled = editRawDROEnabled,
|
||||
editRawDROMode = editRawDROMode,
|
||||
editRawDcpId = editRawDcpId,
|
||||
editRawBaselineLutId = editRawBaselineLutId,
|
||||
editComputationalAperture = editComputationalAperture,
|
||||
@@ -880,7 +880,7 @@ fun PhotoEditScreen(
|
||||
rawNlmNoiseFactor = editRawNlmNoiseFactor,
|
||||
rawExposureCompensation = editRawExposureCompensation,
|
||||
rawAutoExposure = editRawAutoExposure,
|
||||
rawDROEnabled = editRawDROEnabled,
|
||||
rawDROMode = editRawDROMode,
|
||||
rawBlackPointCorrection = editRawBlackPointCorrection,
|
||||
rawWhitePointCorrection = editRawWhitePointCorrection,
|
||||
onSelectDcp = { dcpId ->
|
||||
@@ -907,9 +907,7 @@ fun PhotoEditScreen(
|
||||
onRawAutoExposureChange = {
|
||||
viewModel.saveRawAutoExposureValue(currentPhoto, it)
|
||||
},
|
||||
onRawDROEnabledChange = {
|
||||
viewModel.saveRawDROEnabledValue(currentPhoto, it)
|
||||
},
|
||||
onRawDROModeChange = { viewModel.saveRawDROModeValue(currentPhoto, it) },
|
||||
onRawBlackPointCorrectionChange = {
|
||||
viewModel.saveRawBlackPointCorrectionValue(currentPhoto, it)
|
||||
},
|
||||
|
||||
@@ -199,7 +199,7 @@ fun SettingsScreen(
|
||||
val rawNlmNoiseFactor by viewModel.rawNlmNoiseFactor.collectAsState()
|
||||
val rawExposureCompensation by viewModel.rawExposureCompensation.collectAsState()
|
||||
val rawAutoExposure by viewModel.rawAutoExposure.collectAsState()
|
||||
val rawDROEnabled by viewModel.rawDROEnabled.collectAsState()
|
||||
val droMode by viewModel.droMode.collectAsState()
|
||||
val rawBlackPointCorrection by viewModel.rawBlackPointCorrection.collectAsState()
|
||||
val rawWhitePointCorrection by viewModel.rawWhitePointCorrection.collectAsState()
|
||||
val rawAutoWhiteBalanceEstimate by viewModel.rawAutoWhiteBalanceEstimate.collectAsState()
|
||||
@@ -1214,7 +1214,7 @@ fun SettingsScreen(
|
||||
rawNlmNoiseFactor = rawNlmNoiseFactorUi,
|
||||
rawExposureCompensation = rawExposureCompensationUi,
|
||||
rawAutoExposure = rawAutoExposure,
|
||||
rawDROEnabled = rawDROEnabled,
|
||||
rawDROMode = droMode,
|
||||
rawBlackPointCorrection = rawBlackPointCorrectionUi,
|
||||
rawWhitePointCorrection = rawWhitePointCorrectionUi,
|
||||
onSelectDcp = { viewModel.setRawDcpId(it) },
|
||||
@@ -1231,7 +1231,7 @@ fun SettingsScreen(
|
||||
onRawNlmNoiseFactorChange = { rawNlmNoiseFactorUi = it },
|
||||
onRawExposureCompensationChange = { rawExposureCompensationUi = it },
|
||||
onRawAutoExposureChange = { viewModel.setRawAutoExposure(it) },
|
||||
onRawDROEnabledChange = { viewModel.setRawDROEnabled(it) },
|
||||
onRawDROModeChange = { viewModel.setDroMode(it) },
|
||||
onRawBlackPointCorrectionChange = { rawBlackPointCorrectionUi = it },
|
||||
onRawWhitePointCorrectionChange = { rawWhitePointCorrectionUi = it },
|
||||
onAdjustmentStart = { isRawSliderAdjusting = true },
|
||||
|
||||
@@ -514,6 +514,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
cameraController.setEdgeLevel(it.edgeLevel)
|
||||
// 同步 RAW 设置到相机控制器
|
||||
cameraController.setUseRaw(it.useRaw)
|
||||
cameraController.setDroMode(it.droMode)
|
||||
if (cameraController.state.value.meteringMode != it.meteringMode) {
|
||||
cameraController.setMeteringMode(it.meteringMode)
|
||||
}
|
||||
@@ -660,6 +661,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
cameraController.setUseMFSR(prefs.useMFSR)
|
||||
cameraController.setMultiFrameCount(prefs.multiFrameCount)
|
||||
cameraController.setUseLivePhoto(prefs.useLivePhoto && prefs.captureMode == CaptureMode.PHOTO)
|
||||
cameraController.setDroMode(prefs.droMode)
|
||||
|
||||
// 应用保存的虚拟光圈
|
||||
if (prefs.defaultVirtualAperture > 0f) {
|
||||
@@ -2652,11 +2654,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
val chromaNoiseReductionValue = chromaNoiseReduction.firstOrNull() ?: 0f
|
||||
val photoQualityValue = photoQuality.firstOrNull() ?: 95
|
||||
val droModeString = droMode.value
|
||||
val droModeForProcessing = try {
|
||||
com.hinnka.mycamera.raw.RawProcessingPreferences.DROMode.valueOf(droModeString)
|
||||
} catch (e: Exception) {
|
||||
com.hinnka.mycamera.raw.RawProcessingPreferences.DROMode.OFF
|
||||
}
|
||||
val droModeForProcessing =
|
||||
com.hinnka.mycamera.raw.RawProcessingPreferences.DROMode.fromPersistedName(droModeString)
|
||||
val currentCameraId = cameraController.getCurrentCameraId()
|
||||
|
||||
// 计算旋转角度
|
||||
@@ -2708,7 +2707,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawDenoiseValue = userPrefs?.rawNlmNoiseFactor ?: 0f,
|
||||
rawExposureCompensation = userPrefs?.rawExposureCompensation ?: 0f,
|
||||
rawAutoExposure = userPrefs?.rawAutoExposure ?: true,
|
||||
rawDROEnabled = userPrefs?.rawDROEnabled ?: false,
|
||||
rawBlackPointCorrection = userPrefs?.rawBlackPointCorrection ?: 0f,
|
||||
rawWhitePointCorrection = userPrefs?.rawWhitePointCorrection ?: 0f,
|
||||
rawAutoWhiteBalanceEstimate = userPrefs?.rawAutoWhiteBalanceEstimate ?: false,
|
||||
@@ -2914,11 +2912,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
val chromaNoiseReductionValue = chromaNoiseReduction.firstOrNull() ?: 0f
|
||||
val photoQualityValue = photoQuality.firstOrNull() ?: 95
|
||||
val droModeString = droMode.value
|
||||
val droModeForProcessing = try {
|
||||
com.hinnka.mycamera.raw.RawProcessingPreferences.DROMode.valueOf(droModeString)
|
||||
} catch (e: Exception) {
|
||||
com.hinnka.mycamera.raw.RawProcessingPreferences.DROMode.OFF
|
||||
}
|
||||
val currentCameraId = cameraController.getCurrentCameraId()
|
||||
|
||||
// 计算旋转角度
|
||||
@@ -2973,7 +2966,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawDenoiseValue = userPrefs?.rawNlmNoiseFactor ?: 0f,
|
||||
rawExposureCompensation = userPrefs?.rawExposureCompensation ?: 0f,
|
||||
rawAutoExposure = userPrefs?.rawAutoExposure ?: true,
|
||||
rawDROEnabled = userPrefs?.rawDROEnabled ?: false,
|
||||
rawBlackPointCorrection = userPrefs?.rawBlackPointCorrection ?: 0f,
|
||||
rawWhitePointCorrection = userPrefs?.rawWhitePointCorrection ?: 0f,
|
||||
rawAutoWhiteBalanceEstimate = userPrefs?.rawAutoWhiteBalanceEstimate ?: false,
|
||||
@@ -3054,7 +3046,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
superResolutionScale = superResScale,
|
||||
useGpuAcceleration = useGpuAcceleration.value,
|
||||
exposureBias = state.value.exposureBias,
|
||||
droMode = droModeForProcessing,
|
||||
exportDngWithRawExport = exportDngWithRawExport.value
|
||||
)
|
||||
}
|
||||
@@ -3312,7 +3303,9 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
*/
|
||||
fun setDroMode(mode: String) {
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.saveDroMode(mode)
|
||||
val resolvedMode = com.hinnka.mycamera.raw.RawProcessingPreferences.DROMode.fromPersistedName(mode)
|
||||
userPreferencesRepository.saveDroMode(resolvedMode.name)
|
||||
userPreferencesRepository.updateRawDROEnabled(resolvedMode.isEnabled)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.graphics.BitmapFactory
|
||||
import android.graphics.RectF
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.provider.MediaStore
|
||||
import android.util.LruCache
|
||||
import androidx.compose.runtime.*
|
||||
@@ -38,9 +37,7 @@ import com.hinnka.mycamera.utils.PLog
|
||||
import com.hinnka.mycamera.utils.StartupTrace
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.Semaphore
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.sync.withPermit
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
@@ -236,7 +233,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
// 正在刷新的照片 ID 集合
|
||||
val refreshingPhotos = mutableStateListOf<String>()
|
||||
private val rawEditMetadataJobs = ConcurrentHashMap<String, Job>()
|
||||
|
||||
// 预览图 LRU 缓存,按 Bitmap 字节数计算大小
|
||||
private val previewBitmapCache = object : LruCache<String, Bitmap>(
|
||||
@@ -299,7 +295,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
private set
|
||||
var editRawWhitePointCorrection = MutableStateFlow(0f)
|
||||
private set
|
||||
var editRawDROEnabled = MutableStateFlow(false)
|
||||
var editRawDROMode = MutableStateFlow("OFF")
|
||||
private set
|
||||
var editRawDcpId = MutableStateFlow<String?>(null)
|
||||
private set
|
||||
@@ -1574,8 +1570,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editRawAutoExposure.value = metadata.rawAutoExposure ?: true
|
||||
editRawBlackPointCorrection.value = metadata.rawBlackPointCorrection ?: 0f
|
||||
editRawWhitePointCorrection.value = metadata.rawWhitePointCorrection ?: 0f
|
||||
editRawDROEnabled.value = metadata.rawDROEnabled ?: false
|
||||
|
||||
editRawDROMode.value = RawProcessingPreferences.DROMode.fromPersistedName(metadata.droMode).name
|
||||
editComputationalAperture.value = metadata.computationalAperture
|
||||
editFocusPointX.value = metadata.focusPointX
|
||||
editFocusPointY.value = metadata.focusPointY
|
||||
@@ -1591,7 +1586,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editRawAutoExposure.value = true
|
||||
editRawBlackPointCorrection.value = 0f
|
||||
editRawWhitePointCorrection.value = 0f
|
||||
editRawDROEnabled.value = false
|
||||
editRawDROMode.value = "OFF"
|
||||
editRawDcpId.value = null
|
||||
editRawBaselineLutId.value = null
|
||||
editComputationalAperture.value = null
|
||||
@@ -1626,7 +1621,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editRawAutoExposure.value = true
|
||||
editRawBlackPointCorrection.value = 0f
|
||||
editRawWhitePointCorrection.value = 0f
|
||||
editRawDROEnabled.value = false
|
||||
editRawDROMode.value = "OFF"
|
||||
editRawDcpId.value = null
|
||||
editRawBaselineLutId.value = null
|
||||
}
|
||||
@@ -1730,59 +1725,52 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
val autoExposure = editRawAutoExposure.value
|
||||
val blackPoint = editRawBlackPointCorrection.value
|
||||
val whitePoint = editRawWhitePointCorrection.value
|
||||
val droEnabled = editRawDROEnabled.value
|
||||
val droMode = editRawDROMode.value
|
||||
val dcpId = editRawDcpId.value
|
||||
val baselineLutId = editRawBaselineLutId.value
|
||||
|
||||
val previousJob = rawEditMetadataJobs[mediaData.id]
|
||||
val job = viewModelScope.launch {
|
||||
try {
|
||||
previousJob?.join()
|
||||
val context = getApplication<Application>()
|
||||
PLog.d(
|
||||
TAG,
|
||||
"persist RAW edit metadata: ${mediaData.id}, dro=$droEnabled, denoise=$denoise"
|
||||
viewModelScope.launch {
|
||||
val context = getApplication<Application>()
|
||||
PLog.d(
|
||||
TAG,
|
||||
"persist RAW edit metadata: ${mediaData.id}, dro=$droMode, denoise=$denoise"
|
||||
)
|
||||
GalleryManager.updateMetadata(context, mediaData.id) { current ->
|
||||
current.copy(
|
||||
rawDenoiseValue = denoise,
|
||||
rawExposureCompensation = exposure,
|
||||
rawAutoExposure = autoExposure,
|
||||
rawBlackPointCorrection = blackPoint,
|
||||
rawWhitePointCorrection = whitePoint,
|
||||
droMode = droMode,
|
||||
rawDcpId = dcpId,
|
||||
baselineLutId = baselineLutId
|
||||
)
|
||||
GalleryManager.updateMetadata(context, mediaData.id) { current ->
|
||||
current.copy(
|
||||
rawDenoiseValue = denoise,
|
||||
rawExposureCompensation = exposure,
|
||||
rawAutoExposure = autoExposure,
|
||||
rawBlackPointCorrection = blackPoint,
|
||||
rawWhitePointCorrection = whitePoint,
|
||||
rawDROEnabled = droEnabled,
|
||||
rawDcpId = dcpId,
|
||||
baselineLutId = baselineLutId
|
||||
)
|
||||
}.let { updated ->
|
||||
if (updated != null) {
|
||||
withContext(Dispatchers.Main) {
|
||||
if (currentPhotoMetadataId == mediaData.id || currentMediaMetadata != null) {
|
||||
currentMediaMetadata = updated
|
||||
currentPhotoMetadataId = mediaData.id
|
||||
}
|
||||
mediaData.metadata = updated
|
||||
_photos.value = _photos.value.map { photo ->
|
||||
if (photo.id == mediaData.id) photo.copy(metadata = updated) else photo
|
||||
}
|
||||
if (_latestPhoto.value?.id == mediaData.id) {
|
||||
_latestPhoto.value = _latestPhoto.value?.copy(metadata = updated)
|
||||
}
|
||||
photoRefreshKeys[mediaData.id] = System.currentTimeMillis()
|
||||
}.let { updated ->
|
||||
if (updated != null) {
|
||||
withContext(Dispatchers.Main) {
|
||||
if (currentPhotoMetadataId == mediaData.id || currentMediaMetadata != null) {
|
||||
currentMediaMetadata = updated
|
||||
currentPhotoMetadataId = mediaData.id
|
||||
}
|
||||
GalleryManager.updateThumbnail(
|
||||
context = context,
|
||||
photoId = mediaData.id,
|
||||
photoProcessor = contentRepository.photoProcessor,
|
||||
metadata = updated
|
||||
)
|
||||
mediaData.metadata = updated
|
||||
_photos.value = _photos.value.map { photo ->
|
||||
if (photo.id == mediaData.id) photo.copy(metadata = updated) else photo
|
||||
}
|
||||
if (_latestPhoto.value?.id == mediaData.id) {
|
||||
_latestPhoto.value = _latestPhoto.value?.copy(metadata = updated)
|
||||
}
|
||||
photoRefreshKeys[mediaData.id] = System.currentTimeMillis()
|
||||
}
|
||||
GalleryManager.updateThumbnail(
|
||||
context = context,
|
||||
photoId = mediaData.id,
|
||||
photoProcessor = contentRepository.photoProcessor,
|
||||
metadata = updated
|
||||
)
|
||||
}
|
||||
} finally {
|
||||
rawEditMetadataJobs.remove(mediaData.id, coroutineContext[Job])
|
||||
}
|
||||
}
|
||||
rawEditMetadataJobs[mediaData.id] = job
|
||||
}
|
||||
|
||||
fun saveRawDenoiseValue(mediaData: MediaData, value: Float) {
|
||||
@@ -1800,8 +1788,9 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
persistRawEditMetadata(mediaData)
|
||||
}
|
||||
|
||||
fun saveRawDROEnabledValue(mediaData: MediaData, enabled: Boolean) {
|
||||
editRawDROEnabled.value = enabled
|
||||
fun saveRawDROModeValue(mediaData: MediaData, mode: String) {
|
||||
val resolvedMode = RawProcessingPreferences.DROMode.fromPersistedName(mode)
|
||||
editRawDROMode.value = resolvedMode.name
|
||||
persistRawEditMetadata(mediaData)
|
||||
}
|
||||
|
||||
@@ -2404,15 +2393,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
refreshingPhotos.add(photo.id)
|
||||
try {
|
||||
val context = getApplication<Application>()
|
||||
rawEditMetadataJobs[photo.id]?.let { pendingRawEditJob ->
|
||||
PLog.d(TAG, "refresh RAW preview waiting pending RAW edit metadata: ${photo.id}")
|
||||
pendingRawEditJob.join()
|
||||
}
|
||||
val result = GalleryManager.refreshRawPreview(
|
||||
context,
|
||||
photo.id,
|
||||
RawProcessingPreferences.DROMode.valueOf(droMode.value)
|
||||
)
|
||||
val result = GalleryManager.refreshRawPreview(context, photo.id)
|
||||
if (result != null) {
|
||||
updatePhotoMetadata(photo.id) { it }
|
||||
// 更新刷新密钥以强制 UI 重新加载
|
||||
|
||||
@@ -309,6 +309,9 @@
|
||||
<string name="settings_dro_off">Aus</string>
|
||||
<string name="settings_dro_low">Niedrig</string>
|
||||
<string name="settings_dro_high">Hoch</string>
|
||||
<string name="settings_dro_dr100">DR100</string>
|
||||
<string name="settings_dro_dr200">DR200</string>
|
||||
<string name="settings_dro_dr400">DR400</string>
|
||||
<string name="settings_apply_ultra_hdr">Ultra HDR Belichtungsstrategie</string>
|
||||
<string name="settings_apply_ultra_hdr_description">Reduziert basierend auf Multi-Frame-Stacking und Histogrammanalyse automatisch die Belichtung, um Glanzlichter bei ausreichenden Lichtverhältnissen zu schützen. Nur wirksam, wenn RAW und Multi-Frame aktiviert sind.</string>
|
||||
<string name="settings_color_space">RAW-Farbraum</string>
|
||||
|
||||
@@ -309,6 +309,9 @@
|
||||
<string name="settings_dro_off">Désactivé</string>
|
||||
<string name="settings_dro_low">Bas</string>
|
||||
<string name="settings_dro_high">Haut</string>
|
||||
<string name="settings_dro_dr100">DR100</string>
|
||||
<string name="settings_dro_dr200">DR200</string>
|
||||
<string name="settings_dro_dr400">DR400</string>
|
||||
<string name="settings_apply_ultra_hdr">Stratégie d\'exposition Ultra HDR</string>
|
||||
<string name="settings_apply_ultra_hdr_description">En se basant sur l\'empilement multi-images et l\'analyse de l\'histogramme, réduit automatiquement l\'exposition pour protéger les hautes lumières lorsque l\'éclairage est suffisant. Efficace uniquement lorsque RAW et Multi-images sont activés.</string>
|
||||
<string name="settings_color_space">Espace colorimétrique RAW</string>
|
||||
|
||||
@@ -309,6 +309,9 @@
|
||||
<string name="settings_dro_off">Mati</string>
|
||||
<string name="settings_dro_low">Rendah</string>
|
||||
<string name="settings_dro_high">Tinggi</string>
|
||||
<string name="settings_dro_dr100">DR100</string>
|
||||
<string name="settings_dro_dr200">DR200</string>
|
||||
<string name="settings_dro_dr400">DR400</string>
|
||||
<string name="settings_apply_ultra_hdr">Strategi Eksposur Ultra HDR</string>
|
||||
<string name="settings_apply_ultra_hdr_description">Berdasarkan penumpukan multi-frame dan analisis histogram, secara otomatis mengurangi eksposur untuk melindungi sorotan saat cahaya cukup. Efektif hanya jika RAW dan Multi-Frame diaktifkan.</string>
|
||||
<string name="settings_color_space">Ruang Warna RAW</string>
|
||||
|
||||
@@ -311,6 +311,9 @@
|
||||
<string name="settings_dro_off">オフ</string>
|
||||
<string name="settings_dro_low">低</string>
|
||||
<string name="settings_dro_high">高</string>
|
||||
<string name="settings_dro_dr100">DR100</string>
|
||||
<string name="settings_dro_dr200">DR200</string>
|
||||
<string name="settings_dro_dr400">DR400</string>
|
||||
<string name="settings_apply_ultra_hdr">Ultra HDR露出戦略</string>
|
||||
<string name="settings_apply_ultra_hdr_description">マルチフレーム合成とヒストグラム分析に基づき、十分な光量がある場合に露出を自動的に下げてハイライトを保護します。RAWとマルチフレームが有効な場合のみ機能します。</string>
|
||||
<string name="settings_color_space">RAW色空間</string>
|
||||
|
||||
@@ -311,6 +311,9 @@
|
||||
<string name="settings_dro_off">꺼짐</string>
|
||||
<string name="settings_dro_low">낮음</string>
|
||||
<string name="settings_dro_high">높음</string>
|
||||
<string name="settings_dro_dr100">DR100</string>
|
||||
<string name="settings_dro_dr200">DR200</string>
|
||||
<string name="settings_dro_dr400">DR400</string>
|
||||
<string name="settings_apply_ultra_hdr">Ultra HDR 노출 전략</string>
|
||||
<string name="settings_apply_ultra_hdr_description">멀티 프레임 스태킹 및 히스토그램 분석을 기반으로, 조명이 충분할 때 하이라이트를 보호하기 위해 자동으로 노출을 줄입니다. RAW 및 멀티 프레임이 활성화된 경우에만 유효합니다.</string>
|
||||
<string name="settings_color_space">RAW 색 공간</string>
|
||||
|
||||
@@ -309,6 +309,9 @@
|
||||
<string name="settings_dro_off">Desativado</string>
|
||||
<string name="settings_dro_low">Baixo</string>
|
||||
<string name="settings_dro_high">Alto</string>
|
||||
<string name="settings_dro_dr100">DR100</string>
|
||||
<string name="settings_dro_dr200">DR200</string>
|
||||
<string name="settings_dro_dr400">DR400</string>
|
||||
<string name="settings_apply_ultra_hdr">Estratégia de Exposição Ultra HDR</string>
|
||||
<string name="settings_apply_ultra_hdr_description">Com base no empilhamento de vários quadros e na análise de histograma, reduz automaticamente a exposição para proteger os realces quando a iluminação é suficiente. Eficaz apenas quando RAW e Multi-Frame estão ativados.</string>
|
||||
<string name="settings_color_space">Espaço de Cor RAW</string>
|
||||
|
||||
@@ -309,6 +309,9 @@
|
||||
<string name="settings_dro_off">ปิด</string>
|
||||
<string name="settings_dro_low">ต่ำ</string>
|
||||
<string name="settings_dro_high">สูง</string>
|
||||
<string name="settings_dro_dr100">DR100</string>
|
||||
<string name="settings_dro_dr200">DR200</string>
|
||||
<string name="settings_dro_dr400">DR400</string>
|
||||
<string name="settings_apply_ultra_hdr">กลยุทธ์การเปิดรับแสง Ultra HDR</string>
|
||||
<string name="settings_apply_ultra_hdr_description">อ้างอิงจากการซ้อนภาพหลายเฟรมและการวิเคราะห์ฮิสโตแกรม จะลดการเปิดรับแสงโดยอัตโนมัติเพื่อป้องกันไฮไลท์เมื่อมีแสงเพียงพอ มีผลเมื่อเปิดใช้งาน RAW และ Multi-Frame เท่านั้น</string>
|
||||
<string name="settings_color_space">พื้นที่สี RAW</string>
|
||||
|
||||
@@ -639,6 +639,9 @@
|
||||
<string name="settings_dro_off">关闭</string>
|
||||
<string name="settings_dro_low">中等</string>
|
||||
<string name="settings_dro_high">最高</string>
|
||||
<string name="settings_dro_dr100">DR100</string>
|
||||
<string name="settings_dro_dr200">DR200</string>
|
||||
<string name="settings_dro_dr400">DR400</string>
|
||||
<string name="settings_log_curve_description">选择 RAW 处理的传输函数 (Log 曲线)。</string>
|
||||
<string name="raw_profile_aces_cine">ACES 电影</string>
|
||||
<string name="raw_profile_apple_cinema">Apple 电影</string>
|
||||
|
||||
@@ -427,6 +427,9 @@
|
||||
<string name="settings_dro_off">關閉</string>
|
||||
<string name="settings_dro_low">中等</string>
|
||||
<string name="settings_dro_high">最高</string>
|
||||
<string name="settings_dro_dr100">DR100</string>
|
||||
<string name="settings_dro_dr200">DR200</string>
|
||||
<string name="settings_dro_dr400">DR400</string>
|
||||
<string name="settings_log_curve_description">選擇 RAW 處理的傳輸函數 (Log 曲線)。</string>
|
||||
<string name="raw_profile_aces_cine">ACES 電影</string>
|
||||
<string name="raw_profile_apple_cinema">Apple 電影</string>
|
||||
|
||||
@@ -648,6 +648,9 @@
|
||||
<string name="settings_dro_off">Off</string>
|
||||
<string name="settings_dro_low">Low</string>
|
||||
<string name="settings_dro_high">High</string>
|
||||
<string name="settings_dro_dr100">DR100</string>
|
||||
<string name="settings_dro_dr200">DR200</string>
|
||||
<string name="settings_dro_dr400">DR400</string>
|
||||
<string name="settings_apply_ultra_hdr">Ultra HDR Exposure Strategy</string>
|
||||
<string name="settings_apply_ultra_hdr_description">Based on multi-frame stacking and histogram analysis, automatically reduce exposure to protect highlights when lighting is sufficient. Effective only when RAW and Multi-Frame are enabled.</string>
|
||||
<string name="settings_color_space">RAW Color Space</string>
|
||||
|
||||
Reference in new issue
Block a user