diff --git a/TODO.md b/TODO.md index 7883b821..006751ef 100644 --- a/TODO.md +++ b/TODO.md @@ -16,7 +16,7 @@ - [x] 水印定制持久化 - [x] 边框定制(5203...) - [x] LUT顺序、编辑 -- [ ] 降噪等级 +- [x] 降噪等级 - [ ] 音量键曝光补偿 - [ ] LUT分类 - [ ] 摄像头方向修正 diff --git a/app/src/main/java/com/hinnka/mycamera/camera/Camera2Controller.kt b/app/src/main/java/com/hinnka/mycamera/camera/Camera2Controller.kt index 2c1a80c1..c06cc7dd 100644 --- a/app/src/main/java/com/hinnka/mycamera/camera/Camera2Controller.kt +++ b/app/src/main/java/com/hinnka/mycamera/camera/Camera2Controller.kt @@ -82,8 +82,11 @@ class Camera2Controller(private val context: Context) { private var meteringSkipFrames = 0 // Frame skip counter for software metering stabilization - // 软件降噪/锐化设置(true=使用软件算法,false=使用系统算法) - private var nrOff = true + // 降噪等级 (0=Off, 1=Fast, 2=High Quality, 3=Real-time) + private var nrLevel = 1 + + // 锐化等级 (0=Off, 1=Fast, 2=High Quality, 3=Zero Shutter Lag/Real-time) + private var edgeLevel = 1 private var useRaw = false private var cameraThread: HandlerThread? = null @@ -1137,27 +1140,46 @@ class Camera2Controller(private val context: Context) { */ private fun applyImageQualitySettings(builder: CaptureRequest.Builder, isCapture: Boolean) { try { - val edgeMode = - if (availableEdgeModes.contains(CaptureRequest.EDGE_MODE_OFF)) CaptureRequest.EDGE_MODE_OFF else CaptureRequest.EDGE_MODE_FAST - if (availableEdgeModes.contains(edgeMode)) builder.set(CaptureRequest.EDGE_MODE, edgeMode) - if (nrOff) { - val noiseReductionMode = if (isCapture) { - if (availableNoiseReductionModes.contains(CaptureRequest.NOISE_REDUCTION_MODE_OFF)) CaptureRequest.NOISE_REDUCTION_MODE_OFF else CaptureRequest.NOISE_REDUCTION_MODE_FAST + val edgeMode = when (edgeLevel) { + 0 -> CaptureRequest.EDGE_MODE_OFF + 1 -> CaptureRequest.EDGE_MODE_FAST + 2 -> CaptureRequest.EDGE_MODE_HIGH_QUALITY + 3 -> if (availableEdgeModes.contains(CaptureRequest.EDGE_MODE_ZERO_SHUTTER_LAG)) { + CaptureRequest.EDGE_MODE_ZERO_SHUTTER_LAG + } else { + CaptureRequest.EDGE_MODE_FAST + } + + else -> CaptureRequest.EDGE_MODE_FAST + } + if (availableEdgeModes.contains(edgeMode)) { + builder.set(CaptureRequest.EDGE_MODE, edgeMode) + } else if (availableEdgeModes.contains(CaptureRequest.EDGE_MODE_FAST)) { + builder.set(CaptureRequest.EDGE_MODE, CaptureRequest.EDGE_MODE_FAST) + } + val noiseReductionMode = when (nrLevel) { + 0 -> CaptureRequest.NOISE_REDUCTION_MODE_OFF + 4 -> if (availableNoiseReductionModes.contains(CaptureRequest.NOISE_REDUCTION_MODE_MINIMAL)) { + CaptureRequest.NOISE_REDUCTION_MODE_MINIMAL } else { CaptureRequest.NOISE_REDUCTION_MODE_FAST } - if (availableNoiseReductionModes.contains(noiseReductionMode)) builder.set( - CaptureRequest.NOISE_REDUCTION_MODE, - noiseReductionMode - ) - } else { - // 系统处理模式:使用系统的降噪算法 - val noiseReductionMode = - if (availableNoiseReductionModes.contains(CaptureRequest.NOISE_REDUCTION_MODE_ZERO_SHUTTER_LAG)) CaptureRequest.NOISE_REDUCTION_MODE_ZERO_SHUTTER_LAG else CaptureRequest.NOISE_REDUCTION_MODE_FAST - if (availableNoiseReductionModes.contains(noiseReductionMode)) builder.set( - CaptureRequest.NOISE_REDUCTION_MODE, - noiseReductionMode - ) + + 1 -> CaptureRequest.NOISE_REDUCTION_MODE_FAST + 2 -> CaptureRequest.NOISE_REDUCTION_MODE_HIGH_QUALITY + 3 -> if (availableNoiseReductionModes.contains(CaptureRequest.NOISE_REDUCTION_MODE_ZERO_SHUTTER_LAG)) { + CaptureRequest.NOISE_REDUCTION_MODE_ZERO_SHUTTER_LAG + } else { + CaptureRequest.NOISE_REDUCTION_MODE_FAST + } + + else -> CaptureRequest.NOISE_REDUCTION_MODE_FAST + } + + if (availableNoiseReductionModes.contains(noiseReductionMode)) { + builder.set(CaptureRequest.NOISE_REDUCTION_MODE, noiseReductionMode) + } else if (availableNoiseReductionModes.contains(CaptureRequest.NOISE_REDUCTION_MODE_FAST)) { + builder.set(CaptureRequest.NOISE_REDUCTION_MODE, CaptureRequest.NOISE_REDUCTION_MODE_FAST) } } catch (e: Exception) { PLog.e(TAG, "Failed to apply image quality settings", e) @@ -1165,10 +1187,17 @@ class Camera2Controller(private val context: Context) { } /** - * 设置是否使用软件处理(降噪/锐化) + * 设置锐化等级 */ - fun setNROff(enabled: Boolean) { - nrOff = enabled + fun setEdgeLevel(level: Int) { + edgeLevel = level + } + + /** + * 设置降噪等级 + */ + fun setNRLevel(level: Int) { + nrLevel = level } /** diff --git a/app/src/main/java/com/hinnka/mycamera/data/UserPreferencesRepository.kt b/app/src/main/java/com/hinnka/mycamera/data/UserPreferencesRepository.kt index 2e1de264..31948952 100644 --- a/app/src/main/java/com/hinnka/mycamera/data/UserPreferencesRepository.kt +++ b/app/src/main/java/com/hinnka/mycamera/data/UserPreferencesRepository.kt @@ -30,11 +30,12 @@ data class UserPreferences( val vibrationEnabled: Boolean = true, // 拍摄震动 val volumeKeyCapture: Boolean = false, // 音量键拍摄 val autoSaveAfterCapture: Boolean = true, // 自动保存 - val nrOff: Boolean = false, // 禁用系统降噪 + val nrLevel: Int = 1, // 降噪等级:0=Off, 1=Fast, 2=High Quality, 3=Real-time + val edgeLevel: Int = 1, // 锐化等级:0=Off, 1=Fast, 2=High Quality, 3=Real-time val useRaw: Boolean = false, // 使用 RAW 格式拍摄 - val sharpening: Float = 0.2f, // 0.0 ~ 1.0 锐化强度 + val sharpening: Float = 0f, // 0.0 ~ 1.0 锐化强度 val noiseReduction: Float = 0f, // 0.0 ~ 1.0 降噪强度 - val chromaNoiseReduction: Float = 0.25f, // 0.0 ~ 1.0 减少杂色强度 + val chromaNoiseReduction: Float = 0f, // 0.0 ~ 1.0 减少杂色强度 // 排序顺序 val filterOrder: List = emptyList(), // 滤镜排序(ID列表) val frameOrder: List = emptyList() // 边框排序(ID列表) @@ -58,7 +59,8 @@ class UserPreferencesRepository(private val context: Context) { private val VIBRATION_ENABLED = booleanPreferencesKey("vibration_enabled") private val VOLUME_KEY_CAPTURE = booleanPreferencesKey("volume_key_capture") private val AUTO_SAVE_AFTER_CAPTURE = booleanPreferencesKey("auto_save_after_capture") - private val NR_OFF = booleanPreferencesKey("use_software_processing") + private val NR_LEVEL = androidx.datastore.preferences.core.intPreferencesKey("nr_level") + private val EDGE_LEVEL = androidx.datastore.preferences.core.intPreferencesKey("edge_level") private val USE_RAW = booleanPreferencesKey("use_raw") // 软件处理参数 Keys @@ -87,12 +89,13 @@ class UserPreferencesRepository(private val context: Context) { vibrationEnabled = preferences[VIBRATION_ENABLED] ?: true, volumeKeyCapture = preferences[VOLUME_KEY_CAPTURE] ?: false, autoSaveAfterCapture = preferences[AUTO_SAVE_AFTER_CAPTURE] ?: true, - nrOff = preferences[NR_OFF] ?: false, + nrLevel = preferences[NR_LEVEL] ?: 1, + edgeLevel = preferences[EDGE_LEVEL] ?: 1, useRaw = preferences[USE_RAW] ?: false, // 软件处理参数 - sharpening = preferences[SHARPENING] ?: 0.2f, + sharpening = preferences[SHARPENING] ?: 0f, noiseReduction = preferences[NOISE_REDUCTION] ?: 0f, - chromaNoiseReduction = preferences[CHROMA_NOISE_REDUCTION] ?: 0.25f, + chromaNoiseReduction = preferences[CHROMA_NOISE_REDUCTION] ?: 0f, // 排序 filterOrder = preferences[FILTER_ORDER]?.split(",")?.filter { it.isNotEmpty() } ?: emptyList(), frameOrder = preferences[FRAME_ORDER]?.split(",")?.filter { it.isNotEmpty() } ?: emptyList() @@ -198,11 +201,20 @@ class UserPreferencesRepository(private val context: Context) { } /** - * 保存是否使用软件降噪/锐化 + * 保存降噪等级 */ - suspend fun saveNROff(enabled: Boolean) { + suspend fun saveNRLevel(level: Int) { context.dataStore.edit { preferences -> - preferences[NR_OFF] = enabled + preferences[NR_LEVEL] = level + } + } + + /** + * 保存锐化等级 + */ + suspend fun saveEdgeLevel(level: Int) { + context.dataStore.edit { preferences -> + preferences[EDGE_LEVEL] = level } } diff --git a/app/src/main/java/com/hinnka/mycamera/gallery/PhotoProcessor.kt b/app/src/main/java/com/hinnka/mycamera/gallery/PhotoProcessor.kt index f90d8c74..1f9f1ebd 100644 --- a/app/src/main/java/com/hinnka/mycamera/gallery/PhotoProcessor.kt +++ b/app/src/main/java/com/hinnka/mycamera/gallery/PhotoProcessor.kt @@ -36,9 +36,9 @@ class PhotoProcessor( input: Bitmap, metadata: PhotoMetadata, uri: Uri? = null, - sharpening: Float = 0.2f, + sharpening: Float = 0f, noiseReduction: Float = 0f, - chromaNoiseReduction: Float = 0.25f + chromaNoiseReduction: Float = 0f ): Bitmap = withContext(Dispatchers.Default) { var result = input diff --git a/app/src/main/java/com/hinnka/mycamera/lut/LutTransformation.kt b/app/src/main/java/com/hinnka/mycamera/lut/LutTransformation.kt index b276ffe4..e753b052 100644 --- a/app/src/main/java/com/hinnka/mycamera/lut/LutTransformation.kt +++ b/app/src/main/java/com/hinnka/mycamera/lut/LutTransformation.kt @@ -21,9 +21,9 @@ class PhotoTransformation( private val uri: Uri, private val metadata: PhotoMetadata, private val photoProcessor: PhotoProcessor, - private val sharpening: Float = 0.2f, + private val sharpening: Float = 0f, private val noiseReduction: Float = 0f, - private val chromaNoiseReduction: Float = 0.25f + private val chromaNoiseReduction: Float = 0f ) : Transformation { override val cacheKey: String = "photo_${uri}_${metadata.toJson().hashCode()}_s${sharpening}_n${noiseReduction}_c${chromaNoiseReduction}" diff --git a/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraScreen.kt b/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraScreen.kt index e50f4ea9..126802fb 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraScreen.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraScreen.kt @@ -35,8 +35,10 @@ import androidx.compose.ui.unit.dp import androidx.lifecycle.Lifecycle import androidx.lifecycle.compose.LifecycleEventEffect import com.hinnka.mycamera.R +import com.hinnka.mycamera.camera.AspectRatio import com.hinnka.mycamera.camera.CameraState import com.hinnka.mycamera.camera.CameraUtils +import com.hinnka.mycamera.ui.camera.autoRotate import com.hinnka.mycamera.ui.components.GalleryThumbnail import com.hinnka.mycamera.ui.components.HistogramView import com.hinnka.mycamera.ui.components.LutControlPanel @@ -149,7 +151,10 @@ fun CameraScreen( }, showGrid = state.showGrid, onGridToggle = { viewModel.toggleGrid() }, - onSettingsClick = onSettingsClick + onSettingsClick = { + activePanel = if (activePanel == ActivePanel.SETTINGS) ActivePanel.NONE else ActivePanel.SETTINGS + selectedParameter = null + } ) Box( @@ -289,6 +294,11 @@ fun CameraScreen( Box( modifier = Modifier .fillMaxSize() + .then( + if (activePanel == ActivePanel.SETTINGS) { + Modifier.background(Color.Black.copy(alpha = 0.4f)) + } else Modifier + ) .pointerInput(Unit) { detectTapGestures { // 点击遮罩关闭 LUT 面板 @@ -299,6 +309,21 @@ fun CameraScreen( ) } + // TopSheet for settings + CameraTopSheet( + visible = activePanel == ActivePanel.SETTINGS, + aspectRatio = state.aspectRatio, + onAspectRatioChange = { viewModel.setAspectRatio(it) }, + showLevel = showLevelIndicator, + onLevelToggle = { viewModel.setShowLevelIndicator(it) }, + showGrid = state.showGrid, + onGridToggle = { viewModel.toggleGrid() }, + onMoreSettingsClick = { + activePanel = ActivePanel.NONE + onSettingsClick() + } + ) + // LutControlPanel 显示在遮罩层之上,确保能接收点击事件 if (activePanel != ActivePanel.NONE) { Box( @@ -497,7 +522,8 @@ fun CaptureButton( fun Modifier.autoRotate(dx: Dp = 0.dp, dy: Dp = 0.dp): Modifier = composed { - val targetDegrees = if (OrientationObserver.rotationDegrees != 0f) OrientationObserver.rotationDegrees - 180 else 0f + val targetDegrees = + if (OrientationObserver.rotationDegrees != 0f) OrientationObserver.rotationDegrees - 180 else 0f // 2. 创建动画状态 // label 是为了调试方便,animationSpec 可以调整快慢和回弹 diff --git a/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraTopSheet.kt b/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraTopSheet.kt new file mode 100644 index 00000000..e86d2c13 --- /dev/null +++ b/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraTopSheet.kt @@ -0,0 +1,191 @@ +package com.hinnka.mycamera.ui.camera + +import androidx.compose.animation.* +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.ChevronRight +import androidx.compose.material.icons.filled.Settings +import androidx.compose.material3.* +import androidx.compose.runtime.Composable +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 +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.hinnka.mycamera.R +import com.hinnka.mycamera.camera.AspectRatio + +@Composable +fun CameraTopSheet( + visible: Boolean, + aspectRatio: AspectRatio, + onAspectRatioChange: (AspectRatio) -> Unit, + showLevel: Boolean, + onLevelToggle: (Boolean) -> Unit, + showGrid: Boolean, + onGridToggle: (Boolean) -> Unit, + onMoreSettingsClick: () -> Unit, + modifier: Modifier = Modifier +) { + AnimatedVisibility( + visible = visible, + enter = slideInVertically(initialOffsetY = { -it }) + fadeIn(), + exit = slideOutVertically(targetOffsetY = { -it }) + fadeOut(), + modifier = modifier + ) { + Column( + modifier = Modifier + .fillMaxWidth() + .clip(RoundedCornerShape(bottomStart = 24.dp, bottomEnd = 24.dp)) + .background(Color(0xFF2C3141)) + .padding(top = 48.dp, bottom = 24.dp, start = 24.dp, end = 24.dp) + ) { + // Aspect Ratio Section + Text( + text = stringResource(R.string.aspect_ratio), + color = Color.White.copy(alpha = 0.6f), + fontSize = 12.sp, + fontWeight = FontWeight.Medium, + modifier = Modifier.padding(bottom = 12.dp) + ) + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.spacedBy(10.dp) + ) { + AspectRatio.entries.forEach { ratio -> + val isSelected = aspectRatio == ratio + Box( + modifier = Modifier + .weight(1f) + .height(48.dp) + .clip(RoundedCornerShape(12.dp)) + .background(if (isSelected) Color(0xFFFF6B35) else Color.White.copy(alpha = 0.08f)) + .clickable { onAspectRatioChange(ratio) }, + contentAlignment = Alignment.Center + ) { + Text( + text = ratio.getDisplayName(), + color = Color.White, + fontSize = 14.sp, + fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal + ) + } + } + } + + Spacer(modifier = Modifier.height(24.dp)) + + // Display settings section (Grid & Level) + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.spacedBy(10.dp) + ) { + // Level Indicator Toggle + QuickSettingToggle( + title = stringResource(R.string.settings_level_indicator), + checked = showLevel, + onCheckedChange = onLevelToggle, + modifier = Modifier.weight(1f) + ) + + // Grid Toggle + QuickSettingToggle( + title = stringResource(R.string.settings_grid_lines), + checked = showGrid, + onCheckedChange = onGridToggle, + modifier = Modifier.weight(1f) + ) + } + + Spacer(modifier = Modifier.height(24.dp)) + + // More Settings Button + Surface( + onClick = onMoreSettingsClick, + color = Color.White.copy(alpha = 0.05f), + shape = RoundedCornerShape(12.dp), + modifier = Modifier.fillMaxWidth() + ) { + Row( + modifier = Modifier + .padding(16.dp), + verticalAlignment = Alignment.CenterVertically + ) { + Box( + modifier = Modifier + .size(32.dp) + .clip(RoundedCornerShape(8.dp)) + .background(Color.White.copy(alpha = 0.1f)), + contentAlignment = Alignment.Center + ) { + Icon( + imageVector = Icons.Default.Settings, + contentDescription = null, + tint = Color.White, + modifier = Modifier.size(18.dp) + ) + } + Spacer(modifier = Modifier.width(12.dp)) + Text( + text = stringResource(R.string.settings_title), + color = Color.White, + fontSize = 15.sp, + fontWeight = FontWeight.Medium, + modifier = Modifier.weight(1f) + ) + Icon( + imageVector = Icons.Default.ChevronRight, + contentDescription = null, + tint = Color.White.copy(alpha = 0.3f), + modifier = Modifier.size(20.dp) + ) + } + } + } + } +} + +@Composable +fun QuickSettingToggle( + title: String, + checked: Boolean, + onCheckedChange: (Boolean) -> Unit, + modifier: Modifier = Modifier +) { + Box( + modifier = modifier + .height(56.dp) + .clip(RoundedCornerShape(12.dp)) + .background(if (checked) Color(0xFFFF6B35).copy(alpha = 0.15f) else Color.White.copy(alpha = 0.05f)) + .clickable { onCheckedChange(!checked) } + .padding(horizontal = 16.dp), + contentAlignment = Alignment.CenterStart + ) { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + Text( + text = title, + color = if (checked) Color(0xFFFF6B35) else Color.White.copy(alpha = 0.9f), + fontSize = 14.sp, + fontWeight = if (checked) FontWeight.Bold else FontWeight.Normal + ) + + // Simple indicator + Box( + modifier = Modifier + .size(8.dp) + .clip(androidx.compose.foundation.shape.CircleShape) + .background(if (checked) Color(0xFFFF6B35) else Color.White.copy(alpha = 0.2f)) + ) + } + } +} diff --git a/app/src/main/java/com/hinnka/mycamera/ui/settings/SettingsScreen.kt b/app/src/main/java/com/hinnka/mycamera/ui/settings/SettingsScreen.kt index 258986b0..da794e17 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/settings/SettingsScreen.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/settings/SettingsScreen.kt @@ -11,6 +11,8 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.filled.Check import androidx.compose.material.icons.filled.ChevronRight +import androidx.compose.material.icons.filled.ExpandLess +import androidx.compose.material.icons.filled.ExpandMore import androidx.compose.material.icons.filled.FilterNone import androidx.compose.material.icons.filled.Article import androidx.compose.material3.* @@ -57,18 +59,20 @@ fun SettingsScreen( val vibrationEnabled by viewModel.vibrationEnabled.collectAsState(initial = true) val volumeKeyCapture by viewModel.volumeKeyCapture.collectAsState(initial = false) val autoSaveAfterCapture by viewModel.autoSaveAfterCapture.collectAsState(initial = true) - val nrOff by viewModel.nrOff.collectAsState(initial = false) + val nrLevel by viewModel.nrLevel.collectAsState(initial = 1) + val edgeLevel by viewModel.edgeLevel.collectAsState(initial = 1) val useRaw by viewModel.useRaw.collectAsState(initial = false) // 软件处理参数 - val sharpening by viewModel.sharpening.collectAsState(initial = 0.2f) + val sharpening by viewModel.sharpening.collectAsState(initial = 0f) val noiseReduction by viewModel.noiseReduction.collectAsState(initial = 0f) - val chromaNoiseReduction by viewModel.chromaNoiseReduction.collectAsState(initial = 0.25f) + val chromaNoiseReduction by viewModel.chromaNoiseReduction.collectAsState(initial = 0f) val isPurchased by viewModel.isPurchased.collectAsState() val context = androidx.compose.ui.platform.LocalContext.current // 日志查看器弹窗状态 var showLogViewerDialog by remember { mutableStateOf(false) } + var softwareProcessingExpanded by remember { mutableStateOf(false) } val backgroundColor = Color(0xFF434A5D) @@ -126,19 +130,9 @@ fun SettingsScreen( } // 画面比例设置 - SettingsSection(title = stringResource(R.string.settings_section_capture)) { - AspectRatioSetting( - currentRatio = state.aspectRatio, - onRatioSelected = { viewModel.setAspectRatio(it) } - ) - - val currentCameraInfo = state.getCurrentCameraInfo() - if (currentCameraInfo?.supportsRaw == true) { - HorizontalDivider( - color = Color.White.copy(alpha = 0.1f), - modifier = Modifier.padding(vertical = 8.dp) - ) - + val currentCameraInfo = state.getCurrentCameraInfo() + if (currentCameraInfo?.supportsRaw == true) { + SettingsSection(title = stringResource(R.string.settings_section_capture)) { SwitchSettingItem( title = stringResource(R.string.settings_use_raw), description = stringResource(R.string.settings_use_raw_description), @@ -146,34 +140,9 @@ fun SettingsScreen( onCheckedChange = { viewModel.setUseRaw(it) } ) } + Spacer(modifier = Modifier.height(24.dp)) } - Spacer(modifier = Modifier.height(24.dp)) - - // 显示设置 - SettingsSection(title = stringResource(R.string.settings_section_display)) { - SwitchSettingItem( - title = stringResource(R.string.settings_level_indicator), - description = stringResource(R.string.settings_level_description), - checked = showLevelIndicator, - onCheckedChange = { viewModel.setShowLevelIndicator(it) } - ) - - HorizontalDivider( - color = Color.White.copy(alpha = 0.1f), - modifier = Modifier.padding(vertical = 8.dp) - ) - - SwitchSettingItem( - title = stringResource(R.string.settings_grid_lines), - description = stringResource(R.string.settings_grid_description), - checked = state.showGrid, - onCheckedChange = { viewModel.toggleGrid() } - ) - } - - Spacer(modifier = Modifier.height(24.dp)) - // 内容管理设置 SettingsSection(title = stringResource(R.string.settings_section_management)) { NavigationSettingItem( @@ -196,58 +165,84 @@ fun SettingsScreen( Spacer(modifier = Modifier.height(24.dp)) - // 拍摄设置 - SettingsSection(title = stringResource(R.string.settings_section_operation)) { - val currentCameraInfo = state.getCurrentCameraInfo() - val supportsManualProcessing = currentCameraInfo?.supportsManualProcessing ?: false - - if (supportsManualProcessing) { - SwitchSettingItem( - title = stringResource(R.string.settings_software_processing), - description = stringResource(R.string.settings_software_processing_description), - checked = nrOff, - onCheckedChange = { viewModel.setNROff(it) } - ) - - HorizontalDivider( - color = Color.White.copy(alpha = 0.1f), - modifier = Modifier.padding(vertical = 8.dp) - ) - - SliderSettingItem( - title = stringResource(R.string.settings_sharpening), - description = stringResource(R.string.settings_sharpening_description), - value = sharpening, - valueRange = 0f..1f, - onValueChange = { viewModel.setSharpening(it) } - ) - - Spacer(modifier = Modifier.height(12.dp)) - - SliderSettingItem( - title = stringResource(R.string.settings_noise_reduction), - description = stringResource(R.string.settings_noise_reduction_description), - value = noiseReduction, - valueRange = 0f..1f, - onValueChange = { viewModel.setNoiseReduction(it) } - ) - - Spacer(modifier = Modifier.height(12.dp)) - - SliderSettingItem( - title = stringResource(R.string.settings_chroma_noise_reduction), - description = stringResource(R.string.settings_chroma_noise_reduction_description), - value = chromaNoiseReduction, - valueRange = 0f..1f, - onValueChange = { viewModel.setChromaNoiseReduction(it) } - ) - } + // 影像处理设置 + SettingsSection(title = stringResource(R.string.settings_section_image_processing)) { + QualityLevelSetting( + title = stringResource(R.string.settings_nr_level), + description = stringResource(R.string.settings_nr_level_description), + levels = listOf( + 0 to stringResource(R.string.settings_nr_level_off), + 4 to stringResource(R.string.settings_nr_level_minimal), + 1 to stringResource(R.string.settings_nr_level_fast), + 2 to stringResource(R.string.settings_nr_level_high_quality), + 3 to stringResource(R.string.settings_nr_level_zsl) + ), + currentLevel = nrLevel, + onLevelSelected = { viewModel.setNRLevel(it) } + ) HorizontalDivider( color = Color.White.copy(alpha = 0.1f), - modifier = Modifier.padding(vertical = 8.dp) + modifier = Modifier.padding(vertical = 12.dp) ) + QualityLevelSetting( + title = stringResource(R.string.settings_edge_level), + description = stringResource(R.string.settings_edge_level_description), + levels = listOf( + 0 to stringResource(R.string.settings_nr_level_off), + 1 to stringResource(R.string.settings_nr_level_fast), + 2 to stringResource(R.string.settings_nr_level_high_quality), + 3 to stringResource(R.string.settings_nr_level_zsl) + ), + currentLevel = edgeLevel, + onLevelSelected = { viewModel.setEdgeLevel(it) } + ) + } + + Spacer(modifier = Modifier.height(16.dp)) + + // 软件细节微调 (Fine Tuning Sliders) + SettingsSection( + title = stringResource(R.string.settings_section_software_processing), + description = stringResource(R.string.settings_detail_enhancement_description), + isExpandable = true, + isExpanded = softwareProcessingExpanded, + onToggleExpand = { softwareProcessingExpanded = !softwareProcessingExpanded } + ) { + SliderSettingItem( + title = stringResource(R.string.settings_sharpening), + description = stringResource(R.string.settings_sharpening_description), + value = sharpening, + valueRange = 0f..1f, + onValueChange = { viewModel.setSharpening(it) } + ) + + Spacer(modifier = Modifier.height(12.dp)) + + SliderSettingItem( + title = stringResource(R.string.settings_noise_reduction), + description = stringResource(R.string.settings_noise_reduction_description), + value = noiseReduction, + valueRange = 0f..1f, + onValueChange = { viewModel.setNoiseReduction(it) } + ) + + Spacer(modifier = Modifier.height(12.dp)) + + SliderSettingItem( + title = stringResource(R.string.settings_chroma_noise_reduction), + description = stringResource(R.string.settings_chroma_noise_reduction_description), + value = chromaNoiseReduction, + valueRange = 0f..1f, + onValueChange = { viewModel.setChromaNoiseReduction(it) } + ) + } + + Spacer(modifier = Modifier.height(24.dp)) + + // 拍摄设置(开关项) + SettingsSection(title = stringResource(R.string.settings_section_operation)) { SwitchSettingItem( title = stringResource(R.string.settings_shutter_sound), description = stringResource(R.string.settings_shutter_sound_description), @@ -350,25 +345,81 @@ fun SettingsScreen( fun SettingsSection( title: String, modifier: Modifier = Modifier, + description: String? = null, + isExpandable: Boolean = false, + isExpanded: Boolean = true, + onToggleExpand: () -> Unit = {}, content: @Composable ColumnScope.() -> Unit ) { Column(modifier = modifier) { - Text( - text = title, - color = Color.White.copy(alpha = 0.6f), - fontSize = 14.sp, - fontWeight = FontWeight.Medium, - modifier = Modifier.padding(bottom = 12.dp) - ) + if (!isExpandable) { + Text( + text = title, + color = Color.White.copy(alpha = 0.6f), + fontSize = 14.sp, + fontWeight = FontWeight.Medium, + modifier = Modifier.padding(bottom = 12.dp) + ) + } Column( modifier = Modifier .fillMaxWidth() .clip(RoundedCornerShape(12.dp)) .background(Color.White.copy(alpha = 0.05f)) - .padding(16.dp) ) { - content() + if (isExpandable) { + Row( + modifier = Modifier + .fillMaxWidth() + .clickable(onClick = onToggleExpand) + .padding(16.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + Column(modifier = Modifier.weight(1f)) { + Text( + text = title, + color = Color.White, + fontSize = 16.sp, + fontWeight = FontWeight.Normal + ) + if (description != null) { + Spacer(modifier = Modifier.height(4.dp)) + Text( + text = description, + color = Color.White.copy(alpha = 0.6f), + fontSize = 13.sp, + lineHeight = 18.sp + ) + } + } + + Icon( + imageVector = if (isExpanded) Icons.Default.ExpandLess else Icons.Default.ExpandMore, + contentDescription = null, + tint = Color.White.copy(alpha = 0.6f), + modifier = Modifier.size(24.dp) + ) + } + } + + if (isExpanded) { + Column( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp) + .then(if (isExpandable) Modifier.padding(top = 0.dp) else Modifier) + ) { + if (isExpandable) { + HorizontalDivider( + color = Color.White.copy(alpha = 0.1f), + modifier = Modifier.padding(bottom = 16.dp) + ) + } + content() + } + } } } } @@ -469,70 +520,6 @@ fun NavigationSettingItem( } -/** - * 画面比例设置 - */ -@Composable -fun AspectRatioSetting( - currentRatio: AspectRatio, - onRatioSelected: (AspectRatio) -> Unit, - modifier: Modifier = Modifier -) { - Column(modifier = modifier.fillMaxWidth()) { - Text( - text = stringResource(R.string.aspect_ratio), - color = Color.White, - fontSize = 16.sp, - fontWeight = FontWeight.Normal, - modifier = Modifier.padding(bottom = 12.dp) - ) - - Row( - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.spacedBy(12.dp) - ) { - AspectRatio.entries.forEach { ratio -> - AspectRatioButton( - ratio = ratio, - isSelected = currentRatio == ratio, - onClick = { onRatioSelected(ratio) }, - modifier = Modifier.weight(1f) - ) - } - } - } -} - -/** - * 画面比例按钮 - */ -@Composable -fun AspectRatioButton( - ratio: AspectRatio, - isSelected: Boolean, - onClick: () -> Unit, - modifier: Modifier = Modifier -) { - Box( - modifier = modifier - .aspectRatio(1f) - .clip(RoundedCornerShape(8.dp)) - .background( - if (isSelected) Color(0xFFFF6B35) else Color.White.copy(alpha = 0.1f) - ) - .clickable(onClick = onClick) - .padding(8.dp), - contentAlignment = Alignment.Center - ) { - Text( - text = ratio.getDisplayName(), - color = Color.White, - fontSize = 14.sp, - fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal - ) - } -} - /** * 边框水印设置 */ @@ -770,6 +757,65 @@ private fun PremiumCard( } } + +/** + * 图像质量等级设置(通用组件) + */ +@Composable +fun QualityLevelSetting( + title: String, + description: String, + levels: List>, + currentLevel: Int, + onLevelSelected: (Int) -> Unit, + modifier: Modifier = Modifier +) { + + Column(modifier = modifier.fillMaxWidth()) { + Text( + text = title, + color = Color.White, + fontSize = 16.sp, + fontWeight = FontWeight.Normal, + modifier = Modifier.padding(bottom = 4.dp) + ) + Text( + text = description, + color = Color.White.copy(alpha = 0.6f), + fontSize = 13.sp, + lineHeight = 18.sp, + modifier = Modifier.padding(bottom = 12.dp) + ) + + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.spacedBy(8.dp) + ) { + levels.forEach { (level, label) -> + val isSelected = currentLevel == level + Box( + modifier = Modifier + .weight(1f) + .height(36.dp) + .clip(RoundedCornerShape(8.dp)) + .background( + if (isSelected) Color(0xFFFF6B35) else Color.White.copy(alpha = 0.1f) + ) + .clickable { onLevelSelected(level) }, + contentAlignment = Alignment.Center + ) { + Text( + text = label, + color = Color.White, + fontSize = 12.sp, + fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal + ) + } + } + } + } +} + private fun android.content.Context.findActivity(): android.app.Activity? { var context = this while (context is android.content.ContextWrapper) { diff --git a/app/src/main/java/com/hinnka/mycamera/viewmodel/CameraViewModel.kt b/app/src/main/java/com/hinnka/mycamera/viewmodel/CameraViewModel.kt index ae2ee6ba..0abdea4c 100644 --- a/app/src/main/java/com/hinnka/mycamera/viewmodel/CameraViewModel.kt +++ b/app/src/main/java/com/hinnka/mycamera/viewmodel/CameraViewModel.kt @@ -130,23 +130,26 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) val vibrationEnabled: Flow = userPreferencesRepository.userPreferences.map { it.vibrationEnabled } val volumeKeyCapture: Flow = userPreferencesRepository.userPreferences.map { it.volumeKeyCapture } val autoSaveAfterCapture: Flow = userPreferencesRepository.userPreferences.map { it.autoSaveAfterCapture } - val nrOff: StateFlow = userPreferencesRepository.userPreferences - .map { it.nrOff } - .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), false) + val nrLevel: StateFlow = userPreferencesRepository.userPreferences + .map { it.nrLevel } + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 1) val useRaw: StateFlow = userPreferencesRepository.userPreferences .map { it.useRaw } .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), false) + val edgeLevel: StateFlow = userPreferencesRepository.userPreferences + .map { it.edgeLevel } + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 1) // 软件处理参数 Flow val sharpening: StateFlow = userPreferencesRepository.userPreferences .map { it.sharpening } - .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 0.2f) + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 0f) val noiseReduction: StateFlow = userPreferencesRepository.userPreferences .map { it.noiseReduction } .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 0f) val chromaNoiseReduction: StateFlow = userPreferencesRepository.userPreferences .map { it.chromaNoiseReduction } - .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 0.25f) + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 0f) private var isShutterSoundEnabled = true private var isVibrationEnabled = true @@ -178,8 +181,10 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) userPreferencesRepository.userPreferences.collect { isShutterSoundEnabled = it.shutterSoundEnabled isVibrationEnabled = it.vibrationEnabled - // 同步软件处理设置到相机控制器 - cameraController.setNROff(it.nrOff) + // 同步降噪等级到相机控制器 + cameraController.setNRLevel(it.nrLevel) + // 同步锐化等级到相机控制器 + cameraController.setEdgeLevel(it.edgeLevel) // 同步 RAW 设置到相机控制器 cameraController.setUseRaw(it.useRaw) } @@ -791,11 +796,20 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) } /** - * 设置是否使用软件降噪/锐化 + * 设置降噪等级 */ - fun setNROff(enabled: Boolean) { + fun setNRLevel(level: Int) { viewModelScope.launch { - userPreferencesRepository.saveNROff(enabled) + userPreferencesRepository.saveNRLevel(level) + } + } + + /** + * 设置锐化等级 + */ + fun setEdgeLevel(level: Int) { + viewModelScope.launch { + userPreferencesRepository.saveEdgeLevel(level) } } diff --git a/app/src/main/java/com/hinnka/mycamera/viewmodel/GalleryViewModel.kt b/app/src/main/java/com/hinnka/mycamera/viewmodel/GalleryViewModel.kt index c07e9fd0..db68b055 100644 --- a/app/src/main/java/com/hinnka/mycamera/viewmodel/GalleryViewModel.kt +++ b/app/src/main/java/com/hinnka/mycamera/viewmodel/GalleryViewModel.kt @@ -62,7 +62,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application) // 软件处理参数 val sharpening: StateFlow = userPreferencesRepository.userPreferences .map { it.sharpening } - .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 0.2f) + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 0f) val noiseReduction: StateFlow = userPreferencesRepository.userPreferences .map { it.noiseReduction } @@ -70,7 +70,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application) val chromaNoiseReduction: StateFlow = userPreferencesRepository.userPreferences .map { it.chromaNoiseReduction } - .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 0.25f) + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 0f) // 计费管理器 private val billingManager = com.hinnka.mycamera.billing.BillingManagerImpl(application) @@ -160,11 +160,11 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application) ) // 细节处理编辑状态 (Sharpening, Noise Reduction, Chroma Noise Reduction) - var editSharpening = MutableStateFlow(0.2f) + var editSharpening = MutableStateFlow(0f) private set var editNoiseReduction = MutableStateFlow(0f) private set - var editChromaNoiseReduction = MutableStateFlow(0.25f) + var editChromaNoiseReduction = MutableStateFlow(0f) private set // 最新照片(用于相机界面显示入口) diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 6ac51227..da974b41 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -101,6 +101,8 @@ 边框样式 为拍摄的照片添加装饰性边框和水印 拍摄操作 + 影像处理 + 细节微调 快门声音 拍照时播放快门声音 拍摄震动 @@ -109,14 +111,22 @@ 使用音量键进行拍摄 拍摄后自动保存 拍摄后自动保存照片,否则需要手动确认 - 禁用系统降噪 - 禁用系统默认的降噪处理以获得更多细节。 + 降噪等级 + 调整系统硬件降噪模式。“关闭”常用于配合软件算法以获得更多细节。 + 关闭 + 极低 + 快速 + 高质量 + 零延迟 + 锐化等级 + 调整系统硬件边缘增强(锐化)模式。 锐化 增强图像锐度和边缘清晰度 降噪 减少图像噪点,同时保留细节 减少杂色 减少彩色噪点和伪影 + 手动微调锐化和降噪参数 滤镜强度 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index afcfd3a2..9626d5fe 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -102,6 +102,8 @@ Frame Style Add decorative frame and watermark to photos Operations + Image Processing + Fine Tuning Shutter Sound Play sound when taking a photo Vibration @@ -110,14 +112,22 @@ Use volume keys to take photos Auto Save Automatically save photos after capture - Disable System Noise Reduction - Disable system default noise reduction and sharpening to preserve more details. + Noise Reduction Level + Adjust the hardware noise reduction mode. "Off" helps preserve details when using software processing. + Off + Minimal + Fast + High Quality + ZSL + Sharpening Level + Adjust the hardware edge enhancement (sharpening) mode. Sharpening Enhance image sharpness and edge definition Noise Reduction Reduce image noise while preserving detail Chroma Noise Reduction Reduce color noise and artifacts + Fine-tune sharpening and noise reduction parameters Filter Intensity