fix: add Fix tone mapping capture option

This commit is contained in:
zhoubinjia committed 2026-06-26 11:40:11 +08:00
1 parent d73d82e63a
commit da104fc72c
9 files changed
+57 -3

No files matched your search

@@ -2046,14 +2046,14 @@ class Camera2Controller(private val context: Context) {
}
private fun applyToneMapSettings(builder: CaptureRequest.Builder, state: CameraState, isCapture: Boolean) {
val linearizePreviewInput = state.fixTonemapPreview && !isCapture
val linearizeInput = if (isCapture) state.fixTonemapCapture else state.fixTonemapPreview
val tonemapMode = sanitizeTonemapMode(state.tonemapMode)
when (tonemapMode) {
"SYSTEM_DEFAULT" -> applyDefaultToneMapSettings(builder, state, isCapture)
"SRGB" -> {
if (availableTonemapModes.contains(CaptureRequest.TONEMAP_MODE_CONTRAST_CURVE)) {
builder.set(CaptureRequest.TONEMAP_MODE, CaptureRequest.TONEMAP_MODE_CONTRAST_CURVE)
val srgbCurve = generateSrgbCurve(linearizePreviewInput)
val srgbCurve = generateSrgbCurve(linearizeInput)
val curve = TonemapCurve(srgbCurve, srgbCurve, srgbCurve)
builder.set(CaptureRequest.TONEMAP_CURVE, curve)
}
@@ -2093,7 +2093,6 @@ class Camera2Controller(private val context: Context) {
return when (mode) {
"FAST", "HIGH_QUALITY" -> "SYSTEM_DEFAULT"
"REC709" -> "SRGB"
"RAW_PREVIEW", "SRGB_ACR3", "REC709_ACR3", "LINEAR_PIPELINE" -> "SRGB"
"SYSTEM_DEFAULT", "SRGB" -> mode
else -> "SYSTEM_DEFAULT"
}
@@ -2530,6 +2529,14 @@ class Camera2Controller(private val context: Context) {
}
}
/**
* 设置是否修复自定义色调映射拍摄异常
*/
fun setFixTonemapCapture(enabled: Boolean) {
_state.value = _state.value.copy(fixTonemapCapture = enabled)
PLog.d(TAG, "修复色调映射拍摄异常: $enabled")
}
/**
* 设置虚化模拟光圈大小
*/
@@ -339,6 +339,7 @@ data class CameraState(
val droMode: String = "OFF",
val tonemapMode: String = "SYSTEM_DEFAULT",
val fixTonemapPreview: Boolean = false,
val fixTonemapCapture: Boolean = false,
// 是否正在拍摄 Live Photo (用于 UI 动画)
val isCapturingLivePhoto: Boolean = false,
val applyUltraHDR: Boolean = true,
@@ -171,6 +171,7 @@ data class UserPreferences(
val naturalLightEnabled: Boolean = false, // 是否启用自然光影
val naturalLightPreviousTonemapMode: String = "SYSTEM_DEFAULT", // 自然光影关闭时恢复的色调映射模式
val fixTonemapPreview: Boolean = false, // 修复部分设备自定义色调映射预览异常
val fixTonemapCapture: Boolean = false, // 修复部分设备自定义色调映射拍摄异常
val applyUltraHDR: Boolean = false, // 是否应用 Ultra HDR 策略
val colorSpace: ColorSpace = ColorSpace.SRGB,
val logCurve: TransferCurve = TransferCurve.SRGB,
@@ -356,6 +357,7 @@ class UserPreferencesRepository(private val context: Context) {
private val NATURAL_LIGHT_ENABLED = booleanPreferencesKey("natural_light_enabled")
private val NATURAL_LIGHT_PREVIOUS_TONEMAP_MODE = stringPreferencesKey("natural_light_previous_tonemap_mode")
private val FIX_TONEMAP_PREVIEW = booleanPreferencesKey("fix_tonemap_preview")
private val FIX_TONEMAP_CAPTURE = booleanPreferencesKey("fix_tonemap_capture")
private val APPLY_ULTRA_HDR = booleanPreferencesKey("apply_ultra_hdr")
private val COLOR_SPACE = stringPreferencesKey("color_space")
private val LOG_CURVE = stringPreferencesKey("log_curve")
@@ -531,6 +533,7 @@ class UserPreferencesRepository(private val context: Context) {
preferences[NATURAL_LIGHT_PREVIOUS_TONEMAP_MODE] ?: "SYSTEM_DEFAULT"
),
fixTonemapPreview = preferences[FIX_TONEMAP_PREVIEW] ?: false,
fixTonemapCapture = preferences[FIX_TONEMAP_CAPTURE] ?: false,
applyUltraHDR = preferences[APPLY_ULTRA_HDR] ?: false,
colorSpace = ColorSpace.valueOf(preferences[COLOR_SPACE] ?: ColorSpace.SRGB.name),
logCurve = TransferCurve.fromPersistedName(preferences[LOG_CURVE] ?: TransferCurve.SRGB.name),
@@ -1533,6 +1536,15 @@ class UserPreferencesRepository(private val context: Context) {
}
}
/**
* 保存是否修复自定义色调映射拍摄异常
*/
suspend fun saveFixTonemapCapture(enabled: Boolean) {
context.dataStore.edit { preferences ->
preferences[FIX_TONEMAP_CAPTURE] = enabled
}
}
/**
* 保存是否应用 Ultra HDR 策略
*/
@@ -281,6 +281,7 @@ fun SettingsScreen(
val tonemapMode by viewModel.tonemapMode.collectAsState()
val settingsTonemapMode = remember(tonemapMode) { sanitizeSettingsTonemapMode(tonemapMode) }
val fixTonemapPreview by viewModel.fixTonemapPreview.collectAsState()
val fixTonemapCapture by viewModel.fixTonemapCapture.collectAsState()
val useGpuAcceleration by viewModel.useGpuAcceleration.collectAsState()
val useP010 by viewModel.useP010.collectAsState()
val useHlg10 by viewModel.useHlg10.collectAsState()
@@ -1338,6 +1339,17 @@ fun SettingsScreen(
onCheckedChange = { viewModel.setFixTonemapPreview(it) }
)
HorizontalDivider(
color = Color.White.copy(alpha = 0.1f),
modifier = Modifier.padding(vertical = 12.dp)
)
SwitchSettingItem(
title = stringResource(R.string.settings_fix_tonemap_capture),
description = stringResource(R.string.settings_fix_tonemap_capture_description),
checked = fixTonemapCapture,
onCheckedChange = { viewModel.setFixTonemapCapture(it) }
)
if (state.isP010Supported) {
HorizontalDivider(
@@ -1092,6 +1092,9 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
val fixTonemapPreview: StateFlow<Boolean> = userPreferencesRepository.userPreferences
.map { it.fixTonemapPreview }
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
val fixTonemapCapture: StateFlow<Boolean> = userPreferencesRepository.userPreferences
.map { it.fixTonemapCapture }
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
val applyUltraHDR: StateFlow<Boolean> = userPreferencesRepository.userPreferences
.map { it.applyUltraHDR }
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
@@ -1397,6 +1400,10 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
if (currentCameraState.fixTonemapPreview != effectiveFixTonemapPreview) {
cameraController.setFixTonemapPreview(effectiveFixTonemapPreview)
}
val effectiveFixTonemapCapture = it.fixTonemapCapture && !it.naturalLightEnabled
if (currentCameraState.fixTonemapCapture != effectiveFixTonemapCapture) {
cameraController.setFixTonemapCapture(effectiveFixTonemapCapture)
}
if (cameraController.state.value.meteringMode != it.meteringMode) {
cameraController.setMeteringMode(it.meteringMode)
}
@@ -1572,6 +1579,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
cameraController.setUseLivePhoto(prefs.useLivePhoto && prefs.captureMode == CaptureMode.PHOTO)
cameraController.setTonemapMode(effectiveCameraTonemapMode(prefs))
cameraController.setFixTonemapPreview(prefs.fixTonemapPreview && !prefs.naturalLightEnabled)
cameraController.setFixTonemapCapture(prefs.fixTonemapCapture && !prefs.naturalLightEnabled)
// 应用保存的虚拟光圈
if (prefs.defaultVirtualAperture > 0f) {
@@ -5618,6 +5626,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
}
}
fun setFixTonemapCapture(enabled: Boolean) {
viewModelScope.launch {
userPreferencesRepository.saveFixTonemapCapture(enabled)
}
}
fun togglePhantomMode() {
val newMode = !phantomMode.value
viewModelScope.launch {
+2
View File
@@ -261,6 +261,8 @@
<string name="settings_tonemap_mode_natural_light">แสงเงาธรรมชาติ</string>
<string name="settings_fix_tonemap_preview">แก้ไขข้อยกเว้นการแสดงตัวอย่างการแมปโทน</string>
<string name="settings_fix_tonemap_preview_description">ตัวอย่างอุปกรณ์บางรุ่นมาพร้อมกับ sRGB Gamma อยู่แล้ว หลังจากเปิดใช้งาน กล้องจะแปลงเป็นเส้นตรงในหน้าตัวอย่างเท่านั้น จากนั้นจึงใช้ Tone Curve แบบกำหนดเอง และเอาต์พุตการถ่ายภาพยังคงไม่เปลี่ยนแปลง</string>
<string name="settings_fix_tonemap_capture">แก้ไขข้อยกเว้นการถ่ายภาพการแมปโทน</string>
<string name="settings_fix_tonemap_capture_description">ภาพถ่ายจากอุปกรณ์บางรุ่นมี sRGB Gamma อยู่แล้ว หลังจากเปิดใช้งาน กล้องจะแปลงอินพุตการถ่ายภาพเป็นเส้นตรงก่อนใช้ Tone Curve แบบกำหนดเอง</string>
<!-- LUT -->
<string name="filter_intensity">ความเข้ม LUT</string>
@@ -313,6 +313,8 @@
<string name="settings_tonemap_mode_natural_light">自然光影</string>
<string name="settings_fix_tonemap_preview">修复色调映射预览异常</string>
<string name="settings_fix_tonemap_preview_description">部分设备预览已自带 sRGB Gamma。开启后仅在预览中先转为线性再应用自定义色调曲线,拍摄输出不变。</string>
<string name="settings_fix_tonemap_capture">修复色调映射拍摄异常</string>
<string name="settings_fix_tonemap_capture_description">部分设备拍摄输出已自带 sRGB Gamma。开启后会在拍摄请求中先转为线性再应用自定义色调曲线。</string>
<!-- LUT -->
<string name="filter_intensity">滤镜强度</string>
@@ -211,6 +211,8 @@
<string name="settings_tonemap_mode_natural_light">自然光影</string>
<string name="settings_fix_tonemap_preview">修復色調映射預覽異常</string>
<string name="settings_fix_tonemap_preview_description">部分裝置預覽已自帶 sRGB Gamma。開啟後只在預覽中先轉為線性再套用自訂色調曲線,拍攝輸出不變。</string>
<string name="settings_fix_tonemap_capture">修復色調映射拍攝異常</string>
<string name="settings_fix_tonemap_capture_description">部分裝置拍攝輸出已自帶 sRGB Gamma。開啟後會在拍攝請求中先轉為線性再套用自訂色調曲線。</string>
<!-- LUT -->
<string name="filter_intensity">濾鏡強度</string>
+2
View File
@@ -315,6 +315,8 @@
<string name="settings_tonemap_mode_natural_light">Natural Light</string>
<string name="settings_fix_tonemap_preview">Fix tone mapping preview</string>
<string name="settings_fix_tonemap_preview_description">Linearize preview input before applying custom tone curves on devices whose preview already includes sRGB gamma. Capture output is unchanged.</string>
<string name="settings_fix_tonemap_capture">Fix tone mapping capture</string>
<string name="settings_fix_tonemap_capture_description">Linearize capture input before applying custom tone curves on devices whose captured images already include sRGB gamma.</string>
<string name="settings_background">Background</string>
<string name="settings_background_description">Change the app background image</string>
<string name="settings_custom_background">Custom...</string>