feat: preset recipes and unified creative look state
This commit is contained in:
1 parent
ba936e1214
commit
844454327e
24 files changed
+711
-682
No files matched your search
@@ -310,11 +310,11 @@ class MainActivity : AppCompatActivity() {
|
||||
StartupTrace.mark("MainActivity.setContent start")
|
||||
setContent {
|
||||
StartupComposeReadyEffect()
|
||||
val currentRecipeParams by cameraViewModel.currentRecipeParams.collectAsState()
|
||||
val currentLutLook by cameraViewModel.currentLutLook.collectAsState()
|
||||
val phantomPipCrop by preferenceValue { it.phantomPipCrop }
|
||||
ScreenCaptureRenderConfigStore.save(
|
||||
creativeLutConfig = cameraViewModel.currentLutConfig,
|
||||
creativeColorRecipeParams = currentRecipeParams,
|
||||
creativeLutConfig = currentLutLook.config,
|
||||
creativeColorRecipeParams = currentLutLook.recipe,
|
||||
crop = phantomPipCrop
|
||||
)
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.hinnka.mycamera.color.TransferCurve
|
||||
import com.hinnka.mycamera.gallery.PhotoSavePath
|
||||
import com.hinnka.mycamera.model.AppAppearance
|
||||
import com.hinnka.mycamera.model.CameraPreset
|
||||
import com.hinnka.mycamera.model.EffectParams
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.model.LutSelectorMode
|
||||
import com.hinnka.mycamera.processor.MgcRawMaxMode
|
||||
import com.hinnka.mycamera.raw.CanonPictureStyle
|
||||
@@ -118,7 +118,10 @@ class UserPreferences internal constructor(
|
||||
|
||||
var captureMode by enum("capture_mode", CaptureMode.PHOTO)
|
||||
var aspectRatio by string("aspect_ratio", "RATIO_4_3")
|
||||
var videoLutId by nullableString("video_lut_id")
|
||||
var videoLutId: String? by stored({ p -> p[K.VIDEO_LUT_ID_KEY] }) { p, v ->
|
||||
p.put(K.VIDEO_LUT_ID_KEY, v)
|
||||
videoPresetRecipe = null
|
||||
}
|
||||
var rawBaselineLutId by nullableString("raw_baseline_lut_id")
|
||||
var rawDcpId by nullableString("raw_dcp_id")
|
||||
var rawExposureCompensation by float("raw_exposure_compensation", 0f, normalize = { it.coerceIn(-4f, 4f) })
|
||||
@@ -152,7 +155,6 @@ class UserPreferences internal constructor(
|
||||
var rawSpectralFilmStock by nullableString("raw_spectral_film_stock")
|
||||
var rawSpectralFilmPrint by nullableString("raw_spectral_film_print")
|
||||
var rawFotufilmDocument by nullableString("raw_fotufilm_document")
|
||||
var activeEffectParamsJson by string("active_effect_params_json", "")
|
||||
var customPresetsJson by string("custom_presets_json", "")
|
||||
var activePresetId by nullableString("active_preset_id")
|
||||
var deletedBuiltInIds by string("deleted_built_in_ids", "")
|
||||
@@ -212,7 +214,18 @@ class UserPreferences internal constructor(
|
||||
var lutId: String? by stored({ p -> p[K.LUT_ID_KEY] ?: p[K.LEGACY_PHANTOM_LUT_ID_KEY] }) { p, v ->
|
||||
p.put(K.LUT_ID_KEY, v)
|
||||
p.remove(K.LEGACY_PHANTOM_LUT_ID_KEY)
|
||||
photoPresetRecipe = null
|
||||
}
|
||||
var photoPresetRecipe by json(
|
||||
"photo_preset_recipe",
|
||||
decode = { it?.let(ColorRecipeParams::fromJson) },
|
||||
encode = ColorRecipeParams::toJson,
|
||||
)
|
||||
var videoPresetRecipe by json(
|
||||
"video_preset_recipe",
|
||||
decode = { it?.let(ColorRecipeParams::fromJson) },
|
||||
encode = ColorRecipeParams::toJson,
|
||||
)
|
||||
var separateVideoLutEnabled by bool("separate_video_lut_enabled", false)
|
||||
var rawBaselineLutConfigured: Boolean by stored({ p ->
|
||||
p[K.RAW_BASELINE_LUT_CONFIGURED_KEY] ?: p.contains(K.RAW_BASELINE_LUT_ID_KEY)
|
||||
@@ -623,10 +636,6 @@ class UserPreferences internal constructor(
|
||||
var nrLevel by int("nr_level", NoiseReductionLevel.DEFAULT, normalize = NoiseReductionLevel::normalize)
|
||||
var videoNrLevel by int("video_nr_level", NoiseReductionLevel.DEFAULT, normalize = NoiseReductionLevel::normalize)
|
||||
|
||||
var activeEffectParams: EffectParams by stored({ EffectParams.fromJson(activeEffectParamsJson) }) { _, v ->
|
||||
activeEffectParamsJson = v.toJson()
|
||||
}
|
||||
|
||||
var customPresets: List<CameraPreset> by stored({ CameraPreset.listFromJson(customPresetsJson) }) { _, v ->
|
||||
customPresetsJson = CameraPreset.listToJson(v)
|
||||
}
|
||||
@@ -785,6 +794,7 @@ internal object PreferenceKeys {
|
||||
val TOP_SHEET_ASPECT_RATIOS = stringPreferencesKey("top_sheet_aspect_ratios")
|
||||
val CUSTOM_ASPECT_RATIOS = stringPreferencesKey("custom_aspect_ratios")
|
||||
val LUT_ID_KEY = stringPreferencesKey("lut_id")
|
||||
val VIDEO_LUT_ID_KEY = stringPreferencesKey("video_lut_id")
|
||||
val LEGACY_PHANTOM_LUT_ID_KEY = stringPreferencesKey("phantom_lut_id")
|
||||
val RAW_BASELINE_LUT_ID_KEY = stringPreferencesKey("raw_baseline_lut_id")
|
||||
val RAW_BASELINE_LUT_CONFIGURED_KEY = booleanPreferencesKey("raw_baseline_lut_configured")
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.hinnka.mycamera.gallery
|
||||
|
||||
import com.hinnka.mycamera.lut.LutConfig
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.model.RecipeParam
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
|
||||
internal data class GalleryEditLook(
|
||||
val lutId: String? = null,
|
||||
val lutConfig: LutConfig? = null,
|
||||
val isLutConfigLoading: Boolean = false,
|
||||
val recipe: ColorRecipeParams = ColorRecipeParams.DEFAULT,
|
||||
val edits: PhotoColorRecipeEdits = PhotoColorRecipeEdits(),
|
||||
) {
|
||||
fun switchLut(id: String?, base: ColorRecipeParams): GalleryEditLook {
|
||||
val photoFields = edits.photoFields - RecipeParam.LUT_INTENSITY.name
|
||||
return GalleryEditLook(
|
||||
lutId = id,
|
||||
recipe = base.copyRecipeFields(recipe, photoFields),
|
||||
edits = PhotoColorRecipeEdits(base, photoFields),
|
||||
)
|
||||
}
|
||||
|
||||
fun withPhotoRecipe(params: ColorRecipeParams, changedFields: Set<String>): GalleryEditLook {
|
||||
val photoFields = edits.photoFields - changedFields + params.changedRecipeFields(edits.base)
|
||||
.intersect(changedFields)
|
||||
return copy(recipe = params, edits = edits.copy(photoFields = photoFields))
|
||||
}
|
||||
|
||||
fun withSyncedRecipe(params: ColorRecipeParams, changedFields: Set<String>): GalleryEditLook {
|
||||
val base = edits.base.copyRecipeFields(params, changedFields)
|
||||
return copy(recipe = params, edits = PhotoColorRecipeEdits(base, edits.photoFields - changedFields))
|
||||
}
|
||||
|
||||
fun resetPhotoRecipe(): GalleryEditLook =
|
||||
copy(recipe = edits.base, edits = edits.copy(photoFields = emptySet()))
|
||||
}
|
||||
|
||||
/** The effective values live in MediaMetadata.colorRecipeParams, including explicit curve resets. */
|
||||
internal data class PhotoColorRecipeEdits(
|
||||
val base: ColorRecipeParams = ColorRecipeParams.DEFAULT,
|
||||
val photoFields: Set<String> = emptySet(),
|
||||
) {
|
||||
fun toJson(): String = JSONObject()
|
||||
.put("base", JSONObject(base.toJson()))
|
||||
.put("photoFields", JSONArray(photoFields.toList()))
|
||||
.toString()
|
||||
|
||||
companion object {
|
||||
fun fromJson(json: String?): PhotoColorRecipeEdits? {
|
||||
if (json == null) return null
|
||||
return try {
|
||||
val root = JSONObject(json)
|
||||
val fields = root.getJSONArray("photoFields")
|
||||
PhotoColorRecipeEdits(
|
||||
base = ColorRecipeParams.fromJson(root.getJSONObject("base").toString()),
|
||||
photoFields = buildSet {
|
||||
for (index in 0 until fields.length()) add(fields.getString(index))
|
||||
},
|
||||
)
|
||||
} catch (_: JSONException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun withoutLut(recipe: ColorRecipeParams): PhotoColorRecipeEdits =
|
||||
PhotoColorRecipeEdits(photoFields = recipe.changedRecipeFields(ColorRecipeParams.DEFAULT))
|
||||
}
|
||||
}
|
||||
|
||||
private class RecipeField(
|
||||
val name: String,
|
||||
val differs: (ColorRecipeParams, ColorRecipeParams) -> Boolean,
|
||||
val copyFrom: (ColorRecipeParams, ColorRecipeParams) -> ColorRecipeParams,
|
||||
)
|
||||
|
||||
private fun <T> recipeField(
|
||||
name: String,
|
||||
read: (ColorRecipeParams) -> T,
|
||||
write: (ColorRecipeParams, T) -> ColorRecipeParams,
|
||||
equal: (T, T) -> Boolean = { first, second -> first == second },
|
||||
) = RecipeField(
|
||||
name = name,
|
||||
differs = { first, second -> !equal(read(first), read(second)) },
|
||||
copyFrom = { target, source -> write(target, read(source)) },
|
||||
)
|
||||
|
||||
private fun curveField(name: String, read: (ColorRecipeParams) -> FloatArray?, write: (ColorRecipeParams, FloatArray?) -> ColorRecipeParams) =
|
||||
recipeField(name, read, write) { first, second -> first.contentEquals(second) }
|
||||
|
||||
private val recipeFields = RecipeParam.entries.filterNot { it == RecipeParam.HDF }.map { param ->
|
||||
recipeField(param.name, param::getValue, param::setValue)
|
||||
} + listOf(
|
||||
recipeField("remarks", ColorRecipeParams::remarks, { p, v -> p.copy(remarks = v) }),
|
||||
curveField("masterCurvePoints", ColorRecipeParams::masterCurvePoints) { p, v -> p.copy(masterCurvePoints = v?.copyOf()) },
|
||||
curveField("redCurvePoints", ColorRecipeParams::redCurvePoints) { p, v -> p.copy(redCurvePoints = v?.copyOf()) },
|
||||
curveField("greenCurvePoints", ColorRecipeParams::greenCurvePoints) { p, v -> p.copy(greenCurvePoints = v?.copyOf()) },
|
||||
curveField("blueCurvePoints", ColorRecipeParams::blueCurvePoints) { p, v -> p.copy(blueCurvePoints = v?.copyOf()) },
|
||||
recipeField("gradingShadowHue", ColorRecipeParams::gradingShadowHue, { p, v -> p.copy(gradingShadowHue = v) }),
|
||||
recipeField("gradingShadowAmount", ColorRecipeParams::gradingShadowAmount, { p, v -> p.copy(gradingShadowAmount = v) }),
|
||||
recipeField("gradingShadowLuminance", ColorRecipeParams::gradingShadowLuminance, { p, v -> p.copy(gradingShadowLuminance = v) }),
|
||||
recipeField("gradingMidtoneHue", ColorRecipeParams::gradingMidtoneHue, { p, v -> p.copy(gradingMidtoneHue = v) }),
|
||||
recipeField("gradingMidtoneAmount", ColorRecipeParams::gradingMidtoneAmount, { p, v -> p.copy(gradingMidtoneAmount = v) }),
|
||||
recipeField("gradingMidtoneLuminance", ColorRecipeParams::gradingMidtoneLuminance, { p, v -> p.copy(gradingMidtoneLuminance = v) }),
|
||||
recipeField("gradingHighlightHue", ColorRecipeParams::gradingHighlightHue, { p, v -> p.copy(gradingHighlightHue = v) }),
|
||||
recipeField("gradingHighlightAmount", ColorRecipeParams::gradingHighlightAmount, { p, v -> p.copy(gradingHighlightAmount = v) }),
|
||||
recipeField("gradingHighlightLuminance", ColorRecipeParams::gradingHighlightLuminance, { p, v -> p.copy(gradingHighlightLuminance = v) }),
|
||||
recipeField("gradingBalance", ColorRecipeParams::gradingBalance, { p, v -> p.copy(gradingBalance = v) }),
|
||||
recipeField("gradingBlending", ColorRecipeParams::gradingBlending, { p, v -> p.copy(gradingBlending = v) }),
|
||||
)
|
||||
|
||||
internal fun ColorRecipeParams.changedRecipeFields(other: ColorRecipeParams): Set<String> = buildSet {
|
||||
for (field in recipeFields) {
|
||||
if (field.differs(this@changedRecipeFields, other)) add(field.name)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun ColorRecipeParams.copyRecipeFields(source: ColorRecipeParams, fields: Set<String>): ColorRecipeParams =
|
||||
recipeFields.fold(this) { params, field ->
|
||||
if (field.name in fields) field.copyFrom(params, source) else params
|
||||
}
|
||||
@@ -55,6 +55,8 @@ data class MediaMetadata(
|
||||
val tonemapMode: String? = null,
|
||||
// 色彩配方配置
|
||||
val colorRecipeParams: ColorRecipeParams? = null,
|
||||
/** LUT 配方基底与照片独立调节,用于再次编辑。colorRecipeParams 保留渲染快照。 */
|
||||
val photoColorRecipeEdits: String? = null,
|
||||
val baselineTarget: BaselineColorCorrectionTarget? = null,
|
||||
val baselineLutId: String? = null,
|
||||
val baselineColorRecipeParams: ColorRecipeParams? = null,
|
||||
@@ -314,6 +316,11 @@ data class MediaMetadata(
|
||||
lutId = if (obj.isNull("lutId")) null else obj.optString("lutId"),
|
||||
tonemapMode = if (obj.isNull("tonemapMode")) null else obj.optString("tonemapMode"),
|
||||
colorRecipeParams = colorRecipeParams,
|
||||
photoColorRecipeEdits = if (obj.isNull("photoColorRecipeEdits")) {
|
||||
null
|
||||
} else {
|
||||
obj.optString("photoColorRecipeEdits")
|
||||
},
|
||||
baselineTarget = if (obj.isNull("baselineTarget")) null else runCatching {
|
||||
BaselineColorCorrectionTarget.valueOf(obj.optString("baselineTarget"))
|
||||
}.getOrNull(),
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.hinnka.mycamera.raw.RawToneMappingParameters
|
||||
|
||||
@Database(
|
||||
entities = [GalleryMediaEntity::class],
|
||||
version = 52,
|
||||
version = 53,
|
||||
exportSchema = false
|
||||
)
|
||||
@androidx.room.TypeConverters(GalleryConverters::class)
|
||||
@@ -883,6 +883,12 @@ abstract class GalleryDatabase : RoomDatabase() {
|
||||
}
|
||||
}
|
||||
|
||||
private val MIGRATION_52_53 = object : androidx.room.migration.Migration(52, 53) {
|
||||
override fun migrate(db: androidx.sqlite.db.SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE gallery_media ADD COLUMN photoColorRecipeEdits TEXT")
|
||||
}
|
||||
}
|
||||
|
||||
fun getInstance(context: Context): GalleryDatabase {
|
||||
return INSTANCE ?: synchronized(this) {
|
||||
INSTANCE ?: Room.databaseBuilder(
|
||||
@@ -941,7 +947,8 @@ abstract class GalleryDatabase : RoomDatabase() {
|
||||
MIGRATION_48_49,
|
||||
MIGRATION_49_50,
|
||||
MIGRATION_50_51,
|
||||
MIGRATION_51_52
|
||||
MIGRATION_51_52,
|
||||
MIGRATION_52_53
|
||||
)
|
||||
.fallbackToDestructiveMigrationOnDowngrade(false)
|
||||
.fallbackToDestructiveMigration(false)
|
||||
|
||||
@@ -38,6 +38,7 @@ data class GalleryMediaEntity(
|
||||
val tonemapMode: String?,
|
||||
@Embedded(prefix = "recipe_")
|
||||
val colorRecipeParams: ColorRecipeParams?,
|
||||
val photoColorRecipeEdits: String?,
|
||||
val baselineTarget: String?,
|
||||
val baselineLutId: String?,
|
||||
@Embedded(prefix = "baseline_recipe_")
|
||||
|
||||
@@ -218,6 +218,7 @@ object GalleryMediaStore {
|
||||
lutId = metadata.lutId,
|
||||
tonemapMode = metadata.tonemapMode,
|
||||
colorRecipeParams = metadata.colorRecipeParams,
|
||||
photoColorRecipeEdits = metadata.photoColorRecipeEdits,
|
||||
baselineTarget = metadata.baselineTarget?.name,
|
||||
baselineLutId = metadata.baselineLutId,
|
||||
baselineColorRecipeParams = metadata.baselineColorRecipeParams,
|
||||
@@ -427,6 +428,7 @@ object GalleryMediaStore {
|
||||
lutId = lutId,
|
||||
tonemapMode = tonemapMode,
|
||||
colorRecipeParams = colorRecipeParams,
|
||||
photoColorRecipeEdits = photoColorRecipeEdits,
|
||||
baselineTarget = baselineTarget?.let { runCatching { BaselineColorCorrectionTarget.valueOf(it) }.getOrNull() },
|
||||
baselineLutId = baselineLutId,
|
||||
baselineColorRecipeParams = baselineColorRecipeParams,
|
||||
|
||||
@@ -158,6 +158,7 @@ class LutManager(private val context: Context) {
|
||||
lutId: String,
|
||||
target: BaselineColorCorrectionTarget?
|
||||
): ColorRecipeParams? {
|
||||
if (lutId == "none") return null
|
||||
preferences[recipeKey(lutId, target)]?.let { return ColorRecipeParams.fromJson(it) }
|
||||
if (target != null) return null
|
||||
val hasLegacyRecipe = legacyFieldNames.any { name ->
|
||||
@@ -369,6 +370,7 @@ class LutManager(private val context: Context) {
|
||||
params: ColorRecipeParams,
|
||||
target: BaselineColorCorrectionTarget? = null
|
||||
) {
|
||||
if (lutId == "none") return
|
||||
context.colorRecipeDataStore.edit { preferences ->
|
||||
preferences[recipeKey(lutId, target)] = params.toJson()
|
||||
if (target == null) {
|
||||
|
||||
@@ -21,15 +21,15 @@ import java.nio.ByteOrder
|
||||
*/
|
||||
@UnstableApi
|
||||
class VideoLutEffect(
|
||||
@Volatile var lutConfig: LutConfig?,
|
||||
lutConfig: LutConfig?,
|
||||
recipeParams: ColorRecipeParams?,
|
||||
val sourceLogProfile: VideoLogProfile = VideoLogProfile.OFF,
|
||||
) : GlEffect {
|
||||
@Volatile
|
||||
var recipeParams: ColorRecipeParams? = recipeParams
|
||||
private set
|
||||
internal data class Look(val lutConfig: LutConfig?, val recipeParams: ColorRecipeParams?)
|
||||
|
||||
private var shaderProgram: VideoLutShaderProgram? = null
|
||||
@Volatile
|
||||
internal var look = Look(lutConfig, recipeParams)
|
||||
private set
|
||||
|
||||
private val _outputSize = MutableStateFlow<Size?>(null)
|
||||
|
||||
@@ -42,10 +42,9 @@ class VideoLutEffect(
|
||||
}
|
||||
|
||||
override fun toGlShaderProgram(context: Context, useHdr: Boolean): GlShaderProgram {
|
||||
val (lutConfig, recipeParams) = look
|
||||
PLog.d("VideoLutEffect", "toGlShaderProgram called, useHdr: $useHdr, sourceLog: $sourceLogProfile, initialLut: ${lutConfig?.title}, recipeEnabled: ${recipeParams != null}")
|
||||
return VideoLutShaderProgram(context, useHdr, this).also {
|
||||
shaderProgram = it
|
||||
}
|
||||
return VideoLutShaderProgram(context, useHdr, this)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,9 +52,7 @@ class VideoLutEffect(
|
||||
*/
|
||||
fun update(lutConfig: LutConfig?, recipeParams: ColorRecipeParams?) {
|
||||
PLog.d("VideoLutEffect", "update called, lutConfig: ${lutConfig?.title}, recipeParams: ${recipeParams != null}")
|
||||
this.lutConfig = lutConfig
|
||||
this.recipeParams = recipeParams
|
||||
shaderProgram?.triggerUpdate()
|
||||
look = Look(lutConfig, recipeParams)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -712,8 +709,6 @@ private class VideoLutShaderProgram(
|
||||
private var lastLutConfig: LutConfig? = null
|
||||
private var lastRecipeParams: ColorRecipeParams? = null
|
||||
|
||||
@Volatile
|
||||
private var hasPendingUpdate = false
|
||||
|
||||
init {
|
||||
val vertexShader = GlUtils.compileShader(GLES30.GL_VERTEX_SHADER, VERTEX_SHADER)
|
||||
@@ -736,11 +731,6 @@ private class VideoLutShaderProgram(
|
||||
}
|
||||
}
|
||||
|
||||
fun triggerUpdate() {
|
||||
PLog.d("VideoLutShaderProgram", "triggerUpdate called, hasPendingUpdate: true")
|
||||
hasPendingUpdate = true
|
||||
}
|
||||
|
||||
override fun configure(inputWidth: Int, inputHeight: Int): Size {
|
||||
PLog.d("VideoLutShaderProgram", "configure called, inputWidth: $inputWidth, inputHeight: $inputHeight")
|
||||
this.inputWidth = inputWidth.coerceAtLeast(1)
|
||||
@@ -750,13 +740,12 @@ private class VideoLutShaderProgram(
|
||||
|
||||
override fun drawFrame(inputTexId: Int, presentationTimeUs: Long) {
|
||||
if (programId == 0) throw VideoFrameProcessingException("Video color program unavailable", presentationTimeUs)
|
||||
val currentLutConfig = effect.lutConfig
|
||||
val (currentLutConfig, currentRecipeParams) = effect.look
|
||||
if (currentLutConfig != null &&
|
||||
!effect.sourceLogProfile.matchesLut(currentLutConfig.curve, currentLutConfig.colorSpace)
|
||||
) {
|
||||
throw VideoFrameProcessingException("LUT input does not match source Log profile ${effect.sourceLogProfile}", presentationTimeUs)
|
||||
}
|
||||
val currentRecipeParams = effect.recipeParams
|
||||
val softLight = currentRecipeParams?.softLight ?: 0f
|
||||
val bloom = currentRecipeParams?.bloom ?: 0f
|
||||
val halation = currentRecipeParams?.redHalation ?: 0f
|
||||
@@ -799,7 +788,7 @@ private class VideoLutShaderProgram(
|
||||
deferFilmGrain: Boolean,
|
||||
) {
|
||||
// 检查并重新上传 LUT 纹理
|
||||
if (currentLutConfig != lastLutConfig || hasPendingUpdate) {
|
||||
if (currentLutConfig != lastLutConfig) {
|
||||
lastLutConfig = currentLutConfig
|
||||
if (currentLutConfig != null) {
|
||||
uploadLutTexture(currentLutConfig)
|
||||
@@ -815,14 +804,13 @@ private class VideoLutShaderProgram(
|
||||
val bluePts = currentRecipeParams?.blueCurvePoints
|
||||
val curveActive = masterPts != null || redPts != null || greenPts != null || bluePts != null
|
||||
|
||||
if (currentRecipeParams != lastRecipeParams || hasPendingUpdate) {
|
||||
if (currentRecipeParams != lastRecipeParams) {
|
||||
lastRecipeParams = currentRecipeParams
|
||||
if (curveActive) {
|
||||
uploadCurveTexture(masterPts, redPts, greenPts, bluePts)
|
||||
} else {
|
||||
deleteCurveTexture()
|
||||
}
|
||||
hasPendingUpdate = false
|
||||
}
|
||||
|
||||
GLES30.glUseProgram(programId)
|
||||
|
||||
@@ -172,9 +172,15 @@ private fun MgcFilterSelectionRoute(
|
||||
}
|
||||
val activeLutId = preferences?.lutId
|
||||
?: sortedLuts.firstOrNull { it.isDefault }?.id
|
||||
var editingLutId by remember { mutableStateOf<String?>(null) }
|
||||
val presetLookActive = preferences?.photoPresetRecipe != null
|
||||
val editableLutId = activeLutId?.takeIf { id ->
|
||||
!presetLookActive && id != "none" && sortedLuts.any { it.id == id }
|
||||
}
|
||||
var editingLutId by remember(editableLutId) { mutableStateOf<String?>(null) }
|
||||
val editLut = editableLutId?.let { id -> { editingLutId = id } }
|
||||
|
||||
if (editingLutId == null) {
|
||||
val openedLutId = editingLutId
|
||||
if (openedLutId == null) {
|
||||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
||||
AppModalBottomSheet(
|
||||
containerColor = Color.Black.copy(alpha = 0.8f),
|
||||
@@ -199,13 +205,7 @@ private fun MgcFilterSelectionRoute(
|
||||
.weight(1f)
|
||||
.basicMarquee(),
|
||||
)
|
||||
LutEditButton(
|
||||
onClick = {
|
||||
activeLutId
|
||||
?.takeIf { currentId -> sortedLuts.any { it.id == currentId } }
|
||||
?.let { editingLutId = it }
|
||||
},
|
||||
)
|
||||
if (editLut != null) LutEditButton(onClick = editLut)
|
||||
}
|
||||
|
||||
LutSelector(
|
||||
@@ -222,11 +222,8 @@ private fun MgcFilterSelectionRoute(
|
||||
onLutSelected(lutId)
|
||||
}
|
||||
},
|
||||
onEditClick = {
|
||||
activeLutId
|
||||
?.takeIf { currentId -> sortedLuts.any { it.id == currentId } }
|
||||
?.let { editingLutId = it }
|
||||
},
|
||||
onEditClick = editLut,
|
||||
presetLookActive = presetLookActive,
|
||||
categoryOrder = preferences?.categoryOrder.orEmpty(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -240,7 +237,7 @@ private fun MgcFilterSelectionRoute(
|
||||
}
|
||||
} else {
|
||||
LutEditBottomSheet(
|
||||
lutId = editingLutId!!,
|
||||
lutId = openedLutId,
|
||||
showEffects = true,
|
||||
onDismiss = { editingLutId = null },
|
||||
)
|
||||
|
||||
@@ -42,7 +42,8 @@ class PhotonLookProvider : ContentProvider() {
|
||||
|
||||
val normalizedLutId = lutId.takeUnless { it == LutConfigNone }
|
||||
val lutConfig = normalizedLutId?.let { repository.lutManager.loadLut(it) }
|
||||
val recipe = normalizedLutId?.let { repository.lutManager.loadColorRecipeParams(it) }
|
||||
val recipe = preferences.photoPresetRecipe
|
||||
?: normalizedLutId?.let { repository.lutManager.loadColorRecipeParams(it) }
|
||||
?: ColorRecipeParams.DEFAULT
|
||||
val payload = lutConfig?.takeIf { it.isValid() }?.toByteArray()
|
||||
val recipeJson = recipe.toJson()
|
||||
|
||||
@@ -96,11 +96,12 @@ import com.hinnka.mycamera.gallery.ExifWriter
|
||||
import com.hinnka.mycamera.gallery.GalleryManager
|
||||
import com.hinnka.mycamera.gallery.GalleryManager.loadMetadata
|
||||
import com.hinnka.mycamera.gallery.GalleryManager.saveMetadata
|
||||
import com.hinnka.mycamera.gallery.PhotoColorRecipeEdits
|
||||
import com.hinnka.mycamera.livephoto.GoogleLivePhotoCreator
|
||||
import com.hinnka.mycamera.livephoto.MotionPhotoWriter
|
||||
import com.hinnka.mycamera.livephoto.VivoLivePhotoCreator
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.model.EffectParams
|
||||
import com.hinnka.mycamera.model.toEffectParams
|
||||
import com.hinnka.mycamera.ui.components.ColorRecipePanel
|
||||
import com.hinnka.mycamera.ui.components.CurveChannel
|
||||
import com.hinnka.mycamera.ui.components.LutSelector
|
||||
@@ -574,13 +575,19 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
sourceHeight: Int
|
||||
) = withContext(Dispatchers.IO) {
|
||||
var shouldNotifyGallery = false
|
||||
val userPreferencesRepository =
|
||||
ContentRepository.getInstance(context).userPreferencesRepository
|
||||
val availableLutList = ContentRepository.getInstance(context).getAvailableLuts()
|
||||
val photoProcessor = ContentRepository.getInstance(context).photoProcessor
|
||||
val repository = ContentRepository.getInstance(context)
|
||||
val userPreferencesRepository = repository.userPreferencesRepository
|
||||
val availableLutList = repository.getAvailableLuts()
|
||||
val photoProcessor = repository.photoProcessor
|
||||
val preferences = userPreferencesRepository.userPreferences.firstOrNull()
|
||||
val lutId = preferences?.lutId
|
||||
?: availableLutList.firstOrNull { it.isDefault }?.id
|
||||
val presetRecipe = preferences?.photoPresetRecipe
|
||||
val recipe = presetRecipe ?: lutId?.let { repository.lutManager.loadColorRecipeParams(it) }
|
||||
?: ColorRecipeParams.DEFAULT
|
||||
val metadataRecipe = recipe.takeUnless {
|
||||
presetRecipe == null && it.isSameAs(ColorRecipeParams.DEFAULT)
|
||||
}
|
||||
val saveAsNew = userPreferencesRepository.latest().phantomSaveAsNew
|
||||
val phantomFrameId = preferences?.phantomFrameId
|
||||
val computationalAperture = userPreferencesRepository.latest().defaultVirtualAperture.takeIf { it > 0f }
|
||||
@@ -596,21 +603,16 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
) ?: run {
|
||||
return@withContext
|
||||
}
|
||||
val creativeColorRecipeParams = lutId?.let {
|
||||
ContentRepository.getInstance(context).lutManager.loadColorRecipeParams(it)
|
||||
} ?: ColorRecipeParams.DEFAULT
|
||||
val effectiveCreativeColorRecipeParams = preferences
|
||||
?.activeEffectParams
|
||||
?.applyTo(creativeColorRecipeParams)
|
||||
?: creativeColorRecipeParams
|
||||
val metadataCreativeColorRecipeParams = effectiveCreativeColorRecipeParams
|
||||
.takeUnless { it.isDefault() }
|
||||
|
||||
var updatedMetadata = GalleryManager.updateMetadata(context, photoId) { current ->
|
||||
current.copy(
|
||||
lutId = lutId,
|
||||
frameId = phantomFrameId,
|
||||
colorRecipeParams = metadataCreativeColorRecipeParams,
|
||||
colorRecipeParams = metadataRecipe,
|
||||
photoColorRecipeEdits = if (lutId == "none" && presetRecipe != null) {
|
||||
PhotoColorRecipeEdits(base = presetRecipe).toJson()
|
||||
} else {
|
||||
null
|
||||
},
|
||||
baselineTarget = null,
|
||||
baselineLutId = null,
|
||||
baselineColorRecipeParams = null,
|
||||
@@ -953,23 +955,23 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
|
||||
val scope = rememberCoroutineScope()
|
||||
val processingInfo = processingInfo
|
||||
val currentLutIdFlow = remember {
|
||||
userPreferencesRepository.userPreferences.map {
|
||||
it.lutId
|
||||
}
|
||||
}
|
||||
val currentLutId by currentLutIdFlow.collectAsState(initial = null)
|
||||
val currentEffectParamsFlow = remember {
|
||||
userPreferencesRepository.userPreferences.map {
|
||||
it.activeEffectParams
|
||||
}
|
||||
}
|
||||
val currentEffectParams by currentEffectParamsFlow.collectAsState(
|
||||
initial = EffectParams.DEFAULT
|
||||
)
|
||||
var recipePreviewParams by remember(currentLutId) {
|
||||
val currentLutSelection by remember {
|
||||
userPreferencesRepository.flow { it.lutId to (it.photoPresetRecipe != null) }
|
||||
}.collectAsState(initial = userPreferencesRepository.current.let {
|
||||
it.lutId to (it.photoPresetRecipe != null)
|
||||
})
|
||||
val (currentLutId, presetLookActive) = currentLutSelection
|
||||
val editingLutId = currentLutId?.takeIf { it != "none" && !presetLookActive }
|
||||
var recipePreviewParams by remember(editingLutId) {
|
||||
mutableStateOf<ColorRecipeParams?>(null)
|
||||
}
|
||||
LaunchedEffect(editingLutId) {
|
||||
if (editingLutId == null && showRecipeEditor) {
|
||||
showRecipeEditor = false
|
||||
updateWindowParams(false)
|
||||
composeView?.let { windowManager.updateViewLayout(it, windowParams) }
|
||||
}
|
||||
}
|
||||
LaunchedEffect(expanded, processingInfo, showFilterPicker) {
|
||||
if (expanded && !showFilterPicker) {
|
||||
delay(2000L)
|
||||
@@ -1095,10 +1097,11 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
scope.launch {
|
||||
userPreferencesRepository.update { this.lutId = lutId }
|
||||
PhotonLookContract.notifyLookChanged(context)
|
||||
syncScreenCaptureRenderConfig(lutId)
|
||||
syncScreenCaptureRenderConfig()
|
||||
closeFilterPicker()
|
||||
}
|
||||
},
|
||||
presetLookActive = presetLookActive,
|
||||
categoryOrder = categoryOrder,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
@@ -1157,7 +1160,7 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
) {
|
||||
IconButton(
|
||||
onClick = {
|
||||
if (currentLutId != null) {
|
||||
if (editingLutId != null) {
|
||||
showRecipeEditor = true
|
||||
updateWindowParams(false)
|
||||
composeView?.let {
|
||||
@@ -1165,13 +1168,13 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
}
|
||||
}
|
||||
},
|
||||
enabled = currentLutId != null,
|
||||
enabled = editingLutId != null,
|
||||
modifier = Modifier.size(48.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = AppIcons.Tune,
|
||||
contentDescription = stringResource(R.string.edit),
|
||||
tint = if (currentLutId != null) {
|
||||
tint = if (editingLutId != null) {
|
||||
Color.White
|
||||
} else {
|
||||
Color.White.copy(alpha = 0.3f)
|
||||
@@ -1205,7 +1208,6 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
}
|
||||
}
|
||||
|
||||
val editingLutId = currentLutId
|
||||
if (showRecipeEditor && editingLutId != null) {
|
||||
var editingParams by remember(editingLutId) {
|
||||
mutableStateOf(ColorRecipeParams.DEFAULT)
|
||||
@@ -1219,10 +1221,7 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
editingLutId,
|
||||
params
|
||||
)
|
||||
syncScreenCaptureRenderConfig(
|
||||
lutId = editingLutId,
|
||||
creativeRecipeParamsOverride = params
|
||||
)
|
||||
syncScreenCaptureRenderConfig()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1237,10 +1236,7 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
finalPreviewParams
|
||||
)
|
||||
}
|
||||
syncScreenCaptureRenderConfig(
|
||||
lutId = editingLutId,
|
||||
creativeRecipeParamsOverride = finalPreviewParams
|
||||
)
|
||||
syncScreenCaptureRenderConfig()
|
||||
updateWindowParams(false)
|
||||
composeView?.let { windowManager.updateViewLayout(it, windowParams) }
|
||||
}
|
||||
@@ -1286,16 +1282,9 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
)
|
||||
},
|
||||
showLutIntensity = true,
|
||||
currentEffects = currentEffectParams,
|
||||
currentEffects = editingParams.toEffectParams(),
|
||||
onEffectsChange = { effects ->
|
||||
scope.launch {
|
||||
userPreferencesRepository.update { activeEffectParams = effects }
|
||||
syncScreenCaptureRenderConfig(
|
||||
lutId = currentLutId,
|
||||
creativeRecipeParamsOverride = editingParams,
|
||||
effectParamsOverride = effects
|
||||
)
|
||||
}
|
||||
updateRecipeParams(effects.applyTo(editingParams))
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
@@ -1389,17 +1378,8 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun syncScreenCaptureRenderConfig(
|
||||
lutId: String?,
|
||||
creativeRecipeParamsOverride: ColorRecipeParams? = null,
|
||||
effectParamsOverride: EffectParams? = null
|
||||
) {
|
||||
ScreenCaptureRenderConfigStore.syncFromPreferences(
|
||||
context = context,
|
||||
lutIdOverride = lutId,
|
||||
creativeRecipeParamsOverride = creativeRecipeParamsOverride,
|
||||
effectParamsOverride = effectParamsOverride
|
||||
)
|
||||
private suspend fun syncScreenCaptureRenderConfig() {
|
||||
ScreenCaptureRenderConfigStore.syncFromPreferences(context)
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
|
||||
@@ -320,13 +320,10 @@ private fun ScreenCapturePipContent(
|
||||
glSurfaceView.setLensFacing(1)
|
||||
glSurfaceView.setDeviceRotation(0)
|
||||
glSurfaceView.setCalibrationOffset(0)
|
||||
glSurfaceView.setLut(renderConfig.creativeLutConfig)
|
||||
glSurfaceView.setLutEnabled(renderConfig.creativeLutConfig != null)
|
||||
glSurfaceView.setColorRecipeEnabled(!renderConfig.creativeColorRecipeParams.isDefault())
|
||||
glSurfaceView.setCreativeLook(renderConfig.creativeLutConfig, renderConfig.creativeColorRecipeParams)
|
||||
// MediaProjection feeds the SurfaceTexture with a vertically flipped source space.
|
||||
// Map the user-selected crop from display coordinates into projection coordinates here.
|
||||
glSurfaceView.setSourceCrop(renderConfig.crop.flipVertically())
|
||||
glSurfaceView.setParams(renderConfig.creativeColorRecipeParams)
|
||||
glSurfaceView.getRenderSurface()?.let { surface ->
|
||||
controller.attachPreviewSurface(
|
||||
surface = surface,
|
||||
|
||||
+5
-12
@@ -4,7 +4,6 @@ import android.content.Context
|
||||
import com.hinnka.mycamera.data.ContentRepository
|
||||
import com.hinnka.mycamera.lut.LutConfig
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.model.EffectParams
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
@@ -40,25 +39,19 @@ object ScreenCaptureRenderConfigStore {
|
||||
|
||||
suspend fun syncFromPreferences(
|
||||
context: Context,
|
||||
lutIdOverride: String? = null,
|
||||
cropOverride: PhantomPipCrop? = null,
|
||||
creativeRecipeParamsOverride: ColorRecipeParams? = null,
|
||||
effectParamsOverride: EffectParams? = null
|
||||
) {
|
||||
val repository = ContentRepository.getInstance(context.applicationContext)
|
||||
val preferences = repository.userPreferencesRepository.userPreferences.firstOrNull()
|
||||
val creativeLutId = lutIdOverride ?: preferences?.lutId
|
||||
val creativeRecipeParams = creativeRecipeParamsOverride
|
||||
val creativeLutId = preferences?.lutId
|
||||
?: repository.getAvailableLuts().firstOrNull { it.isDefault }?.id
|
||||
val creativeRecipeParams = preferences?.photoPresetRecipe
|
||||
?: creativeLutId?.let { repository.lutManager.loadColorRecipeParams(it) }
|
||||
?: ColorRecipeParams.DEFAULT
|
||||
val effectParams = effectParamsOverride
|
||||
?: preferences?.activeEffectParams
|
||||
?: EffectParams.DEFAULT
|
||||
|
||||
save(
|
||||
creativeLutConfig = creativeLutId?.let { repository.lutManager.loadLut(it) },
|
||||
creativeColorRecipeParams = effectParams.applyTo(creativeRecipeParams),
|
||||
crop = cropOverride ?: preferences?.phantomPipCrop ?: _config.value.crop
|
||||
creativeColorRecipeParams = creativeRecipeParams,
|
||||
crop = preferences?.phantomPipCrop ?: _config.value.crop
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -239,14 +239,13 @@ class CameraGLSurfaceView @JvmOverloads constructor(
|
||||
renderer.meteringEnabled = enabled
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 LUT
|
||||
*
|
||||
* @param lutConfig LUT 配置,传 null 表示移除 LUT
|
||||
*/
|
||||
fun setLut(lutConfig: LutConfig?) {
|
||||
/** Apply the creative LUT and its recipe on the same render thread turn. */
|
||||
fun setCreativeLook(lutConfig: LutConfig?, recipe: ColorRecipeParams) {
|
||||
queueEvent {
|
||||
renderer.setLut(lutConfig)
|
||||
renderer.lutEnabled = lutConfig != null
|
||||
renderer.setRecipeParams(recipe)
|
||||
renderer.colorRecipeEnabled = !recipe.isDefault()
|
||||
requestRender()
|
||||
}
|
||||
}
|
||||
@@ -262,14 +261,6 @@ class CameraGLSurfaceView @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 LUT 是否启用
|
||||
*/
|
||||
fun setLutEnabled(enabled: Boolean) {
|
||||
renderer.lutEnabled = enabled
|
||||
requestRender()
|
||||
}
|
||||
|
||||
fun setBaselineLutEnabled(enabled: Boolean) {
|
||||
renderer.baselineLutEnabled = enabled
|
||||
requestRender()
|
||||
@@ -304,27 +295,11 @@ class CameraGLSurfaceView @JvmOverloads constructor(
|
||||
*/
|
||||
fun isLutEnabled(): Boolean = renderer.lutEnabled
|
||||
|
||||
/**
|
||||
* 设置色彩配方是否启用
|
||||
*/
|
||||
fun setColorRecipeEnabled(enabled: Boolean) {
|
||||
renderer.colorRecipeEnabled = enabled
|
||||
requestRender()
|
||||
}
|
||||
|
||||
fun setBaselineColorRecipeEnabled(enabled: Boolean) {
|
||||
renderer.baselineColorRecipeEnabled = enabled
|
||||
requestRender()
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置参数
|
||||
*/
|
||||
fun setParams(params: ColorRecipeParams) {
|
||||
renderer.setRecipeParams(params)
|
||||
requestRender()
|
||||
}
|
||||
|
||||
fun setBaselineParams(params: ColorRecipeParams) {
|
||||
renderer.updateBaselineRecipeParams(params)
|
||||
requestRender()
|
||||
|
||||
@@ -309,19 +309,15 @@ fun CameraPreviewGL(
|
||||
}
|
||||
}
|
||||
}
|
||||
val colorRecipeEnabled = !colorRecipeParams.isDefault()
|
||||
val baselineColorRecipeEnabled = !baselineColorRecipeParams.isDefault()
|
||||
// 更新 LUT 设置
|
||||
glSurfaceView.setEnginePreview(enginePreviewPlan.value)
|
||||
glSurfaceView.setBaselineLut(baselineLut)
|
||||
glSurfaceView.setBaselineLutEnabled(baselineLut != null)
|
||||
glSurfaceView.setLut(currentLut)
|
||||
glSurfaceView.setLutEnabled(currentLut != null)
|
||||
glSurfaceView.setCreativeLook(currentLut, colorRecipeParams)
|
||||
glSurfaceView.setBaselineColorRecipeEnabled(baselineColorRecipeEnabled)
|
||||
glSurfaceView.setColorRecipeEnabled(colorRecipeEnabled)
|
||||
|
||||
glSurfaceView.setBaselineParams(baselineColorRecipeParams)
|
||||
glSurfaceView.setParams(colorRecipeParams)
|
||||
|
||||
glSurfaceView.setMeteringPoint((meteringPoint ?: focusPoint)?.takeIf {
|
||||
focusPointSource == FocusPointSource.MANUAL
|
||||
|
||||
@@ -262,9 +262,14 @@ fun CameraScreen(
|
||||
val focusPeakingEnabled by preferenceValue { it.focusPeakingEnabled }
|
||||
val eyeFocusEnabled by preferenceValue { it.eyeFocusEnabled }
|
||||
val keepScreenOn by preferenceValue { it.keepScreenOn }
|
||||
val currentLutId by viewModel.currentLutId.collectAsState()
|
||||
val lookSelection by viewModel.lutLookSelection.collectAsState()
|
||||
val currentLutId = lookSelection.lutId
|
||||
val presetLookSelected = lookSelection.presetRecipe != null
|
||||
val lutSwipeState = rememberLutSwipeState()
|
||||
val currentRecipeParams by viewModel.currentRecipeParams.collectAsState()
|
||||
val currentLutLook by viewModel.currentLutLook.collectAsState()
|
||||
val currentRecipeParams = currentLutLook.recipe
|
||||
val canEditCurrentLut = !presetLookSelected && !currentLutLook.fromPreset &&
|
||||
currentLutId != "none" && currentLutLook.id == currentLutId
|
||||
val lutSelectorMode by viewModel.lutSelectorMode.collectAsState()
|
||||
val activePresetId by preferenceValue { it.activePresetId }
|
||||
val activePresetModified by viewModel.isActivePresetModified.collectAsState()
|
||||
@@ -298,9 +303,12 @@ fun CameraScreen(
|
||||
val multipleExposureState = viewModel.multipleExposureState
|
||||
val canStartShutterAnimation by viewModel.canStartShutterAnimation.collectAsState()
|
||||
val currentCaptureModeForEffects by rememberUpdatedState(state.captureMode)
|
||||
var previewRecipeParamsOverride by remember(currentLutId, activePresetId) {
|
||||
var previewRecipeParamsOverride by remember(currentLutId, activePresetId, presetLookSelected) {
|
||||
mutableStateOf<ColorRecipeParams?>(null)
|
||||
}
|
||||
val previewRecipeParams = previewRecipeParamsOverride
|
||||
?.takeIf { canEditCurrentLut }
|
||||
?: currentRecipeParams
|
||||
var pendingCaptureAnimationBitmap by remember { mutableStateOf<Bitmap?>(null) }
|
||||
var captureAnimationJob by remember { mutableStateOf<Job?>(null) }
|
||||
var cameraScreenBounds by remember { mutableStateOf<Rect?>(null) }
|
||||
@@ -513,7 +521,7 @@ fun CameraScreen(
|
||||
processedBitmap = if (animationStyle == DevelopAnimationStyle.INSTANT_PRINT) {
|
||||
viewModel.renderCaptureAnimationFrame(bitmap, metadata)
|
||||
} else {
|
||||
viewModel.applyLut(bitmap)
|
||||
viewModel.applyCaptureLook(bitmap, metadata)
|
||||
}
|
||||
processedBitmap.copyForCaptureAnimation()?.let {
|
||||
captureAnimationSnapshot = CaptureAnimationSnapshot(
|
||||
@@ -1312,10 +1320,10 @@ fun CameraScreen(
|
||||
lensFacing = if (state.getCurrentCameraInfo()?.lensFacing == android.hardware.camera2.CameraCharacteristics.LENS_FACING_FRONT) 0 else 1,
|
||||
calibrationOffset = calibrationOffset,
|
||||
baselineLut = viewModel.currentBaselineLutConfig,
|
||||
currentLut = viewModel.currentLutConfig,
|
||||
currentLut = currentLutLook.config,
|
||||
enginePreviewPlan = viewModel.currentEnginePreviewPlan,
|
||||
baselineColorRecipeParams = currentBaselineRecipeParams,
|
||||
colorRecipeParams = previewRecipeParamsOverride ?: currentRecipeParams,
|
||||
colorRecipeParams = previewRecipeParams,
|
||||
focusPoint = state.focusPoint,
|
||||
meteringPoint = state.meteringPoint,
|
||||
canMoveMeteringPoint = state.supportsPointMetering &&
|
||||
@@ -1645,11 +1653,15 @@ fun CameraScreen(
|
||||
currentLutId = currentLutId,
|
||||
thumbnail = viewModel.previewThumbnail,
|
||||
presetThumbnailInput = viewModel.presetThumbnailInput,
|
||||
onLutSelected = { viewModel.setLut(it) },
|
||||
onLutSelected = {
|
||||
discardTransientLookEdits()
|
||||
viewModel.setLut(it)
|
||||
},
|
||||
allPresets = selectablePresets,
|
||||
presetModeEnabled = !isVideoLog,
|
||||
activePresetId = activePresetId,
|
||||
activePresetModified = activePresetModified,
|
||||
presetLookActive = presetLookSelected,
|
||||
selectedMode = if (isVideoLog) LutSelectorMode.Style else lutSelectorMode,
|
||||
onModeSelected = { viewModel.setLutSelectorMode(it) },
|
||||
availableFrames = viewModel.availableFrameList,
|
||||
@@ -1680,9 +1692,9 @@ fun CameraScreen(
|
||||
activePanel = ActivePanel.NONE
|
||||
onPresetManagementClick()
|
||||
},
|
||||
onEditClick = {
|
||||
activePanel = ActivePanel.EDIT
|
||||
},
|
||||
onEditClick = if (canEditCurrentLut) {
|
||||
{ activePanel = ActivePanel.EDIT }
|
||||
} else null,
|
||||
onManageClick = { lutId ->
|
||||
activePanel = ActivePanel.NONE
|
||||
onFilterManagementClick(lutId)
|
||||
@@ -1979,17 +1991,19 @@ fun CameraScreen(
|
||||
contentTopPadding = CameraTopBarBaseTopPadding + topSafePadding
|
||||
)
|
||||
|
||||
if (activePanel == ActivePanel.EDIT) {
|
||||
LutEditBottomSheet(
|
||||
lutId = currentLutId,
|
||||
initialParams = previewRecipeParamsOverride ?: currentRecipeParams,
|
||||
onParamsPreviewChange = { previewRecipeParamsOverride = it },
|
||||
showEffects = true,
|
||||
onDismiss = {
|
||||
previewRecipeParamsOverride = null
|
||||
activePanel = ActivePanel.FILTERS
|
||||
}
|
||||
)
|
||||
if (activePanel == ActivePanel.EDIT && canEditCurrentLut) {
|
||||
key(currentLutId) {
|
||||
LutEditBottomSheet(
|
||||
lutId = currentLutId,
|
||||
initialParams = previewRecipeParams,
|
||||
onParamsPreviewChange = { previewRecipeParamsOverride = it },
|
||||
showEffects = true,
|
||||
onDismiss = {
|
||||
previewRecipeParamsOverride = null
|
||||
activePanel = ActivePanel.FILTERS
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
captureAnimationSnapshot?.let { snapshot ->
|
||||
|
||||
@@ -89,7 +89,7 @@ fun ColorWalkScreen(
|
||||
value = viewModel.recommendLutsForColor(selectedColor.toArgb())
|
||||
}
|
||||
|
||||
val currentLutId by viewModel.currentLutId.collectAsState()
|
||||
val lookSelection by viewModel.lutLookSelection.collectAsState()
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
@@ -247,7 +247,7 @@ fun ColorWalkScreen(
|
||||
CompactLutRecommendationItem(
|
||||
lut = lut,
|
||||
color = selectedColor,
|
||||
isCurrent = currentLutId == lut.id,
|
||||
isCurrent = lookSelection.lutId == lut.id,
|
||||
onClick = {
|
||||
viewModel.setLut(lut.id)
|
||||
}
|
||||
|
||||
@@ -132,6 +132,7 @@ fun ColorRecipePanel(
|
||||
onEffectsChange: ((EffectParams) -> Unit)? = null,
|
||||
headerControls: (@Composable () -> Unit)? = null,
|
||||
containerShape: Shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp),
|
||||
onResetAll: (() -> Unit)? = null,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val isBakeable: (RecipeParam) -> Boolean = { param ->
|
||||
@@ -430,7 +431,7 @@ fun ColorRecipePanel(
|
||||
.height(30.dp)
|
||||
.clip(CircleShape)
|
||||
.background(Color.White.copy(alpha = 0.08f))
|
||||
.clickable { resetAllParams() }
|
||||
.clickable(onClick = onResetAll ?: ::resetAllParams)
|
||||
.padding(horizontal = 12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
||||
|
||||
@@ -196,7 +196,8 @@ fun LutSelector(
|
||||
presentation: LutSelectorPresentation = LutSelectorPresentation.Horizontal,
|
||||
onExpandedChange: (Boolean) -> Unit = {},
|
||||
presetThumbnailInput: com.hinnka.mycamera.lut.PresetThumbnailInput? = null,
|
||||
onEditPreset: ((String) -> Unit)? = null
|
||||
onEditPreset: ((String) -> Unit)? = null,
|
||||
presetLookActive: Boolean = false,
|
||||
) {
|
||||
val favoriteText = stringResource(R.string.favorite)
|
||||
val uncategorizedText = stringResource(R.string.uncategorized)
|
||||
@@ -209,6 +210,9 @@ fun LutSelector(
|
||||
}
|
||||
|
||||
val activeLutId = currentLutId
|
||||
val editActiveLut = onEditClick.takeIf {
|
||||
!presetLookActive && activeLutId != null && activeLutId != "none"
|
||||
}
|
||||
val supportsFrames = onFrameSelected != null
|
||||
val supportsPresets = presetModeEnabled
|
||||
val expanded = presentation == LutSelectorPresentation.Expanded
|
||||
@@ -256,15 +260,15 @@ fun LutSelector(
|
||||
isSelected = activeLutId == lut.id,
|
||||
isVip = lut.isVip,
|
||||
onClick = {
|
||||
if (activeLutId != lut.id) {
|
||||
if (activeLutId != lut.id || presetLookActive) {
|
||||
browsedCategory = selectedCategory
|
||||
onLutSelected(lut.id)
|
||||
} else if (presentation == LutSelectorPresentation.Horizontal || lut.id != "none") {
|
||||
onEditClick?.invoke()
|
||||
} else {
|
||||
editActiveLut?.invoke()
|
||||
}
|
||||
},
|
||||
onEditClick = onEditClick.takeIf {
|
||||
presentation != LutSelectorPresentation.Horizontal && activeLutId == lut.id && lut.id != "none"
|
||||
onEditClick = editActiveLut.takeIf {
|
||||
presentation != LutSelectorPresentation.Horizontal && activeLutId == lut.id
|
||||
},
|
||||
onManageClick = onManageClick?.let { manage ->
|
||||
{
|
||||
@@ -438,8 +442,10 @@ fun LutSelector(
|
||||
LutItem(
|
||||
id = lut.id, name = lut.getName(), previewBitmap = thumbnail,
|
||||
isSelected = selected, isVip = lut.isVip, thumbnailOnly = true,
|
||||
onClick = click,
|
||||
onEditClick = onEditClick.takeUnless { lut.id == "none" },
|
||||
onClick = if (selected && presetLookActive) {
|
||||
{ onLutSelected(lut.id) }
|
||||
} else click,
|
||||
onEditClick = editActiveLut,
|
||||
onManageClick = onManageClick?.let { manage -> { manage(lut.id) } },
|
||||
modifier = cardModifier
|
||||
)
|
||||
@@ -548,8 +554,8 @@ fun LutSelector(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
if (onEditClick != null && activeLutId != null) {
|
||||
LutEditButton(onClick = onEditClick)
|
||||
if (editActiveLut != null) {
|
||||
LutEditButton(onClick = editActiveLut)
|
||||
}
|
||||
|
||||
if (onManageClick != null) {
|
||||
|
||||
@@ -146,9 +146,7 @@ private data class PreviewRenderSignature(
|
||||
val photoId: String,
|
||||
val refreshKey: Long,
|
||||
val editLutId: String?,
|
||||
val editPhotoRecipeParams: ColorRecipeParams?,
|
||||
val editLutRecipeParams: ColorRecipeParams?,
|
||||
val editLutConfig: Any?,
|
||||
val recipeParams: ColorRecipeParams,
|
||||
val editFrameId: String?,
|
||||
val editFrameCustomProperties: Map<String, String>,
|
||||
val editSharpening: Float,
|
||||
@@ -244,13 +242,12 @@ fun GalleryEditScreen(
|
||||
val currentPhotos by viewModel.currentPhotos.collectAsState()
|
||||
val currentPhoto = currentPhotos.getOrNull(viewModel.currentPhotoIndex)
|
||||
val editSourcePhoto = currentPhoto?.relatedPhoto ?: currentPhoto
|
||||
val editLutId by viewModel.editLutId.collectAsState()
|
||||
val editLook by viewModel.editLook.collectAsState()
|
||||
val editLutId = editLook.lutId
|
||||
val effectiveRecipe = editLook.recipe
|
||||
val activeColorMatchReferenceId by produceState<String?>(null, editLutId) {
|
||||
value = viewModel.aiColorMatchReferenceId(editLutId)
|
||||
}
|
||||
val editLutRecipeParams by viewModel.editLutRecipeParams.collectAsState()
|
||||
val editPhotoRecipeParams by viewModel.editPhotoRecipeParams.collectAsState()
|
||||
val editLutConfig = viewModel.editLutConfig
|
||||
val availableLuts = viewModel.selectableEditLuts
|
||||
val videoSourceProfile = viewModel.editVideoSourceProfile
|
||||
val lutSwipeState = rememberLutSwipeState()
|
||||
@@ -426,13 +423,12 @@ fun GalleryEditScreen(
|
||||
fun currentPreviewSignature(fast: Boolean = false): PreviewRenderSignature? {
|
||||
val photo = editSourcePhoto ?: return null
|
||||
val rawDevelopIsBaked = isRaw
|
||||
val look = editLook
|
||||
return PreviewRenderSignature(
|
||||
photoId = photo.id,
|
||||
refreshKey = refreshKey,
|
||||
editLutId = editLutId,
|
||||
editPhotoRecipeParams = editPhotoRecipeParams,
|
||||
editLutRecipeParams = editLutRecipeParams,
|
||||
editLutConfig = editLutConfig,
|
||||
editLutId = look.lutId,
|
||||
recipeParams = look.recipe,
|
||||
editFrameId = editFrameId,
|
||||
editFrameCustomProperties = editFrameCustomProperties.toMap(),
|
||||
editSharpening = if (rawDevelopIsBaked) 0f else editSharpening,
|
||||
@@ -959,7 +955,7 @@ fun GalleryEditScreen(
|
||||
val nextLut = viewModel.peekNextLut()
|
||||
// 先确认以横向为主,竖向/斜向手势不触发切换
|
||||
val horizontal = abs(dx) > abs(dy) * 1.5f
|
||||
if (horizontal && nextLut != null && nextLut.id != editLutId) {
|
||||
if (horizontal && nextLut != null && nextLut.id != (editLook.lutId ?: "none")) {
|
||||
swipeTracking = true
|
||||
lutSwipeState.begin(
|
||||
width = size.width,
|
||||
@@ -1087,8 +1083,9 @@ fun GalleryEditScreen(
|
||||
if (videoSourceProfile != null) {
|
||||
VideoEditPlayer(
|
||||
photo = currentPhoto,
|
||||
lutConfig = if (showOrigin) null else editLutConfig,
|
||||
recipeParams = if (showOrigin) null else (editPhotoRecipeParams ?: editLutRecipeParams),
|
||||
lutConfig = if (showOrigin) null else editLook.lutConfig,
|
||||
recipeParams = if (showOrigin) null else effectiveRecipe,
|
||||
updateLook = showOrigin || !editLook.isLutConfigLoading,
|
||||
sourceLogProfile = videoSourceProfile,
|
||||
modifier = previewMediaModifier
|
||||
)
|
||||
@@ -1573,11 +1570,9 @@ fun GalleryEditScreen(
|
||||
onProfileSelected = viewModel::selectEditVideoSourceProfile,
|
||||
)
|
||||
}
|
||||
val effectiveRecipe =
|
||||
editPhotoRecipeParams ?: editLutRecipeParams
|
||||
LutSelector(
|
||||
availableLuts = availableLuts,
|
||||
currentLutId = editLutId,
|
||||
currentLutId = editLutId ?: "none",
|
||||
thumbnail = thumbnailBitmap.takeUnless { videoSourceProfile?.isEnabled == true },
|
||||
onLutSelected = { viewModel.setEditLut(it) },
|
||||
onManageClick = { onFilterManagementClick(it) },
|
||||
@@ -1614,12 +1609,9 @@ fun GalleryEditScreen(
|
||||
LutIntensitySlider(
|
||||
intensity = effectiveRecipe.lutIntensity,
|
||||
onIntensityChange = { intensity ->
|
||||
viewModel.setPhotoRecipeParams(
|
||||
RecipeParam.LUT_INTENSITY.setValue(
|
||||
effectiveRecipe,
|
||||
intensity
|
||||
)
|
||||
)
|
||||
viewModel.updatePhotoRecipeParams { current ->
|
||||
RecipeParam.LUT_INTENSITY.setValue(current, intensity)
|
||||
}
|
||||
},
|
||||
enabled = editLutId != null,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
@@ -1703,55 +1695,52 @@ fun GalleryEditScreen(
|
||||
}
|
||||
EDIT_TAB_ADJUSTMENTS -> {
|
||||
Spacer(modifier = Modifier.height(6.dp))
|
||||
val effectiveRecipe = editPhotoRecipeParams ?: editLutRecipeParams
|
||||
val applyEffectsToVideo by viewModel.editApplyEffectsToVideo.collectAsState()
|
||||
val canSyncAdjustmentsToLut = editLutId != null && !PhotoColorMatch.isId(editLutId)
|
||||
|
||||
ColorRecipePanel(
|
||||
currentParams = effectiveRecipe,
|
||||
onParamChange = { param, value ->
|
||||
viewModel.setPhotoRecipeParams(
|
||||
param.setValue(effectiveRecipe, value)
|
||||
)
|
||||
viewModel.updatePhotoRecipeParams { current ->
|
||||
param.setValue(current, value)
|
||||
}
|
||||
},
|
||||
onParamsChange = { params ->
|
||||
viewModel.setPhotoRecipeParams(
|
||||
params
|
||||
)
|
||||
viewModel.updatePhotoRecipeParams(displayed = effectiveRecipe, params = params)
|
||||
},
|
||||
onRemarksChange = { remarks ->
|
||||
viewModel.setPhotoRecipeParams(
|
||||
effectiveRecipe.copy(remarks = remarks)
|
||||
)
|
||||
viewModel.updatePhotoRecipeParams { current ->
|
||||
current.copy(remarks = remarks)
|
||||
}
|
||||
},
|
||||
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.updatePhotoRecipeParams { current ->
|
||||
when (channel) {
|
||||
CurveChannel.MASTER -> current.copy(masterCurvePoints = points)
|
||||
CurveChannel.RED -> current.copy(redCurvePoints = points)
|
||||
CurveChannel.GREEN -> current.copy(greenCurvePoints = points)
|
||||
CurveChannel.BLUE -> current.copy(blueCurvePoints = points)
|
||||
}
|
||||
}
|
||||
viewModel.setPhotoRecipeParams(
|
||||
updated
|
||||
)
|
||||
},
|
||||
onResetAll = viewModel::resetPhotoRecipeParams,
|
||||
imageHistogram = imageHistogram,
|
||||
currentEffects = effectiveRecipe.toEffectParams(),
|
||||
onEffectsChange = { effects ->
|
||||
val latestRecipe = viewModel.editPhotoRecipeParams.value
|
||||
?: viewModel.editLutRecipeParams.value
|
||||
viewModel.setPhotoRecipeParams(
|
||||
effects.applyTo(latestRecipe)
|
||||
viewModel.updatePhotoRecipeParams(
|
||||
displayed = effectiveRecipe,
|
||||
params = effects.applyTo(effectiveRecipe)
|
||||
)
|
||||
},
|
||||
headerControls = if (
|
||||
editLutId != null || currentPhoto.isMotionPhoto
|
||||
canSyncAdjustmentsToLut || currentPhoto.isMotionPhoto
|
||||
) {
|
||||
{
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
if (editLutId != null) {
|
||||
if (canSyncAdjustmentsToLut) {
|
||||
CompactToggleChip(
|
||||
title = stringResource(
|
||||
R.string.edit_sync_lut_recipe
|
||||
@@ -2678,6 +2667,7 @@ private fun VideoEditPlayer(
|
||||
photo: MediaData,
|
||||
lutConfig: LutConfig?,
|
||||
recipeParams: ColorRecipeParams?,
|
||||
updateLook: Boolean,
|
||||
sourceLogProfile: VideoLogProfile,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
@@ -2688,24 +2678,26 @@ private fun VideoEditPlayer(
|
||||
|
||||
PLog.d("VideoEditPlayer", "VideoEditPlayer composable recomposing/initializing. photoId: ${photo.id}, mediaUri: $mediaUri")
|
||||
|
||||
var isPlayerActive by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(photo.id) {
|
||||
var isPlayerActive by remember(photo.id, mediaUri, sourceLogProfile) { mutableStateOf(false) }
|
||||
LaunchedEffect(photo.id, mediaUri, sourceLogProfile, updateLook) {
|
||||
if (isPlayerActive || !updateLook) return@LaunchedEffect
|
||||
delay(150) // Wait for the transitions to complete and EGL context release
|
||||
isPlayerActive = true
|
||||
}
|
||||
|
||||
val videoLutEffect = remember(photo.id, mediaUri, sourceLogProfile) {
|
||||
val videoLutEffect = remember(photo.id, mediaUri, sourceLogProfile, isPlayerActive) {
|
||||
if (!isPlayerActive) return@remember null
|
||||
PLog.d("VideoEditPlayer", "Instantiating new VideoLutEffect.")
|
||||
VideoLutEffect(lutConfig, recipeParams, sourceLogProfile)
|
||||
}
|
||||
|
||||
val exoPlayer = remember(photo.id, mediaUri, isPlayerActive, videoLutEffect) {
|
||||
if (!isPlayerActive) return@remember null
|
||||
val exoPlayer = remember(videoLutEffect) {
|
||||
val effect = videoLutEffect ?: return@remember null
|
||||
PLog.d("VideoEditPlayer", "Re-creating loopable ExoPlayer instance for video preview.")
|
||||
ExoPlayer.Builder(context, VideoEditRenderersFactory(context, sourceLogProfile.isEnabled)).build().apply {
|
||||
setMediaItem(MediaItem.fromUri(mediaUri))
|
||||
repeatMode = Player.REPEAT_MODE_ONE
|
||||
setVideoEffects(listOf(videoLutEffect))
|
||||
setVideoEffects(listOf(effect))
|
||||
prepare()
|
||||
playWhenReady = true
|
||||
|
||||
@@ -2720,7 +2712,8 @@ private fun VideoEditPlayer(
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(lutConfig, recipeParams, exoPlayer) {
|
||||
LaunchedEffect(lutConfig, recipeParams, updateLook, exoPlayer) {
|
||||
if (!updateLook || videoLutEffect == null) return@LaunchedEffect
|
||||
PLog.d("VideoEditPlayer", "Updating VideoLutEffect with lutConfig: ${lutConfig?.title}, recipeParams: ${recipeParams != null}")
|
||||
videoLutEffect.update(lutConfig, recipeParams)
|
||||
|
||||
|
||||
@@ -263,7 +263,7 @@ fun PresetEditorScreen(
|
||||
SettingsSection(title = stringResource(R.string.filter), isExpandable = false) {
|
||||
LutSelector(
|
||||
availableLuts = availableLuts,
|
||||
currentLutId = selectedLutId,
|
||||
currentLutId = selectedLutId ?: "none",
|
||||
thumbnail = null,
|
||||
onLutSelected = { selectedLutId = it },
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
@@ -298,7 +298,7 @@ fun PresetEditorScreen(
|
||||
}
|
||||
},
|
||||
hideNonBakeable = true,
|
||||
showLutIntensity = true,
|
||||
showLutIntensity = selectedLutId != null && selectedLutId != "none",
|
||||
currentEffects = effects,
|
||||
onEffectsChange = { effects = it },
|
||||
containerShape = RoundedCornerShape(12.dp),
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.hinnka.mycamera.frame.FramePreviewFactory
|
||||
import com.hinnka.mycamera.frame.FramePreviewSelection
|
||||
import com.hinnka.mycamera.gallery.GalleryManager
|
||||
import com.hinnka.mycamera.gallery.MediaMetadata
|
||||
import com.hinnka.mycamera.gallery.PhotoColorRecipeEdits
|
||||
import com.hinnka.mycamera.gallery.PhotoSavePath
|
||||
import com.hinnka.mycamera.lut.BaselineColorCorrectionTarget
|
||||
import com.hinnka.mycamera.lut.BakedLutExporter
|
||||
@@ -142,6 +143,7 @@ private data class CaptureSettingsSnapshot(
|
||||
val lutId: String,
|
||||
val frameId: String?,
|
||||
val recipe: ColorRecipeParams,
|
||||
val photoColorRecipeEdits: String?,
|
||||
val cameraId: String,
|
||||
val sensorOrientation: Int,
|
||||
val lensFacing: Int,
|
||||
@@ -521,9 +523,7 @@ internal fun resolveLutIdForCaptureMode(
|
||||
|
||||
private data class CameraFeatureUpdate(
|
||||
val captureMode: SettingValue<CaptureMode>? = null,
|
||||
val lutId: String? = null, // null leaves the selection unchanged; "none" explicitly disables the LUT.
|
||||
val colorRecipe: SettingValue<ColorRecipeParams>? = null,
|
||||
val effects: SettingValue<EffectParams>? = null,
|
||||
val preset: SettingValue<CameraPreset?>? = null,
|
||||
val aspectRatio: SettingValue<AspectRatio>? = null,
|
||||
val useRaw: SettingValue<Boolean>? = null,
|
||||
val useJpgMax: SettingValue<Boolean>? = null,
|
||||
@@ -561,10 +561,32 @@ private data class CameraFeatureUpdate(
|
||||
val rawFotufilmDocument: SettingValue<FotufilmDocument?>? = null,
|
||||
val droMode: SettingValue<String>? = null,
|
||||
val rawBaselineLutId: SettingValue<String?>? = null,
|
||||
val activePresetId: SettingValue<String?>? = null,
|
||||
val useMultipleExposure: SettingValue<Boolean>? = null,
|
||||
)
|
||||
|
||||
internal data class CameraLookSelection(
|
||||
val lutId: String,
|
||||
val presetRecipe: ColorRecipeParams? = null,
|
||||
) {
|
||||
companion object {
|
||||
val None = CameraLookSelection("none")
|
||||
}
|
||||
}
|
||||
|
||||
data class CameraLutLook(
|
||||
val id: String,
|
||||
val config: LutConfig?,
|
||||
val recipe: ColorRecipeParams,
|
||||
val fromPreset: Boolean = false,
|
||||
) {
|
||||
companion object {
|
||||
val None = CameraLutLook("none", null, ColorRecipeParams.DEFAULT)
|
||||
}
|
||||
}
|
||||
|
||||
private fun CameraLutLook.photoColorRecipeEdits(): String? =
|
||||
if (id == "none" && fromPreset) PhotoColorRecipeEdits(base = recipe).toJson() else null
|
||||
|
||||
/**
|
||||
* 相机 ViewModel
|
||||
* 使用 Camera2Controller 支持隐藏摄像头
|
||||
@@ -650,9 +672,9 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
private val _canStartShutterAnimation = MutableStateFlow(false)
|
||||
val canStartShutterAnimation = _canStartShutterAnimation.asStateFlow()
|
||||
|
||||
// LUT 相关状态
|
||||
var currentLutConfig: LutConfig? by mutableStateOf(null)
|
||||
private set
|
||||
// 预览和拍摄使用同一个已加载快照,直到新 LUT 和配方都已就绪。
|
||||
private val _currentLutLook = MutableStateFlow(CameraLutLook.None)
|
||||
val currentLutLook = _currentLutLook.asStateFlow()
|
||||
|
||||
var currentBaselineLutConfig: LutConfig? by mutableStateOf(null)
|
||||
private set
|
||||
@@ -660,21 +682,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
private val _currentEnginePreviewPlan = MutableStateFlow<RawEnginePreviewPlan?>(null)
|
||||
val currentEnginePreviewPlan = _currentEnginePreviewPlan.asStateFlow()
|
||||
|
||||
var currentLutId = MutableStateFlow("standard")
|
||||
private set
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
val currentRecipeParams: StateFlow<ColorRecipeParams> = currentLutId.flatMapLatest { id ->
|
||||
contentRepository.lutManager.getColorRecipeParams(id)
|
||||
}.stateIn(
|
||||
scope = viewModelScope,
|
||||
started = SharingStarted.Eagerly,
|
||||
initialValue = ColorRecipeParams.DEFAULT
|
||||
)
|
||||
|
||||
val currentEffectParams: StateFlow<EffectParams> = currentRecipeParams
|
||||
.map { it.toEffectParams() }
|
||||
.stateIn(viewModelScope, SharingStarted.Eagerly, EffectParams.DEFAULT)
|
||||
private val _lutLookSelection = MutableStateFlow(CameraLookSelection("standard"))
|
||||
internal val lutLookSelection = _lutLookSelection.asStateFlow()
|
||||
|
||||
// 合并内置预设与用户自定义预设
|
||||
val allPresets: StateFlow<List<com.hinnka.mycamera.model.CameraPreset>> = userPreferencesRepository.userPreferences
|
||||
@@ -762,21 +771,17 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
if (initialized) prefs to presets else null
|
||||
},
|
||||
state.map { it.aspectRatio.name to it.isProfessionalMode }.distinctUntilChanged(),
|
||||
currentLutId.flatMapLatest { lutId ->
|
||||
contentRepository.lutManager.getColorRecipeParams(lutId).map { recipe ->
|
||||
lutId to recipe
|
||||
}
|
||||
}
|
||||
) { inputs, (aspectRatio, isProfessionalMode), (lutId, recipe) ->
|
||||
currentLutLook
|
||||
) { inputs, (aspectRatio, isProfessionalMode), look ->
|
||||
inputs?.let { (prefs, presets) ->
|
||||
ActivePresetMatchState(
|
||||
prefs = prefs,
|
||||
presets = presets,
|
||||
isProfessionalMode = isProfessionalMode,
|
||||
aspectRatio = aspectRatio,
|
||||
lutId = lutId,
|
||||
recipe = recipe,
|
||||
effects = recipe.toEffectParams()
|
||||
lutId = look.id,
|
||||
recipe = look.recipe,
|
||||
effects = look.recipe.toEffectParams()
|
||||
)
|
||||
}
|
||||
}.stateIn(viewModelScope, SharingStarted.Eagerly, null)
|
||||
@@ -806,11 +811,10 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
var draftPreset: com.hinnka.mycamera.model.CameraPreset? = null
|
||||
|
||||
private val presetApplyMutex = Mutex()
|
||||
private val cameraLookMutex = Mutex()
|
||||
private val presetMutationMutex = Mutex()
|
||||
private var presetApplyGeneration = 0L
|
||||
private var lutLoadJob: Job? = null
|
||||
private var lutLoadGeneration = 0L
|
||||
private var shootingModeSwitchJob: Job? = null
|
||||
|
||||
fun prepareCurrentSettingsPresetDraft(name: String): com.hinnka.mycamera.model.CameraPreset {
|
||||
@@ -828,12 +832,13 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
name: String,
|
||||
isBuiltIn: Boolean
|
||||
): com.hinnka.mycamera.model.CameraPreset {
|
||||
val look = currentLutLook.value
|
||||
return com.hinnka.mycamera.model.CameraPreset(
|
||||
id = id,
|
||||
name = name,
|
||||
lutId = CameraPreset.normalizeLutId(currentLutId.value),
|
||||
colorRecipe = currentRecipeParams.value.withoutIndependentEffects(),
|
||||
effects = currentRecipeParams.value.toEffectParams(),
|
||||
lutId = CameraPreset.normalizeLutId(look.id),
|
||||
colorRecipe = look.recipe.withoutIndependentEffects(),
|
||||
effects = look.recipe.toEffectParams(),
|
||||
aspectRatio = state.value.aspectRatio.name,
|
||||
ultraHdrGainMapEnabled = userPreferencesRepository.current.ultraHdrGainMapEnabled,
|
||||
frameId = currentFrameId,
|
||||
@@ -874,17 +879,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
)
|
||||
}
|
||||
|
||||
fun getMergedRecipeParams(recipe: ColorRecipeParams = currentRecipeParams.value): ColorRecipeParams {
|
||||
return recipe
|
||||
}
|
||||
|
||||
fun applyPreset(preset: com.hinnka.mycamera.model.CameraPreset?) {
|
||||
val applyGeneration = ++presetApplyGeneration
|
||||
presetApplyInProgress.value = true
|
||||
viewModelScope.launch {
|
||||
var applied = false
|
||||
try {
|
||||
presetApplyMutex.withLock {
|
||||
cameraLookMutex.withLock {
|
||||
if (presetApplyGeneration != applyGeneration) {
|
||||
return@withLock
|
||||
}
|
||||
@@ -901,17 +901,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
preset.toCameraFeatureUpdate(
|
||||
includePhotoSettings = includePhotoSettings,
|
||||
includeProfessionalSettings = includeProfessionalSettings
|
||||
).copy(activePresetId = SettingValue(preset?.id))
|
||||
)
|
||||
)
|
||||
applied = true
|
||||
}
|
||||
|
||||
if (applied && presetApplyGeneration == applyGeneration) {
|
||||
activePresetMatchState.filterNotNull().first { matchState ->
|
||||
(preset != null && !preset.isAvailableInMode(matchState.isProfessionalMode)) ||
|
||||
(matchState.prefs.activePresetId == preset?.id &&
|
||||
(preset == null || matchState.toPresetMatchSnapshot().matches(preset)))
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (presetApplyGeneration == applyGeneration) {
|
||||
@@ -936,9 +927,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
null
|
||||
}
|
||||
val sharedUpdate = CameraFeatureUpdate(
|
||||
lutId = CameraPreset.normalizeLutId(this?.lutId) ?: "none",
|
||||
colorRecipe = SettingValue(this?.colorRecipe ?: ColorRecipeParams.DEFAULT),
|
||||
effects = SettingValue(this?.effects ?: EffectParams.DEFAULT),
|
||||
preset = SettingValue(this),
|
||||
aspectRatio = ratio?.let(::SettingValue),
|
||||
frameId = SettingValue(this?.frameId)
|
||||
)
|
||||
@@ -1055,15 +1044,14 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
desiredUseRaw != prefs.useRaw ||
|
||||
desiredMultiFrameOutputScale != currentState.multiFrameOutputScale
|
||||
|
||||
update.colorRecipe?.let {
|
||||
val recipeLutId = update.lutId ?: currentLutId.value
|
||||
val recipeWithEffects = update.effects?.value?.applyTo(it.value) ?: it.value
|
||||
contentRepository.lutManager.saveColorRecipeParams(recipeLutId, recipeWithEffects)
|
||||
}
|
||||
|
||||
update.lutId?.let {
|
||||
setLut(it, persist = false)
|
||||
val preset = update.preset?.value
|
||||
val presetLook = update.preset?.let {
|
||||
CameraLookSelection(
|
||||
lutId = CameraPreset.normalizeLutId(preset?.lutId) ?: "none",
|
||||
presetRecipe = preset?.let { it.effects.applyTo(it.colorRecipe) },
|
||||
)
|
||||
}
|
||||
val presetLoadJob = presetLook?.let(::applyLut)
|
||||
|
||||
update.aspectRatio?.let {
|
||||
cameraController.setAspectRatio(it.value)
|
||||
@@ -1102,7 +1090,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
// Photo mode disables the active Log profile without clearing the saved selection.
|
||||
cameraController.setVideoLogProfile(prefs.videoLogProfile)
|
||||
}
|
||||
resolveLutIdForMode(prefs, targetCaptureMode)?.let(::applyLut)
|
||||
resolveLookForMode(prefs, targetCaptureMode)?.let(::applyLut)
|
||||
currentSurfaceTexture = null
|
||||
cameraController.closeCamera()
|
||||
}
|
||||
@@ -1167,10 +1155,18 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
userPreferencesRepository.update {
|
||||
update.captureMode?.let { captureMode = it.value }
|
||||
update.lutId?.let {
|
||||
if (persistLutInVideoSlot) videoLutId = it else lutId = it
|
||||
presetLook?.let { look ->
|
||||
photoPresetRecipe = null
|
||||
videoPresetRecipe = null
|
||||
if (persistLutInVideoSlot) {
|
||||
videoLutId = look.lutId
|
||||
videoPresetRecipe = look.presetRecipe
|
||||
} else {
|
||||
lutId = look.lutId
|
||||
photoPresetRecipe = look.presetRecipe
|
||||
}
|
||||
activePresetId = preset?.id
|
||||
}
|
||||
update.effects?.let { activeEffectParams = it.value }
|
||||
update.aspectRatio?.let { aspectRatio = it.value.name }
|
||||
if (update.useRaw != null || desiredUseRaw != prefs.useRaw) useRaw = desiredUseRaw
|
||||
if (update.useJpgMax != null || desiredUseJpgMax != prefs.useJpgMax) useJpgMax = desiredUseJpgMax
|
||||
@@ -1209,15 +1205,15 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawBaselineLutId = it.value
|
||||
rawBaselineLutConfigured = true
|
||||
}
|
||||
update.activePresetId?.let { activePresetId = it.value }
|
||||
}
|
||||
if (update.lutId != null && !persistLutInVideoSlot) {
|
||||
if (presetLook != null) {
|
||||
PhotonLookContract.notifyLookChanged(getApplication<Application>())
|
||||
}
|
||||
|
||||
if (reconfigureCameraIfNeeded && needsCameraReopen && !captureModeWillChange) {
|
||||
reopenCamera()
|
||||
}
|
||||
presetLoadJob?.join()
|
||||
}
|
||||
|
||||
private fun resolveCaptureRawRenderingEngine(userPrefs: UserPreferences?): RawRenderingEngine {
|
||||
@@ -1326,8 +1322,16 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
if (userPreferencesRepository.current.activePresetId == presetId) {
|
||||
userPreferencesRepository.update { activePresetId = null }
|
||||
cameraLookMutex.withLock {
|
||||
if (userPreferencesRepository.latest().activePresetId == presetId) {
|
||||
userPreferencesRepository.update {
|
||||
activePresetId = null
|
||||
photoPresetRecipe = null
|
||||
videoPresetRecipe = null
|
||||
}
|
||||
resolveLookForMode(userPreferencesRepository.latest(), state.value.captureMode)?.let(::applyLut)
|
||||
PhotonLookContract.notifyLookChanged(getApplication<Application>())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2155,9 +2159,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
cameraController.setMeteringMode(prefs.meteringMode)
|
||||
|
||||
// 根据启动时的拍摄模式应用照片 LUT 或独立的视频 LUT。
|
||||
resolveLutIdForMode(prefs, prefs.captureMode)?.let {
|
||||
setLut(it, persist = false)
|
||||
}
|
||||
resolveLookForMode(prefs, prefs.captureMode)?.let(::applyLut)
|
||||
|
||||
// 应用保存的边框配置
|
||||
if (prefs.frameId != null) {
|
||||
@@ -2192,7 +2194,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
} else {
|
||||
// 如果没有任何偏好设置,使用配置文件中的默认 LUT(第一个)
|
||||
val defaultLut = availableLutList.firstOrNull { it.isDefault }
|
||||
defaultLut?.let { setLut(it.id, persist = false) }
|
||||
defaultLut?.let { applyLut(CameraLookSelection(it.id)) }
|
||||
}
|
||||
|
||||
_isInitialized.value = true
|
||||
@@ -2203,7 +2205,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
viewModelScope.launch {
|
||||
state.collect { currentState ->
|
||||
if (currentState.captureMode == CaptureMode.VIDEO) {
|
||||
validateAndCancelNonMatchingVideoLut(currentState.videoConfig.logProfile, currentLutConfig)
|
||||
validateAndCancelNonMatchingVideoLut(currentState.videoConfig.logProfile)
|
||||
}
|
||||
glSurfaceView?.let { view ->
|
||||
view.setVideoLogProfile(currentState.videoConfig.logProfile)
|
||||
@@ -2686,37 +2688,16 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
|
||||
private fun restorePreviewLutAfterResume() {
|
||||
val lutId = currentLutId.value
|
||||
val loadGeneration = lutLoadGeneration
|
||||
PLog.d(TAG, "restorePreviewLutAfterResume: lutId=$lutId")
|
||||
viewModelScope.launch {
|
||||
val candidateLut = withContext(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadLut(lutId)
|
||||
}
|
||||
if (currentLutId.value != lutId || lutLoadGeneration != loadGeneration) {
|
||||
return@launch
|
||||
}
|
||||
val profile = state.value.videoConfig.logProfile
|
||||
val loadedLut = candidateLut?.takeIf {
|
||||
state.value.captureMode != CaptureMode.VIDEO || profile.matchesLut(it.curve, it.colorSpace)
|
||||
}
|
||||
if (candidateLut != null && loadedLut == null) applyLut("none")
|
||||
currentLutConfig = loadedLut
|
||||
cameraController.setLutEnabled(loadedLut != null)
|
||||
cameraController.setLogLutActive(loadedLut?.curve?.isLog == true)
|
||||
glSurfaceView?.let { view ->
|
||||
val currentState = state.value
|
||||
view.setEnginePreview(currentEnginePreviewPlan.value)
|
||||
view.setBaselineLut(currentBaselineLutConfig)
|
||||
view.setBaselineLutEnabled(currentBaselineLutConfig != null)
|
||||
view.setBaselineParams(currentBaselineRecipeParams.value)
|
||||
view.setLut(loadedLut)
|
||||
view.setLutEnabled(loadedLut != null)
|
||||
view.setParams(currentRecipeParams.value)
|
||||
view.setColorRecipeEnabled(!currentRecipeParams.value.isDefault())
|
||||
view.setVideoLogProfile(currentState.videoConfig.logProfile)
|
||||
view.restoreRenderStateAfterResume()
|
||||
}
|
||||
updateLut(reload = true)
|
||||
val look = currentLutLook.value
|
||||
glSurfaceView?.let { view ->
|
||||
view.setEnginePreview(currentEnginePreviewPlan.value)
|
||||
view.setBaselineLut(currentBaselineLutConfig)
|
||||
view.setBaselineLutEnabled(currentBaselineLutConfig != null)
|
||||
view.setBaselineParams(currentBaselineRecipeParams.value)
|
||||
view.setCreativeLook(look.config, look.recipe)
|
||||
view.setVideoLogProfile(state.value.videoConfig.logProfile)
|
||||
view.restoreRenderStateAfterResume()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2770,6 +2751,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
lutId = lutIdToSave,
|
||||
frameId = frameIdToSave,
|
||||
colorRecipeParams = settings.recipe,
|
||||
photoColorRecipeEdits = settings.photoColorRecipeEdits,
|
||||
baselineTarget = baselineMetadata?.first,
|
||||
baselineLutId = baselineMetadata?.second,
|
||||
baselineColorRecipeParams = baselineMetadata?.third,
|
||||
@@ -3091,12 +3073,13 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
cameraController.stopVideoRecording()
|
||||
} else {
|
||||
val currentState = state.value
|
||||
val look = currentLutLook.value
|
||||
val orientationOffset = userPreferences.value.cameraOrientationOffsets[
|
||||
currentState.currentCameraId
|
||||
] ?: 0
|
||||
cameraController.startVideoRecording(
|
||||
creativeLutConfig = currentLutConfig.takeIf { currentState.lutEnabled },
|
||||
creativeRecipeParams = getMergedRecipeParams(),
|
||||
creativeLutConfig = look.config.takeIf { currentState.lutEnabled },
|
||||
creativeRecipeParams = look.recipe,
|
||||
orientationOffsetDegrees = orientationOffset
|
||||
)
|
||||
}
|
||||
@@ -3118,7 +3101,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
val timerSeconds = state.value.timerSeconds
|
||||
|
||||
// 检查 VIP 权限
|
||||
val currentLut = getLutInfo(currentLutId.value)
|
||||
val currentLut = getLutInfo(currentLutLook.value.id)
|
||||
if (currentLut?.isVip == true && !isPurchased.value) {
|
||||
showPaymentDialog = true
|
||||
return
|
||||
@@ -3140,20 +3123,24 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
private fun snapshotCaptureSettings() = CaptureSettingsSnapshot(
|
||||
state = state.value,
|
||||
preferences = userPreferencesRepository.current,
|
||||
lutId = currentLutId.value,
|
||||
frameId = currentFrameId,
|
||||
recipe = getMergedRecipeParams(),
|
||||
cameraId = cameraController.getCurrentCameraId(),
|
||||
sensorOrientation = cameraController.getSensorOrientation(),
|
||||
lensFacing = cameraController.getLensFacing(),
|
||||
deviceRotation = OrientationObserver.captureRotationDegrees.toInt(),
|
||||
blackBorderCrop = currentRawBlackBorderCrop(),
|
||||
portraitMask = capturePortraitMaskSnapshot(),
|
||||
multipleExposure = multipleExposureState.enabled,
|
||||
)
|
||||
private fun snapshotCaptureSettings(): CaptureSettingsSnapshot {
|
||||
val look = currentLutLook.value
|
||||
return CaptureSettingsSnapshot(
|
||||
state = state.value,
|
||||
preferences = userPreferencesRepository.current,
|
||||
lutId = look.id,
|
||||
frameId = currentFrameId,
|
||||
recipe = look.recipe,
|
||||
photoColorRecipeEdits = look.photoColorRecipeEdits(),
|
||||
cameraId = cameraController.getCurrentCameraId(),
|
||||
sensorOrientation = cameraController.getSensorOrientation(),
|
||||
lensFacing = cameraController.getLensFacing(),
|
||||
deviceRotation = OrientationObserver.captureRotationDegrees.toInt(),
|
||||
blackBorderCrop = currentRawBlackBorderCrop(),
|
||||
portraitMask = capturePortraitMaskSnapshot(),
|
||||
multipleExposure = multipleExposureState.enabled,
|
||||
)
|
||||
}
|
||||
|
||||
private fun submitPhotoCapture() {
|
||||
val settings = snapshotCaptureSettings()
|
||||
@@ -3321,11 +3308,11 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
vibrationHelper.vibrate()
|
||||
}
|
||||
|
||||
val capturedLutId = currentLutId.value
|
||||
val look = currentLutLook.value
|
||||
glSurfaceView?.capturePreviewFrame { bitmap ->
|
||||
contentRepository.recordLutCapture(capturedLutId)
|
||||
contentRepository.recordLutCapture(look.id)
|
||||
viewModelScope.launch {
|
||||
saveVideoSnapshot(bitmap)
|
||||
saveVideoSnapshot(bitmap, look)
|
||||
}
|
||||
} ?: PLog.w(TAG, "captureVideoFrame skipped: glSurfaceView unavailable")
|
||||
}
|
||||
@@ -3597,12 +3584,14 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
if (state.value.captureMode == mode && !rawNeedsUpdate) return
|
||||
|
||||
shootingModeSwitchJob = viewModelScope.launch {
|
||||
applyCameraFeatureUpdate(
|
||||
CameraFeatureUpdate(
|
||||
captureMode = SettingValue(mode),
|
||||
useRaw = useRaw?.let(::SettingValue),
|
||||
cameraLookMutex.withLock {
|
||||
applyCameraFeatureUpdate(
|
||||
CameraFeatureUpdate(
|
||||
captureMode = SettingValue(mode),
|
||||
useRaw = useRaw?.let(::SettingValue),
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3690,7 +3679,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.update { videoLogProfile = logProfile }
|
||||
}
|
||||
validateAndCancelNonMatchingVideoLut(logProfile, currentLutConfig)
|
||||
validateAndCancelNonMatchingVideoLut(logProfile)
|
||||
}
|
||||
|
||||
fun setVideoLogLutMode(mode: VideoLogLutMode) {
|
||||
@@ -3703,12 +3692,13 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
* 验证并取消选择非匹配的视频 LUT
|
||||
* 如果当前处于视频模式且启用了 Log,若当前选中的 LUT 与 Log 格式不匹配,则取消该 LUT
|
||||
*/
|
||||
private fun validateAndCancelNonMatchingVideoLut(logProfile: VideoLogProfile, lutConfig: LutConfig?) {
|
||||
if (logProfile != VideoLogProfile.OFF && lutConfig != null) {
|
||||
if (!logProfile.matchesLut(lutConfig.curve, lutConfig.colorSpace)) {
|
||||
PLog.d(TAG, "Cancelling selected LUT [${lutConfig.title}] because it does not match video log profile [${logProfile.name}] colorSpace/curve")
|
||||
setLut(null, persist = false)
|
||||
}
|
||||
private fun validateAndCancelNonMatchingVideoLut(logProfile: VideoLogProfile) {
|
||||
val look = currentLutLook.value
|
||||
val lutConfig = look.config ?: return
|
||||
if (logProfile != VideoLogProfile.OFF && !logProfile.matchesLut(lutConfig.curve, lutConfig.colorSpace)) {
|
||||
PLog.d(TAG, "Cancelling active LUT [${lutConfig.title}] because it does not match video log profile [${logProfile.name}] colorSpace/curve")
|
||||
if (look.id == lutLookSelection.value.lutId) applyLut(CameraLookSelection.None)
|
||||
else publishLutLook(CameraLutLook.None)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3947,154 +3937,141 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
/**
|
||||
* 设置当前 LUT
|
||||
*/
|
||||
fun setLut(lutId: String?, persist: Boolean = true) {
|
||||
val normalizedLutId = lutId ?: "none"
|
||||
val profile = state.value.videoConfig.logProfile
|
||||
if (state.value.captureMode == CaptureMode.VIDEO && profile.isEnabled && normalizedLutId != "none") {
|
||||
val info = availableLutList.firstOrNull { it.id == normalizedLutId }
|
||||
if (info != null && !profile.matchesLut(info.inputCurve, info.inputColorSpace)) {
|
||||
if (!persist) applyLut("none")
|
||||
return
|
||||
}
|
||||
}
|
||||
applyLut(normalizedLutId)
|
||||
fun setLut(lutId: String?) {
|
||||
selectLut(lutId, videoSlot = null)
|
||||
}
|
||||
|
||||
if (persist) {
|
||||
val useVideoSlot = state.value.captureMode == CaptureMode.VIDEO &&
|
||||
userPreferences.value.separateVideoLutEnabled
|
||||
viewModelScope.launch {
|
||||
if (useVideoSlot) {
|
||||
userPreferencesRepository.update { videoLutId = normalizedLutId }
|
||||
} else {
|
||||
userPreferencesRepository.update { this.lutId = normalizedLutId }
|
||||
PhotonLookContract.notifyLookChanged(getApplication<Application>())
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun canSelectLut(lutId: String): Boolean {
|
||||
val cameraState = state.value
|
||||
val profile = cameraState.videoConfig.logProfile
|
||||
if (cameraState.captureMode != CaptureMode.VIDEO || !profile.isEnabled || lutId == "none") return true
|
||||
val info = contentRepository.lutManager.getLutInfo(lutId) ?: return true
|
||||
return profile.matchesLut(info.inputCurve, info.inputColorSpace)
|
||||
}
|
||||
|
||||
private var lutIntensitySaveJob: Job? = null
|
||||
|
||||
fun updateLutIntensity(intensity: Float) {
|
||||
val lutId = currentLutId.value
|
||||
if (lutId == "none") return
|
||||
val current = currentRecipeParams.value
|
||||
val updated = current.copy(lutIntensity = RecipeParam.LUT_INTENSITY.clamp(intensity))
|
||||
val look = currentLutLook.value
|
||||
val selection = lutLookSelection.value
|
||||
if (selection.presetRecipe != null || look.fromPreset || look.id == "none" || look.id != selection.lutId) return
|
||||
val updated = look.recipe.copy(lutIntensity = RecipeParam.LUT_INTENSITY.clamp(intensity))
|
||||
lutIntensitySaveJob?.cancel()
|
||||
lutIntensitySaveJob = viewModelScope.launch {
|
||||
delay(200)
|
||||
contentRepository.lutManager.saveColorRecipeParams(lutId, updated)
|
||||
contentRepository.lutManager.saveColorRecipeParams(look.id, updated)
|
||||
}
|
||||
}
|
||||
|
||||
fun setPhotoLut(lutId: String?) {
|
||||
val normalizedLutId = lutId ?: "none"
|
||||
val shouldApply = state.value.captureMode != CaptureMode.VIDEO ||
|
||||
!userPreferences.value.separateVideoLutEnabled
|
||||
if (shouldApply) {
|
||||
applyLut(normalizedLutId)
|
||||
}
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.update { this.lutId = normalizedLutId }
|
||||
PhotonLookContract.notifyLookChanged(getApplication<Application>())
|
||||
}
|
||||
selectLut(lutId, videoSlot = false)
|
||||
}
|
||||
|
||||
fun setVideoLut(lutId: String?) {
|
||||
val normalizedLutId = lutId ?: "none"
|
||||
if (state.value.captureMode == CaptureMode.VIDEO &&
|
||||
userPreferences.value.separateVideoLutEnabled
|
||||
) {
|
||||
applyLut(normalizedLutId)
|
||||
}
|
||||
selectLut(lutId, videoSlot = true)
|
||||
}
|
||||
|
||||
private fun selectLut(lutId: String?, videoSlot: Boolean?) {
|
||||
val selection = CameraLookSelection(CameraPreset.normalizeLutId(lutId) ?: "none")
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.update { videoLutId = normalizedLutId }
|
||||
cameraLookMutex.withLock {
|
||||
val prefs = userPreferencesRepository.latest()
|
||||
val activeVideoSlot = state.value.captureMode == CaptureMode.VIDEO && prefs.separateVideoLutEnabled
|
||||
val useVideoSlot = videoSlot ?: activeVideoSlot
|
||||
if (useVideoSlot == activeVideoSlot) {
|
||||
if (videoSlot == null && !canSelectLut(selection.lutId)) return@withLock
|
||||
applyLut(selection)
|
||||
}
|
||||
userPreferencesRepository.update {
|
||||
if (useVideoSlot) videoLutId = selection.lutId else this.lutId = selection.lutId
|
||||
}
|
||||
if (!useVideoSlot) PhotonLookContract.notifyLookChanged(getApplication<Application>())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setSeparateVideoLutEnabled(enabled: Boolean) {
|
||||
if (userPreferences.value.separateVideoLutEnabled == enabled) return
|
||||
viewModelScope.launch {
|
||||
val currentPreferences = userPreferencesRepository.userPreferences.first()
|
||||
val initialVideoLutId = currentPreferences.videoLutId
|
||||
?: currentPreferences.lutId
|
||||
?: currentLutId.value
|
||||
userPreferencesRepository.update {
|
||||
separateVideoLutEnabled = enabled
|
||||
if (enabled && videoLutId == null && initialVideoLutId != null) videoLutId = initialVideoLutId
|
||||
}
|
||||
if (state.value.captureMode == CaptureMode.VIDEO) {
|
||||
val updatedPreferences = currentPreferences.edited {
|
||||
cameraLookMutex.withLock {
|
||||
val prefs = userPreferencesRepository.latest()
|
||||
if (prefs.separateVideoLutEnabled == enabled) return@withLock
|
||||
val initialVideoLutId = prefs.lutId ?: lutLookSelection.value.lutId
|
||||
userPreferencesRepository.update {
|
||||
separateVideoLutEnabled = enabled
|
||||
videoLutId = currentPreferences.videoLutId ?: initialVideoLutId
|
||||
if (enabled && videoLutId == null) videoLutId = initialVideoLutId
|
||||
}
|
||||
resolveLutIdForMode(updatedPreferences, CaptureMode.VIDEO)?.let {
|
||||
applyLut(it)
|
||||
if (state.value.captureMode == CaptureMode.VIDEO) {
|
||||
resolveLookForMode(userPreferencesRepository.latest(), CaptureMode.VIDEO)?.let(::applyLut)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun resolveLutIdForMode(preferences: UserPreferences, mode: CaptureMode): String? {
|
||||
private fun resolveLookForMode(preferences: UserPreferences, mode: CaptureMode): CameraLookSelection? {
|
||||
val lutManager = contentRepository.lutManager
|
||||
return resolveLutIdForCaptureMode(
|
||||
photoLutId = preferences.lutId?.takeIf { lutManager.getLutInfo(it) != null },
|
||||
videoLutId = preferences.videoLutId?.takeIf { lutManager.getLutInfo(it) != null },
|
||||
val photoLutId = preferences.lutId?.takeIf { it == "none" || lutManager.getLutInfo(it) != null }
|
||||
val videoLutId = preferences.videoLutId?.takeIf { it == "none" || lutManager.getLutInfo(it) != null }
|
||||
val lutId = resolveLutIdForCaptureMode(
|
||||
photoLutId = photoLutId,
|
||||
videoLutId = videoLutId,
|
||||
separateVideoLutEnabled = preferences.separateVideoLutEnabled,
|
||||
captureMode = mode,
|
||||
defaultLutId = lutManager.getAvailableLuts().firstOrNull { it.isDefault }?.id,
|
||||
)
|
||||
) ?: return null
|
||||
val presetRecipe = if (mode == CaptureMode.VIDEO && preferences.separateVideoLutEnabled && videoLutId != null) {
|
||||
preferences.videoPresetRecipe
|
||||
} else if (photoLutId != null) {
|
||||
preferences.photoPresetRecipe
|
||||
} else {
|
||||
null
|
||||
}
|
||||
return CameraLookSelection(lutId, presetRecipe)
|
||||
}
|
||||
|
||||
private fun applyLut(normalizedLutId: String) {
|
||||
val loadGeneration = ++lutLoadGeneration
|
||||
private fun applyLut(request: CameraLookSelection): Job? {
|
||||
lutLoadJob?.cancel()
|
||||
val profile = state.value.videoConfig.logProfile
|
||||
if (state.value.captureMode == CaptureMode.VIDEO && profile.isEnabled &&
|
||||
!profile.matchesLut(currentLutConfig?.curve, currentLutConfig?.colorSpace)) {
|
||||
currentLutConfig = null
|
||||
cameraController.setLogLutActive(false)
|
||||
val selection = request.takeIf { canSelectLut(it.lutId) } ?: CameraLookSelection.None
|
||||
val lutId = selection.lutId
|
||||
val presetRecipe = selection.presetRecipe
|
||||
_lutLookSelection.value = selection
|
||||
if (lutId == "none") {
|
||||
publishLutLook(CameraLutLook(lutId, null, presetRecipe ?: ColorRecipeParams.DEFAULT, presetRecipe != null))
|
||||
return null
|
||||
}
|
||||
currentLutId.value = normalizedLutId
|
||||
if (normalizedLutId == "none") {
|
||||
currentLutConfig = null
|
||||
// LUT 已禁用,通知相机控制器
|
||||
cameraController.setLogLutActive(false)
|
||||
cameraController.setLutEnabled(false)
|
||||
} else {
|
||||
val hadActiveLut = currentLutConfig != null
|
||||
if (!hadActiveLut) {
|
||||
// 首次启动时先保持”未启用”状态,避免 Live Photo 在 LUT 文件尚未加载完成前录入原始画面。
|
||||
cameraController.setLutEnabled(false)
|
||||
}
|
||||
lutLoadJob = viewModelScope.launch {
|
||||
val loadedLut = withContext(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadLut(normalizedLutId)
|
||||
}
|
||||
if (lutLoadGeneration != loadGeneration || currentLutId.value != normalizedLutId) {
|
||||
return@launch
|
||||
}
|
||||
if (state.value.captureMode == CaptureMode.VIDEO) {
|
||||
val logProfile = state.value.videoConfig.logProfile
|
||||
if (logProfile != VideoLogProfile.OFF && loadedLut != null) {
|
||||
if (!logProfile.matchesLut(loadedLut.curve, loadedLut.colorSpace)) {
|
||||
PLog.d(TAG, "Deselecting newly selected LUT [${loadedLut.title}] because it does not match video log profile [${logProfile.name}] colorSpace/curve")
|
||||
setLut(null, persist = false)
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
}
|
||||
currentLutConfig = loadedLut
|
||||
cameraController.setLogLutActive(loadedLut?.curve?.isLog == true)
|
||||
cameraController.setLutEnabled(loadedLut != null)
|
||||
if (lutLoadGeneration == loadGeneration) {
|
||||
lutLoadJob = null
|
||||
}
|
||||
}
|
||||
if (hadActiveLut) {
|
||||
cameraController.setLutEnabled(true)
|
||||
}
|
||||
|
||||
val currentState = state.value
|
||||
if (currentState.captureMode == CaptureMode.VIDEO) {
|
||||
validateAndCancelNonMatchingVideoLut(currentState.videoConfig.logProfile)
|
||||
if (lutLookSelection.value.lutId != lutId) return null
|
||||
}
|
||||
return viewModelScope.launch {
|
||||
val loadedLut = withContext(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadLut(lutId)
|
||||
}
|
||||
fun publishRecipe(recipe: ColorRecipeParams) {
|
||||
val activeState = state.value
|
||||
val profile = activeState.videoConfig.logProfile
|
||||
if (activeState.captureMode == CaptureMode.VIDEO && profile.isEnabled && loadedLut != null &&
|
||||
!profile.matchesLut(loadedLut.curve, loadedLut.colorSpace)
|
||||
) {
|
||||
PLog.d(TAG, "Deselecting newly selected LUT [${loadedLut.title}] because it does not match video log profile [${profile.name}] colorSpace/curve")
|
||||
applyLut(CameraLookSelection.None)
|
||||
return
|
||||
}
|
||||
publishLutLook(CameraLutLook(lutId, loadedLut, recipe, presetRecipe != null))
|
||||
}
|
||||
if (presetRecipe != null) {
|
||||
publishRecipe(presetRecipe)
|
||||
} else {
|
||||
contentRepository.lutManager.getColorRecipeParams(lutId).collect(::publishRecipe)
|
||||
}
|
||||
}.also { lutLoadJob = it }
|
||||
}
|
||||
|
||||
private fun publishLutLook(look: CameraLutLook) {
|
||||
_currentLutLook.value = look
|
||||
cameraController.setLogLutActive(look.config?.curve?.isLog == true)
|
||||
cameraController.setLutEnabled(look.config != null)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4103,7 +4080,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
fun peekNextLut(): LutInfo? {
|
||||
val luts = selectableLutList
|
||||
if (luts.isEmpty()) return null
|
||||
val currentIndex = luts.indexOfFirst { it.id == currentLutId.value }
|
||||
val currentIndex = luts.indexOfFirst { it.id == lutLookSelection.value.lutId }
|
||||
val nextIndex = if (currentIndex == -1 || currentIndex == luts.size - 1) 0 else currentIndex + 1
|
||||
return luts[nextIndex]
|
||||
}
|
||||
@@ -4114,7 +4091,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
fun peekPreviousLut(): LutInfo? {
|
||||
val luts = selectableLutList
|
||||
if (luts.isEmpty()) return null
|
||||
val currentIndex = luts.indexOfFirst { it.id == currentLutId.value }
|
||||
val currentIndex = luts.indexOfFirst { it.id == lutLookSelection.value.lutId }
|
||||
val prevIndex = if (currentIndex <= 0) luts.size - 1 else currentIndex - 1
|
||||
return luts[prevIndex]
|
||||
}
|
||||
@@ -4139,13 +4116,13 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
return previousLut
|
||||
}
|
||||
|
||||
fun updateLut() {
|
||||
fun updateLut(reload: Boolean = false) {
|
||||
viewModelScope.launch {
|
||||
presetApplyMutex.withLock {
|
||||
cameraLookMutex.withLock {
|
||||
val preferences = userPreferencesRepository.userPreferences.first()
|
||||
val newLutId = resolveLutIdForMode(preferences, state.value.captureMode) ?: return@withLock
|
||||
if (currentLutId.value != newLutId) {
|
||||
setLut(newLutId, persist = false)
|
||||
val look = resolveLookForMode(preferences, state.value.captureMode) ?: return@withLock
|
||||
if (reload || lutLookSelection.value != look) {
|
||||
applyLut(look)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4274,15 +4251,13 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
return rotated
|
||||
}
|
||||
|
||||
suspend fun applyLut(bitmap: Bitmap): Bitmap = withContext(Dispatchers.IO) {
|
||||
currentLutConfig?.let { lut ->
|
||||
val params = getMergedRecipeParams(contentRepository.lutManager.loadColorRecipeParams(currentLutId.value))
|
||||
contentRepository.imageProcessor.applyLut(
|
||||
bitmap = bitmap,
|
||||
lutConfig = lut,
|
||||
colorRecipeParams = params
|
||||
)
|
||||
} ?: bitmap
|
||||
suspend fun applyCaptureLook(bitmap: Bitmap, metadata: MediaMetadata): Bitmap = withContext(Dispatchers.IO) {
|
||||
val lut = metadata.lutId?.let(contentRepository.lutManager::loadLut) ?: return@withContext bitmap
|
||||
contentRepository.imageProcessor.applyLut(
|
||||
bitmap = bitmap,
|
||||
lutConfig = lut,
|
||||
colorRecipeParams = metadata.colorRecipeParams
|
||||
)
|
||||
}
|
||||
|
||||
/** The display preview already includes its look; only composite the captured photo's frame. */
|
||||
@@ -5305,6 +5280,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
lutId = lutIdToSave,
|
||||
frameId = frameIdToSave,
|
||||
colorRecipeParams = settings.recipe,
|
||||
photoColorRecipeEdits = settings.photoColorRecipeEdits,
|
||||
baselineTarget = baselineMetadata?.first,
|
||||
baselineLutId = baselineMetadata?.second,
|
||||
baselineColorRecipeParams = baselineMetadata?.third,
|
||||
@@ -5427,18 +5403,20 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun saveVideoSnapshot(bitmap: Bitmap) {
|
||||
private suspend fun saveVideoSnapshot(bitmap: Bitmap, look: CameraLutLook) {
|
||||
savePreviewBitmapCapture(
|
||||
bitmap = bitmap,
|
||||
metadataCaptureMode = "video_snapshot",
|
||||
ratio = mapVideoAspectRatioToPhotoAspectRatio(state.value.videoConfig.aspectRatio)
|
||||
ratio = mapVideoAspectRatioToPhotoAspectRatio(state.value.videoConfig.aspectRatio),
|
||||
look = look
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun savePreviewBitmapCapture(
|
||||
bitmap: Bitmap,
|
||||
metadataCaptureMode: String,
|
||||
ratio: AspectRatio?
|
||||
ratio: AspectRatio?,
|
||||
look: CameraLutLook,
|
||||
) {
|
||||
try {
|
||||
val context = getApplication<Application>()
|
||||
@@ -5468,9 +5446,10 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
|
||||
val metadata = MediaMetadata(
|
||||
lutId = currentLutId.value,
|
||||
lutId = look.id,
|
||||
frameId = currentFrameId,
|
||||
colorRecipeParams = getMergedRecipeParams(),
|
||||
colorRecipeParams = look.recipe,
|
||||
photoColorRecipeEdits = look.photoColorRecipeEdits(),
|
||||
sharpening = sharpeningValue,
|
||||
noiseReduction = noiseReductionValue,
|
||||
chromaNoiseReduction = chromaNoiseReductionValue,
|
||||
@@ -5733,6 +5712,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
lutId = lutIdToSave,
|
||||
frameId = frameIdToSave,
|
||||
colorRecipeParams = settings.recipe,
|
||||
photoColorRecipeEdits = settings.photoColorRecipeEdits,
|
||||
baselineTarget = baselineMetadata?.first,
|
||||
baselineLutId = baselineMetadata?.second,
|
||||
baselineColorRecipeParams = baselineMetadata?.third,
|
||||
@@ -6056,6 +6036,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
lutId = lutIdToSave,
|
||||
frameId = frameIdToSave,
|
||||
colorRecipeParams = settings.recipe,
|
||||
photoColorRecipeEdits = settings.photoColorRecipeEdits,
|
||||
baselineTarget = baselineMetadata?.first,
|
||||
baselineLutId = baselineMetadata?.second,
|
||||
baselineColorRecipeParams = baselineMetadata?.third,
|
||||
|
||||
@@ -22,16 +22,19 @@ import androidx.lifecycle.viewModelScope
|
||||
import com.hinnka.mycamera.data.ContentRepository
|
||||
import com.hinnka.mycamera.frame.FrameInfo
|
||||
import com.hinnka.mycamera.gallery.GalleryManager
|
||||
import com.hinnka.mycamera.gallery.GalleryEditLook
|
||||
import com.hinnka.mycamera.gallery.ProcessingPhoto
|
||||
import com.hinnka.mycamera.gallery.MediaData
|
||||
import com.hinnka.mycamera.gallery.AestheticScoreRepository
|
||||
import com.hinnka.mycamera.gallery.MediaMetadata
|
||||
import com.hinnka.mycamera.gallery.MediaType
|
||||
import com.hinnka.mycamera.gallery.PhotoColorRecipeEdits
|
||||
import com.hinnka.mycamera.gallery.PostEditGeometry
|
||||
import com.hinnka.mycamera.gallery.changedRecipeFields
|
||||
import com.hinnka.mycamera.gallery.copyRecipeFields
|
||||
import com.hinnka.mycamera.hdr.HdrGainmapStrength
|
||||
import com.hinnka.mycamera.hdr.UnifiedGainmapProducer
|
||||
import com.hinnka.mycamera.lut.BaselineColorCorrectionTarget
|
||||
import com.hinnka.mycamera.lut.LutConfig
|
||||
import com.hinnka.mycamera.lut.sortLutsByUserOrder
|
||||
import com.hinnka.mycamera.lut.LutInfo
|
||||
import com.hinnka.mycamera.lut.PhotoTransformation
|
||||
@@ -271,8 +274,9 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
private set
|
||||
|
||||
// LUT 编辑状态
|
||||
var editLutId = MutableStateFlow<String?>(null)
|
||||
private set
|
||||
private val _editLook = MutableStateFlow(GalleryEditLook())
|
||||
internal val editLook = _editLook.asStateFlow()
|
||||
private var editLutLoadJob: Job? = null
|
||||
|
||||
var editSyncAdjustmentsToLut by mutableStateOf(false)
|
||||
private set
|
||||
@@ -288,28 +292,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editApplyEffectsToVideo.value = apply
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
var editLutRecipeParams = editLutId.flatMapLatest { id ->
|
||||
if (id == null) {
|
||||
flowOf(ColorRecipeParams.DEFAULT)
|
||||
} else {
|
||||
contentRepository.lutManager.getColorRecipeParams(id)
|
||||
.map { params -> pendingEditLutRecipeSync[id] ?: params }
|
||||
}
|
||||
}.stateIn(
|
||||
scope = viewModelScope,
|
||||
started = SharingStarted.Eagerly,
|
||||
initialValue = ColorRecipeParams.DEFAULT
|
||||
)
|
||||
|
||||
/** 当前预览、保存使用的完整配方,与独立调节草稿分开保存。 */
|
||||
var editPhotoRecipeParams = MutableStateFlow<ColorRecipeParams?>(null)
|
||||
private set
|
||||
|
||||
private var independentEditPhotoRecipeParams = ColorRecipeParams.DEFAULT
|
||||
|
||||
var editLutConfig: LutConfig? by mutableStateOf(null)
|
||||
private set
|
||||
var editVideoSourceProfile: VideoLogProfile? by mutableStateOf(null)
|
||||
private set
|
||||
var editVideoProfileDetected by mutableStateOf(false)
|
||||
@@ -318,7 +300,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
val selectableEditLuts: List<LutInfo>
|
||||
get() = availableLuts.filter {
|
||||
(editVideoSourceProfile ?: VideoLogProfile.OFF).matchesLut(it.inputCurve, it.inputColorSpace)
|
||||
it.id == "none" ||
|
||||
(editVideoSourceProfile ?: VideoLogProfile.OFF).matchesLut(it.inputCurve, it.inputColorSpace)
|
||||
}
|
||||
|
||||
fun selectEditVideoSourceProfile(profile: VideoLogProfile) {
|
||||
@@ -330,7 +313,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
private fun clearIncompatibleVideoLut() {
|
||||
val profile = editVideoSourceProfile ?: return
|
||||
val selected = availableLuts.firstOrNull { it.id == editLutId.value } ?: return
|
||||
val selected = availableLuts.firstOrNull { it.id == editLook.value.lutId } ?: return
|
||||
if (!profile.matchesLut(selected.inputCurve, selected.inputColorSpace)) {
|
||||
PLog.d(TAG, "Clearing LUT ${selected.id}: input does not match source $profile")
|
||||
setEditLut(null)
|
||||
@@ -1497,7 +1480,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
currentPhotoMetadataId = photo?.id
|
||||
currentMediaMetadata = metadata
|
||||
metadata?.let { m ->
|
||||
editLutId.value = m.lutId
|
||||
editFrameId.value = m.frameId
|
||||
editSharpening.value = m.sharpening ?: 0f
|
||||
editNoiseReduction.value = DenoiseStrength.clamp(m.noiseReduction)
|
||||
@@ -1539,14 +1521,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
_editAiDenoiseEnabled.value = aiDenoiseApplied
|
||||
restoreCropEditState(photo, m)
|
||||
|
||||
// 加载 LUT 配置
|
||||
m.lutId?.let { id ->
|
||||
viewModelScope.launch {
|
||||
editLutConfig = withContext(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadLut(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
} ?: run {
|
||||
editRotationDegrees.value = 0
|
||||
editStraightenDegrees.value = 0f
|
||||
@@ -2147,7 +2121,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editVideoSourceProfile = null
|
||||
editVideoProfileDetected = false
|
||||
editVideoProfileOverride = null
|
||||
editLutConfig = null
|
||||
|
||||
if (currentMediaMetadata == null || currentPhotoMetadataId != targetPhoto.id) {
|
||||
val context = getApplication<Application>()
|
||||
@@ -2165,14 +2138,10 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
isEditing = true
|
||||
editSyncAdjustmentsToLut = false
|
||||
independentEditPhotoRecipeParams = ColorRecipeParams.DEFAULT
|
||||
publishEditLook(restoreEditLook(currentMediaMetadata), targetPhoto.isVideo)
|
||||
// 从当前元数据恢复编辑状态
|
||||
currentMediaMetadata?.let { metadata ->
|
||||
editLutId.value = metadata.lutId
|
||||
editFrameId.value = metadata.frameId
|
||||
val recipe = snapshotEditRecipe(metadata.colorRecipeParams, metadata.lutId)
|
||||
editPhotoRecipeParams.value = recipe
|
||||
independentEditPhotoRecipeParams = recipe.deepCopy()
|
||||
editApplyEffectsToVideo.value = metadata.applyEffectsToVideo
|
||||
|
||||
if (!targetPhoto.isVideo) {
|
||||
@@ -2225,9 +2194,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editFocusPointY.value = metadata.focusPointY
|
||||
}
|
||||
} ?: run {
|
||||
editLutId.value = null
|
||||
editFrameId.value = null
|
||||
editPhotoRecipeParams.value = ColorRecipeParams.DEFAULT
|
||||
editApplyEffectsToVideo.value = false
|
||||
|
||||
if (!targetPhoto.isVideo) {
|
||||
@@ -2272,8 +2239,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
// Resolve the source from the file before exposing the video effect to the player.
|
||||
val manualProfile = VideoColorMetadata.manualProfile(currentMediaMetadata?.customProperties)
|
||||
viewModelScope.launch {
|
||||
if (targetPhoto.isVideo) {
|
||||
if (targetPhoto.isVideo) {
|
||||
viewModelScope.launch {
|
||||
val detectedProfile = withContext(Dispatchers.IO) {
|
||||
VideoColorMetadata.readProfile(getApplication(), targetPhoto.sourceUri ?: targetPhoto.uri)
|
||||
}
|
||||
@@ -2283,12 +2250,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editVideoSourceProfile = detectedProfile ?: manualProfile ?: VideoLogProfile.OFF
|
||||
clearIncompatibleVideoLut()
|
||||
}
|
||||
editLutId.value?.let { id ->
|
||||
val config = withContext(Dispatchers.IO) { contentRepository.lutManager.loadLut(id) }
|
||||
if (isEditing && getCurrentPhoto()?.id == targetPhoto.id && editLutId.value == id) {
|
||||
editLutConfig = config
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2361,11 +2322,9 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editVideoProfileDetected = false
|
||||
editVideoProfileOverride = null
|
||||
editSyncAdjustmentsToLut = false
|
||||
editLutId.value = null
|
||||
editLutConfig = null
|
||||
editLutLoadJob?.cancel()
|
||||
_editLook.value = GalleryEditLook()
|
||||
editFrameId.value = null
|
||||
editPhotoRecipeParams.value = null
|
||||
independentEditPhotoRecipeParams = ColorRecipeParams.DEFAULT
|
||||
editApplyEffectsToVideo.value = false
|
||||
editCropRect.value = null
|
||||
editCropAspectOption.value = CropAspectOption.Free
|
||||
@@ -2399,51 +2358,78 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editRawFotufilmDocument.value = null
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换绑定状态时保留当前调节,开启绑定后才将调节写入当前 LUT。
|
||||
*/
|
||||
fun setSyncAdjustmentsToLut(enabled: Boolean) {
|
||||
val shouldSync = enabled && editLutId.value != null
|
||||
if (editSyncAdjustmentsToLut == shouldSync) return
|
||||
|
||||
val params = snapshotEditRecipe(editPhotoRecipeParams.value, editLutId.value)
|
||||
editSyncAdjustmentsToLut = shouldSync
|
||||
if (shouldSync) {
|
||||
setPhotoRecipeParams(params)
|
||||
} else {
|
||||
editPhotoRecipeParams.value = params
|
||||
}
|
||||
val lutId = editLook.value.lutId
|
||||
editSyncAdjustmentsToLut = enabled && lutId != null && !PhotoColorMatch.isId(lutId)
|
||||
}
|
||||
|
||||
private fun snapshotEditRecipe(params: ColorRecipeParams?, lutId: String?): ColorRecipeParams {
|
||||
// 旧照片可能只保存了 LUT 引用。读取一次实际配方后独立编辑,保持进入编辑时的画面。
|
||||
// 按 ID 读取也避免快速切换后取消同步时,拿到 StateFlow 尚未更新的上一个 LUT 配方。
|
||||
val recipe = params ?: lutId?.let { id ->
|
||||
private fun loadEditLutRecipe(lutId: String?): ColorRecipeParams =
|
||||
lutId?.let { id ->
|
||||
pendingEditLutRecipeSync[id] ?: runBlocking(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadColorRecipeParams(id)
|
||||
}
|
||||
} ?: ColorRecipeParams.DEFAULT
|
||||
return recipe.deepCopy()
|
||||
|
||||
private fun restoreEditLook(metadata: MediaMetadata?): GalleryEditLook {
|
||||
val lutId = CameraPreset.normalizeLutId(metadata?.lutId)
|
||||
val recipe = metadata?.colorRecipeParams?.deepCopy() ?: loadEditLutRecipe(lutId)
|
||||
val edits = PhotoColorRecipeEdits.fromJson(metadata?.photoColorRecipeEdits)
|
||||
?: if (lutId == null) {
|
||||
PhotoColorRecipeEdits.withoutLut(recipe)
|
||||
} else {
|
||||
// 旧照片只记录合成结果。保留拍摄时的外观,后续只跟踪明确的照片调节。
|
||||
PhotoColorRecipeEdits(base = recipe)
|
||||
}
|
||||
return GalleryEditLook(lutId = lutId, recipe = recipe, edits = edits)
|
||||
}
|
||||
|
||||
/** 设置照片调节,并根据本次编辑的绑定状态同步到 LUT。 */
|
||||
fun setPhotoRecipeParams(params: ColorRecipeParams) {
|
||||
editPhotoRecipeParams.value = params
|
||||
if (!editSyncAdjustmentsToLut) {
|
||||
independentEditPhotoRecipeParams = params.deepCopy()
|
||||
private fun publishEditLook(look: GalleryEditLook, loadConfig: Boolean) {
|
||||
editLutLoadJob?.cancel()
|
||||
val id = look.lutId
|
||||
if (id == null || !loadConfig) {
|
||||
_editLook.value = look
|
||||
return
|
||||
}
|
||||
if (editSyncAdjustmentsToLut) {
|
||||
val lutId = editLutId.value ?: return
|
||||
pendingEditLutRecipeSync[lutId] = params.deepCopy()
|
||||
editLutRecipeSyncJob?.cancel()
|
||||
editLutRecipeSyncJob = viewModelScope.launch {
|
||||
delay(250)
|
||||
editLutRecipeSyncJob = null
|
||||
flushPendingEditLutRecipeSync()
|
||||
_editLook.value = look.copy(isLutConfigLoading = true)
|
||||
editLutLoadJob = viewModelScope.launch {
|
||||
val config = withContext(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadLut(id)
|
||||
}
|
||||
_editLook.update { it.copy(lutConfig = config, isLutConfigLoading = false) }
|
||||
}
|
||||
}
|
||||
|
||||
fun updatePhotoRecipeParams(update: (ColorRecipeParams) -> ColorRecipeParams) {
|
||||
val recipe = editLook.value.recipe
|
||||
updatePhotoRecipeParams(recipe, update(recipe))
|
||||
}
|
||||
|
||||
fun updatePhotoRecipeParams(displayed: ColorRecipeParams, params: ColorRecipeParams) {
|
||||
val changedFields = params.changedRecipeFields(displayed)
|
||||
if (changedFields.isEmpty()) return
|
||||
val look = editLook.value
|
||||
val recipe = look.recipe.copyRecipeFields(params, changedFields)
|
||||
val lutId = look.lutId
|
||||
if (!editSyncAdjustmentsToLut || lutId == null) {
|
||||
_editLook.value = look.withPhotoRecipe(recipe, changedFields)
|
||||
return
|
||||
}
|
||||
|
||||
val lutRecipe = loadEditLutRecipe(lutId).copyRecipeFields(recipe, changedFields)
|
||||
_editLook.value = look.withSyncedRecipe(recipe, changedFields)
|
||||
pendingEditLutRecipeSync[lutId] = lutRecipe
|
||||
editLutRecipeSyncJob?.cancel()
|
||||
editLutRecipeSyncJob = viewModelScope.launch {
|
||||
delay(250)
|
||||
editLutRecipeSyncJob = null
|
||||
flushPendingEditLutRecipeSync()
|
||||
}
|
||||
}
|
||||
|
||||
fun resetPhotoRecipeParams() {
|
||||
_editLook.update { it.resetPhotoRecipe() }
|
||||
}
|
||||
|
||||
private suspend fun flushPendingEditLutRecipeSync() {
|
||||
editLutRecipeSyncJob?.cancel()
|
||||
editLutRecipeSyncJob = null
|
||||
@@ -2534,42 +2520,16 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
fun setEditLut(lutId: String?) {
|
||||
if (lutId != null && getCurrentPhoto()?.isVideo == true &&
|
||||
fun setEditLut(selectedId: String?) {
|
||||
val lutId = CameraPreset.normalizeLutId(selectedId)
|
||||
val look = editLook.value
|
||||
val isVideo = getCurrentPhoto()?.isVideo == true
|
||||
if (look.lutId == lutId) return
|
||||
if (lutId != null && isVideo &&
|
||||
(editVideoSourceProfile == null || selectableEditLuts.none { it.id == lutId })
|
||||
) return
|
||||
if (lutId == null) {
|
||||
editSyncAdjustmentsToLut = false
|
||||
}
|
||||
if (editLutId.value != lutId) {
|
||||
val lutRecipe = lutId?.let { id ->
|
||||
pendingEditLutRecipeSync[id] ?: runBlocking(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadSavedColorRecipeParams(id)
|
||||
}
|
||||
}
|
||||
// LUT 配方完整应用,但不能覆盖独立调节草稿;离开带配方的 LUT 后恢复草稿。
|
||||
editPhotoRecipeParams.value = (
|
||||
lutRecipe ?: if (editSyncAdjustmentsToLut) {
|
||||
ColorRecipeParams.DEFAULT
|
||||
} else {
|
||||
independentEditPhotoRecipeParams
|
||||
}
|
||||
).deepCopy()
|
||||
}
|
||||
editLutId.value = lutId
|
||||
if (lutId == null) {
|
||||
editLutConfig = null
|
||||
return
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
val config = withContext(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadLut(lutId)
|
||||
}
|
||||
if (editLutId.value == lutId) {
|
||||
editLutConfig = config
|
||||
}
|
||||
}
|
||||
editSyncAdjustmentsToLut = false
|
||||
publishEditLook(look.switchLut(lutId, loadEditLutRecipe(lutId)), isVideo)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2578,7 +2538,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
fun peekNextLut(): LutInfo? {
|
||||
val availableLuts = selectableEditLuts
|
||||
if (availableLuts.isEmpty()) return null
|
||||
val currentLut = editLutId.value
|
||||
val currentLut = editLook.value.lutId ?: "none"
|
||||
val currentIndex = availableLuts.indexOfFirst { it.id == currentLut }
|
||||
val nextIndex = (currentIndex + 1) % availableLuts.size
|
||||
return availableLuts[nextIndex]
|
||||
@@ -2590,7 +2550,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
fun peekPreviousLut(): LutInfo? {
|
||||
val availableLuts = selectableEditLuts
|
||||
if (availableLuts.isEmpty()) return null
|
||||
val currentLut = editLutId.value
|
||||
val currentLut = editLook.value.lutId ?: "none"
|
||||
val currentIndex = availableLuts.indexOfFirst { it.id == currentLut }
|
||||
val prevIndex = if (currentIndex <= 0) availableLuts.size - 1 else currentIndex - 1
|
||||
return availableLuts[prevIndex]
|
||||
@@ -2647,11 +2607,13 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
fun copyCurrentEditSettings(customProperties: Map<String, String>) {
|
||||
val normalizedCrop = editCropRect.value?.let(::RectF)
|
||||
val sourceIsRaw = getCurrentPhoto()?.let(::isRawMedia) == true
|
||||
val look = editLook.value
|
||||
val lutId = PhotoColorMatch.transferable(look.lutId)
|
||||
copiedEditSettings = CopiedEditSettings(
|
||||
metadata = MediaMetadata(
|
||||
lutId = PhotoColorMatch.transferable(editLutId.value),
|
||||
colorRecipeParams = (editPhotoRecipeParams.value ?: editLutRecipeParams.value)
|
||||
.deepCopy(),
|
||||
lutId = lutId,
|
||||
colorRecipeParams = look.recipe.deepCopy(),
|
||||
photoColorRecipeEdits = look.copiedRecipeEdits(lutId),
|
||||
sharpening = editSharpening.value.takeUnless { sourceIsRaw },
|
||||
noiseReduction = editNoiseReduction.value.takeUnless { sourceIsRaw },
|
||||
chromaNoiseReduction =
|
||||
@@ -2682,9 +2644,10 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
fun createPresetFromCurrentEdit(base: CameraPreset): CameraPreset {
|
||||
val sourcePhoto = getCurrentPhoto()?.let { it.relatedPhoto ?: it }
|
||||
val sourceIsRaw = sourcePhoto?.let(::isRawMedia) == true
|
||||
val effectiveRecipe = editPhotoRecipeParams.value ?: editLutRecipeParams.value
|
||||
val look = editLook.value
|
||||
val effectiveRecipe = look.recipe
|
||||
val lookPreset = base.copy(
|
||||
lutId = CameraPreset.normalizeLutId(PhotoColorMatch.transferable(editLutId.value)),
|
||||
lutId = PhotoColorMatch.transferable(look.lutId),
|
||||
colorRecipe = effectiveRecipe.withoutIndependentEffects(),
|
||||
effects = effectiveRecipe.toEffectParams(),
|
||||
frameId = editFrameId.value,
|
||||
@@ -2779,12 +2742,9 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
onComplete(false)
|
||||
return@launch
|
||||
}
|
||||
val effectiveRecipe = metadata.colorRecipeParams
|
||||
?: metadata.lutId?.let { lutId ->
|
||||
withContext(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadColorRecipeParams(lutId)
|
||||
}
|
||||
}
|
||||
val look = restoreEditLook(metadata)
|
||||
val lutId = PhotoColorMatch.transferable(look.lutId)
|
||||
val hasRecipe = metadata.colorRecipeParams != null || look.lutId != null
|
||||
val baseWidth = metadata.width.takeIf { it > 0 } ?: sourcePhoto.width
|
||||
val baseHeight = metadata.height.takeIf { it > 0 } ?: sourcePhoto.height
|
||||
val (cropWidth, cropHeight) = PostEditGeometry.editedDimensions(
|
||||
@@ -2806,8 +2766,9 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
copiedEditSettings = CopiedEditSettings(
|
||||
metadata = MediaMetadata(
|
||||
lutId = PhotoColorMatch.transferable(metadata.lutId),
|
||||
colorRecipeParams = effectiveRecipe?.deepCopy(),
|
||||
lutId = lutId,
|
||||
colorRecipeParams = look.recipe.deepCopy().takeIf { hasRecipe },
|
||||
photoColorRecipeEdits = if (hasRecipe) look.copiedRecipeEdits(lutId) else null,
|
||||
sharpening = metadata.sharpening.takeUnless { sourceIsRaw },
|
||||
noiseReduction = metadata.noiseReduction.takeUnless { sourceIsRaw },
|
||||
chromaNoiseReduction =
|
||||
@@ -2849,10 +2810,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
editSyncAdjustmentsToLut = false
|
||||
|
||||
editLutId.value = settings.lutId
|
||||
val recipe = snapshotEditRecipe(settings.colorRecipeParams, settings.lutId)
|
||||
editPhotoRecipeParams.value = recipe
|
||||
independentEditPhotoRecipeParams = recipe.deepCopy()
|
||||
publishEditLook(restoreEditLook(settings), getCurrentPhoto()?.isVideo == true)
|
||||
editFrameId.value = settings.frameId
|
||||
val targetIsRaw = getCurrentPhoto()?.let(::isRawMedia) == true
|
||||
if (!targetIsRaw) {
|
||||
@@ -2885,16 +2843,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
)
|
||||
|
||||
clearIncompatibleVideoLut()
|
||||
editLutId.value?.let { lutId ->
|
||||
viewModelScope.launch {
|
||||
val config = withContext(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadLut(lutId)
|
||||
}
|
||||
if (editLutId.value == lutId) editLutConfig = config
|
||||
}
|
||||
} ?: run {
|
||||
editLutConfig = null
|
||||
}
|
||||
if (canPasteBokeh) updateBokehPhoto()
|
||||
return settings.customProperties.toMap()
|
||||
}
|
||||
@@ -2908,6 +2856,9 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
)
|
||||
}
|
||||
|
||||
private fun GalleryEditLook.copiedRecipeEdits(transferableLutId: String?): String =
|
||||
(if (transferableLutId == lutId) edits else PhotoColorRecipeEdits.withoutLut(recipe)).toJson()
|
||||
|
||||
/**
|
||||
* 设置锐化强度
|
||||
*/
|
||||
@@ -3668,11 +3619,12 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
?: MediaMetadata()
|
||||
|
||||
if (useGlobalEdit) {
|
||||
val look = editLook.value
|
||||
val spectralFilmTuning = editRawSpectralFilmTuning.value
|
||||
finalMetadata = (currentMediaMetadata ?: metadata).copy(
|
||||
lutId = editLutId.value,
|
||||
lutId = look.lutId,
|
||||
frameId = editFrameId.value,
|
||||
colorRecipeParams = recipeParamsOverride ?: editPhotoRecipeParams.value ?: editLutRecipeParams.value,
|
||||
colorRecipeParams = recipeParamsOverride ?: look.recipe,
|
||||
sharpening = editSharpening.value,
|
||||
noiseReduction = editNoiseReduction.value,
|
||||
chromaNoiseReduction = editChromaNoiseReduction.value,
|
||||
@@ -3961,8 +3913,9 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
* 保存编辑(只更新元数据,不修改原图)
|
||||
*/
|
||||
fun saveEditMetadata(photo: MediaData, onComplete: (Boolean) -> Unit = {}) {
|
||||
val look = editLook.value
|
||||
// 检查 VIP 权限
|
||||
val currentLut = availableLuts.find { it.id == editLutId.value }
|
||||
val currentLut = availableLuts.find { it.id == look.lutId }
|
||||
if (currentLut?.isVip == true && !isPurchased.value) {
|
||||
showPaymentDialog = true
|
||||
onComplete(false)
|
||||
@@ -3980,7 +3933,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
val importedId = GalleryManager.importPhoto(
|
||||
context,
|
||||
photo.uri,
|
||||
editLutId.value
|
||||
look.lutId
|
||||
)
|
||||
if (importedId != null) {
|
||||
photo.metadata = GalleryManager.loadMetadata(context, importedId)
|
||||
@@ -4027,7 +3980,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
val spectralFilmTuning = editRawSpectralFilmTuning.value
|
||||
val success = GalleryManager.updateMetadata(context, targetPhotoId) { current ->
|
||||
current.copy(
|
||||
lutId = editLutId.value,
|
||||
lutId = look.lutId,
|
||||
frameId = editFrameId.value,
|
||||
customProperties = (currentMediaMetadata?.customProperties
|
||||
?: targetMetadata?.customProperties.orEmpty()).toMutableMap().apply {
|
||||
@@ -4036,7 +3989,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editVideoProfileOverride?.let { put(VideoColorMetadata.OVERRIDE_KEY, it.name) }
|
||||
}
|
||||
},
|
||||
colorRecipeParams = editPhotoRecipeParams.value,
|
||||
colorRecipeParams = look.recipe,
|
||||
photoColorRecipeEdits = look.edits.toJson(),
|
||||
sharpening = editSharpening.value,
|
||||
noiseReduction = editNoiseReduction.value,
|
||||
chromaNoiseReduction = editChromaNoiseReduction.value,
|
||||
@@ -4375,6 +4329,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
customProperties = (settings.customProperties - VideoColorMetadata.OVERRIDE_KEY) +
|
||||
current.customProperties.filterKeys { it == VideoColorMetadata.OVERRIDE_KEY },
|
||||
colorRecipeParams = settings.colorRecipeParams?.deepCopy(),
|
||||
photoColorRecipeEdits = settings.photoColorRecipeEdits,
|
||||
sharpening = if (copyDetailProcessing && settings.sharpening != null) {
|
||||
settings.sharpening
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user