fix: lut apply

This commit is contained in:
Hinnka committed 2026-03-28 17:32:45 +08:00
1 parent 39cc72a80b
commit 61acc2151b
4 files changed
+63 -29

No files matched your search

@@ -1011,19 +1011,9 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
}
private suspend fun syncScreenCaptureRenderConfig(lutId: String?) {
val preferences = userPreferencesRepository.userPreferences.firstOrNull()
val lutManager = ContentRepository.getInstance(context).lutManager
val lutConfig = lutId?.let { id ->
withContext(Dispatchers.IO) { lutManager.loadLut(id) }
}
val colorRecipeParams = lutId?.let { id ->
lutManager.getColorRecipeParams(id).first()
} ?: ColorRecipeParams.DEFAULT
ScreenCaptureRenderConfigStore.save(
lutConfig = lutConfig,
colorRecipeParams = colorRecipeParams,
crop = preferences?.phantomPipCrop ?: ScreenCaptureRenderConfigStore.config.value.crop
ScreenCaptureRenderConfigStore.syncFromPreferences(
context = context,
lutIdOverride = lutId,
)
}
@@ -98,22 +98,26 @@ class ScreenCapturePipActivity : ComponentActivity() {
return
}
setContent {
PhotonCameraTheme {
ComposeSurface(
modifier = Modifier.fillMaxSize(),
color = Color.Black
) {
ScreenCapturePipContent(
controller = controller,
isInPiPMode = isInPiPMode,
onRequestPip = { enterPipIfPossible() }
)
lifecycleScope.launch {
ScreenCaptureRenderConfigStore.syncFromPreferences(this@ScreenCapturePipActivity)
setContent {
PhotonCameraTheme {
ComposeSurface(
modifier = Modifier.fillMaxSize(),
color = Color.Black
) {
ScreenCapturePipContent(
controller = controller,
isInPiPMode = isInPiPMode,
onRequestPip = { enterPipIfPossible() }
)
}
}
}
}
controller.startCapture(grant.resultCode, grant.data)
controller.startCapture(grant.resultCode, grant.data)
}
}
override fun onUserLeaveHint() {
@@ -1,10 +1,16 @@
package com.hinnka.mycamera.screencapture
import android.content.Context
import com.hinnka.mycamera.data.ContentRepository
import com.hinnka.mycamera.lut.LutConfig
import com.hinnka.mycamera.model.ColorRecipeParams
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.withContext
object ScreenCaptureRenderConfigStore {
data class RenderConfig(
@@ -33,4 +39,30 @@ object ScreenCaptureRenderConfigStore {
crop = crop.normalized()
)
}
suspend fun syncFromPreferences(
context: Context,
lutIdOverride: String? = null,
cropOverride: PhantomPipCrop? = null
) {
val repository = ContentRepository.getInstance(context.applicationContext)
val preferences = repository.userPreferencesRepository.userPreferences.firstOrNull()
val effectiveLutId = lutIdOverride
?: preferences?.lutId
?: repository.getAvailableLuts().firstOrNull { it.isDefault }?.id
val lutManager = repository.lutManager
val lutConfig = effectiveLutId?.let { lutId ->
withContext(Dispatchers.IO) { lutManager.loadLut(lutId) }
}
val colorRecipeParams = effectiveLutId?.let { lutId ->
lutManager.getColorRecipeParams(lutId).first()
} ?: ColorRecipeParams.DEFAULT
save(
lutConfig = lutConfig,
colorRecipeParams = colorRecipeParams,
crop = cropOverride ?: preferences?.phantomPipCrop ?: _config.value.crop
)
}
}
@@ -1168,18 +1168,26 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
// LUT 已禁用,通知相机控制器
cameraController.setLutEnabled(false)
} else {
val hadActiveLut = currentLutConfig != null
if (!hadActiveLut) {
// 首次启动时先保持“未启用”状态,避免 Live Photo 在 LUT 文件尚未加载完成前录入原始画面。
cameraController.setLutEnabled(false)
}
viewModelScope.launch {
currentLutConfig = withContext(Dispatchers.IO) {
val loadedLut = withContext(Dispatchers.IO) {
contentRepository.lutManager.loadLut(lutId)
}
currentLutConfig = loadedLut
currentRecipeParams = contentRepository.lutManager.getColorRecipeParams(lutId).stateIn(
viewModelScope,
started = SharingStarted.Lazily,
initialValue = ColorRecipeParams.DEFAULT,
)
cameraController.setLutEnabled(loadedLut != null)
}
if (hadActiveLut) {
cameraController.setLutEnabled(true)
}
// LUT 已启用,通知相机控制器
cameraController.setLutEnabled(true)
}
// 保存到用户偏好设置