feat: remove max external lens magnification
This commit is contained in:
1 parent
15afde580a
commit
567ed9bb78
9 files changed
+83
-73
No files matched your search
+2
-11
@@ -1,7 +1,6 @@
|
||||
package com.hinnka.mycamera.stabilization
|
||||
|
||||
const val MIN_EXTERNAL_LENS_MAGNIFICATION = 1f
|
||||
const val MAX_EXTERNAL_LENS_MAGNIFICATION = 4f
|
||||
|
||||
/** Optical calibration applied only while a teleconverter covers [physicalCameraId]. */
|
||||
data class ExternalLensStabilizationConfig(
|
||||
@@ -14,22 +13,14 @@ data class ExternalLensStabilizationConfig(
|
||||
|
||||
fun normalized(): ExternalLensStabilizationConfig {
|
||||
val normalizedCameraId = physicalCameraId.trim()
|
||||
val normalizedMagnification = if (magnification.isFinite()) {
|
||||
magnification.coerceIn(
|
||||
MIN_EXTERNAL_LENS_MAGNIFICATION,
|
||||
MAX_EXTERNAL_LENS_MAGNIFICATION,
|
||||
)
|
||||
} else {
|
||||
MIN_EXTERNAL_LENS_MAGNIFICATION
|
||||
}
|
||||
return if (normalizedCameraId.isEmpty() ||
|
||||
normalizedMagnification <= MIN_EXTERNAL_LENS_MAGNIFICATION
|
||||
!magnification.isFinite() || magnification <= MIN_EXTERNAL_LENS_MAGNIFICATION
|
||||
) {
|
||||
Disabled
|
||||
} else {
|
||||
ExternalLensStabilizationConfig(
|
||||
physicalCameraId = normalizedCameraId,
|
||||
magnification = normalizedMagnification,
|
||||
magnification = magnification,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ fun GalleryEditScreen(
|
||||
var showBaselineLutEditSheet by remember { mutableStateOf(false) }
|
||||
var baselineLutEditId by remember { mutableStateOf<String?>(null) }
|
||||
var showRawBaselineLutSelectorSheet by remember { mutableStateOf(false) }
|
||||
var syncAdjustmentsToLut by remember(editLutId) { mutableStateOf(false) }
|
||||
val syncAdjustmentsToLut = viewModel.editSyncAdjustmentsToLut
|
||||
|
||||
BackHandler {
|
||||
viewModel.exitEditMode()
|
||||
@@ -1413,8 +1413,7 @@ fun GalleryEditScreen(
|
||||
RecipeParam.LUT_INTENSITY.setValue(
|
||||
effectiveRecipe,
|
||||
intensity
|
||||
),
|
||||
syncToCurrentLut = syncAdjustmentsToLut
|
||||
)
|
||||
)
|
||||
},
|
||||
enabled = editLutId != null,
|
||||
@@ -1515,26 +1514,22 @@ fun GalleryEditScreen(
|
||||
ColorPaletteMapper.updatePaletteState(
|
||||
effectiveRecipe,
|
||||
state.normalized()
|
||||
),
|
||||
syncToCurrentLut = syncAdjustmentsToLut
|
||||
)
|
||||
)
|
||||
},
|
||||
onParamChange = { param, value ->
|
||||
viewModel.setPhotoRecipeParams(
|
||||
param.setValue(effectiveRecipe, value),
|
||||
syncToCurrentLut = syncAdjustmentsToLut
|
||||
param.setValue(effectiveRecipe, value)
|
||||
)
|
||||
},
|
||||
onParamsChange = { params ->
|
||||
viewModel.setPhotoRecipeParams(
|
||||
params,
|
||||
syncToCurrentLut = syncAdjustmentsToLut
|
||||
params
|
||||
)
|
||||
},
|
||||
onRemarksChange = { remarks ->
|
||||
viewModel.setPhotoRecipeParams(
|
||||
effectiveRecipe.copy(remarks = remarks),
|
||||
syncToCurrentLut = syncAdjustmentsToLut
|
||||
effectiveRecipe.copy(remarks = remarks)
|
||||
)
|
||||
},
|
||||
onCurveChange = { channel, points ->
|
||||
@@ -1545,8 +1540,7 @@ fun GalleryEditScreen(
|
||||
CurveChannel.BLUE -> effectiveRecipe.copy(blueCurvePoints = points)
|
||||
}
|
||||
viewModel.setPhotoRecipeParams(
|
||||
updated,
|
||||
syncToCurrentLut = syncAdjustmentsToLut
|
||||
updated
|
||||
)
|
||||
},
|
||||
imageHistogram = imageHistogram,
|
||||
@@ -1555,8 +1549,7 @@ fun GalleryEditScreen(
|
||||
val latestRecipe = viewModel.editPhotoRecipeParams.value
|
||||
?: viewModel.editLutRecipeParams.value
|
||||
viewModel.setPhotoRecipeParams(
|
||||
effects.applyTo(latestRecipe),
|
||||
syncToCurrentLut = syncAdjustmentsToLut
|
||||
effects.applyTo(latestRecipe)
|
||||
)
|
||||
},
|
||||
headerControls = if (
|
||||
@@ -1573,15 +1566,7 @@ fun GalleryEditScreen(
|
||||
R.string.edit_sync_lut_recipe
|
||||
),
|
||||
checked = syncAdjustmentsToLut,
|
||||
onCheckedChange = { enabled ->
|
||||
syncAdjustmentsToLut = enabled
|
||||
if (enabled) {
|
||||
viewModel.setPhotoRecipeParams(
|
||||
effectiveRecipe,
|
||||
syncToCurrentLut = true
|
||||
)
|
||||
}
|
||||
}
|
||||
onCheckedChange = viewModel::setSyncAdjustmentsToLut
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,6 @@ import com.hinnka.mycamera.stabilization.DEFAULT_VIDEO_STABILIZATION_STRENGTH
|
||||
import com.hinnka.mycamera.stabilization.ExternalLensStabilizationConfig
|
||||
import com.hinnka.mycamera.stabilization.MIN_VIDEO_STABILIZATION_LOOKAHEAD
|
||||
import com.hinnka.mycamera.stabilization.MAX_VIDEO_STABILIZATION_LOOKAHEAD
|
||||
import com.hinnka.mycamera.stabilization.MAX_EXTERNAL_LENS_MAGNIFICATION
|
||||
import com.hinnka.mycamera.stabilization.MIN_EXTERNAL_LENS_MAGNIFICATION
|
||||
import com.hinnka.mycamera.stabilization.normalizeStabilizationLookahead
|
||||
import com.hinnka.mycamera.stabilization.normalizeStabilizationStrength
|
||||
@@ -4487,8 +4486,7 @@ private fun ExternalLensStabilizationDialog(
|
||||
}
|
||||
val magnification = magnificationText.replace(',', '.').toFloatOrNull()
|
||||
val magnificationValid = magnification != null &&
|
||||
magnification > MIN_EXTERNAL_LENS_MAGNIFICATION &&
|
||||
magnification <= MAX_EXTERNAL_LENS_MAGNIFICATION
|
||||
magnification.isFinite() && magnification > MIN_EXTERNAL_LENS_MAGNIFICATION
|
||||
val lensLabels = options.map { it.cameraId to externalLensStabilizationLabel(it) }
|
||||
val selectedLensLabel = lensLabels.firstOrNull { it.first == selectedCameraId }
|
||||
?.second.orEmpty()
|
||||
@@ -4587,7 +4585,6 @@ private fun ExternalLensStabilizationDialog(
|
||||
} else {
|
||||
R.string.settings_external_lens_stabilization_magnification_error
|
||||
},
|
||||
MAX_EXTERNAL_LENS_MAGNIFICATION,
|
||||
)
|
||||
)
|
||||
},
|
||||
@@ -4627,9 +4624,7 @@ private fun ExternalLensStabilizationDialog(
|
||||
}
|
||||
|
||||
private fun editableExternalLensMagnification(magnification: Float): String =
|
||||
String.format(Locale.US, "%.2f", magnification)
|
||||
.trimEnd('0')
|
||||
.trimEnd('.')
|
||||
magnification.toString().toBigDecimal().stripTrailingZeros().toPlainString()
|
||||
|
||||
private fun sanitizeExternalLensMagnificationInput(value: String): String {
|
||||
val normalized = value.replace(',', '.')
|
||||
@@ -4644,7 +4639,7 @@ private fun sanitizeExternalLensMagnificationInput(value: String): String {
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toString().take(5)
|
||||
return result.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -56,7 +56,9 @@ import com.hinnka.mycamera.utils.PLog
|
||||
import com.hinnka.mycamera.utils.StartupTrace
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.Semaphore
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.sync.withPermit
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
@@ -255,6 +257,13 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
var editLutId = MutableStateFlow<String?>(null)
|
||||
private set
|
||||
|
||||
var editSyncAdjustmentsToLut by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
private var editLutRecipeSyncJob: Job? = null
|
||||
private val pendingEditLutRecipeSync = mutableMapOf<String, ColorRecipeParams>()
|
||||
private val editLutRecipeSyncMutex = Mutex()
|
||||
|
||||
var editApplyEffectsToVideo = MutableStateFlow(false)
|
||||
private set
|
||||
|
||||
@@ -268,6 +277,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
flowOf(ColorRecipeParams.DEFAULT)
|
||||
} else {
|
||||
contentRepository.lutManager.getColorRecipeParams(id)
|
||||
.map { params -> pendingEditLutRecipeSync[id] ?: params }
|
||||
}
|
||||
}.stateIn(
|
||||
scope = viewModelScope,
|
||||
@@ -275,13 +285,10 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
initialValue = ColorRecipeParams.DEFAULT
|
||||
)
|
||||
|
||||
/** 仅此照片的色彩配方覆盖,null 表示跟随 LUT 默认配方 */
|
||||
/** 照片独立的色彩配方;仅开启同步并切换 LUT 时,null 表示读取该 LUT 的配方。 */
|
||||
var editPhotoRecipeParams = MutableStateFlow<ColorRecipeParams?>(null)
|
||||
private set
|
||||
|
||||
private var editLutRecipeSyncJob: Job? = null
|
||||
private var pendingEditLutRecipeSync: Pair<String, ColorRecipeParams>? = null
|
||||
|
||||
var editLutConfig: LutConfig? by mutableStateOf(null)
|
||||
private set
|
||||
|
||||
@@ -2008,11 +2015,12 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
|
||||
isEditing = true
|
||||
editSyncAdjustmentsToLut = false
|
||||
// 从当前元数据恢复编辑状态
|
||||
currentMediaMetadata?.let { metadata ->
|
||||
editLutId.value = metadata.lutId
|
||||
editFrameId.value = metadata.frameId
|
||||
editPhotoRecipeParams.value = metadata.colorRecipeParams
|
||||
editPhotoRecipeParams.value = snapshotEditRecipe(metadata.colorRecipeParams, metadata.lutId)
|
||||
editApplyEffectsToVideo.value = metadata.applyEffectsToVideo
|
||||
|
||||
if (!targetPhoto.isVideo) {
|
||||
@@ -2068,6 +2076,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
} ?: run {
|
||||
editLutId.value = null
|
||||
editFrameId.value = null
|
||||
editPhotoRecipeParams.value = ColorRecipeParams.DEFAULT
|
||||
editApplyEffectsToVideo.value = false
|
||||
|
||||
if (!targetPhoto.isVideo) {
|
||||
@@ -2186,6 +2195,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
flushPendingEditLutRecipeSync()
|
||||
}
|
||||
isEditing = false
|
||||
editSyncAdjustmentsToLut = false
|
||||
editLutId.value = null
|
||||
editLutConfig = null
|
||||
editFrameId.value = null
|
||||
@@ -2225,16 +2235,34 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置照片级别的色彩配方覆盖(null = 清除覆盖,跟随 LUT 默认)
|
||||
* 切换绑定状态时保留当前调节,开启绑定后才将调节写入当前 LUT。
|
||||
*/
|
||||
fun setPhotoRecipeParams(
|
||||
params: ColorRecipeParams?,
|
||||
syncToCurrentLut: Boolean = false
|
||||
) {
|
||||
fun setSyncAdjustmentsToLut(enabled: Boolean) {
|
||||
val shouldSync = enabled && editLutId.value != null
|
||||
if (editSyncAdjustmentsToLut == shouldSync) return
|
||||
|
||||
val params = snapshotEditRecipe(editPhotoRecipeParams.value, editLutId.value)
|
||||
editSyncAdjustmentsToLut = shouldSync
|
||||
setPhotoRecipeParams(params)
|
||||
}
|
||||
|
||||
private fun snapshotEditRecipe(params: ColorRecipeParams?, lutId: String?): ColorRecipeParams {
|
||||
// 旧照片可能只保存了 LUT 引用。读取一次实际配方后独立编辑,保持进入编辑时的画面。
|
||||
// 按 ID 读取也避免快速切换后取消同步时,拿到 StateFlow 尚未更新的上一个 LUT 配方。
|
||||
val recipe = params ?: lutId?.let { id ->
|
||||
pendingEditLutRecipeSync[id] ?: runBlocking(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadColorRecipeParams(id)
|
||||
}
|
||||
} ?: ColorRecipeParams.DEFAULT
|
||||
return recipe.deepCopy()
|
||||
}
|
||||
|
||||
/** 设置照片调节,并根据本次编辑的绑定状态同步到 LUT。 */
|
||||
fun setPhotoRecipeParams(params: ColorRecipeParams) {
|
||||
editPhotoRecipeParams.value = params
|
||||
if (syncToCurrentLut && params != null) {
|
||||
if (editSyncAdjustmentsToLut) {
|
||||
val lutId = editLutId.value ?: return
|
||||
pendingEditLutRecipeSync = lutId to params
|
||||
pendingEditLutRecipeSync[lutId] = params.deepCopy()
|
||||
editLutRecipeSyncJob?.cancel()
|
||||
editLutRecipeSyncJob = viewModelScope.launch {
|
||||
delay(250)
|
||||
@@ -2247,16 +2275,26 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
private suspend fun flushPendingEditLutRecipeSync() {
|
||||
editLutRecipeSyncJob?.cancel()
|
||||
editLutRecipeSyncJob = null
|
||||
val (lutId, params) = pendingEditLutRecipeSync ?: return
|
||||
pendingEditLutRecipeSync = null
|
||||
contentRepository.lutManager.saveColorRecipeParams(lutId, params)
|
||||
editLutRecipeSyncMutex.withLock {
|
||||
// 按 LUT 保留尚未落盘的调节,快速切换不会覆盖前一个 LUT 的待保存配方。
|
||||
val pending = pendingEditLutRecipeSync.toMap()
|
||||
for ((lutId, params) in pending) {
|
||||
contentRepository.lutManager.saveColorRecipeParams(lutId, params)
|
||||
if (pendingEditLutRecipeSync[lutId] === params) {
|
||||
pendingEditLutRecipeSync.remove(lutId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 LUT
|
||||
*/
|
||||
fun setEditLut(lutId: String?) {
|
||||
if (editLutId.value != lutId) {
|
||||
if (lutId == null) {
|
||||
setSyncAdjustmentsToLut(false)
|
||||
}
|
||||
if (editLutId.value != lutId && editSyncAdjustmentsToLut) {
|
||||
editPhotoRecipeParams.value = null
|
||||
}
|
||||
editLutId.value = lutId
|
||||
@@ -2445,12 +2483,13 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
val copied = copiedEditSettings ?: return null
|
||||
val settings = copied.metadata
|
||||
|
||||
pendingEditLutRecipeSync = null
|
||||
editLutRecipeSyncJob?.cancel()
|
||||
editLutRecipeSyncJob = null
|
||||
viewModelScope.launch {
|
||||
flushPendingEditLutRecipeSync()
|
||||
}
|
||||
editSyncAdjustmentsToLut = false
|
||||
|
||||
editLutId.value = settings.lutId
|
||||
editPhotoRecipeParams.value = settings.colorRecipeParams?.deepCopy()
|
||||
editPhotoRecipeParams.value = snapshotEditRecipe(settings.colorRecipeParams, settings.lutId)
|
||||
editFrameId.value = settings.frameId
|
||||
val targetIsRaw = getCurrentPhoto()?.let(::isRawMedia) == true
|
||||
if (!targetIsRaw) {
|
||||
|
||||
@@ -216,8 +216,8 @@
|
||||
<string name="settings_external_lens_stabilization_magnification">外接倍率</string>
|
||||
<string name="settings_external_lens_stabilization_magnification_description">填寫增倍鏡的實際光學倍率,用於校正 EIS+ 的焦距和 OIS 位移。</string>
|
||||
<string name="settings_external_lens_stabilization_custom_magnification">自訂倍率</string>
|
||||
<string name="settings_external_lens_stabilization_custom_magnification_hint">大於 1.0x,最大 %1$.1fx</string>
|
||||
<string name="settings_external_lens_stabilization_magnification_error">請輸入大於 1.0x 且不超過 %1$.1fx 的倍率</string>
|
||||
<string name="settings_external_lens_stabilization_custom_magnification_hint">大於 1.0x</string>
|
||||
<string name="settings_external_lens_stabilization_magnification_error">請輸入有效且大於 1.0x 的倍率</string>
|
||||
<string name="settings_external_lens_stabilization_no_physical_lens">未發現相容的後置物理鏡頭。</string>
|
||||
<string name="settings_external_lens_stabilization_apply">套用</string>
|
||||
<string name="settings_video_lock_white_balance">鎖定白平衡</string>
|
||||
|
||||
@@ -216,8 +216,8 @@
|
||||
<string name="settings_external_lens_stabilization_magnification">外接倍率</string>
|
||||
<string name="settings_external_lens_stabilization_magnification_description">填写增倍镜的实际光学倍率,用于校正 EIS+ 的焦距和 OIS 位移。</string>
|
||||
<string name="settings_external_lens_stabilization_custom_magnification">自定义倍率</string>
|
||||
<string name="settings_external_lens_stabilization_custom_magnification_hint">大于 1.0x,最大 %1$.1fx</string>
|
||||
<string name="settings_external_lens_stabilization_magnification_error">请输入大于 1.0x 且不超过 %1$.1fx 的倍率</string>
|
||||
<string name="settings_external_lens_stabilization_custom_magnification_hint">大于 1.0x</string>
|
||||
<string name="settings_external_lens_stabilization_magnification_error">请输入有效且大于 1.0x 的倍率</string>
|
||||
<string name="settings_external_lens_stabilization_no_physical_lens">未发现兼容的后置物理镜头。</string>
|
||||
<string name="settings_external_lens_stabilization_apply">应用</string>
|
||||
<string name="settings_video_lock_white_balance">锁定白平衡</string>
|
||||
|
||||
@@ -216,8 +216,8 @@
|
||||
<string name="settings_external_lens_stabilization_magnification">外接倍率</string>
|
||||
<string name="settings_external_lens_stabilization_magnification_description">填寫增倍鏡的實際光學倍率,用於校正 EIS+ 的焦距和 OIS 位移。</string>
|
||||
<string name="settings_external_lens_stabilization_custom_magnification">自訂倍率</string>
|
||||
<string name="settings_external_lens_stabilization_custom_magnification_hint">大於 1.0x,最大 %1$.1fx</string>
|
||||
<string name="settings_external_lens_stabilization_magnification_error">請輸入大於 1.0x 且不超過 %1$.1fx 的倍率</string>
|
||||
<string name="settings_external_lens_stabilization_custom_magnification_hint">大於 1.0x</string>
|
||||
<string name="settings_external_lens_stabilization_magnification_error">請輸入有效且大於 1.0x 的倍率</string>
|
||||
<string name="settings_external_lens_stabilization_no_physical_lens">未發現相容的後置物理鏡頭。</string>
|
||||
<string name="settings_external_lens_stabilization_apply">套用</string>
|
||||
<string name="settings_video_lock_white_balance">鎖定白平衡</string>
|
||||
|
||||
@@ -216,8 +216,8 @@
|
||||
<string name="settings_external_lens_stabilization_magnification">外接倍率</string>
|
||||
<string name="settings_external_lens_stabilization_magnification_description">填寫增倍鏡的實際光學倍率,用於校正 EIS+ 的焦距和 OIS 位移。</string>
|
||||
<string name="settings_external_lens_stabilization_custom_magnification">自訂倍率</string>
|
||||
<string name="settings_external_lens_stabilization_custom_magnification_hint">大於 1.0x,最大 %1$.1fx</string>
|
||||
<string name="settings_external_lens_stabilization_magnification_error">請輸入大於 1.0x 且不超過 %1$.1fx 的倍率</string>
|
||||
<string name="settings_external_lens_stabilization_custom_magnification_hint">大於 1.0x</string>
|
||||
<string name="settings_external_lens_stabilization_magnification_error">請輸入有效且大於 1.0x 的倍率</string>
|
||||
<string name="settings_external_lens_stabilization_no_physical_lens">未發現相容的後置物理鏡頭。</string>
|
||||
<string name="settings_external_lens_stabilization_apply">套用</string>
|
||||
<string name="settings_video_lock_white_balance">鎖定白平衡</string>
|
||||
|
||||
@@ -226,8 +226,8 @@
|
||||
<string name="settings_external_lens_stabilization_magnification">External magnification</string>
|
||||
<string name="settings_external_lens_stabilization_magnification_description">Use the real optical magnification of the teleconverter. This corrects focal length and OIS motion for EIS+.</string>
|
||||
<string name="settings_external_lens_stabilization_custom_magnification">Custom magnification</string>
|
||||
<string name="settings_external_lens_stabilization_custom_magnification_hint">Greater than 1.0x, up to %1$.1fx</string>
|
||||
<string name="settings_external_lens_stabilization_magnification_error">Enter a value greater than 1.0x and no more than %1$.1fx</string>
|
||||
<string name="settings_external_lens_stabilization_custom_magnification_hint">Greater than 1.0x</string>
|
||||
<string name="settings_external_lens_stabilization_magnification_error">Enter a valid magnification greater than 1.0x</string>
|
||||
<string name="settings_external_lens_stabilization_no_physical_lens">No compatible rear physical lens was discovered.</string>
|
||||
<string name="settings_external_lens_stabilization_apply">Apply</string>
|
||||
<string name="settings_video_lock_white_balance">Lock White Balance</string>
|
||||
|
||||
Reference in new issue
Block a user