feat: professional mode only camera presets

This commit is contained in:
zhoubinjia committed 2026-11-18 17:19:24 +08:00
1 parent 1b7877df71
commit fb1e048648
7 files changed
+91 -92

No files matched your search

@@ -407,6 +407,9 @@ data class CameraState(
val effectiveMeteringMode: MeteringMode
get() = if (meteringPoint != null) MeteringMode.SPOT else meteringMode
val isProfessionalMode: Boolean
get() = captureMode == CaptureMode.PHOTO && useRaw && isRawSupported
val meteringReferencePoint: Pair<Float, Float>?
get() = meteringPoint ?: focusPoint?.takeIf { focusPointSource == FocusPointSource.MANUAL }
@@ -62,8 +62,11 @@ data class CameraPreset(
// 专业模式基准色彩校正
val rawBaselineLutId: String? = null,
// 是否为内置预设
val isBuiltIn: Boolean = false
val isBuiltIn: Boolean = false,
val professionalModeOnly: Boolean = false,
) {
fun isAvailableInMode(isProfessionalMode: Boolean): Boolean = !professionalModeOnly || isProfessionalMode
fun toJson(): String = gson.toJson(normalizedForPersistence())
fun withoutLegacyHdf(): CameraPreset {
@@ -209,32 +212,6 @@ data class CameraPreset(
lutId = "standard",
colorRecipe = ColorRecipeParams.DEFAULT,
effects = EffectParams.DEFAULT,
frameId = null,
rawDcpId = null,
isBuiltIn = true
),
CameraPreset(
id = "builtin_hasselblad_natural",
name = "builtin_hasselblad_natural",
lutId = null,
colorRecipe = ColorRecipeParams.DEFAULT,
effects = EffectParams.DEFAULT,
rawRenderingEngine = RawRenderingEngine.Hncs.name,
isBuiltIn = true
),
CameraPreset(
id = "builtin_portrait",
name = "builtin_portrait",
lutId = "canon_portrait",
colorRecipe = ColorRecipeParams.DEFAULT.copy(
tonality = -0.6f,
sharpness = -0.2f
),
effects = EffectParams.DEFAULT.copy(
clarity = -0.2f,
),
frameId = "polaroid",
rawDcpId = null,
isBuiltIn = true
),
CameraPreset(
@@ -255,44 +232,16 @@ data class CameraPreset(
vignette = -0.2f,
),
frameId = "leica",
rawDcpId = null,
rawDROMode = "DR100",
isBuiltIn = true
),
CameraPreset(
id = "builtin_cinematic",
name = "builtin_cinematic",
lutId = "sony_fl2",
colorRecipe = ColorRecipeParams.DEFAULT.copy(
shadows = -0.08f,
highlights = 0.05f
),
lutId = "film_kodak_5207",
colorRecipe = ColorRecipeParams.DEFAULT,
effects = EffectParams.DEFAULT,
frameId = "xpan",
aspectRatio = AspectRatio.XPAN.name,
rawDcpId = null,
rawDROMode = "DR100",
isBuiltIn = true
),
CameraPreset(
id = "builtin_classic_film",
name = "builtin_classic_film",
lutId = null,
colorRecipe = ColorRecipeParams.DEFAULT.copy(
temperature = 0.08f,
contrast = 1.05f
),
effects = EffectParams.DEFAULT.copy(
vignette = -0.25f,
filmGrain = 0.25f,
halation = 0.25f,
),
frameId = "time",
rawDcpId = null,
rawRenderingEngine = RawRenderingEngine.Spektrafilm.name,
rawSpectralFilmStock = "kodak_gold_200",
rawSpectralFilmPrint = "kodak_2383",
rawDROMode = "OFF",
isBuiltIn = true
),
CameraPreset(
@@ -300,12 +249,37 @@ data class CameraPreset(
name = "builtin_monochrome",
lutId = "monochrome",
colorRecipe = ColorRecipeParams.DEFAULT.copy(
contrast = 1.2f
contrast = 1.2f,
masterCurvePoints = floatArrayOf(0.1f, 0f, 0.9f, 1f),
),
effects = EffectParams.DEFAULT,
frameId = "black_border",
rawDcpId = null,
rawDROMode = "DR100",
isBuiltIn = true
),
CameraPreset(
id = "builtin_hasselblad_natural",
name = "builtin_hasselblad_natural",
lutId = null,
colorRecipe = ColorRecipeParams.DEFAULT.copy(
masterCurvePoints = floatArrayOf(0f, 0f, 0.33f, 0.28f, 0.65f, 0.70f, 1f, 1f),
),
effects = EffectParams.DEFAULT,
frameId = "hasselblad",
rawRenderingEngine = RawRenderingEngine.Hncs.name,
rawHncsColorMatchingEnabled = false,
professionalModeOnly = true,
isBuiltIn = true
),
CameraPreset(
id = "builtin_classic_film",
name = "builtin_classic_film",
lutId = null,
colorRecipe = ColorRecipeParams.DEFAULT,
effects = EffectParams.DEFAULT,
frameId = "time",
rawRenderingEngine = RawRenderingEngine.Fotufilm.name,
rawFotufilmDocument = """{"stock":"ultramax400","paper":"endura-premier"}""",
professionalModeOnly = true,
isBuiltIn = true
),
)
@@ -48,6 +48,7 @@ internal object CameraPresetJsonCodec {
return CameraPreset(
id = id,
name = name,
professionalModeOnly = obj.boolean("professionalModeOnly", false),
lutId = obj.stringOrNull("lutId"),
colorRecipe = parseColorRecipe(obj.get("colorRecipe")),
effects = parseEffects(obj.get("effects")),
@@ -264,7 +264,6 @@ fun CameraScreen(
val lutSelectorMode by viewModel.lutSelectorMode.collectAsState()
val activePresetId by preferenceValue { it.activePresetId }
val activePresetModified by viewModel.isActivePresetModified.collectAsState()
val customPresets by preferenceValue { it.customPresets }
val currentBaselineRecipeParams by viewModel.currentBaselineRecipeParams.collectAsState()
val categoryOrder by preferenceValue { it.categoryOrder }
val useRaw by preferenceValue { it.useRaw }
@@ -1621,6 +1620,9 @@ fun CameraScreen(
val filterSelector: @Composable () -> Unit = {
val allPresets by viewModel.allPresets.collectAsState()
val selectablePresets = remember(allPresets, state.isProfessionalMode) {
allPresets.filter { it.isAvailableInMode(state.isProfessionalMode) }
}
val defaultPresetName = stringResource(R.string.preset_new_preset_default)
val isVideoLog = isVideoMode && state.videoConfig.logProfile.isEnabled
@@ -1631,7 +1633,7 @@ fun CameraScreen(
thumbnail = viewModel.previewThumbnail,
presetThumbnailInput = viewModel.presetThumbnailInput,
onLutSelected = { viewModel.setLut(it) },
allPresets = allPresets,
allPresets = selectablePresets,
presetModeEnabled = !isVideoLog,
activePresetId = activePresetId,
activePresetModified = activePresetModified,
@@ -2246,7 +2248,7 @@ private fun Controls(
CaptureModeSwitcher(
shootingMode = when {
state.captureMode == CaptureMode.VIDEO -> CameraShootingMode.VIDEO
state.useRaw && state.isRawSupported -> CameraShootingMode.PROFESSIONAL
state.isProfessionalMode -> CameraShootingMode.PROFESSIONAL
else -> CameraShootingMode.PHOTO
},
professionalModeEnabled = state.isRawSupported,
@@ -81,6 +81,7 @@ fun PresetEditorScreen(
}
var presetName by remember { mutableStateOf(sourcePreset.name) }
var professionalModeOnly by remember { mutableStateOf(sourcePreset.professionalModeOnly) }
var selectedLutId by remember { mutableStateOf(sourcePreset.lutId) }
var colorRecipe by remember { mutableStateOf(sourcePreset.colorRecipe) }
var effects by remember { mutableStateOf(sourcePreset.effects) }
@@ -134,6 +135,7 @@ fun PresetEditorScreen(
val encodedDocument by remember { derivedStateOf { FotufilmDocumentStorage.encode(rawFotufilmDocument) } }
val editedPreset = sourcePreset.copy(
name = presetName,
professionalModeOnly = professionalModeOnly,
lutId = selectedLutId,
colorRecipe = colorRecipe,
effects = effects,
@@ -251,6 +253,11 @@ fun PresetEditorScreen(
.border(1.dp, Color.White.copy(alpha = 0.1f), RoundedCornerShape(8.dp))
.padding(horizontal = 12.dp, vertical = 12.dp)
)
SwitchSettingItem(
title = stringResource(R.string.preset_professional_mode_only),
checked = professionalModeOnly,
onCheckedChange = { professionalModeOnly = it },
)
}
SettingsSection(title = stringResource(R.string.filter), isExpandable = false) {
@@ -46,6 +46,7 @@ import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@@ -98,6 +99,8 @@ fun PresetManagementScreen(
modifier: Modifier = Modifier
) {
val allPresets by viewModel.allPresets.collectAsState()
val cameraState by viewModel.state.collectAsState()
val isProfessionalMode by remember(viewModel) { derivedStateOf { cameraState.isProfessionalMode } }
val activePresetId by preferenceValue { it.activePresetId }
val activePresetModified by viewModel.isActivePresetModified.collectAsState()
val context = LocalContext.current
@@ -277,12 +280,15 @@ fun PresetManagementScreen(
) {
itemsIndexed(localPresets, key = { _, preset -> preset.id }) { _, preset ->
val displayName = presetDisplayName(preset)
val selectable = preset.isAvailableInMode(isProfessionalMode)
val isActive = selectable && activePresetId == preset.id
ReorderableItem(reorderableLazyListState, key = preset.id) { isDragging ->
PresetManagementItem(
preset = preset,
displayName = displayName,
isActive = activePresetId == preset.id,
isModified = activePresetModified && activePresetId == preset.id,
selectable = selectable,
isActive = isActive,
isModified = isActive && activePresetModified,
isDragging = isDragging,
isExporting = exportingPresetId == preset.id,
dragModifier = Modifier.draggableHandle(),
@@ -368,6 +374,7 @@ fun PresetManagementScreen(
private fun PresetManagementItem(
preset: CameraPreset,
displayName: String,
selectable: Boolean,
isActive: Boolean,
isModified: Boolean,
isDragging: Boolean,
@@ -388,7 +395,7 @@ private fun PresetManagementItem(
Card(
modifier = Modifier
.fillMaxWidth()
.clickable(onClick = onSelect)
.clickable(enabled = selectable, onClick = onSelect)
.border(1.dp, borderColor, RoundedCornerShape(10.dp)),
shape = RoundedCornerShape(10.dp),
colors = CardDefaults.cardColors(containerColor = cardColor)
@@ -431,6 +438,7 @@ private fun PresetManagementItem(
FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(3.dp)) {
val rawRenderingEngine = RawRenderingEngine.fromPersistedName(preset.rawRenderingEngine)
if (preset.professionalModeOnly) PresetFeatureText(stringResource(R.string.preset_professional_mode_only))
PresetFeatureText(preset.aspectRatio.removePrefix("RATIO_").replace("_", ":"))
if (rawRenderingEngine == RawRenderingEngine.Spektrafilm ||
rawRenderingEngine == RawRenderingEngine.Fotufilm
@@ -481,6 +481,7 @@ private data class PresetMatchSnapshot(
private data class ActivePresetMatchState(
val prefs: UserPreferences,
val presets: List<com.hinnka.mycamera.model.CameraPreset>,
val isProfessionalMode: Boolean,
val aspectRatio: String,
val lutId: String,
val recipe: ColorRecipeParams,
@@ -520,7 +521,7 @@ internal fun resolveLutIdForCaptureMode(
private data class CameraFeatureUpdate(
val captureMode: SettingValue<CaptureMode>? = null,
val lutId: SettingValue<String?>? = null,
val lutId: String? = null, // null leaves the selection unchanged; "none" explicitly disables the LUT.
val colorRecipe: SettingValue<ColorRecipeParams>? = null,
val effects: SettingValue<EffectParams>? = null,
val aspectRatio: SettingValue<AspectRatio>? = null,
@@ -685,6 +686,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
builtInsById[saved.id]?.let { builtin ->
builtin.copy(
name = saved.name,
professionalModeOnly = saved.professionalModeOnly,
lutId = saved.lutId,
colorRecipe = saved.colorRecipe,
effects = saved.effects,
@@ -758,17 +760,18 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
) { prefs, presets, initialized ->
if (initialized) prefs to presets else null
},
state.map { it.aspectRatio.name }.distinctUntilChanged(),
state.map { it.aspectRatio.name to it.isProfessionalMode }.distinctUntilChanged(),
currentLutId.flatMapLatest { lutId ->
contentRepository.lutManager.getColorRecipeParams(lutId).map { recipe ->
lutId to recipe
}
}
) { inputs, aspectRatio, (lutId, recipe) ->
) { inputs, (aspectRatio, isProfessionalMode), (lutId, recipe) ->
inputs?.let { (prefs, presets) ->
ActivePresetMatchState(
prefs = prefs,
presets = presets,
isProfessionalMode = isProfessionalMode,
aspectRatio = aspectRatio,
lutId = lutId,
recipe = recipe,
@@ -794,7 +797,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
val presetId = matchState?.prefs?.activePresetId ?: return@combine false
val preset = matchState.presets.firstOrNull { it.id == presetId }
?: return@combine false
!matchState.toPresetMatchSnapshot().matches(preset)
preset.isAvailableInMode(matchState.isProfessionalMode) && !matchState.toPresetMatchSnapshot().matches(preset)
}
}
.distinctUntilChanged()
@@ -886,8 +889,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
}
val currentState = state.value
val includePhotoSettings = currentState.captureMode == CaptureMode.PHOTO
val includeProfessionalSettings = includePhotoSettings &&
userPreferencesRepository.current.useRaw && currentState.isRawSupported
val includeProfessionalSettings = currentState.isProfessionalMode
if (preset != null && !preset.isAvailableInMode(includeProfessionalSettings)) return@withLock
PLog.d(
TAG,
"Applying preset id=${preset?.id}, captureMode=${currentState.captureMode}, " +
@@ -904,8 +907,9 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
if (applied && presetApplyGeneration == applyGeneration) {
activePresetMatchState.filterNotNull().first { matchState ->
matchState.prefs.activePresetId == preset?.id &&
(preset == null || matchState.toPresetMatchSnapshot().matches(preset))
(preset != null && !preset.isAvailableInMode(matchState.isProfessionalMode)) ||
(matchState.prefs.activePresetId == preset?.id &&
(preset == null || matchState.toPresetMatchSnapshot().matches(preset)))
}
}
} finally {
@@ -931,7 +935,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
null
}
val sharedUpdate = CameraFeatureUpdate(
lutId = SettingValue(CameraPreset.normalizeLutId(this?.lutId)),
lutId = CameraPreset.normalizeLutId(this?.lutId) ?: "none",
colorRecipe = SettingValue(this?.colorRecipe ?: ColorRecipeParams.DEFAULT),
effects = SettingValue(this?.effects ?: EffectParams.DEFAULT),
aspectRatio = ratio?.let(::SettingValue),
@@ -1043,8 +1047,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
val currentState = state.value
val targetCaptureMode = update.captureMode?.value ?: currentState.captureMode
val captureModeWillChange = targetCaptureMode != currentState.captureMode
val persistLutInVideoSlot = currentState.captureMode == CaptureMode.VIDEO &&
prefs.separateVideoLutEnabled && update.lutId != null
val persistLutInVideoSlot = currentState.captureMode == CaptureMode.VIDEO && prefs.separateVideoLutEnabled
val targetAspectRatio = update.aspectRatio?.value
val needsCameraReopen =
targetAspectRatio != null && targetAspectRatio != currentState.aspectRatio ||
@@ -1052,17 +1055,13 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
desiredMultiFrameOutputScale != currentState.multiFrameOutputScale
update.colorRecipe?.let {
val recipeLutId = if (update.lutId != null) {
update.lutId.value ?: "none"
} else {
currentLutId.value
}
val recipeLutId = update.lutId ?: currentLutId.value
val recipeWithEffects = update.effects?.value?.applyTo(it.value) ?: it.value
contentRepository.lutManager.saveColorRecipeParams(recipeLutId, recipeWithEffects)
}
update.lutId?.let {
setLut(it.value, persist = false)
setLut(it, persist = false)
}
update.aspectRatio?.let {
@@ -1167,7 +1166,9 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
userPreferencesRepository.update {
update.captureMode?.let { captureMode = it.value }
if (!persistLutInVideoSlot) update.lutId?.let { lutId = it.value }
update.lutId?.let {
if (persistLutInVideoSlot) videoLutId = it else lutId = it
}
update.effects?.let { activeEffectParams = it.value }
update.aspectRatio?.let { aspectRatio = it.value.name }
if (update.useRaw != null || desiredUseRaw != prefs.useRaw) useRaw = desiredUseRaw
@@ -1203,8 +1204,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
}
update.activePresetId?.let { activePresetId = it.value }
}
if (persistLutInVideoSlot) {
userPreferencesRepository.update { videoLutId = update.lutId.value ?: "none" }
if (update.lutId != null && !persistLutInVideoSlot) {
PhotonLookContract.notifyLookChanged(getApplication<Application>())
}
if (reconfigureCameraIfNeeded && needsCameraReopen && !captureModeWillChange) {
@@ -1246,11 +1247,13 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
fun unsavedCameraPreset(preset: CameraPreset): CameraPreset? {
val matchState = activePresetMatchState.value ?: return null
if (!preset.isAvailableInMode(matchState.isProfessionalMode)) return null
if (presetApplyInProgress.value || matchState.prefs.activePresetId != preset.id) return null
val snapshot = matchState.toPresetMatchSnapshot()
if (snapshot.matches(preset)) return null
if (snapshot.isProfessionalMode) {
return createPresetFromCurrentSettings(preset.id, preset.name, preset.isBuiltIn)
.copy(professionalModeOnly = preset.professionalModeOnly)
}
// Only merge fields this shooting mode actually applied from the preset.
return preset.copy(
@@ -1357,8 +1360,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
effects = effects,
captureMode = prefs.captureMode,
aspectRatio = aspectRatio,
isProfessionalMode = prefs.captureMode == CaptureMode.PHOTO &&
prefs.useRaw && prefs.useRawMax,
isProfessionalMode = isProfessionalMode,
ultraHdrGainMapEnabled = prefs.ultraHdrGainMapEnabled,
frameId = prefs.frameId,
rawDcpId = prefs.rawDcpId,
@@ -4140,10 +4142,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
fun updateLut() {
viewModelScope.launch {
val preferences = userPreferencesRepository.userPreferences.first()
val newLutId = resolveLutIdForMode(preferences, state.value.captureMode) ?: return@launch
if (currentLutId.value != newLutId) {
setLut(newLutId, persist = false)
presetApplyMutex.withLock {
val preferences = userPreferencesRepository.userPreferences.first()
val newLutId = resolveLutIdForMode(preferences, state.value.captureMode) ?: return@withLock
if (currentLutId.value != newLutId) {
setLut(newLutId, persist = false)
}
}
}
}