feat: update RAW processing defaults and metering weight constraints

This commit is contained in:
Hinnka committed 2026-05-01 21:21:28 +08:00
1 parent 72eabfb1ac
commit a63e960fe6
8 files changed
+58 -58

No files matched your search

@@ -58,12 +58,12 @@ data class UserPreferences(
val rawDcpId: String? = null,
val rawNlmNoiseFactor: Float = 0f,
val rawExposureCompensation: Float = 0f,
val rawAutoExposure: Boolean = false,
val rawMeteringCenterWeight: Float = 0.5f,
val rawAutoExposure: Boolean = true,
val rawMeteringCenterWeight: Float = 0f,
val rawBlackPointCorrection: Float = 0f,
val rawWhitePointCorrection: Float = 0f,
val rawAutoWhiteBalanceEstimate: Boolean = false,
val rawAutoBlackLevelCorrection: Boolean = false,
val rawAutoBlackLevelCorrection: Boolean = true,
val exportDngWithRawExport: Boolean = false,
val frameId: String? = null,
val showHistogram: Boolean = true,
@@ -253,12 +253,12 @@ class UserPreferencesRepository(private val context: Context) {
rawDcpId = preferences[RAW_DCP_ID_KEY],
rawNlmNoiseFactor = preferences[RAW_NLM_NOISE_FACTOR_KEY] ?: 0f,
rawExposureCompensation = preferences[RAW_EXPOSURE_COMPENSATION_KEY] ?: 0f,
rawAutoExposure = preferences[RAW_AUTO_EXPOSURE_KEY] ?: false,
rawMeteringCenterWeight = preferences[RAW_METERING_CENTER_WEIGHT_KEY]?.coerceIn(0f, 2f) ?: 0.5f,
rawAutoExposure = preferences[RAW_AUTO_EXPOSURE_KEY] ?: true,
rawMeteringCenterWeight = preferences[RAW_METERING_CENTER_WEIGHT_KEY]?.coerceIn(0f, 1f) ?: 0f,
rawBlackPointCorrection = preferences[RAW_BLACK_POINT_CORRECTION_KEY] ?: 0f,
rawWhitePointCorrection = preferences[RAW_WHITE_POINT_CORRECTION_KEY] ?: 0f,
rawAutoWhiteBalanceEstimate = preferences[RAW_AUTO_WHITE_BALANCE_ESTIMATE_KEY] ?: false,
rawAutoBlackLevelCorrection = preferences[RAW_AUTO_BLACK_LEVEL_CORRECTION_KEY] ?: false,
rawAutoBlackLevelCorrection = preferences[RAW_AUTO_BLACK_LEVEL_CORRECTION_KEY] ?: true,
exportDngWithRawExport = preferences[EXPORT_DNG_WITH_RAW_EXPORT_KEY] ?: false,
phantomBaselineLutId = preferences[PHANTOM_BASELINE_LUT_ID_KEY],
frameId = preferences[FRAME_ID_KEY],
@@ -499,7 +499,7 @@ class UserPreferencesRepository(private val context: Context) {
suspend fun saveRawMeteringCenterWeight(value: Float) {
context.dataStore.edit { preferences ->
preferences[RAW_METERING_CENTER_WEIGHT_KEY] = value.coerceIn(0f, 2f)
preferences[RAW_METERING_CENTER_WEIGHT_KEY] = value.coerceIn(0f, 1f)
}
}
@@ -117,7 +117,7 @@ object GalleryManager {
): Boolean {
return metadata?.rawAutoBlackLevelCorrection
?: (ContentRepository.getInstance(context).userPreferencesRepository.userPreferences.firstOrNull()
?.rawAutoBlackLevelCorrection ?: false)
?.rawAutoBlackLevelCorrection ?: true)
}
private suspend fun resolveRawAutoWhiteBalanceEstimate(
@@ -135,7 +135,7 @@ object GalleryManager {
): Boolean {
return metadata?.rawAutoExposure
?: (ContentRepository.getInstance(context).userPreferencesRepository.userPreferences.firstOrNull()
?.rawAutoExposure ?: false)
?.rawAutoExposure ?: true)
}
private suspend fun resolveRawMeteringCenterWeight(
@@ -144,7 +144,7 @@ object GalleryManager {
): Float {
return metadata?.rawMeteringCenterWeight
?: (ContentRepository.getInstance(context).userPreferencesRepository.userPreferences.firstOrNull()
?.rawMeteringCenterWeight ?: 0.5f)
?.rawMeteringCenterWeight ?: 0f)
}
private val _photoLibraryChangedEvents = MutableSharedFlow<Unit>(extraBufferCapacity = 16)
val photoLibraryChangedEvents: SharedFlow<Unit> = _photoLibraryChangedEvents.asSharedFlow()
@@ -55,7 +55,7 @@ class PhotoProcessor(
private suspend fun resolveRawAutoBlackLevelCorrection(metadata: MediaMetadata): Boolean {
return metadata.rawAutoBlackLevelCorrection
?: (userPreferencesRepository.userPreferences.firstOrNull()?.rawAutoBlackLevelCorrection ?: false)
?: (userPreferencesRepository.userPreferences.firstOrNull()?.rawAutoBlackLevelCorrection ?: true)
}
private suspend fun resolveRawAutoWhiteBalanceEstimate(metadata: MediaMetadata): Boolean {
@@ -65,12 +65,12 @@ class PhotoProcessor(
private suspend fun resolveRawAutoExposure(metadata: MediaMetadata): Boolean {
return metadata.rawAutoExposure
?: (userPreferencesRepository.userPreferences.firstOrNull()?.rawAutoExposure ?: false)
?: (userPreferencesRepository.userPreferences.firstOrNull()?.rawAutoExposure ?: true)
}
private suspend fun resolveRawMeteringCenterWeight(metadata: MediaMetadata): Float {
return metadata.rawMeteringCenterWeight
?: (userPreferencesRepository.userPreferences.firstOrNull()?.rawMeteringCenterWeight ?: 0.5f)
?: (userPreferencesRepository.userPreferences.firstOrNull()?.rawMeteringCenterWeight ?: 0f)
}
suspend fun prepareUltraHdrSource(
@@ -15,7 +15,7 @@ object MeteringSystem {
width: Int,
height: Int,
metadata: RawMetadata?,
centerWeight: Float = 0.5f
centerWeight: Float = 0f
): Float {
val pixelCount = width * height
val allLumas = FloatArray(pixelCount)
@@ -95,7 +95,7 @@ object MeteringSystem {
// 1. 基础权重:画面中心
val distSqC = (pzx - 0.5f).let { it * it } + (pzy - 0.5f).let { it * it }
val normalizedCenterWeight = (centerWeight.coerceIn(0f, 2f) / 2f).toDouble()
val normalizedCenterWeight = centerWeight.coerceIn(0f, 1f).toDouble()
val evaluativeWeight = 1.0
val centerSigma = 0.22 - 0.19 * normalizedCenterWeight
val centerBoost = 1.0 + 7.0 * normalizedCenterWeight
@@ -256,12 +256,12 @@ class RawDemosaicProcessor {
rotation: Int,
exposureBias: Float = 0f,
rawExposureCompensation: Float = 0f,
rawAutoExposure: Boolean = false,
rawMeteringCenterWeight: Float = 0.5f,
rawAutoExposure: Boolean = true,
rawMeteringCenterWeight: Float = 0f,
rawBlackPointCorrection: Float = 0f,
rawWhitePointCorrection: Float = 0f,
rawAutoWhiteBalanceEstimate: Boolean = false,
rawAutoBlackLevelCorrection: Boolean = false,
rawAutoBlackLevelCorrection: Boolean = true,
sharpeningValue: Float = 0f,
denoiseValue: Float? = null,
rawDcpId: String? = null,
@@ -315,12 +315,12 @@ class RawDemosaicProcessor {
cropRegion: Rect?,
rotation: Int,
rawExposureCompensation: Float = 0f,
rawAutoExposure: Boolean = false,
rawMeteringCenterWeight: Float = 0.5f,
rawAutoExposure: Boolean = true,
rawMeteringCenterWeight: Float = 0f,
rawBlackPointCorrection: Float = 0f,
rawWhitePointCorrection: Float = 0f,
rawAutoWhiteBalanceEstimate: Boolean = false,
rawAutoBlackLevelCorrection: Boolean = false,
rawAutoBlackLevelCorrection: Boolean = true,
sharpeningValue: Float = 0f,
denoiseValue: Float? = null,
chromaDenoiseValue: Float? = null,
@@ -372,12 +372,12 @@ class RawDemosaicProcessor {
rotation: Int,
exposureBias: Float = 0f,
rawExposureCompensation: Float = 0f,
rawAutoExposure: Boolean = false,
rawMeteringCenterWeight: Float = 0.5f,
rawAutoExposure: Boolean = true,
rawMeteringCenterWeight: Float = 0f,
rawBlackPointCorrection: Float = 0f,
rawWhitePointCorrection: Float = 0f,
rawAutoWhiteBalanceEstimate: Boolean = false,
rawAutoBlackLevelCorrection: Boolean = false,
rawAutoBlackLevelCorrection: Boolean = true,
sharpeningValue: Float = 0f,
denoiseValue: Float? = null,
rawDcpId: String? = null,
@@ -433,12 +433,12 @@ class RawDemosaicProcessor {
rotation: Int,
exposureBias: Float = 0f,
rawExposureCompensation: Float = 0f,
rawAutoExposure: Boolean = false,
rawMeteringCenterWeight: Float = 0.5f,
rawAutoExposure: Boolean = true,
rawMeteringCenterWeight: Float = 0f,
rawBlackPointCorrection: Float = 0f,
rawWhitePointCorrection: Float = 0f,
rawAutoWhiteBalanceEstimate: Boolean = false,
rawAutoBlackLevelCorrection: Boolean = false,
rawAutoBlackLevelCorrection: Boolean = true,
sharpeningValue: Float = 0f,
denoiseValue: Float? = null,
chromaDenoiseValue: Float? = null,
@@ -2170,7 +2170,7 @@ class RawDemosaicProcessor {
val ev = (ln(gain) / ln(2f)).coerceIn(-2f, 4f)
PLog.d(
TAG,
"RAW auto exposure: gain=$gain ev=$ev centerWeight=${rawMeteringCenterWeight.coerceIn(0f, 2f)}"
"RAW auto exposure: gain=$gain ev=$ev centerWeight=${rawMeteringCenterWeight.coerceIn(0f, 1f)}"
)
ev
} catch (e: Exception) {
@@ -71,7 +71,7 @@ fun RawEditPanel(
description = stringResource(R.string.settings_raw_metering_center_weight_description),
value = rawMeteringCenterWeight,
valueRange = 0f..1f,
resetValue = 0.5f,
resetValue = 0f,
enabled = rawAutoExposure,
onValueChange = {
onAdjustmentStart()
@@ -233,10 +233,10 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
.stateIn(viewModelScope, SharingStarted.Eagerly, 0f)
val rawAutoExposure: StateFlow<Boolean> = userPreferencesRepository.userPreferences
.map { it.rawAutoExposure }
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
.stateIn(viewModelScope, SharingStarted.Eagerly, true)
val rawMeteringCenterWeight: StateFlow<Float> = userPreferencesRepository.userPreferences
.map { it.rawMeteringCenterWeight }
.stateIn(viewModelScope, SharingStarted.Eagerly, 0.5f)
.stateIn(viewModelScope, SharingStarted.Eagerly, 0f)
val rawBlackPointCorrection: StateFlow<Float> = userPreferencesRepository.userPreferences
.map { it.rawBlackPointCorrection }
.stateIn(viewModelScope, SharingStarted.Eagerly, 0f)
@@ -248,7 +248,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
val rawAutoBlackLevelCorrection: StateFlow<Boolean> = userPreferencesRepository.userPreferences
.map { it.rawAutoBlackLevelCorrection }
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
.stateIn(viewModelScope, SharingStarted.Eagerly, true)
val exportDngWithRawExport: StateFlow<Boolean> = userPreferencesRepository.userPreferences
.map { it.exportDngWithRawExport }
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
@@ -864,12 +864,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
rawDcpId = userPrefs?.rawDcpId,
rawDenoiseValue = userPrefs?.rawNlmNoiseFactor ?: 0f,
rawExposureCompensation = userPrefs?.rawExposureCompensation ?: 0f,
rawAutoExposure = userPrefs?.rawAutoExposure ?: false,
rawMeteringCenterWeight = userPrefs?.rawMeteringCenterWeight ?: 0.5f,
rawAutoExposure = userPrefs?.rawAutoExposure ?: true,
rawMeteringCenterWeight = userPrefs?.rawMeteringCenterWeight ?: 0f,
rawBlackPointCorrection = userPrefs?.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = userPrefs?.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = userPrefs?.rawAutoWhiteBalanceEstimate ?: false,
rawAutoBlackLevelCorrection = userPrefs?.rawAutoBlackLevelCorrection ?: false,
rawAutoBlackLevelCorrection = userPrefs?.rawAutoBlackLevelCorrection ?: true,
width = width,
height = height,
ratio = aspectRatio,
@@ -2542,12 +2542,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
rawDcpId = userPrefs?.rawDcpId,
rawDenoiseValue = userPrefs?.rawNlmNoiseFactor ?: 0f,
rawExposureCompensation = userPrefs?.rawExposureCompensation ?: 0f,
rawAutoExposure = userPrefs?.rawAutoExposure ?: false,
rawMeteringCenterWeight = userPrefs?.rawMeteringCenterWeight ?: 0.5f,
rawAutoExposure = userPrefs?.rawAutoExposure ?: true,
rawMeteringCenterWeight = userPrefs?.rawMeteringCenterWeight ?: 0f,
rawBlackPointCorrection = userPrefs?.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = userPrefs?.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = userPrefs?.rawAutoWhiteBalanceEstimate ?: false,
rawAutoBlackLevelCorrection = userPrefs?.rawAutoBlackLevelCorrection ?: false,
rawAutoBlackLevelCorrection = userPrefs?.rawAutoBlackLevelCorrection ?: true,
width = image.width,
height = image.height,
ratio = aspectRatio,
@@ -2654,12 +2654,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
rawDcpId = userPrefs?.rawDcpId,
rawDenoiseValue = userPrefs?.rawNlmNoiseFactor ?: 0f,
rawExposureCompensation = userPrefs?.rawExposureCompensation ?: 0f,
rawAutoExposure = userPrefs?.rawAutoExposure ?: false,
rawMeteringCenterWeight = userPrefs?.rawMeteringCenterWeight ?: 0.5f,
rawAutoExposure = userPrefs?.rawAutoExposure ?: true,
rawMeteringCenterWeight = userPrefs?.rawMeteringCenterWeight ?: 0f,
rawBlackPointCorrection = userPrefs?.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = userPrefs?.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = userPrefs?.rawAutoWhiteBalanceEstimate ?: false,
rawAutoBlackLevelCorrection = userPrefs?.rawAutoBlackLevelCorrection ?: false,
rawAutoBlackLevelCorrection = userPrefs?.rawAutoBlackLevelCorrection ?: true,
width = bitmap.width,
height = bitmap.height,
ratio = mapVideoAspectRatioToPhotoAspectRatio(currentState.videoConfig.aspectRatio),
@@ -2795,12 +2795,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
rawDcpId = userPrefs?.rawDcpId,
rawDenoiseValue = userPrefs?.rawNlmNoiseFactor ?: 0f,
rawExposureCompensation = userPrefs?.rawExposureCompensation ?: 0f,
rawAutoExposure = userPrefs?.rawAutoExposure ?: false,
rawMeteringCenterWeight = userPrefs?.rawMeteringCenterWeight ?: 0.5f,
rawAutoExposure = userPrefs?.rawAutoExposure ?: true,
rawMeteringCenterWeight = userPrefs?.rawMeteringCenterWeight ?: 0f,
rawBlackPointCorrection = userPrefs?.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = userPrefs?.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = userPrefs?.rawAutoWhiteBalanceEstimate ?: false,
rawAutoBlackLevelCorrection = userPrefs?.rawAutoBlackLevelCorrection ?: false,
rawAutoBlackLevelCorrection = userPrefs?.rawAutoBlackLevelCorrection ?: true,
width = (images[0].width.toFloat() * superResScale).roundToInt(),
height = (images[0].height.toFloat() * superResScale).roundToInt(),
ratio = aspectRatio,
@@ -2944,12 +2944,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
rawDcpId = userPrefs?.rawDcpId,
rawDenoiseValue = userPrefs?.rawNlmNoiseFactor ?: 0f,
rawExposureCompensation = userPrefs?.rawExposureCompensation ?: 0f,
rawAutoExposure = userPrefs?.rawAutoExposure ?: false,
rawMeteringCenterWeight = userPrefs?.rawMeteringCenterWeight ?: 0.5f,
rawAutoExposure = userPrefs?.rawAutoExposure ?: true,
rawMeteringCenterWeight = userPrefs?.rawMeteringCenterWeight ?: 0f,
rawBlackPointCorrection = userPrefs?.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = userPrefs?.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = userPrefs?.rawAutoWhiteBalanceEstimate ?: false,
rawAutoBlackLevelCorrection = userPrefs?.rawAutoBlackLevelCorrection ?: false,
rawAutoBlackLevelCorrection = userPrefs?.rawAutoBlackLevelCorrection ?: true,
width = image.width,
height = image.height,
ratio = aspectRatio,
@@ -289,9 +289,9 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
private set
var editRawExposureCompensation = MutableStateFlow(0f)
private set
var editRawAutoExposure = MutableStateFlow(false)
var editRawAutoExposure = MutableStateFlow(true)
private set
var editRawMeteringCenterWeight = MutableStateFlow(0.5f)
var editRawMeteringCenterWeight = MutableStateFlow(0f)
private set
var editRawBlackPointCorrection = MutableStateFlow(0f)
private set
@@ -1019,8 +1019,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
editChromaNoiseReduction.value = m.chromaNoiseReduction ?: 0f
editRawDenoise.value = m.rawDenoiseValue ?: 0f
editRawExposureCompensation.value = m.rawExposureCompensation ?: 0f
editRawAutoExposure.value = m.rawAutoExposure ?: false
editRawMeteringCenterWeight.value = m.rawMeteringCenterWeight ?: 0.5f
editRawAutoExposure.value = m.rawAutoExposure ?: true
editRawMeteringCenterWeight.value = m.rawMeteringCenterWeight ?: 0f
editRawBlackPointCorrection.value = m.rawBlackPointCorrection ?: 0f
editRawWhitePointCorrection.value = m.rawWhitePointCorrection ?: 0f
editRawDcpId.value = m.rawDcpId
@@ -1566,8 +1566,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
?: (if (metadata.isImported) 0f else chromaNoiseReduction.value)
editRawDenoise.value = metadata.rawDenoiseValue ?: 0f
editRawExposureCompensation.value = metadata.rawExposureCompensation ?: 0f
editRawAutoExposure.value = metadata.rawAutoExposure ?: false
editRawMeteringCenterWeight.value = metadata.rawMeteringCenterWeight ?: 0.5f
editRawAutoExposure.value = metadata.rawAutoExposure ?: true
editRawMeteringCenterWeight.value = metadata.rawMeteringCenterWeight ?: 0f
editRawBlackPointCorrection.value = metadata.rawBlackPointCorrection ?: 0f
editRawWhitePointCorrection.value = metadata.rawWhitePointCorrection ?: 0f
editRawDcpId.value = metadata.rawDcpId
@@ -1585,8 +1585,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
editChromaNoiseReduction.value = chromaNoiseReduction.value
editRawDenoise.value = 0.2f
editRawExposureCompensation.value = 0f
editRawAutoExposure.value = false
editRawMeteringCenterWeight.value = 0.5f
editRawAutoExposure.value = true
editRawMeteringCenterWeight.value = 0f
editRawBlackPointCorrection.value = 0f
editRawWhitePointCorrection.value = 0f
editRawDcpId.value = null
@@ -1619,8 +1619,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
editCropAspectOption.value = CropAspectOption.Free
editRawDenoise.value = 0.2f
editRawExposureCompensation.value = 0f
editRawAutoExposure.value = false
editRawMeteringCenterWeight.value = 0.5f
editRawAutoExposure.value = true
editRawMeteringCenterWeight.value = 0f
editRawBlackPointCorrection.value = 0f
editRawWhitePointCorrection.value = 0f
editRawDcpId.value = null
@@ -1756,7 +1756,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
}
fun saveRawMeteringCenterWeightValue(mediaData: MediaData, value: Float) {
editRawMeteringCenterWeight.value = value.coerceIn(0f, 2f)
editRawMeteringCenterWeight.value = value.coerceIn(0f, 1f)
persistRawEditMetadata(mediaData)
}