From 87524fd31029ffc85e4094b2dd3eefc8bfec15c7 Mon Sep 17 00:00:00 2001 From: zhoubinjia Date: Thu, 30 Jul 2026 15:44:00 +0800 Subject: [PATCH] feat: support edit without lut --- .../mycamera/lut/BaselineColorCorrection.kt | 25 +- .../mycamera/ui/gallery/GalleryEditScreen.kt | 240 +++++++++--------- 2 files changed, 132 insertions(+), 133 deletions(-) diff --git a/app/src/main/java/com/hinnka/mycamera/lut/BaselineColorCorrection.kt b/app/src/main/java/com/hinnka/mycamera/lut/BaselineColorCorrection.kt index b69201cf..b1a13338 100644 --- a/app/src/main/java/com/hinnka/mycamera/lut/BaselineColorCorrection.kt +++ b/app/src/main/java/com/hinnka/mycamera/lut/BaselineColorCorrection.kt @@ -99,18 +99,8 @@ class ColorCorrectionPipelineResolver( creativeLutId: String?, creativeRecipeParams: ColorRecipeParams?, ): ResolvedColorCorrectionStack { - val baselineLayer = baselineLutId?.let { lutId -> - LutRenderLayer( - lutConfig = lutManager.loadLut(lutId), - colorRecipeParams = baselineRecipeParams ?: ColorRecipeParams.DEFAULT, - ) - } - val creativeLayer = creativeLutId?.let { lutId -> - LutRenderLayer( - lutConfig = lutManager.loadLut(lutId), - colorRecipeParams = creativeRecipeParams ?: ColorRecipeParams.DEFAULT, - ) - } + val baselineLayer = resolveLayer(baselineLutId, baselineRecipeParams) + val creativeLayer = resolveLayer(creativeLutId, creativeRecipeParams) return ResolvedColorCorrectionStack( target = target, baselineLutId = baselineLutId, @@ -119,4 +109,15 @@ class ColorCorrectionPipelineResolver( creativeLayer = creativeLayer, ) } + + private suspend fun resolveLayer( + lutId: String?, + colorRecipeParams: ColorRecipeParams?, + ): LutRenderLayer? { + if (lutId == null && colorRecipeParams == null) return null + return LutRenderLayer( + lutConfig = lutId?.let { lutManager.loadLut(it) }, + colorRecipeParams = colorRecipeParams ?: ColorRecipeParams.DEFAULT, + ) + } } diff --git a/app/src/main/java/com/hinnka/mycamera/ui/gallery/GalleryEditScreen.kt b/app/src/main/java/com/hinnka/mycamera/ui/gallery/GalleryEditScreen.kt index 8d4d922f..86907aae 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/gallery/GalleryEditScreen.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/gallery/GalleryEditScreen.kt @@ -267,7 +267,7 @@ fun GalleryEditScreen( ) var previewRenderRequestId by remember { mutableLongStateOf(0L) } val shouldCalculateImageHistogram = - (editTab == EDIT_TAB_ADJUSTMENTS && editLutId != null) || isBaselineLutEditSheetVisible + editTab == EDIT_TAB_ADJUSTMENTS || isBaselineLutEditSheetVisible fun currentPreviewSignature(fast: Boolean = false): PreviewRenderSignature? { val photo = editSourcePhoto ?: return null @@ -1090,131 +1090,127 @@ fun GalleryEditScreen( } EDIT_TAB_ADJUSTMENTS -> { Spacer(modifier = Modifier.height(6.dp)) - if (editLutId == null) { - Text( - text = stringResource(R.string.edit_select_lut_hint), - color = Color.White.copy(alpha = 0.55f), - fontSize = 13.sp, - textAlign = TextAlign.Center, - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 24.dp, vertical = 28.dp) - ) - } else { - val effectiveRecipe = editPhotoRecipeParams ?: editLutRecipeParams - val paletteState = ColorPaletteState( - x = effectiveRecipe.paletteX, - y = effectiveRecipe.paletteY, - density = effectiveRecipe.paletteDensity - ).normalized() - val applyEffectsToVideo by viewModel.editApplyEffectsToVideo.collectAsState() + val effectiveRecipe = editPhotoRecipeParams ?: editLutRecipeParams + val paletteState = ColorPaletteState( + x = effectiveRecipe.paletteX, + y = effectiveRecipe.paletteY, + density = effectiveRecipe.paletteDensity + ).normalized() + val applyEffectsToVideo by viewModel.editApplyEffectsToVideo.collectAsState() - ColorRecipePanel( - currentParams = effectiveRecipe, - paletteState = paletteState, - onPaletteStateChange = { state -> - viewModel.setPhotoRecipeParams( - ColorPaletteMapper.updatePaletteState( - effectiveRecipe, - state.normalized() - ), - syncToCurrentLut = syncAdjustmentsToLut - ) - }, - onParamChange = { param, value -> - viewModel.setPhotoRecipeParams( - param.setValue(effectiveRecipe, value), - syncToCurrentLut = syncAdjustmentsToLut - ) - }, - onParamsChange = { params -> - viewModel.setPhotoRecipeParams( - params, - syncToCurrentLut = syncAdjustmentsToLut - ) - }, - onRemarksChange = { remarks -> - viewModel.setPhotoRecipeParams( - effectiveRecipe.copy(remarks = remarks), - syncToCurrentLut = syncAdjustmentsToLut - ) - }, - onCurveChange = { channel, points -> - val updated = when (channel) { - CurveChannel.MASTER -> effectiveRecipe.copy(masterCurvePoints = points) - CurveChannel.RED -> effectiveRecipe.copy(redCurvePoints = points) - CurveChannel.GREEN -> effectiveRecipe.copy(greenCurvePoints = points) - CurveChannel.BLUE -> effectiveRecipe.copy(blueCurvePoints = points) - } - viewModel.setPhotoRecipeParams( - updated, - syncToCurrentLut = syncAdjustmentsToLut - ) - }, - imageHistogram = imageHistogram, - showLutIntensity = true, - currentEffects = effectiveRecipe.toEffectParams(), - onEffectsChange = { effects -> - val latestRecipe = viewModel.editPhotoRecipeParams.value - ?: viewModel.editLutRecipeParams.value - viewModel.setPhotoRecipeParams( - effects.applyTo(latestRecipe), - syncToCurrentLut = syncAdjustmentsToLut - ) - }, - optionControls = { + ColorRecipePanel( + currentParams = effectiveRecipe, + paletteState = paletteState, + onPaletteStateChange = { state -> + viewModel.setPhotoRecipeParams( + ColorPaletteMapper.updatePaletteState( + effectiveRecipe, + state.normalized() + ), + syncToCurrentLut = syncAdjustmentsToLut + ) + }, + onParamChange = { param, value -> + viewModel.setPhotoRecipeParams( + param.setValue(effectiveRecipe, value), + syncToCurrentLut = syncAdjustmentsToLut + ) + }, + onParamsChange = { params -> + viewModel.setPhotoRecipeParams( + params, + syncToCurrentLut = syncAdjustmentsToLut + ) + }, + onRemarksChange = { remarks -> + viewModel.setPhotoRecipeParams( + effectiveRecipe.copy(remarks = remarks), + syncToCurrentLut = syncAdjustmentsToLut + ) + }, + onCurveChange = { channel, points -> + val updated = when (channel) { + CurveChannel.MASTER -> effectiveRecipe.copy(masterCurvePoints = points) + CurveChannel.RED -> effectiveRecipe.copy(redCurvePoints = points) + CurveChannel.GREEN -> effectiveRecipe.copy(greenCurvePoints = points) + CurveChannel.BLUE -> effectiveRecipe.copy(blueCurvePoints = points) + } + viewModel.setPhotoRecipeParams( + updated, + syncToCurrentLut = syncAdjustmentsToLut + ) + }, + imageHistogram = imageHistogram, + showLutIntensity = true, + currentEffects = effectiveRecipe.toEffectParams(), + onEffectsChange = { effects -> + val latestRecipe = viewModel.editPhotoRecipeParams.value + ?: viewModel.editLutRecipeParams.value + viewModel.setPhotoRecipeParams( + effects.applyTo(latestRecipe), + syncToCurrentLut = syncAdjustmentsToLut + ) + }, + optionControls = if ( + editLutId != null || currentPhoto.isMotionPhoto + ) { + { Column(modifier = Modifier.fillMaxWidth()) { - Row( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 10.dp, vertical = 7.dp), - verticalAlignment = Alignment.CenterVertically - ) { - Column( + if (editLutId != null) { + Row( modifier = Modifier - .weight(1f) - .padding(end = 10.dp) + .fillMaxWidth() + .padding(horizontal = 10.dp, vertical = 7.dp), + verticalAlignment = Alignment.CenterVertically ) { - Text( - text = stringResource(R.string.edit_sync_lut_recipe), - color = Color.White, - fontSize = 12.sp, - fontWeight = FontWeight.Medium - ) - Text( - text = stringResource( - R.string.edit_sync_lut_recipe_description - ), - color = Color.White.copy(alpha = 0.48f), - fontSize = 9.sp, - lineHeight = 12.sp + Column( + modifier = Modifier + .weight(1f) + .padding(end = 10.dp) + ) { + Text( + text = stringResource(R.string.edit_sync_lut_recipe), + color = Color.White, + fontSize = 12.sp, + fontWeight = FontWeight.Medium + ) + Text( + text = stringResource( + R.string.edit_sync_lut_recipe_description + ), + color = Color.White.copy(alpha = 0.48f), + fontSize = 9.sp, + lineHeight = 12.sp + ) + } + Switch( + checked = syncAdjustmentsToLut, + onCheckedChange = { enabled -> + syncAdjustmentsToLut = enabled + if (enabled) { + viewModel.setPhotoRecipeParams( + effectiveRecipe, + syncToCurrentLut = true + ) + } + }, + colors = SwitchDefaults.colors( + checkedThumbColor = Color.Black, + checkedTrackColor = AccentOrange, + uncheckedThumbColor = Color.White.copy(alpha = 0.75f), + uncheckedTrackColor = Color.White.copy(alpha = 0.16f), + uncheckedBorderColor = Color.White.copy(alpha = 0.3f) + ) ) } - Switch( - checked = syncAdjustmentsToLut, - onCheckedChange = { enabled -> - syncAdjustmentsToLut = enabled - if (enabled) { - viewModel.setPhotoRecipeParams( - effectiveRecipe, - syncToCurrentLut = true - ) - } - }, - colors = SwitchDefaults.colors( - checkedThumbColor = Color.Black, - checkedTrackColor = AccentOrange, - uncheckedThumbColor = Color.White.copy(alpha = 0.75f), - uncheckedTrackColor = Color.White.copy(alpha = 0.16f), - uncheckedBorderColor = Color.White.copy(alpha = 0.3f) - ) - ) } if (currentPhoto.isMotionPhoto) { - HorizontalDivider( - color = Color.White.copy(alpha = 0.08f) - ) + if (editLutId != null) { + HorizontalDivider( + color = Color.White.copy(alpha = 0.08f) + ) + } Row( modifier = Modifier .fillMaxWidth() @@ -1247,10 +1243,12 @@ fun GalleryEditScreen( } } } - }, - modifier = Modifier.fillMaxWidth() - ) - } + } + } else { + null + }, + modifier = Modifier.fillMaxWidth() + ) } EDIT_TAB_DETAIL -> { Spacer(modifier = Modifier.height(16.dp))