feat: support photo-level color recipe overrides
This commit is contained in:
1 parent
dbb692e368
commit
0089d7457d
6 files changed
+183
-41
No files matched your search
@@ -1,13 +1,20 @@
|
||||
package com.hinnka.mycamera.ui.camera
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.ModalBottomSheet
|
||||
import androidx.compose.material3.SegmentedButton
|
||||
import androidx.compose.material3.SegmentedButtonDefaults
|
||||
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.rememberModalBottomSheetState
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
@@ -18,19 +25,22 @@ import com.hinnka.mycamera.R
|
||||
import com.hinnka.mycamera.model.ColorPaletteMapper
|
||||
import com.hinnka.mycamera.model.ColorPaletteState
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.model.RecipeParam
|
||||
import com.hinnka.mycamera.ui.components.ColorRecipePanel
|
||||
import com.hinnka.mycamera.ui.components.ColorRecipePalettePanel
|
||||
import com.hinnka.mycamera.ui.components.CustomSliderThinThumb
|
||||
import com.hinnka.mycamera.viewmodel.LutEditViewModel
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
enum class RecipeScope { LUT_GLOBAL, PHOTO_LOCAL }
|
||||
|
||||
/**
|
||||
* LUT编辑底部弹窗
|
||||
*
|
||||
* 为选中的LUT设置专属的色彩配方参数
|
||||
* 当 photoRecipeParams 非 null 时,说明这张照片已有独立配方覆盖。
|
||||
* onPhotoParamsChange 提供后会在顶部显示 scope 切换,允许用户选择:
|
||||
* - LUT 默认:修改 LUT 全局配方(原有行为)
|
||||
* - 仅此照片:修改照片级覆盖,不影响 LUT
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -39,44 +49,70 @@ fun LutEditBottomSheet(
|
||||
onDismiss: () -> Unit,
|
||||
initialParams: ColorRecipeParams? = null,
|
||||
onParamsPreviewChange: ((ColorRecipeParams) -> Unit)? = null,
|
||||
// 照片级配方相关(为 null 则隐藏 scope 切换,保持纯 LUT 编辑模式)
|
||||
photoRecipeParams: ColorRecipeParams? = null,
|
||||
onPhotoParamsChange: ((ColorRecipeParams?) -> Unit)? = null,
|
||||
defaultScope: RecipeScope = RecipeScope.LUT_GLOBAL,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val viewModel: LutEditViewModel = viewModel()
|
||||
val lutEditViewModel: LutEditViewModel = viewModel()
|
||||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
||||
val backgroundColor = Color(0xFF151515)
|
||||
val scope = rememberCoroutineScope()
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
val showScopeToggle = onPhotoParamsChange != null
|
||||
|
||||
var currentScope by remember { mutableStateOf(defaultScope) }
|
||||
var editingParams by remember { mutableStateOf(ColorRecipeParams.DEFAULT) }
|
||||
var paletteState by remember { mutableStateOf(ColorPaletteState.DEFAULT) }
|
||||
var saveJob by remember { mutableStateOf<Job?>(null) }
|
||||
val openingInitialParams = remember(lutId) { initialParams }
|
||||
|
||||
fun scheduleSave(params: ColorRecipeParams) {
|
||||
// 切换 scope 时加载对应的参数
|
||||
suspend fun loadParamsForScope(scope: RecipeScope, lutParams: ColorRecipeParams) {
|
||||
val params = when (scope) {
|
||||
RecipeScope.LUT_GLOBAL -> lutParams
|
||||
RecipeScope.PHOTO_LOCAL -> photoRecipeParams ?: lutParams
|
||||
}
|
||||
editingParams = params
|
||||
paletteState = ColorPaletteState(
|
||||
x = params.paletteX,
|
||||
y = params.paletteY,
|
||||
density = params.paletteDensity
|
||||
).normalized()
|
||||
}
|
||||
|
||||
fun scheduleLutSave(params: ColorRecipeParams) {
|
||||
saveJob?.cancel()
|
||||
saveJob = scope.launch {
|
||||
saveJob = coroutineScope.launch {
|
||||
delay(250)
|
||||
viewModel.saveLutColorRecipe(lutId, params)
|
||||
lutEditViewModel.saveLutColorRecipe(lutId, params)
|
||||
}
|
||||
}
|
||||
|
||||
fun flushSave() {
|
||||
fun flushLutSave() {
|
||||
saveJob?.cancel()
|
||||
viewModel.saveLutColorRecipe(lutId, editingParams)
|
||||
lutEditViewModel.saveLutColorRecipe(lutId, editingParams)
|
||||
}
|
||||
|
||||
fun onParamsUpdated(newParams: ColorRecipeParams) {
|
||||
editingParams = newParams
|
||||
onParamsPreviewChange?.invoke(newParams)
|
||||
when (currentScope) {
|
||||
RecipeScope.LUT_GLOBAL -> scheduleLutSave(newParams)
|
||||
RecipeScope.PHOTO_LOCAL -> onPhotoParamsChange?.invoke(newParams)
|
||||
}
|
||||
}
|
||||
|
||||
// 初始加载
|
||||
LaunchedEffect(lutId) {
|
||||
val loadedParams = openingInitialParams ?: viewModel.getColorRecipe(lutId)
|
||||
editingParams = loadedParams
|
||||
paletteState = ColorPaletteState(
|
||||
x = loadedParams.paletteX,
|
||||
y = loadedParams.paletteY,
|
||||
density = loadedParams.paletteDensity
|
||||
).normalized()
|
||||
val lutParams = openingInitialParams ?: lutEditViewModel.getColorRecipe(lutId)
|
||||
loadParamsForScope(currentScope, lutParams)
|
||||
}
|
||||
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = {
|
||||
flushSave()
|
||||
if (currentScope == RecipeScope.LUT_GLOBAL) flushLutSave()
|
||||
onDismiss()
|
||||
},
|
||||
sheetState = sheetState,
|
||||
@@ -89,13 +125,94 @@ fun LutEditBottomSheet(
|
||||
.fillMaxWidth()
|
||||
.navigationBarsPadding()
|
||||
) {
|
||||
// Scope 切换(仅在 gallery 编辑模式下显示)
|
||||
if (showScopeToggle) {
|
||||
SingleChoiceSegmentedButtonRow(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 24.dp, vertical = 8.dp)
|
||||
) {
|
||||
RecipeScope.entries.forEachIndexed { index, scope ->
|
||||
SegmentedButton(
|
||||
selected = currentScope == scope,
|
||||
onClick = {
|
||||
if (currentScope != scope) {
|
||||
// 切换前先把当前 scope 的未提交 LUT 改动 flush 掉
|
||||
if (currentScope == RecipeScope.LUT_GLOBAL) flushLutSave()
|
||||
currentScope = scope
|
||||
coroutineScope.launch {
|
||||
val lutParams = lutEditViewModel.getColorRecipe(lutId)
|
||||
loadParamsForScope(scope, lutParams)
|
||||
// 切换后预览也跟着刷新
|
||||
onParamsPreviewChange?.invoke(editingParams)
|
||||
}
|
||||
}
|
||||
},
|
||||
shape = SegmentedButtonDefaults.itemShape(
|
||||
index = index,
|
||||
count = RecipeScope.entries.size
|
||||
),
|
||||
colors = SegmentedButtonDefaults.colors(
|
||||
activeContainerColor = Color(0xFF2A2A2A),
|
||||
activeContentColor = Color.White,
|
||||
inactiveContainerColor = Color.Transparent,
|
||||
inactiveContentColor = Color.White.copy(alpha = 0.5f),
|
||||
activeBorderColor = Color.White.copy(alpha = 0.3f),
|
||||
inactiveBorderColor = Color.White.copy(alpha = 0.15f)
|
||||
)
|
||||
) {
|
||||
Text(
|
||||
text = when (scope) {
|
||||
RecipeScope.LUT_GLOBAL -> stringResource(R.string.recipe_scope_lut)
|
||||
RecipeScope.PHOTO_LOCAL -> stringResource(R.string.recipe_scope_photo)
|
||||
},
|
||||
fontSize = 12.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 仅此照片模式下的提示 + 重置按钮
|
||||
if (currentScope == RecipeScope.PHOTO_LOCAL) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 24.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.recipe_scope_photo_hint),
|
||||
color = Color.White.copy(alpha = 0.4f),
|
||||
fontSize = 10.sp
|
||||
)
|
||||
if (photoRecipeParams != null) {
|
||||
Text(
|
||||
text = stringResource(R.string.recipe_scope_photo_reset),
|
||||
color = Color(0xFFFF9800).copy(alpha = 0.8f),
|
||||
fontSize = 10.sp,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(4.dp))
|
||||
.clickable {
|
||||
onPhotoParamsChange?.invoke(null)
|
||||
coroutineScope.launch {
|
||||
val lutParams = lutEditViewModel.getColorRecipe(lutId)
|
||||
loadParamsForScope(RecipeScope.PHOTO_LOCAL, lutParams)
|
||||
onParamsPreviewChange?.invoke(editingParams)
|
||||
}
|
||||
}
|
||||
.padding(horizontal = 6.dp, vertical = 2.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
}
|
||||
}
|
||||
|
||||
LutIntensitySlider(
|
||||
intensity = editingParams.lutIntensity,
|
||||
onIntensityChange = {
|
||||
val newParams = editingParams.copy(lutIntensity = it)
|
||||
editingParams = newParams
|
||||
onParamsPreviewChange?.invoke(newParams)
|
||||
scheduleSave(newParams)
|
||||
onParamsUpdated(editingParams.copy(lutIntensity = it))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -105,22 +222,13 @@ fun LutEditBottomSheet(
|
||||
onPaletteStateChange = { newState ->
|
||||
val normalizedState = newState.normalized()
|
||||
paletteState = normalizedState
|
||||
val newParams = ColorPaletteMapper.updatePaletteState(editingParams, normalizedState)
|
||||
editingParams = newParams
|
||||
onParamsPreviewChange?.invoke(newParams)
|
||||
scheduleSave(newParams)
|
||||
onParamsUpdated(ColorPaletteMapper.updatePaletteState(editingParams, normalizedState))
|
||||
},
|
||||
onParamChange = { param, value ->
|
||||
val newParams = param.setValue(editingParams, value)
|
||||
editingParams = newParams
|
||||
onParamsPreviewChange?.invoke(newParams)
|
||||
scheduleSave(newParams)
|
||||
onParamsUpdated(param.setValue(editingParams, value))
|
||||
},
|
||||
onRemarksChange = {
|
||||
val newParams = editingParams.copy(remarks = it)
|
||||
editingParams = newParams
|
||||
onParamsPreviewChange?.invoke(newParams)
|
||||
scheduleSave(newParams)
|
||||
onParamsUpdated(editingParams.copy(remarks = it))
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
|
||||
@@ -49,6 +49,7 @@ import com.hinnka.mycamera.frame.TextType
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.raw.RawProfile
|
||||
import com.hinnka.mycamera.ui.camera.LutEditBottomSheet
|
||||
import com.hinnka.mycamera.ui.camera.RecipeScope
|
||||
import com.hinnka.mycamera.ui.components.*
|
||||
import com.hinnka.mycamera.ui.theme.AccentOrange
|
||||
import com.hinnka.mycamera.viewmodel.CameraViewModel
|
||||
@@ -74,6 +75,7 @@ fun PhotoEditScreen(
|
||||
val currentPhoto = viewModel.getCurrentPhoto()
|
||||
val editLutId by viewModel.editLutId.collectAsState()
|
||||
val editLutRecipeParams by viewModel.editLutRecipeParams.collectAsState()
|
||||
val editPhotoRecipeParams by viewModel.editPhotoRecipeParams.collectAsState()
|
||||
val editLutConfig = viewModel.editLutConfig
|
||||
val availableLuts = viewModel.availableLuts
|
||||
val showPaymentDialog = viewModel.showPaymentDialog
|
||||
@@ -136,7 +138,7 @@ fun PhotoEditScreen(
|
||||
currentPhoto,
|
||||
refreshKey,
|
||||
editLutId,
|
||||
previewRecipeParamsOverride ?: editLutRecipeParams,
|
||||
previewRecipeParamsOverride ?: editPhotoRecipeParams ?: editLutRecipeParams,
|
||||
editLutConfig,
|
||||
editFrameId,
|
||||
editFrameCustomProperties,
|
||||
@@ -518,10 +520,14 @@ fun PhotoEditScreen(
|
||||
}
|
||||
|
||||
if (editLutId != null) {
|
||||
val hasPhotoOverride = editPhotoRecipeParams != null
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(Color.White.copy(alpha = 0.1f))
|
||||
.background(
|
||||
if (hasPhotoOverride) Color(0xFFFF9800).copy(alpha = 0.15f)
|
||||
else Color.White.copy(alpha = 0.1f)
|
||||
)
|
||||
.clickable { showLutEditDialog = true }
|
||||
.padding(horizontal = 10.dp, vertical = 6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
@@ -530,7 +536,7 @@ fun PhotoEditScreen(
|
||||
Icon(
|
||||
imageVector = Icons.Default.Tune,
|
||||
contentDescription = null,
|
||||
tint = Color(0xFFFFD700),
|
||||
tint = if (hasPhotoOverride) Color(0xFFFF9800) else Color(0xFFFFD700),
|
||||
modifier = Modifier.size(14.dp)
|
||||
)
|
||||
Text(
|
||||
@@ -693,12 +699,15 @@ fun PhotoEditScreen(
|
||||
if (showLutEditDialog && editLutId != null) {
|
||||
LutEditBottomSheet(
|
||||
lutId = editLutId!!,
|
||||
initialParams = previewRecipeParamsOverride ?: editLutRecipeParams,
|
||||
initialParams = previewRecipeParamsOverride ?: editPhotoRecipeParams ?: editLutRecipeParams,
|
||||
onParamsPreviewChange = { previewRecipeParamsOverride = it },
|
||||
onDismiss = {
|
||||
previewRecipeParamsOverride = null
|
||||
showLutEditDialog = false
|
||||
}
|
||||
},
|
||||
photoRecipeParams = editPhotoRecipeParams,
|
||||
onPhotoParamsChange = { viewModel.setPhotoRecipeParams(it) },
|
||||
defaultScope = RecipeScope.PHOTO_LOCAL
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -188,6 +188,10 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
initialValue = ColorRecipeParams.DEFAULT
|
||||
)
|
||||
|
||||
/** 仅此照片的色彩配方覆盖,null 表示跟随 LUT 默认配方 */
|
||||
var editPhotoRecipeParams = MutableStateFlow<ColorRecipeParams?>(null)
|
||||
private set
|
||||
|
||||
var editLutConfig: LutConfig? by mutableStateOf(null)
|
||||
private set
|
||||
|
||||
@@ -1258,6 +1262,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
currentPhotoMetadata?.let { metadata ->
|
||||
editLutId.value = metadata.lutId
|
||||
editFrameId.value = metadata.frameId
|
||||
editPhotoRecipeParams.value = metadata.colorRecipeParams
|
||||
// 智能初始化:导入的照片默认值为 0,App 拍摄的则回退到当前全局配置
|
||||
editSharpening.value =
|
||||
metadata.sharpening ?: (if (metadata.isImported) 0f else sharpening.value)
|
||||
@@ -1304,11 +1309,19 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editLutId.value = null
|
||||
editLutConfig = null
|
||||
editFrameId.value = null
|
||||
editPhotoRecipeParams.value = null
|
||||
editCropRect.value = null
|
||||
editCropAspectOption.value = CropAspectOption.Free
|
||||
editRawDenoise.value = 0.2f
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置照片级别的色彩配方覆盖(null = 清除覆盖,跟随 LUT 默认)
|
||||
*/
|
||||
fun setPhotoRecipeParams(params: ColorRecipeParams?) {
|
||||
editPhotoRecipeParams.value = params
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 LUT
|
||||
*/
|
||||
@@ -1532,7 +1545,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
finalMetadata = (currentPhotoMetadata ?: metadata).copy(
|
||||
lutId = editLutId.value,
|
||||
frameId = editFrameId.value,
|
||||
colorRecipeParams = recipeParamsOverride ?: editLutRecipeParams.value,
|
||||
colorRecipeParams = recipeParamsOverride ?: editPhotoRecipeParams.value ?: editLutRecipeParams.value,
|
||||
sharpening = editSharpening.value,
|
||||
noiseReduction = editNoiseReduction.value,
|
||||
chromaNoiseReduction = editChromaNoiseReduction.value,
|
||||
@@ -1752,7 +1765,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
val metadata = currentPhotoMetadata?.copy(
|
||||
lutId = editLutId.value,
|
||||
frameId = editFrameId.value,
|
||||
colorRecipeParams = editLutRecipeParams.value,
|
||||
colorRecipeParams = editPhotoRecipeParams.value ?: editLutRecipeParams.value,
|
||||
sharpening = editSharpening.value,
|
||||
noiseReduction = editNoiseReduction.value,
|
||||
chromaNoiseReduction = editChromaNoiseReduction.value,
|
||||
|
||||
@@ -226,6 +226,10 @@
|
||||
|
||||
<!-- Color Recipe -->
|
||||
<string name="color_recipe">色彩配方</string>
|
||||
<string name="recipe_scope_lut">LUT 默认</string>
|
||||
<string name="recipe_scope_photo">仅此照片</string>
|
||||
<string name="recipe_scope_photo_reset">恢复 LUT 默认</string>
|
||||
<string name="recipe_scope_photo_hint">调整仅作用于这张照片</string>
|
||||
|
||||
<!-- Color Recipe Parameters -->
|
||||
<string name="recipe_param_exposure">曝光</string>
|
||||
|
||||
@@ -224,6 +224,10 @@
|
||||
|
||||
<!-- Color Recipe -->
|
||||
<string name="color_recipe">色彩配方</string>
|
||||
<string name="recipe_scope_lut">LUT 預設</string>
|
||||
<string name="recipe_scope_photo">僅此照片</string>
|
||||
<string name="recipe_scope_photo_reset">恢復 LUT 預設</string>
|
||||
<string name="recipe_scope_photo_hint">調整僅作用於這張照片</string>
|
||||
|
||||
<!-- Color Recipe Parameters -->
|
||||
<string name="recipe_param_exposure">曝光</string>
|
||||
|
||||
@@ -231,6 +231,10 @@
|
||||
|
||||
<!-- Color Recipe -->
|
||||
<string name="color_recipe">Color Recipe</string>
|
||||
<string name="recipe_scope_lut">LUT Default</string>
|
||||
<string name="recipe_scope_photo">This Photo</string>
|
||||
<string name="recipe_scope_photo_reset">Reset to LUT Default</string>
|
||||
<string name="recipe_scope_photo_hint">Adjustments apply to this photo only</string>
|
||||
|
||||
<!-- Color Recipe Parameters -->
|
||||
<string name="recipe_param_exposure">Exposure</string>
|
||||
|
||||
Reference in new issue
Block a user