feat: remove float scale

This commit is contained in:
zhoubinjia committed 2026-03-24 14:35:01 +08:00
1 parent 5c8a364047
commit d78f3009a9
7 files changed
+37 -63

No files matched your search

@@ -66,7 +66,7 @@ data class UserPreferences(
val useMultipleExposure: Boolean = false, // 是否启用多重曝光
val multipleExposureCount: Int = 2, // 多重曝光张数
val useMFSR: Boolean = false, // 是否启用 RAW 多帧超分
val rawSuperResolutionScale: Float = 1f, // RAW 多帧超分倍率
val superResolutionScale: Float = 1.5f, // RAW 多帧超分倍率
val photoQuality: Int = 95, // 照片质量: 90, 95, 100
val useLivePhoto: Boolean = false, // 是否启用 Live Photo (Motion Photo)
val enableDevelopAnimation: Boolean = false, // 是否启用拍摄后的显影动画
@@ -204,7 +204,7 @@ class UserPreferencesRepository(private val context: Context) {
useMultipleExposure = preferences[USE_MULTIPLE_EXPOSURE] ?: false,
multipleExposureCount = preferences[MULTIPLE_EXPOSURE_COUNT] ?: 2,
useMFSR = preferences[USE_SUPER_RESOLUTION] ?: false,
rawSuperResolutionScale = preferences[RAW_SUPER_RESOLUTION_SCALE] ?: 1.5f,
superResolutionScale = preferences[RAW_SUPER_RESOLUTION_SCALE] ?: 1.5f,
photoQuality = preferences[PHOTO_QUALITY] ?: 95,
useLivePhoto = preferences[USE_LIVE_PHOTO] ?: false,
enableDevelopAnimation = preferences[ENABLE_DEVELOP_ANIMATION] ?: false,
@@ -543,7 +543,7 @@ class UserPreferencesRepository(private val context: Context) {
}
}
suspend fun saveRawSuperResolutionScale(scale: Float) {
suspend fun saveSuperResolutionScale(scale: Float) {
context.dataStore.edit { preferences ->
preferences[RAW_SUPER_RESOLUTION_SCALE] = scale.coerceIn(1.0f, 2.0f)
}
@@ -34,7 +34,6 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.firstOrNull
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileOutputStream
import java.nio.ByteBuffer
@@ -1347,7 +1346,7 @@ object PhotoManager {
rotation,
aspectRatio,
yuvFile.absolutePath,
currentUseSuperResolution,
false,
useGpuAcceleration,
ColorSpace.get(metadata.colorSpace)
)
@@ -1402,8 +1401,7 @@ object PhotoManager {
useSuperResolution: Boolean = false,
superResolutionScale: Float = 1.0f,
useGpuAcceleration: Boolean = true,
exposureBias: Float? = null,
droMode: RawProcessingPreferences.DROMode = RawProcessingPreferences.DROMode.OFF
exposureBias: Float? = null
) = withContext(Dispatchers.IO) {
try {
val photoDir = getPhotoDir(context, photoId, true)
@@ -1441,7 +1439,6 @@ object PhotoManager {
whiteLevel = rawMetadata.whiteLevel.toInt(),
whiteBalanceGains = rawMetadata.whiteBalanceGains,
noiseModel = rawMetadata.noiseProfile,
// LibRaw 路径目前没有应用 LSC。多帧先保持一致,避免把亮度系统性抬高。
lensShading = null,
lensShadingWidth = 0,
lensShadingHeight = 0,
@@ -1452,7 +1449,7 @@ object PhotoManager {
currentUseSuperResolution = false
rawStackResult = MultiFrameStacker.processBurstRaw(
images, rawMetadata.cfaPattern,
currentUseSuperResolution,
false,
1.0f,
useGpuAcceleration,
masterBlackLevel = rawMetadata.blackLevel,
@@ -1500,17 +1497,11 @@ object PhotoManager {
bitmap = BitmapUtils.flipHorizontal(bitmap)
}
bitmap?.let {
val buffer = ByteBuffer.allocateDirect(it.width * it.height * 8)
it.copyPixelsToBuffer(buffer)
YuvProcessor.saveCompressedArgb(buffer, it.width, it.height, yuvFile.absolutePath)
}
bitmap
} ?: return@withContext
processingScope.launch {
trySaveStackedRawDng(
val dngWritten = trySaveStackedRawDng(
context = context,
photoId = photoId,
dngFile = dngFile,
@@ -1526,6 +1517,17 @@ object PhotoManager {
metadata = metadata,
shouldAutoSave = shouldAutoSave
)
if (!dngWritten) {
try {
result.let {
val buffer = ByteBuffer.allocateDirect(it.width * it.height * 8)
it.copyPixelsToBuffer(buffer)
YuvProcessor.saveCompressedArgb(buffer, it.width, it.height, yuvFile.absolutePath)
}
} catch (e: Throwable) {
PLog.e(TAG, "saveRawStackedPhoto saveCompressedArgb", e)
}
}
}
// Save Original (Stacked Result)
@@ -1567,7 +1569,7 @@ object PhotoManager {
thumbnail: Bitmap?,
metadata: PhotoMetadata,
shouldAutoSave: Boolean,
) {
): Boolean {
val tempDngFile = File(dngFile.parentFile, "temp_stacked.dng")
val dngWritten = try {
FileOutputStream(tempDngFile).use { outputStream ->
@@ -1597,7 +1599,7 @@ object PhotoManager {
if (!dngWritten || !tempDngFile.exists() || tempDngFile.length() <= 0L) {
tempDngFile.delete()
return
return false
}
try {
@@ -1614,12 +1616,14 @@ object PhotoManager {
dngFile.delete()
}
PLog.w(TAG, "Failed to persist stacked RAW DNG, ignoring", e)
return
return false
}
if (shouldAutoSave) {
exportDng(context, photoId, dngFile, metadata)
}
return true
}
@@ -1684,8 +1688,7 @@ object PhotoManager {
useSuperResolution,
superResolutionScale,
useGpuAcceleration,
exposureBias,
droMode
exposureBias
)
}
@@ -127,7 +127,6 @@ fun SettingsScreen(
val edgeLevel by viewModel.edgeLevel.collectAsState(initial = 1)
val useRaw by viewModel.useRaw.collectAsState(initial = false)
val useSuperResolution by viewModel.useMFSR.collectAsState(initial = false)
val rawSuperResolutionScale by viewModel.rawSuperResolutionScale.collectAsState(initial = 1f)
// 软件处理参数
val sharpening by viewModel.sharpening.collectAsState(initial = 0f)
val noiseReduction by viewModel.noiseReduction.collectAsState(initial = 0f)
@@ -722,25 +721,6 @@ fun SettingsScreen(
modifier = Modifier.padding(vertical = 12.dp)
)
QualityLevelSetting(
title = stringResource(R.string.settings_super_resolution_scale),
description = stringResource(R.string.settings_super_resolution_scale_description),
levels = listOf(
1f to "1x",
1.25f to "1.25x",
1.5f to "1.5x",
1.75f to "1.75x",
2.0f to "2.0x"
),
currentLevel = rawSuperResolutionScale,
onLevelSelected = { viewModel.setRawSuperResolutionScale(it) }
)
HorizontalDivider(
color = Color.White.copy(alpha = 0.1f),
modifier = Modifier.padding(vertical = 12.dp)
)
SwitchSettingItem(
title = stringResource(R.string.settings_use_multiple_exposure),
description = stringResource(R.string.settings_use_multiple_exposure_description),
@@ -178,9 +178,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
val useMFSR: StateFlow<Boolean> = userPreferencesRepository.userPreferences
.map { it.useMFSR }
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
val rawSuperResolutionScale: StateFlow<Float> = userPreferencesRepository.userPreferences
.map { it.rawSuperResolutionScale }
.stateIn(viewModelScope, SharingStarted.Eagerly, 1f)
val useLivePhoto: StateFlow<Boolean> = userPreferencesRepository.userPreferences
.map { it.useLivePhoto }
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
@@ -1427,8 +1424,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
fun setUseMFNR(enabled: Boolean) {
if (enabled) {
setUseMultipleExposure(false)
setUseRaw(false)
cameraController.setUseMFSR(false)
setUseMFSR(false)
}
cameraController.setUseMFNR(enabled)
viewModelScope.launch {
@@ -1462,7 +1458,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
fun setUseMFSR(enabled: Boolean) {
if (enabled) {
setUseMultipleExposure(false)
setUseRaw(true)
setUseMFNR(false)
}
cameraController.setUseMFSR(enabled)
@@ -1472,9 +1467,9 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
reopenCamera()
}
fun setRawSuperResolutionScale(scale: Float) {
fun setSuperResolutionScale(scale: Float) {
viewModelScope.launch {
userPreferencesRepository.saveRawSuperResolutionScale(scale)
userPreferencesRepository.saveSuperResolutionScale(scale)
}
}
@@ -1539,10 +1534,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
fun setUseRaw(useRaw: Boolean) {
if (useRaw) {
setUseMFNR(false)
setUseMultipleExposure(false)
} else {
setUseMFSR(false)
}
cameraController.setUseRaw(useRaw)
viewModelScope.launch {
@@ -2103,8 +2095,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
val rotation = (baseRotation + orientationOffset) % 360
val useSuperRes = useMFSR.value
val rawSuperResScale =
if (useSuperRes && useRaw.value) rawSuperResolutionScale.value else 1.0f
val superResScale = if (useSuperRes) 2f else 1.0f
val aperture = if (state.value.isVirtualApertureEnabled) state.value.virtualAperture else null
val defaultHdrEffectEnabled = defaultHdrEffectEnabled(
@@ -2124,8 +2115,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
sharpening = sharpeningValue,
noiseReduction = noiseReductionValue,
chromaNoiseReduction = chromaNoiseReductionValue,
width = (images[0].width.toFloat() * rawSuperResScale).roundToInt(),
height = (images[0].height.toFloat() * rawSuperResScale).roundToInt(),
width = (images[0].width.toFloat() * superResScale).roundToInt(),
height = (images[0].height.toFloat() * superResScale).roundToInt(),
ratio = aspectRatio,
rotation = rotation,
deviceModel = captureInfo.model,
@@ -2163,7 +2154,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
characteristics ?: return
val photoId = PhotoManager.preparePhoto(
context, metadata, captureResult, previewThumbnail,
useLivePhoto.value, rawSuperResScale
useLivePhoto.value, superResScale
)
if (photoId == null) {
PLog.e(TAG, "Failed to save burst image")
@@ -2188,7 +2179,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
chromaNoiseReductionValue,
photoQualityValue,
useSuperResolution = useSuperRes,
superResolutionScale = rawSuperResScale,
superResolutionScale = superResScale,
useGpuAcceleration = useGpuAcceleration.value,
exposureBias = state.value.exposureBias,
droMode = droModeForProcessing
+2 -2
View File
@@ -130,9 +130,9 @@
<string name="settings_multi_frame_count">多帧降噪帧数</string>
<string name="settings_multi_frame_count_description">YUV 多帧降噪使用的帧数(帧数越多降噪越明显,但处理也越慢)。</string>
<string name="settings_use_super_resolution">多帧超分</string>
<string name="settings_use_super_resolution_description">启用 RAW 多帧超分,仅作用于 RAW 多帧拍摄。</string>
<string name="settings_use_super_resolution_description">启用多帧超分</string>
<string name="settings_super_resolution_scale">超分倍率</string>
<string name="settings_super_resolution_scale_description">设置 RAW 多帧超分倍率,默认 1x。</string>
<string name="settings_super_resolution_scale_description">设置多帧超分倍率,默认 1x。</string>
<string name="settings_raw_engine">RAW 处理引擎</string>
<string name="settings_raw_engine_description">选择用于处理 RAW 数据的引擎</string>
<string name="settings_raw_engine_native">原生</string>
+1 -1
View File
@@ -131,7 +131,7 @@
<string name="settings_multi_frame_count_description">多幀合成所使用的幀數(幀數越多效果越好,但合成也越慢)。</string>
<string name="settings_use_super_resolution">超解析度</string>
<string name="settings_use_super_resolution_description">使用 2x 多幀超解析度以獲得更多細節。(需要開啟多幀合成)</string>
<string name="settings_super_resolution_scale_description">设置 RAW 多帧超分倍率,默认 1x。</string>
<string name="settings_super_resolution_scale_description">设置多帧超分倍率,默认 1.5x。</string>
<string name="settings_raw_engine">RAW 處理引擎</string>
<string name="settings_raw_engine_description">選擇用於處理 RAW 資料的引擎</string>
<string name="settings_raw_engine_native">原生</string>
+2 -2
View File
@@ -132,9 +132,9 @@
<string name="settings_multi_frame_count">Multi-Frame Denoise Count</string>
<string name="settings_multi_frame_count_description">Number of frames used for YUV multi-frame denoise (more frames reduce noise more, but take longer).</string>
<string name="settings_use_super_resolution">Multi-Frame Super Resolution</string>
<string name="settings_use_super_resolution_description">Enable RAW multi-frame super resolution. This toggle only affects RAW multi-frame capture.</string>
<string name="settings_use_super_resolution_description">Enable multi-frame super resolution.</string>
<string name="settings_super_resolution_scale">Super Resolution Scale</string>
<string name="settings_super_resolution_scale_description">Set the RAW multi-frame super resolution scale. Default is 1x.</string>
<string name="settings_super_resolution_scale_description">Set the multi-frame super resolution scale. Default is 1x.</string>
<string name="settings_raw_engine">RAW Processing Engine</string>
<string name="settings_raw_engine_description">Choose the engine for RAW data processing</string>
<string name="settings_raw_engine_native">Native</string>