feat: remark
This commit is contained in:
1 parent
39e5c9e7bf
commit
6ee6d1fddc
8 files changed
+173
-24
No files matched your search
@@ -29,6 +29,7 @@ import com.hinnka.mycamera.utils.BitmapUtils
|
||||
import com.hinnka.mycamera.utils.PLog
|
||||
import com.hinnka.mycamera.utils.RawProcessor
|
||||
import com.hinnka.mycamera.utils.YuvProcessor
|
||||
import com.hinnka.mycamera.viewmodel.GalleryViewModel
|
||||
import kotlinx.coroutines.*
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
@@ -105,9 +106,8 @@ object PhotoManager {
|
||||
chromaNoiseReductionValue: Float,
|
||||
photoQuality: Int = 95,
|
||||
suffix: String? = null,
|
||||
onComplete: (Boolean) -> Unit = {}
|
||||
) {
|
||||
withContext(Dispatchers.IO) {
|
||||
): Boolean {
|
||||
return withContext(Dispatchers.IO) {
|
||||
val tempExportFile = File(context.cacheDir, "temp_export_${System.nanoTime()}.jpg")
|
||||
try {
|
||||
// 读取照片
|
||||
@@ -119,7 +119,7 @@ object PhotoManager {
|
||||
} ?: photoProcessor.process(
|
||||
context, id, metadata,
|
||||
sharpeningValue, noiseReductionValue, chromaNoiseReductionValue
|
||||
) ?: return@withContext
|
||||
) ?: return@withContext false
|
||||
|
||||
PLog.d(TAG, "processedBitmap = ${processedBitmap.colorSpace?.name}")
|
||||
|
||||
@@ -242,21 +242,18 @@ object PhotoManager {
|
||||
)
|
||||
saveMetadata(context, id, updatedMetadata)
|
||||
PLog.d(TAG, "Exported URI saved: $uri for photo $id")
|
||||
|
||||
return@withContext true
|
||||
}
|
||||
|
||||
processedBitmap.recycle()
|
||||
withContext(Dispatchers.Main) {
|
||||
onComplete(uri != null)
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
PLog.e(TAG, "Failed to export photo", e)
|
||||
withContext(Dispatchers.Main) {
|
||||
onComplete(false)
|
||||
}
|
||||
} finally {
|
||||
tempExportFile.delete()
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,8 @@ class LutManager(private val context: Context) {
|
||||
private fun bleachBypassKey(lutId: String) = floatPreferencesKey("${lutId}_bleachBypass")
|
||||
private fun halationKey(lutId: String) = floatPreferencesKey("${lutId}_halation")
|
||||
private fun lutIntensityKey(lutId: String) = floatPreferencesKey("${lutId}_lutIntensity")
|
||||
private fun remarksKey(lutId: String) =
|
||||
androidx.datastore.preferences.core.stringPreferencesKey("${lutId}_remarks")
|
||||
}
|
||||
|
||||
// LUT 缓存
|
||||
@@ -80,7 +82,8 @@ class LutManager(private val context: Context) {
|
||||
vignette = preferences[vignetteKey(lutId)] ?: 0f,
|
||||
bleachBypass = preferences[bleachBypassKey(lutId)] ?: 0f,
|
||||
halation = preferences[halationKey(lutId)] ?: 0f,
|
||||
lutIntensity = preferences[lutIntensityKey(lutId)] ?: 1f
|
||||
lutIntensity = preferences[lutIntensityKey(lutId)] ?: 1f,
|
||||
remarks = preferences[remarksKey(lutId)] ?: ""
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -219,6 +222,7 @@ class LutManager(private val context: Context) {
|
||||
preferences[bleachBypassKey(lutId)] = params.bleachBypass
|
||||
preferences[halationKey(lutId)] = params.halation
|
||||
preferences[lutIntensityKey(lutId)] = params.lutIntensity
|
||||
preferences[remarksKey(lutId)] = params.remarks
|
||||
}
|
||||
PLog.d(TAG, "Color recipe params saved for LUT [$lutId]: $params")
|
||||
}
|
||||
@@ -245,7 +249,8 @@ class LutManager(private val context: Context) {
|
||||
vignette = preferences[vignetteKey(lutId)] ?: 0f,
|
||||
bleachBypass = preferences[bleachBypassKey(lutId)] ?: 0f,
|
||||
halation = preferences[halationKey(lutId)] ?: 0f,
|
||||
lutIntensity = preferences[lutIntensityKey(lutId)] ?: 1f
|
||||
lutIntensity = preferences[lutIntensityKey(lutId)] ?: 1f,
|
||||
remarks = preferences[remarksKey(lutId)] ?: ""
|
||||
)
|
||||
}.firstOrNull() ?: ColorRecipeParams.DEFAULT
|
||||
}
|
||||
@@ -281,6 +286,7 @@ class LutManager(private val context: Context) {
|
||||
preferences.remove(bleachBypassKey(lutId))
|
||||
preferences.remove(halationKey(lutId))
|
||||
preferences.remove(lutIntensityKey(lutId))
|
||||
preferences.remove(remarksKey(lutId))
|
||||
}
|
||||
PLog.d(TAG, "Color recipe params deleted for LUT [$lutId]")
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ data class ColorRecipeParams(
|
||||
val bleachBypass: Float = 0f, // 0.0 ~ 1.0 (留银冲洗强度,0为无效果)
|
||||
val halation: Float = 0f, // 0.0 ~ 1.0 (光晕/高光扩散强度,0为无效果,模拟 GR3 HDF)
|
||||
val lutIntensity: Float = 1f, // 0.0 ~ 1.0 (LUT强度,1为完全应用)
|
||||
val remarks: String = "", // 用户备注
|
||||
) {
|
||||
/**
|
||||
* 检查参数是否为默认值(无任何调整)
|
||||
@@ -39,7 +40,8 @@ data class ColorRecipeParams(
|
||||
filmGrain == 0f &&
|
||||
vignette == 0f &&
|
||||
bleachBypass == 0f &&
|
||||
halation == 0f
|
||||
halation == 0f &&
|
||||
remarks.isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +61,8 @@ data class ColorRecipeParams(
|
||||
vignette == other.vignette &&
|
||||
bleachBypass == other.bleachBypass &&
|
||||
halation == other.halation &&
|
||||
lutIntensity == other.lutIntensity
|
||||
lutIntensity == other.lutIntensity &&
|
||||
remarks == other.remarks
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -54,6 +54,16 @@ fun LutEditBottomSheet(
|
||||
.fillMaxWidth()
|
||||
.navigationBarsPadding()
|
||||
) {
|
||||
// 备注栏 (最上面单独起一行)
|
||||
com.hinnka.mycamera.ui.components.ColorRecipeRemarksBar(
|
||||
remarks = editingParams.remarks,
|
||||
onRemarksChange = {
|
||||
editingParams = editingParams.copy(remarks = it)
|
||||
viewModel.saveLutColorRecipe(lutId, editingParams)
|
||||
},
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
)
|
||||
|
||||
LutIntensitySlider(
|
||||
intensity = editingParams.lutIntensity,
|
||||
onIntensityChange = {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.hinnka.mycamera.ui.components
|
||||
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
@@ -17,6 +18,20 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Edit
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import com.hinnka.mycamera.R
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.model.RecipeParam
|
||||
@@ -134,6 +149,116 @@ fun ColorRecipePanel(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 色彩配方备注栏
|
||||
*/
|
||||
@Composable
|
||||
fun ColorRecipeRemarksBar(
|
||||
remarks: String,
|
||||
onRemarksChange: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var isEditing by remember { mutableStateOf(false) }
|
||||
var text by remember(remarks) { mutableStateOf(remarks) }
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
val focusManager = LocalFocusManager.current
|
||||
|
||||
LaunchedEffect(isEditing) {
|
||||
if (isEditing) {
|
||||
focusRequester.requestFocus()
|
||||
}
|
||||
}
|
||||
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(Color.White.copy(alpha = 0.05f)) // 极简半透明白
|
||||
.border(
|
||||
width = 0.5.dp,
|
||||
color = if (isEditing) Color(0xFFFFD700).copy(alpha = 0.5f) else Color.White.copy(alpha = 0.1f),
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
)
|
||||
.clickable(enabled = !isEditing) { isEditing = true }
|
||||
.padding(horizontal = 14.dp, vertical = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
// 左侧提示图标
|
||||
Icon(
|
||||
imageVector = Icons.Default.Edit,
|
||||
contentDescription = null,
|
||||
tint = Color.White.copy(alpha = 0.3f),
|
||||
modifier = Modifier.size(14.dp)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.width(10.dp))
|
||||
|
||||
Box(modifier = Modifier.weight(1f)) {
|
||||
if (isEditing) {
|
||||
BasicTextField(
|
||||
value = text,
|
||||
onValueChange = { text = it },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.focusRequester(focusRequester),
|
||||
textStyle = TextStyle(
|
||||
color = Color.White,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.Medium
|
||||
),
|
||||
cursorBrush = SolidColor(Color.White),
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions(
|
||||
onDone = {
|
||||
onRemarksChange(text)
|
||||
isEditing = false
|
||||
focusManager.clearFocus()
|
||||
}
|
||||
),
|
||||
decorationBox = { innerTextField ->
|
||||
if (text.isEmpty()) {
|
||||
Text(
|
||||
text = stringResource(R.string.recipe_placeholder_remarks),
|
||||
color = Color.White.copy(alpha = 0.25f),
|
||||
fontSize = 13.sp
|
||||
)
|
||||
}
|
||||
innerTextField()
|
||||
}
|
||||
)
|
||||
} else {
|
||||
Text(
|
||||
text = if (remarks.isEmpty()) stringResource(R.string.recipe_placeholder_remarks) else remarks,
|
||||
color = if (remarks.isEmpty()) Color.White.copy(alpha = 0.3f) else Color.White,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
maxLines = 1,
|
||||
overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 状态切换按钮
|
||||
IconButton(
|
||||
onClick = {
|
||||
if (isEditing) {
|
||||
onRemarksChange(text)
|
||||
focusManager.clearFocus()
|
||||
}
|
||||
isEditing = !isEditing
|
||||
},
|
||||
modifier = Modifier.size(20.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = if (isEditing) Icons.Default.Check else Icons.Default.Edit,
|
||||
contentDescription = null,
|
||||
tint = if (isEditing) Color(0xFFFFD700) else Color.White.copy(alpha = 0.5f),
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 色彩配方参数滑块
|
||||
*/
|
||||
|
||||
@@ -1444,6 +1444,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
context,
|
||||
photo.uri,
|
||||
editLutId.value,
|
||||
photo.uri.lastPathSegment,
|
||||
sourceUri = photo.uri.toString()
|
||||
)
|
||||
} else {
|
||||
@@ -1545,20 +1546,23 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
onComplete: (Boolean) -> Unit = {}
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
val metadata = PhotoManager.loadMetadata(getApplication(), photo.id) ?: photo.metadata
|
||||
var photoId = photo.id
|
||||
if (selectedTab == GalleryTab.SYSTEM) {
|
||||
photoId = _photos.value.find { it.metadata?.sourceUri == photo.uri.toString() }?.id ?: photoId
|
||||
}
|
||||
val metadata = PhotoManager.loadMetadata(getApplication(), photoId) ?: photo.metadata
|
||||
?: PhotoMetadata()
|
||||
val context = getApplication<Application>()
|
||||
PhotoManager.exportPhoto(
|
||||
context, photo.id, bitmap, contentRepository.photoProcessor, metadata,
|
||||
val success = PhotoManager.exportPhoto(
|
||||
context, photoId, bitmap, contentRepository.photoProcessor, metadata,
|
||||
sharpening.value, noiseReduction.value,
|
||||
chromaNoiseReduction.value, photoQuality.firstOrNull() ?: 95, suffix
|
||||
) { success ->
|
||||
if (success) {
|
||||
exitEditMode()
|
||||
loadPhotos()
|
||||
}
|
||||
onComplete(success)
|
||||
)
|
||||
if (success) {
|
||||
exitEditMode()
|
||||
loadPhotos()
|
||||
}
|
||||
onComplete(success)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -227,6 +227,8 @@
|
||||
<string name="recipe_tab_light">亮度</string>
|
||||
<string name="recipe_tab_texture">效果</string>
|
||||
<string name="recipe_tab_post">细节</string>
|
||||
<string name="recipe_tab_remarks">备注</string>
|
||||
<string name="recipe_placeholder_remarks">点击添加备注信息…</string>
|
||||
|
||||
<!-- Post-Processing Parameters (Capture/Edit only) -->
|
||||
<string name="recipe_param_sharpening">锐化</string>
|
||||
|
||||
@@ -232,6 +232,8 @@
|
||||
<string name="recipe_tab_light">Light</string>
|
||||
<string name="recipe_tab_texture">Texture</string>
|
||||
<string name="recipe_tab_post">Post</string>
|
||||
<string name="recipe_tab_remarks">Notes</string>
|
||||
<string name="recipe_placeholder_remarks">Tap to add notes…</string>
|
||||
|
||||
<!-- Post-Processing Parameters (Capture/Edit only) -->
|
||||
<string name="recipe_param_sharpening">Sharpening</string>
|
||||
|
||||
Reference in new issue
Block a user