fix: tonemap and natural light
This commit is contained in:
1 parent
b2eaf933c4
commit
4a30b9b909
10 files changed
+27
-116
No files matched your search
@@ -52,19 +52,11 @@ private fun sanitizeTonemapMode(mode: String): String {
|
|||||||
return when (mode) {
|
return when (mode) {
|
||||||
"FAST", "HIGH_QUALITY" -> "SYSTEM_DEFAULT"
|
"FAST", "HIGH_QUALITY" -> "SYSTEM_DEFAULT"
|
||||||
"REC709" -> "SRGB"
|
"REC709" -> "SRGB"
|
||||||
"RAW_PREVIEW", "SRGB_ACR3", "REC709_ACR3", "LINEAR_PIPELINE" -> "SRGB"
|
|
||||||
"SYSTEM_DEFAULT", "SRGB" -> mode
|
"SYSTEM_DEFAULT", "SRGB" -> mode
|
||||||
else -> "SYSTEM_DEFAULT"
|
else -> "SYSTEM_DEFAULT"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isLegacyNaturalLightTonemap(mode: String?): Boolean {
|
|
||||||
return mode == "LINEAR_PIPELINE" ||
|
|
||||||
mode == "RAW_PREVIEW" ||
|
|
||||||
mode == "SRGB_ACR3" ||
|
|
||||||
mode == "REC709_ACR3"
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class VolumeKeyAction {
|
enum class VolumeKeyAction {
|
||||||
NONE,
|
NONE,
|
||||||
CAPTURE,
|
CAPTURE,
|
||||||
@@ -169,7 +161,6 @@ data class UserPreferences(
|
|||||||
val droMode: String = "OFF", // DRO 模式
|
val droMode: String = "OFF", // DRO 模式
|
||||||
val tonemapMode: String = "SYSTEM_DEFAULT", // 色调映射模式
|
val tonemapMode: String = "SYSTEM_DEFAULT", // 色调映射模式
|
||||||
val naturalLightEnabled: Boolean = false, // 是否启用自然光影
|
val naturalLightEnabled: Boolean = false, // 是否启用自然光影
|
||||||
val naturalLightPreviousTonemapMode: String = "SYSTEM_DEFAULT", // 自然光影关闭时恢复的色调映射模式
|
|
||||||
val naturalLightWarningShown: Boolean = false, // 是否已提示自然光影兼容性风险
|
val naturalLightWarningShown: Boolean = false, // 是否已提示自然光影兼容性风险
|
||||||
val fixTonemapPreview: Boolean = false, // 修复部分设备自定义色调映射预览异常
|
val fixTonemapPreview: Boolean = false, // 修复部分设备自定义色调映射预览异常
|
||||||
val fixTonemapCapture: Boolean = false, // 修复部分设备自定义色调映射拍摄异常
|
val fixTonemapCapture: Boolean = false, // 修复部分设备自定义色调映射拍摄异常
|
||||||
@@ -356,7 +347,6 @@ class UserPreferencesRepository(private val context: Context) {
|
|||||||
private val DRO_MODE = stringPreferencesKey("dro_mode")
|
private val DRO_MODE = stringPreferencesKey("dro_mode")
|
||||||
private val TONEMAP_MODE = stringPreferencesKey("tonemap_mode")
|
private val TONEMAP_MODE = stringPreferencesKey("tonemap_mode")
|
||||||
private val NATURAL_LIGHT_ENABLED = booleanPreferencesKey("natural_light_enabled")
|
private val NATURAL_LIGHT_ENABLED = booleanPreferencesKey("natural_light_enabled")
|
||||||
private val NATURAL_LIGHT_PREVIOUS_TONEMAP_MODE = stringPreferencesKey("natural_light_previous_tonemap_mode")
|
|
||||||
private val NATURAL_LIGHT_WARNING_SHOWN = booleanPreferencesKey("natural_light_warning_shown")
|
private val NATURAL_LIGHT_WARNING_SHOWN = booleanPreferencesKey("natural_light_warning_shown")
|
||||||
private val FIX_TONEMAP_PREVIEW = booleanPreferencesKey("fix_tonemap_preview")
|
private val FIX_TONEMAP_PREVIEW = booleanPreferencesKey("fix_tonemap_preview")
|
||||||
private val FIX_TONEMAP_CAPTURE = booleanPreferencesKey("fix_tonemap_capture")
|
private val FIX_TONEMAP_CAPTURE = booleanPreferencesKey("fix_tonemap_capture")
|
||||||
@@ -529,11 +519,7 @@ class UserPreferencesRepository(private val context: Context) {
|
|||||||
useGpuAcceleration = preferences[USE_GPU_ACCELERATION] ?: DeviceUtil.defaultGpuAcceleration,
|
useGpuAcceleration = preferences[USE_GPU_ACCELERATION] ?: DeviceUtil.defaultGpuAcceleration,
|
||||||
droMode = preferences[DRO_MODE] ?: if (preferences[RAW_DRO_ENABLED_KEY] == true) "DR100" else "OFF",
|
droMode = preferences[DRO_MODE] ?: if (preferences[RAW_DRO_ENABLED_KEY] == true) "DR100" else "OFF",
|
||||||
tonemapMode = sanitizeTonemapMode(preferences[TONEMAP_MODE] ?: "SYSTEM_DEFAULT"),
|
tonemapMode = sanitizeTonemapMode(preferences[TONEMAP_MODE] ?: "SYSTEM_DEFAULT"),
|
||||||
naturalLightEnabled = preferences[NATURAL_LIGHT_ENABLED]
|
naturalLightEnabled = preferences[NATURAL_LIGHT_ENABLED] ?: false,
|
||||||
?: isLegacyNaturalLightTonemap(preferences[TONEMAP_MODE]),
|
|
||||||
naturalLightPreviousTonemapMode = sanitizeTonemapMode(
|
|
||||||
preferences[NATURAL_LIGHT_PREVIOUS_TONEMAP_MODE] ?: "SYSTEM_DEFAULT"
|
|
||||||
),
|
|
||||||
naturalLightWarningShown = preferences[NATURAL_LIGHT_WARNING_SHOWN] ?: false,
|
naturalLightWarningShown = preferences[NATURAL_LIGHT_WARNING_SHOWN] ?: false,
|
||||||
fixTonemapPreview = preferences[FIX_TONEMAP_PREVIEW] ?: false,
|
fixTonemapPreview = preferences[FIX_TONEMAP_PREVIEW] ?: false,
|
||||||
fixTonemapCapture = preferences[FIX_TONEMAP_CAPTURE] ?: false,
|
fixTonemapCapture = preferences[FIX_TONEMAP_CAPTURE] ?: false,
|
||||||
@@ -1514,22 +1500,6 @@ class UserPreferencesRepository(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun saveNaturalLightState(
|
|
||||||
enabled: Boolean,
|
|
||||||
previousTonemapMode: String? = null,
|
|
||||||
tonemapMode: String? = null
|
|
||||||
) {
|
|
||||||
context.dataStore.edit { preferences ->
|
|
||||||
previousTonemapMode?.let {
|
|
||||||
preferences[NATURAL_LIGHT_PREVIOUS_TONEMAP_MODE] = sanitizeTonemapMode(it)
|
|
||||||
}
|
|
||||||
tonemapMode?.let {
|
|
||||||
preferences[TONEMAP_MODE] = sanitizeTonemapMode(it)
|
|
||||||
}
|
|
||||||
preferences[NATURAL_LIGHT_ENABLED] = enabled
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun saveNaturalLightWarningShown(shown: Boolean) {
|
suspend fun saveNaturalLightWarningShown(shown: Boolean) {
|
||||||
context.dataStore.edit { preferences ->
|
context.dataStore.edit { preferences ->
|
||||||
preferences[NATURAL_LIGHT_WARNING_SHOWN] = shown
|
preferences[NATURAL_LIGHT_WARNING_SHOWN] = shown
|
||||||
|
|||||||
@@ -1673,7 +1673,7 @@ object GalleryManager {
|
|||||||
previewBitmap = BitmapUtils.flipHorizontal(previewBitmap)
|
previewBitmap = BitmapUtils.flipHorizontal(previewBitmap)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metadata.usesLinearPipelineToneMap()) {
|
if (metadata.usesNaturalLightToneMap()) {
|
||||||
val toneMappedPreview = photoProcessor.processCapturePreviewToneMap(previewBitmap, metadata)
|
val toneMappedPreview = photoProcessor.processCapturePreviewToneMap(previewBitmap, metadata)
|
||||||
if (toneMappedPreview !== previewBitmap && !previewBitmap.isRecycled) {
|
if (toneMappedPreview !== previewBitmap && !previewBitmap.isRecycled) {
|
||||||
previewBitmap.recycle()
|
previewBitmap.recycle()
|
||||||
@@ -2489,7 +2489,7 @@ object GalleryManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var previewBitmap = result
|
var previewBitmap = result
|
||||||
if (metadata.usesLinearPipelineToneMap()) {
|
if (metadata.usesNaturalLightToneMap()) {
|
||||||
previewBitmap = photoProcessor.processCapturePreviewToneMap(result, metadata)
|
previewBitmap = photoProcessor.processCapturePreviewToneMap(result, metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import java.text.SimpleDateFormat
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.math.log2
|
import kotlin.math.log2
|
||||||
|
|
||||||
|
const val TONEMAP_MODE_NATURAL_LIGHT = "NATURAL_LIGHT"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 照片元数据
|
* 照片元数据
|
||||||
*
|
*
|
||||||
@@ -177,15 +179,12 @@ data class MediaMetadata(
|
|||||||
val resolution: String
|
val resolution: String
|
||||||
get() = "${width}x${height}"
|
get() = "${width}x${height}"
|
||||||
|
|
||||||
fun usesLinearPipelineToneMap(): Boolean {
|
fun usesNaturalLightToneMap(): Boolean {
|
||||||
return when (tonemapMode) {
|
return tonemapMode == TONEMAP_MODE_NATURAL_LIGHT
|
||||||
"LINEAR_PIPELINE", "RAW_PREVIEW", "SRGB_ACR3", "REC709_ACR3" -> true
|
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun shouldApplyNaturalLightDefaultChromaDenoise(): Boolean {
|
fun shouldApplyNaturalLightDefaultChromaDenoise(): Boolean {
|
||||||
return usesLinearPipelineToneMap() && captureNoiseReductionLevel in LOW_HARDWARE_NOISE_REDUCTION_LEVELS
|
return usesNaturalLightToneMap() && captureNoiseReductionLevel in LOW_HARDWARE_NOISE_REDUCTION_LEVELS
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -483,7 +483,7 @@ class PhotoProcessor(
|
|||||||
input: Bitmap,
|
input: Bitmap,
|
||||||
metadata: MediaMetadata,
|
metadata: MediaMetadata,
|
||||||
): Bitmap = withContext(Dispatchers.IO) {
|
): Bitmap = withContext(Dispatchers.IO) {
|
||||||
if (!metadata.usesLinearPipelineToneMap()) return@withContext input
|
if (!metadata.usesNaturalLightToneMap()) return@withContext input
|
||||||
if (shouldDecodeHlgInput(metadata)) return@withContext input
|
if (shouldDecodeHlgInput(metadata)) return@withContext input
|
||||||
lutImageProcessor.applyLut(
|
lutImageProcessor.applyLut(
|
||||||
bitmap = input,
|
bitmap = input,
|
||||||
@@ -491,8 +491,7 @@ class PhotoProcessor(
|
|||||||
lutConfig = null,
|
lutConfig = null,
|
||||||
colorRecipeParams = null,
|
colorRecipeParams = null,
|
||||||
linearInputToneMap = true,
|
linearInputToneMap = true,
|
||||||
naturalLightInputSrgb = metadata.tonemapMode == "SRGB_ACR3" ||
|
naturalLightInputSrgb = true,
|
||||||
metadata.tonemapMode == "REC709_ACR3",
|
|
||||||
linearInputExposureEv = metadata.rawExposureCompensation ?: 0f,
|
linearInputExposureEv = metadata.rawExposureCompensation ?: 0f,
|
||||||
rawRenderingEngine = metadata.rawRenderingEngine,
|
rawRenderingEngine = metadata.rawRenderingEngine,
|
||||||
rawToneMappingParameters = metadata.rawToneMappingParameters
|
rawToneMappingParameters = metadata.rawToneMappingParameters
|
||||||
|
|||||||
@@ -174,9 +174,6 @@ class LutRenderer : GLSurfaceView.Renderer {
|
|||||||
@Volatile
|
@Volatile
|
||||||
var rawPreviewWhitePointCorrection: Float = 0f
|
var rawPreviewWhitePointCorrection: Float = 0f
|
||||||
|
|
||||||
@Volatile
|
|
||||||
var rawPreviewLinearizeInput: Boolean = false
|
|
||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
var rawPreviewRenderingEngine: RawRenderingEngine = RawRenderingEngine.AdobeCurve
|
var rawPreviewRenderingEngine: RawRenderingEngine = RawRenderingEngine.AdobeCurve
|
||||||
|
|
||||||
@@ -847,10 +844,6 @@ class LutRenderer : GLSurfaceView.Renderer {
|
|||||||
GLES30.glGetUniformLocation(program, "uWhitePoint"),
|
GLES30.glGetUniformLocation(program, "uWhitePoint"),
|
||||||
(1f + rawPreviewWhitePointCorrection).coerceAtLeast(blackPoint + 0.01f)
|
(1f + rawPreviewWhitePointCorrection).coerceAtLeast(blackPoint + 0.01f)
|
||||||
)
|
)
|
||||||
GLES30.glUniform1i(
|
|
||||||
GLES30.glGetUniformLocation(program, "uLinearizeInput"),
|
|
||||||
if (rawPreviewLinearizeInput) 1 else 0
|
|
||||||
)
|
|
||||||
drawRawPreviewQuad(program)
|
drawRawPreviewQuad(program)
|
||||||
GlUtils.checkGlError("renderRawPreviewInputStage")
|
GlUtils.checkGlError("renderRawPreviewInputStage")
|
||||||
return true
|
return true
|
||||||
@@ -3768,7 +3761,6 @@ class LutRenderer : GLSurfaceView.Renderer {
|
|||||||
exposureCompensation: Float,
|
exposureCompensation: Float,
|
||||||
blackPointCorrection: Float,
|
blackPointCorrection: Float,
|
||||||
whitePointCorrection: Float,
|
whitePointCorrection: Float,
|
||||||
linearizeInput: Boolean,
|
|
||||||
renderingEngine: RawRenderingEngine,
|
renderingEngine: RawRenderingEngine,
|
||||||
toneMappingParameters: RawToneMappingParameters
|
toneMappingParameters: RawToneMappingParameters
|
||||||
) {
|
) {
|
||||||
@@ -3776,7 +3768,6 @@ class LutRenderer : GLSurfaceView.Renderer {
|
|||||||
rawPreviewExposureCompensation = exposureCompensation
|
rawPreviewExposureCompensation = exposureCompensation
|
||||||
rawPreviewBlackPointCorrection = blackPointCorrection
|
rawPreviewBlackPointCorrection = blackPointCorrection
|
||||||
rawPreviewWhitePointCorrection = whitePointCorrection
|
rawPreviewWhitePointCorrection = whitePointCorrection
|
||||||
rawPreviewLinearizeInput = linearizeInput
|
|
||||||
rawPreviewRenderingEngine = renderingEngine
|
rawPreviewRenderingEngine = renderingEngine
|
||||||
rawPreviewToneMappingParameters = toneMappingParameters
|
rawPreviewToneMappingParameters = toneMappingParameters
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ internal object RawPreviewShaders {
|
|||||||
uniform float uExposureEv;
|
uniform float uExposureEv;
|
||||||
uniform float uBlackPoint;
|
uniform float uBlackPoint;
|
||||||
uniform float uWhitePoint;
|
uniform float uWhitePoint;
|
||||||
uniform bool uLinearizeInput;
|
|
||||||
|
|
||||||
vec3 srgbToLinear(vec3 color) {
|
vec3 srgbToLinear(vec3 color) {
|
||||||
vec3 clampedColor = max(color, vec3(0.0));
|
vec3 clampedColor = max(color, vec3(0.0));
|
||||||
@@ -29,9 +28,7 @@ internal object RawPreviewShaders {
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 color = texture(uCameraTexture, vTexCoord).rgb;
|
vec3 color = texture(uCameraTexture, vTexCoord).rgb;
|
||||||
if (uLinearizeInput) {
|
color = srgbToLinear(color);
|
||||||
color = srgbToLinear(color);
|
|
||||||
}
|
|
||||||
float blackPoint = clamp(uBlackPoint, 0.0, 0.99);
|
float blackPoint = clamp(uBlackPoint, 0.0, 0.99);
|
||||||
float whitePoint = max(uWhitePoint, blackPoint + 0.01);
|
float whitePoint = max(uWhitePoint, blackPoint + 0.01);
|
||||||
color = max((color - vec3(blackPoint)) / (whitePoint - blackPoint), vec3(0.0));
|
color = max((color - vec3(blackPoint)) / (whitePoint - blackPoint), vec3(0.0));
|
||||||
|
|||||||
@@ -200,7 +200,6 @@ class CameraGLSurfaceView @JvmOverloads constructor(
|
|||||||
exposureCompensation: Float,
|
exposureCompensation: Float,
|
||||||
blackPointCorrection: Float,
|
blackPointCorrection: Float,
|
||||||
whitePointCorrection: Float,
|
whitePointCorrection: Float,
|
||||||
linearizeInput: Boolean,
|
|
||||||
renderingEngine: RawRenderingEngine,
|
renderingEngine: RawRenderingEngine,
|
||||||
toneMappingParameters: RawToneMappingParameters
|
toneMappingParameters: RawToneMappingParameters
|
||||||
) {
|
) {
|
||||||
@@ -210,7 +209,6 @@ class CameraGLSurfaceView @JvmOverloads constructor(
|
|||||||
exposureCompensation = exposureCompensation,
|
exposureCompensation = exposureCompensation,
|
||||||
blackPointCorrection = blackPointCorrection,
|
blackPointCorrection = blackPointCorrection,
|
||||||
whitePointCorrection = whitePointCorrection,
|
whitePointCorrection = whitePointCorrection,
|
||||||
linearizeInput = linearizeInput,
|
|
||||||
renderingEngine = renderingEngine,
|
renderingEngine = renderingEngine,
|
||||||
toneMappingParameters = toneMappingParameters
|
toneMappingParameters = toneMappingParameters
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ fun CameraPreviewGL(
|
|||||||
videoLogProfile: VideoLogProfile = VideoLogProfile.OFF,
|
videoLogProfile: VideoLogProfile = VideoLogProfile.OFF,
|
||||||
isHlgInput: Boolean = false,
|
isHlgInput: Boolean = false,
|
||||||
naturalLightEnabled: Boolean = false,
|
naturalLightEnabled: Boolean = false,
|
||||||
fixTonemapPreview: Boolean = false,
|
|
||||||
rawExposureCompensation: Float = 0f,
|
rawExposureCompensation: Float = 0f,
|
||||||
rawBlackPointCorrection: Float = 0f,
|
rawBlackPointCorrection: Float = 0f,
|
||||||
rawWhitePointCorrection: Float = 0f,
|
rawWhitePointCorrection: Float = 0f,
|
||||||
@@ -276,7 +275,6 @@ fun CameraPreviewGL(
|
|||||||
exposureCompensation = rawExposureCompensation,
|
exposureCompensation = rawExposureCompensation,
|
||||||
blackPointCorrection = rawBlackPointCorrection,
|
blackPointCorrection = rawBlackPointCorrection,
|
||||||
whitePointCorrection = rawWhitePointCorrection,
|
whitePointCorrection = rawWhitePointCorrection,
|
||||||
linearizeInput = naturalLightEnabled || fixTonemapPreview,
|
|
||||||
renderingEngine = rawRenderingEngine,
|
renderingEngine = rawRenderingEngine,
|
||||||
toneMappingParameters = rawToneMappingParameters
|
toneMappingParameters = rawToneMappingParameters
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -208,7 +208,6 @@ fun CameraScreen(
|
|||||||
val rawToneMappingParameters by viewModel.rawToneMappingParameters.collectAsState()
|
val rawToneMappingParameters by viewModel.rawToneMappingParameters.collectAsState()
|
||||||
val naturalLightEnabled by viewModel.naturalLightEnabled.collectAsState()
|
val naturalLightEnabled by viewModel.naturalLightEnabled.collectAsState()
|
||||||
val naturalLightWarningShown by viewModel.naturalLightWarningShown.collectAsState()
|
val naturalLightWarningShown by viewModel.naturalLightWarningShown.collectAsState()
|
||||||
val fixTonemapPreview by viewModel.fixTonemapPreview.collectAsState()
|
|
||||||
val rawSpectralFilmStock by viewModel.rawSpectralFilmStock.collectAsState()
|
val rawSpectralFilmStock by viewModel.rawSpectralFilmStock.collectAsState()
|
||||||
val rawSpectralFilmSelection by viewModel.rawSpectralFilmSelection.collectAsState()
|
val rawSpectralFilmSelection by viewModel.rawSpectralFilmSelection.collectAsState()
|
||||||
val rawSpectralFilmPrint by viewModel.rawSpectralFilmPrint.collectAsState()
|
val rawSpectralFilmPrint by viewModel.rawSpectralFilmPrint.collectAsState()
|
||||||
@@ -954,7 +953,6 @@ fun CameraScreen(
|
|||||||
videoLogProfile = state.videoConfig.logProfile,
|
videoLogProfile = state.videoConfig.logProfile,
|
||||||
isHlgInput = if (hlgHardwareCompatibilityEnabled) state.isHLG else false,
|
isHlgInput = if (hlgHardwareCompatibilityEnabled) state.isHLG else false,
|
||||||
naturalLightEnabled = naturalLightEnabled,
|
naturalLightEnabled = naturalLightEnabled,
|
||||||
fixTonemapPreview = fixTonemapPreview,
|
|
||||||
rawExposureCompensation = rawExposureCompensation,
|
rawExposureCompensation = rawExposureCompensation,
|
||||||
rawBlackPointCorrection = rawBlackPointCorrection,
|
rawBlackPointCorrection = rawBlackPointCorrection,
|
||||||
rawWhitePointCorrection = rawWhitePointCorrection,
|
rawWhitePointCorrection = rawWhitePointCorrection,
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import com.hinnka.mycamera.frame.FramePreviewFactory
|
|||||||
import com.hinnka.mycamera.gallery.GalleryManager
|
import com.hinnka.mycamera.gallery.GalleryManager
|
||||||
import com.hinnka.mycamera.gallery.MediaMetadata
|
import com.hinnka.mycamera.gallery.MediaMetadata
|
||||||
import com.hinnka.mycamera.gallery.PhotoSavePath
|
import com.hinnka.mycamera.gallery.PhotoSavePath
|
||||||
|
import com.hinnka.mycamera.gallery.TONEMAP_MODE_NATURAL_LIGHT
|
||||||
import com.hinnka.mycamera.lut.BaselineColorCorrectionTarget
|
import com.hinnka.mycamera.lut.BaselineColorCorrectionTarget
|
||||||
import com.hinnka.mycamera.lut.BakedLutExporter
|
import com.hinnka.mycamera.lut.BakedLutExporter
|
||||||
import com.hinnka.mycamera.lut.LutConfig
|
import com.hinnka.mycamera.lut.LutConfig
|
||||||
@@ -101,7 +102,6 @@ data class MultipleExposureSessionState(
|
|||||||
|
|
||||||
private const val TONEMAP_MODE_SYSTEM_DEFAULT = "SYSTEM_DEFAULT"
|
private const val TONEMAP_MODE_SYSTEM_DEFAULT = "SYSTEM_DEFAULT"
|
||||||
private const val TONEMAP_MODE_SRGB = "SRGB"
|
private const val TONEMAP_MODE_SRGB = "SRGB"
|
||||||
private const val TONEMAP_MODE_LINEAR_PIPELINE = "LINEAR_PIPELINE"
|
|
||||||
|
|
||||||
private fun sanitizeViewModelTonemapMode(mode: String): String {
|
private fun sanitizeViewModelTonemapMode(mode: String): String {
|
||||||
return when (mode) {
|
return when (mode) {
|
||||||
@@ -665,34 +665,17 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
|
|
||||||
private fun metadataTonemapMode(prefs: UserPreferences?): String {
|
private fun metadataTonemapMode(prefs: UserPreferences?): String {
|
||||||
return if (prefs?.naturalLightEnabled == true) {
|
return if (prefs?.naturalLightEnabled == true) {
|
||||||
"SRGB_ACR3"
|
TONEMAP_MODE_NATURAL_LIGHT
|
||||||
} else {
|
} else {
|
||||||
sanitizeViewModelTonemapMode(prefs?.tonemapMode ?: TONEMAP_MODE_SYSTEM_DEFAULT)
|
sanitizeViewModelTonemapMode(prefs?.tonemapMode ?: TONEMAP_MODE_SYSTEM_DEFAULT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun saveTonemapModeWithFeatureGuards(mode: String) {
|
private suspend fun disableNaturalLightIfNeeded(reason: String, prefs: UserPreferences? = null) {
|
||||||
val resolvedMode = sanitizeViewModelTonemapMode(mode)
|
|
||||||
val prefs = userPreferencesRepository.userPreferences.first()
|
|
||||||
if (prefs.naturalLightEnabled) {
|
|
||||||
userPreferencesRepository.saveNaturalLightState(
|
|
||||||
enabled = true,
|
|
||||||
previousTonemapMode = resolvedMode,
|
|
||||||
tonemapMode = TONEMAP_MODE_SRGB
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
userPreferencesRepository.saveTonemapMode(resolvedMode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun clearNaturalLightTonemapIfNeeded(reason: String, prefs: UserPreferences? = null) {
|
|
||||||
val currentPrefs = prefs ?: userPreferencesRepository.userPreferences.first()
|
val currentPrefs = prefs ?: userPreferencesRepository.userPreferences.first()
|
||||||
if (currentPrefs.naturalLightEnabled) {
|
if (currentPrefs.naturalLightEnabled) {
|
||||||
PLog.d(TAG, "Disabling Natural Light tone map: $reason")
|
PLog.d(TAG, "Disabling Natural Light tone map: $reason")
|
||||||
userPreferencesRepository.saveNaturalLightState(
|
userPreferencesRepository.saveNaturalLightEnabled(false)
|
||||||
enabled = false,
|
|
||||||
tonemapMode = currentPrefs.naturalLightPreviousTonemapMode
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1356,7 +1339,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
(multipleExposureEnabled || shouldDisableNaturalLightForHdrComposition(it))
|
(multipleExposureEnabled || shouldDisableNaturalLightForHdrComposition(it))
|
||||||
) {
|
) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
clearNaturalLightTonemapIfNeeded(
|
disableNaturalLightIfNeeded(
|
||||||
reason = "conflicting persisted camera feature state",
|
reason = "conflicting persisted camera feature state",
|
||||||
prefs = it
|
prefs = it
|
||||||
)
|
)
|
||||||
@@ -1395,14 +1378,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
if (currentCameraState.tonemapMode != effectiveTonemapMode) {
|
if (currentCameraState.tonemapMode != effectiveTonemapMode) {
|
||||||
cameraController.setTonemapMode(effectiveTonemapMode)
|
cameraController.setTonemapMode(effectiveTonemapMode)
|
||||||
}
|
}
|
||||||
val effectiveFixTonemapPreview = it.fixTonemapPreview && !it.naturalLightEnabled
|
cameraController.setFixTonemapPreview(it.fixTonemapPreview)
|
||||||
if (currentCameraState.fixTonemapPreview != effectiveFixTonemapPreview) {
|
cameraController.setFixTonemapCapture(it.fixTonemapCapture)
|
||||||
cameraController.setFixTonemapPreview(effectiveFixTonemapPreview)
|
|
||||||
}
|
|
||||||
val effectiveFixTonemapCapture = it.fixTonemapCapture && !it.naturalLightEnabled
|
|
||||||
if (currentCameraState.fixTonemapCapture != effectiveFixTonemapCapture) {
|
|
||||||
cameraController.setFixTonemapCapture(effectiveFixTonemapCapture)
|
|
||||||
}
|
|
||||||
if (cameraController.state.value.meteringMode != it.meteringMode) {
|
if (cameraController.state.value.meteringMode != it.meteringMode) {
|
||||||
cameraController.setMeteringMode(it.meteringMode)
|
cameraController.setMeteringMode(it.meteringMode)
|
||||||
}
|
}
|
||||||
@@ -1577,8 +1554,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
cameraController.setMultiFrameCount(prefs.multiFrameCount)
|
cameraController.setMultiFrameCount(prefs.multiFrameCount)
|
||||||
cameraController.setUseLivePhoto(prefs.useLivePhoto && prefs.captureMode == CaptureMode.PHOTO)
|
cameraController.setUseLivePhoto(prefs.useLivePhoto && prefs.captureMode == CaptureMode.PHOTO)
|
||||||
cameraController.setTonemapMode(effectiveCameraTonemapMode(prefs))
|
cameraController.setTonemapMode(effectiveCameraTonemapMode(prefs))
|
||||||
cameraController.setFixTonemapPreview(prefs.fixTonemapPreview && !prefs.naturalLightEnabled)
|
cameraController.setFixTonemapPreview(prefs.fixTonemapPreview)
|
||||||
cameraController.setFixTonemapCapture(prefs.fixTonemapCapture && !prefs.naturalLightEnabled)
|
cameraController.setFixTonemapCapture(prefs.fixTonemapCapture)
|
||||||
|
|
||||||
// 应用保存的虚拟光圈
|
// 应用保存的虚拟光圈
|
||||||
if (prefs.defaultVirtualAperture > 0f) {
|
if (prefs.defaultVirtualAperture > 0f) {
|
||||||
@@ -2078,7 +2055,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
fun setUseMultipleExposure(enabled: Boolean) {
|
fun setUseMultipleExposure(enabled: Boolean) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
clearNaturalLightTonemapIfNeeded("multiple exposure enabled")
|
disableNaturalLightIfNeeded("multiple exposure enabled")
|
||||||
}
|
}
|
||||||
applyCameraFeatureUpdate(
|
applyCameraFeatureUpdate(
|
||||||
CameraFeatureUpdate(useMultipleExposure = SettingValue(enabled))
|
CameraFeatureUpdate(useMultipleExposure = SettingValue(enabled))
|
||||||
@@ -3476,7 +3453,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
if (enabled) {
|
if (enabled) {
|
||||||
val prefs = userPreferencesRepository.userPreferences.first()
|
val prefs = userPreferencesRepository.userPreferences.first()
|
||||||
if (shouldDisableNaturalLightForHdrComposition(prefs)) {
|
if (shouldDisableNaturalLightForHdrComposition(prefs)) {
|
||||||
clearNaturalLightTonemapIfNeeded(
|
disableNaturalLightIfNeeded(
|
||||||
reason = "HDR composition enabled while RAW is off",
|
reason = "HDR composition enabled while RAW is off",
|
||||||
prefs = prefs
|
prefs = prefs
|
||||||
)
|
)
|
||||||
@@ -3560,7 +3537,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
if (!useRaw) {
|
if (!useRaw) {
|
||||||
val prefs = userPreferencesRepository.userPreferences.first()
|
val prefs = userPreferencesRepository.userPreferences.first()
|
||||||
if (prefs.useHdrComposition) {
|
if (prefs.useHdrComposition) {
|
||||||
clearNaturalLightTonemapIfNeeded(
|
disableNaturalLightIfNeeded(
|
||||||
reason = "RAW disabled while HDR composition is active",
|
reason = "RAW disabled while HDR composition is active",
|
||||||
prefs = prefs
|
prefs = prefs
|
||||||
)
|
)
|
||||||
@@ -5028,7 +5005,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
multipleExposureFrameCount = expectedFrameCount,
|
multipleExposureFrameCount = expectedFrameCount,
|
||||||
baselineTarget = BaselineColorCorrectionTarget.JPG,
|
baselineTarget = BaselineColorCorrectionTarget.JPG,
|
||||||
).let { hdrMetadata ->
|
).let { hdrMetadata ->
|
||||||
if (hdrMetadata.usesLinearPipelineToneMap()) {
|
if (hdrMetadata.usesNaturalLightToneMap()) {
|
||||||
PLog.d(TAG, "YUV HDR bracket stores SYSTEM_DEFAULT tonemap metadata")
|
PLog.d(TAG, "YUV HDR bracket stores SYSTEM_DEFAULT tonemap metadata")
|
||||||
hdrMetadata.copy(tonemapMode = "SYSTEM_DEFAULT")
|
hdrMetadata.copy(tonemapMode = "SYSTEM_DEFAULT")
|
||||||
} else {
|
} else {
|
||||||
@@ -5561,14 +5538,14 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
*/
|
*/
|
||||||
fun setTonemapMode(mode: String) {
|
fun setTonemapMode(mode: String) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
saveTonemapModeWithFeatureGuards(mode)
|
userPreferencesRepository.saveTonemapMode(sanitizeViewModelTonemapMode(mode))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setNaturalLightToneMapEnabled(enabled: Boolean) {
|
fun setNaturalLightToneMapEnabled(enabled: Boolean) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val prefs = userPreferencesRepository.userPreferences.first()
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
|
val prefs = userPreferencesRepository.userPreferences.first()
|
||||||
val shouldDisableMultipleExposure = prefs.useMultipleExposure
|
val shouldDisableMultipleExposure = prefs.useMultipleExposure
|
||||||
val shouldDisableHdrComposition = shouldDisableNaturalLightForHdrComposition(prefs)
|
val shouldDisableHdrComposition = shouldDisableNaturalLightForHdrComposition(prefs)
|
||||||
|
|
||||||
@@ -5589,23 +5566,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (enabled) {
|
userPreferencesRepository.saveNaturalLightEnabled(enabled)
|
||||||
val previousTonemapMode = if (prefs.naturalLightEnabled) {
|
|
||||||
prefs.naturalLightPreviousTonemapMode
|
|
||||||
} else {
|
|
||||||
prefs.tonemapMode
|
|
||||||
}
|
|
||||||
userPreferencesRepository.saveNaturalLightState(
|
|
||||||
enabled = true,
|
|
||||||
previousTonemapMode = previousTonemapMode,
|
|
||||||
tonemapMode = TONEMAP_MODE_SRGB
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
userPreferencesRepository.saveNaturalLightState(
|
|
||||||
enabled = false,
|
|
||||||
tonemapMode = prefs.naturalLightPreviousTonemapMode
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user