feat: color recipe
This commit is contained in:
1 parent
cdd5650223
commit
d799d2811a
30 files changed
+1430
-576
No files matched your search
@@ -1,7 +1,10 @@
|
||||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Bash(./gradlew assembleDebug:*)"
|
||||
"Bash(./gradlew assembleDebug:*)",
|
||||
"Bash(wc -l:*)",
|
||||
"Bash(./gradlew compileDebugKotlin:*)",
|
||||
"Bash(./gradlew assembleGoogleDebug:*)"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,9 @@
|
||||
- [x] LUT自定义命名
|
||||
- [x] 静音拍照添加震动
|
||||
- [x] 定制水印
|
||||
- [ ] 闪光灯异常
|
||||
- [ ] 影调配方
|
||||
- [ ] 水印定制持久化
|
||||
- [ ] raw 格式照片处理 / Halide
|
||||
- [ ] 视频拍摄
|
||||
|
||||
@@ -19,4 +21,31 @@
|
||||
* AGC ToolKit Pro
|
||||
* DAZZ
|
||||
* varlens
|
||||
* kapi
|
||||
* kapi
|
||||
|
||||
# Crashes
|
||||
|
||||
* 01-15 19:03:30.760 18622 18622 E AndroidRuntime: FATAL EXCEPTION: main
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: Process: com.hinnka.mycamera, PID: 18622
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: java.lang.IllegalStateException: Cannot transition entry that is not in the back stack
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at androidx.navigation.internal.NavControllerImpl.prepareForTransition$navigation_runtime_release(NavControllerImpl.kt:293)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at androidx.navigation.NavController$NavControllerNavigatorState.prepareForTransition(NavController.android.kt:149)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at androidx.navigation.compose.ComposeNavigator.prepareForTransition(ComposeNavigator.kt:77)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at androidx.navigation.compose.NavHostKt$NavHost$25$1.invokeSuspend(NavHost.kt:529)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at androidx.navigation.compose.NavHostKt$NavHost$25$1.invoke(Unknown Source:8)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at androidx.navigation.compose.NavHostKt$NavHost$25$1.invoke(Unknown Source:4)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at androidx.activity.compose.ComposePredictiveBackHandler$launchNewGesture$1.invokeSuspend(PredictiveBackHandler.kt:227)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch(AndroidUiDispatcher.android.kt:79)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch(AndroidUiDispatcher.android.kt:41)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.run(AndroidUiDispatcher.android.kt:57)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:1051)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:107)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:266)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at android.os.Looper.loop(Looper.java:361)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:10344)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:675)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1002)
|
||||
01-15 19:03:30.760 18622 18622 E AndroidRuntime: Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.ui.platform.MotionDurationScaleImpl@5920955, androidx.compose.runtime.BroadcastFrameClock@ac40f6a, StandaloneCoroutine{Cancelling}@8290c5b, AndroidUiDispatcher@4a02cf8]
|
||||
@@ -36,12 +36,14 @@ import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavType
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import androidx.navigation.navArgument
|
||||
import com.hinnka.mycamera.ui.camera.CameraScreen
|
||||
import com.hinnka.mycamera.ui.camera.LutEditBottomSheet
|
||||
import com.hinnka.mycamera.ui.gallery.GalleryScreen
|
||||
import com.hinnka.mycamera.ui.gallery.PhotoDetailScreen
|
||||
import com.hinnka.mycamera.ui.gallery.PhotoEditScreen
|
||||
@@ -172,84 +174,86 @@ fun NavigationHost(
|
||||
BuglyHelper.setUserScene(context, destination.route.hashCode())
|
||||
}
|
||||
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = Routes.CAMERA,
|
||||
enterTransition = {
|
||||
slideInHorizontally(initialOffsetX = { it }) + fadeIn()
|
||||
},
|
||||
exitTransition = {
|
||||
slideOutHorizontally(targetOffsetX = { -it }) + fadeOut()
|
||||
},
|
||||
popEnterTransition = {
|
||||
slideInHorizontally(initialOffsetX = { -it }) + fadeIn()
|
||||
},
|
||||
popExitTransition = {
|
||||
slideOutHorizontally(targetOffsetX = { it }) + fadeOut()
|
||||
}
|
||||
) {
|
||||
composable(Routes.CAMERA) {
|
||||
CameraScreen(
|
||||
viewModel = cameraViewModel,
|
||||
galleryViewModel = galleryViewModel,
|
||||
onGalleryClick = {
|
||||
navController.navigate(Routes.GALLERY)
|
||||
val latestPhoto = galleryViewModel.latestPhoto.value
|
||||
if (latestPhoto != null && System.currentTimeMillis() - latestPhoto.dateAdded < 3 * 60 * 1000) {
|
||||
navController.navigate(Routes.photoDetail(0))
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = Routes.CAMERA,
|
||||
enterTransition = {
|
||||
slideInHorizontally(initialOffsetX = { it }) + fadeIn()
|
||||
},
|
||||
exitTransition = {
|
||||
slideOutHorizontally(targetOffsetX = { -it }) + fadeOut()
|
||||
},
|
||||
popEnterTransition = {
|
||||
slideInHorizontally(initialOffsetX = { -it }) + fadeIn()
|
||||
},
|
||||
popExitTransition = {
|
||||
slideOutHorizontally(targetOffsetX = { it }) + fadeOut()
|
||||
}
|
||||
) {
|
||||
composable(Routes.CAMERA) {
|
||||
CameraScreen(
|
||||
viewModel = cameraViewModel,
|
||||
galleryViewModel = galleryViewModel,
|
||||
onGalleryClick = {
|
||||
navController.navigate(Routes.GALLERY)
|
||||
val latestPhoto = galleryViewModel.latestPhoto.value
|
||||
if (latestPhoto != null && System.currentTimeMillis() - latestPhoto.dateAdded < 3 * 60 * 1000) {
|
||||
navController.navigate(Routes.photoDetail(0))
|
||||
}
|
||||
},
|
||||
onSettingsClick = {
|
||||
navController.navigate(Routes.SETTINGS)
|
||||
}
|
||||
},
|
||||
onSettingsClick = {
|
||||
navController.navigate(Routes.SETTINGS)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.GALLERY) {
|
||||
GalleryScreen(
|
||||
viewModel = galleryViewModel,
|
||||
onBack = {
|
||||
navController.popBackStack()
|
||||
},
|
||||
onPhotoClick = { index ->
|
||||
navController.navigate(Routes.photoDetail(index))
|
||||
}
|
||||
)
|
||||
}
|
||||
composable(Routes.GALLERY) {
|
||||
GalleryScreen(
|
||||
viewModel = galleryViewModel,
|
||||
onBack = {
|
||||
navController.popBackStack()
|
||||
},
|
||||
onPhotoClick = { index ->
|
||||
navController.navigate(Routes.photoDetail(index))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
composable(
|
||||
route = Routes.PHOTO_DETAIL,
|
||||
arguments = listOf(navArgument("index") { type = NavType.IntType })
|
||||
) { backStackEntry ->
|
||||
val index = backStackEntry.arguments?.getInt("index") ?: 0
|
||||
PhotoDetailScreen(
|
||||
viewModel = galleryViewModel,
|
||||
initialIndex = index,
|
||||
onBack = {
|
||||
navController.popBackStack()
|
||||
},
|
||||
onEdit = {
|
||||
navController.navigate(Routes.PHOTO_EDIT)
|
||||
}
|
||||
)
|
||||
}
|
||||
composable(
|
||||
route = Routes.PHOTO_DETAIL,
|
||||
arguments = listOf(navArgument("index") { type = NavType.IntType })
|
||||
) { backStackEntry ->
|
||||
val index = backStackEntry.arguments?.getInt("index") ?: 0
|
||||
PhotoDetailScreen(
|
||||
viewModel = galleryViewModel,
|
||||
initialIndex = index,
|
||||
onBack = {
|
||||
navController.popBackStack()
|
||||
},
|
||||
onEdit = {
|
||||
navController.navigate(Routes.PHOTO_EDIT)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.PHOTO_EDIT) {
|
||||
PhotoEditScreen(
|
||||
viewModel = galleryViewModel,
|
||||
onBack = {
|
||||
navController.popBackStack()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.SETTINGS) {
|
||||
SettingsScreen(
|
||||
viewModel = cameraViewModel,
|
||||
onBack = {
|
||||
navController.popBackStack()
|
||||
}
|
||||
)
|
||||
composable(Routes.PHOTO_EDIT) {
|
||||
PhotoEditScreen(
|
||||
viewModel = galleryViewModel,
|
||||
onBack = {
|
||||
navController.popBackStack()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.SETTINGS) {
|
||||
SettingsScreen(
|
||||
viewModel = cameraViewModel,
|
||||
onBack = {
|
||||
navController.popBackStack()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1552,13 +1552,6 @@ class Camera2Controller(private val context: Context) {
|
||||
_state.value = _state.value.copy(aspectRatio = ratio)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 LUT 强度
|
||||
*/
|
||||
fun setLutIntensity(intensity: Float) {
|
||||
_state.value = _state.value.copy(lutIntensity = intensity)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 LUT 启用状态
|
||||
*
|
||||
|
||||
@@ -144,10 +144,9 @@ data class CameraState(
|
||||
|
||||
// LUT 设置
|
||||
val currentLutName: String? = null,
|
||||
val lutIntensity: Float = 1.0f,
|
||||
val lutEnabled: Boolean = false,
|
||||
val availableLuts: List<String> = emptyList(),
|
||||
|
||||
|
||||
// 直方图数据 (256个灰度值)
|
||||
val histogram: IntArray? = null,
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ class ContentRepository private constructor(context: Context) {
|
||||
fun getInstance(context: Context): ContentRepository {
|
||||
return INSTANCE ?: synchronized(this) {
|
||||
INSTANCE ?: ContentRepository(context.applicationContext).also {
|
||||
it.initialize()
|
||||
INSTANCE = it
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(na
|
||||
data class UserPreferences(
|
||||
val aspectRatio: String = "RATIO_4_3",
|
||||
val lutId: String? = null, // 默认为 null,由 CameraViewModel 根据配置文件设置
|
||||
val lutIntensity: Float = 1.0f,
|
||||
val frameId: String? = null,
|
||||
val showAppBranding: Boolean = true,
|
||||
val showHistogram: Boolean = true,
|
||||
@@ -44,7 +43,6 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
// DataStore Keys
|
||||
private val ASPECT_RATIO_KEY = stringPreferencesKey("aspect_ratio")
|
||||
private val LUT_ID_KEY = stringPreferencesKey("lut_id")
|
||||
private val LUT_INTENSITY_KEY = floatPreferencesKey("lut_intensity")
|
||||
private val FRAME_ID_KEY = stringPreferencesKey("frame_id")
|
||||
private val SHOW_APP_BRANDING_KEY = booleanPreferencesKey("show_app_branding")
|
||||
private val SHOW_HISTOGRAM = booleanPreferencesKey("show_histogram")
|
||||
@@ -64,7 +62,6 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
UserPreferences(
|
||||
aspectRatio = preferences[ASPECT_RATIO_KEY] ?: "RATIO_4_3",
|
||||
lutId = preferences[LUT_ID_KEY], // 不提供默认值,由 CameraViewModel 处理
|
||||
lutIntensity = preferences[LUT_INTENSITY_KEY] ?: 1.0f,
|
||||
frameId = preferences[FRAME_ID_KEY],
|
||||
showAppBranding = preferences[SHOW_APP_BRANDING_KEY] ?: true,
|
||||
showHistogram = preferences[SHOW_HISTOGRAM] ?: true,
|
||||
@@ -85,27 +82,17 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
preferences[ASPECT_RATIO_KEY] = aspectRatio
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存 LUT 配置
|
||||
*/
|
||||
suspend fun saveLutConfig(lutId: String?, intensity: Float) {
|
||||
suspend fun saveLutConfig(lutId: String?) {
|
||||
context.dataStore.edit { preferences ->
|
||||
if (lutId != null) {
|
||||
preferences[LUT_ID_KEY] = lutId
|
||||
} else {
|
||||
preferences.remove(LUT_ID_KEY)
|
||||
}
|
||||
preferences[LUT_INTENSITY_KEY] = intensity
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存 LUT 强度
|
||||
*/
|
||||
suspend fun saveLutIntensity(intensity: Float) {
|
||||
context.dataStore.edit { preferences ->
|
||||
preferences[LUT_INTENSITY_KEY] = intensity
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.hinnka.mycamera.frame
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.*
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import com.hinnka.mycamera.R
|
||||
@@ -38,14 +37,12 @@ class FrameRenderer(private val context: Context) {
|
||||
* @param originalBitmap 原始照片
|
||||
* @param template 边框模板
|
||||
* @param metadata EXIF 元数据
|
||||
* @param showAppBranding 是否显示 App 品牌
|
||||
* @return 带边框的照片
|
||||
*/
|
||||
fun render(
|
||||
originalBitmap: Bitmap,
|
||||
template: FrameTemplate,
|
||||
metadata: PhotoMetadata,
|
||||
showAppBranding: Boolean = true,
|
||||
): Bitmap {
|
||||
|
||||
PLog.d(TAG, "render: $metadata")
|
||||
@@ -137,7 +134,7 @@ class FrameRenderer(private val context: Context) {
|
||||
when (layout.position) {
|
||||
FramePosition.BOTTOM -> {
|
||||
drawFrameContent(
|
||||
canvas, template.elements, metadata, showAppBranding,
|
||||
canvas, template.elements, metadata,
|
||||
left = padding.toFloat(),
|
||||
top = originalBitmap.height.toFloat(),
|
||||
right = (outputWidth - padding).toFloat(),
|
||||
@@ -148,7 +145,7 @@ class FrameRenderer(private val context: Context) {
|
||||
|
||||
FramePosition.TOP -> {
|
||||
drawFrameContent(
|
||||
canvas, template.elements, metadata, showAppBranding,
|
||||
canvas, template.elements, metadata,
|
||||
left = padding.toFloat(),
|
||||
top = 0f,
|
||||
right = (outputWidth - padding).toFloat(),
|
||||
@@ -160,7 +157,7 @@ class FrameRenderer(private val context: Context) {
|
||||
FramePosition.BOTH -> {
|
||||
// 顶部
|
||||
drawFrameContent(
|
||||
canvas, template.elements, metadata, showAppBranding,
|
||||
canvas, template.elements, metadata,
|
||||
left = padding.toFloat(),
|
||||
top = 0f,
|
||||
right = (outputWidth - padding).toFloat(),
|
||||
@@ -169,7 +166,7 @@ class FrameRenderer(private val context: Context) {
|
||||
)
|
||||
// 底部
|
||||
drawFrameContent(
|
||||
canvas, template.elements, metadata, showAppBranding,
|
||||
canvas, template.elements, metadata,
|
||||
left = padding.toFloat(),
|
||||
top = (originalBitmap.height + frameHeight).toFloat(),
|
||||
right = (outputWidth - padding).toFloat(),
|
||||
@@ -196,7 +193,7 @@ class FrameRenderer(private val context: Context) {
|
||||
|
||||
// 绘制水印内容
|
||||
drawFrameContent(
|
||||
canvas, template.elements, metadata, showAppBranding,
|
||||
canvas, template.elements, metadata,
|
||||
left = padding.toFloat(),
|
||||
top = overlayTop + padding.toFloat(),
|
||||
right = (outputWidth - padding).toFloat(),
|
||||
@@ -209,7 +206,7 @@ class FrameRenderer(private val context: Context) {
|
||||
// 四周边框模式:底部信息区
|
||||
val infoTop = (originalBitmap.height + borderWidth * 2).toFloat()
|
||||
drawFrameContent(
|
||||
canvas, template.elements, metadata, showAppBranding,
|
||||
canvas, template.elements, metadata,
|
||||
left = padding.toFloat(),
|
||||
top = infoTop,
|
||||
right = (outputWidth - padding).toFloat(),
|
||||
@@ -226,7 +223,6 @@ class FrameRenderer(private val context: Context) {
|
||||
canvas: Canvas,
|
||||
elements: List<FrameElement>,
|
||||
metadata: PhotoMetadata,
|
||||
showAppBranding: Boolean,
|
||||
left: Float,
|
||||
top: Float,
|
||||
right: Float,
|
||||
@@ -236,16 +232,14 @@ class FrameRenderer(private val context: Context) {
|
||||
// 将元素按对齐方式分组并过滤不可见元素
|
||||
val startElements = filterVisibleGroup(
|
||||
elements.filter { getAlignment(it) == ElementAlignment.START },
|
||||
metadata,
|
||||
showAppBranding
|
||||
metadata
|
||||
)
|
||||
val centerElements = filterVisibleGroup(
|
||||
elements.filter { getAlignment(it) == ElementAlignment.CENTER },
|
||||
metadata,
|
||||
showAppBranding
|
||||
metadata
|
||||
)
|
||||
val endElements =
|
||||
filterVisibleGroup(elements.filter { getAlignment(it) == ElementAlignment.END }, metadata, showAppBranding)
|
||||
filterVisibleGroup(elements.filter { getAlignment(it) == ElementAlignment.END }, metadata)
|
||||
|
||||
val visibleElements = startElements + centerElements + endElements
|
||||
|
||||
@@ -295,7 +289,7 @@ class FrameRenderer(private val context: Context) {
|
||||
val centerY = getLineCenterY(line)
|
||||
|
||||
val x = currentXPerLine.getOrDefault(line, initialX)
|
||||
val width = drawElement(canvas, element, metadata, showAppBranding, x, centerY, leftToRight, scale)
|
||||
val width = drawElement(canvas, element, metadata, x, centerY, leftToRight, scale)
|
||||
|
||||
val nextX = if (leftToRight) x + width else x - width
|
||||
|
||||
@@ -323,7 +317,7 @@ class FrameRenderer(private val context: Context) {
|
||||
for ((line, lineElements) in elementsByLine) {
|
||||
// 计算该行的总宽度(扣除最后一个元素的间距)
|
||||
val lineWidth = lineElements.sumOf {
|
||||
measureElementWidth(it, metadata, showAppBranding, scale).toDouble()
|
||||
measureElementWidth(it, metadata, scale).toDouble()
|
||||
}.toFloat() - elementSpacing // 减去最后一个元素多余的间距
|
||||
|
||||
// 计算该行的起始 X 位置(居中)
|
||||
@@ -334,7 +328,7 @@ class FrameRenderer(private val context: Context) {
|
||||
var currentX = startX
|
||||
for ((index, element) in lineElements.withIndex()) {
|
||||
val isLast = index == lineElements.size - 1
|
||||
val width = drawElement(canvas, element, metadata, showAppBranding, currentX, centerY, true, scale)
|
||||
val width = drawElement(canvas, element, metadata, currentX, centerY, true, scale)
|
||||
// 最后一个元素不加间距
|
||||
currentX += if (isLast) (width - elementSpacing) else width
|
||||
}
|
||||
@@ -383,7 +377,7 @@ class FrameRenderer(private val context: Context) {
|
||||
): Float {
|
||||
val xPerLine = mutableMapOf<Int, Float>()
|
||||
for (element in elements) {
|
||||
val width = measureElementWidth(element, metadata, showAppBranding, scale)
|
||||
val width = measureElementWidth(element, metadata, scale)
|
||||
val line = getLine(element)
|
||||
|
||||
if (line == -1) {
|
||||
@@ -400,11 +394,10 @@ class FrameRenderer(private val context: Context) {
|
||||
return xPerLine.values.maxOrNull() ?: 0f
|
||||
}
|
||||
|
||||
private fun isElementVisible(element: FrameElement, metadata: PhotoMetadata, showAppBranding: Boolean): Boolean {
|
||||
private fun isElementVisible(element: FrameElement, metadata: PhotoMetadata): Boolean {
|
||||
return when (element) {
|
||||
is FrameElement.Text -> getTextContent(element, metadata, showAppBranding) != null
|
||||
is FrameElement.Text -> getTextContent(element, metadata) != null
|
||||
is FrameElement.Logo -> {
|
||||
if (element.logoType == LogoType.APP && !showAppBranding) return false
|
||||
val logoKey = metadata.customProperties["LOGO"]
|
||||
logoKey != "none"
|
||||
}
|
||||
@@ -417,9 +410,8 @@ class FrameRenderer(private val context: Context) {
|
||||
private fun filterVisibleGroup(
|
||||
elements: List<FrameElement>,
|
||||
metadata: PhotoMetadata,
|
||||
showAppBranding: Boolean
|
||||
): List<FrameElement> {
|
||||
val initiallyVisible = elements.filter { isElementVisible(it, metadata, showAppBranding) }
|
||||
val initiallyVisible = elements.filter { isElementVisible(it, metadata) }
|
||||
val result = mutableListOf<FrameElement>()
|
||||
for (i in initiallyVisible.indices) {
|
||||
val element = initiallyVisible[i]
|
||||
@@ -449,12 +441,11 @@ class FrameRenderer(private val context: Context) {
|
||||
private fun measureElementWidth(
|
||||
element: FrameElement,
|
||||
metadata: PhotoMetadata,
|
||||
showAppBranding: Boolean,
|
||||
scale: Float = 1f
|
||||
): Float {
|
||||
return when (element) {
|
||||
is FrameElement.Text -> {
|
||||
val text = getTextContent(element, metadata, showAppBranding) ?: return 0f
|
||||
val text = getTextContent(element, metadata) ?: return 0f
|
||||
textPaint.textSize = spToPx(element.fontSizeSp) * scale
|
||||
textPaint.typeface = getTypeface(element.fontWeight)
|
||||
textPaint.measureText(text) + dpToPx(8) * scale
|
||||
@@ -490,7 +481,6 @@ class FrameRenderer(private val context: Context) {
|
||||
canvas: Canvas,
|
||||
element: FrameElement,
|
||||
metadata: PhotoMetadata,
|
||||
showAppBranding: Boolean,
|
||||
x: Float,
|
||||
centerY: Float,
|
||||
leftToRight: Boolean,
|
||||
@@ -501,7 +491,6 @@ class FrameRenderer(private val context: Context) {
|
||||
canvas,
|
||||
element,
|
||||
metadata,
|
||||
showAppBranding,
|
||||
x,
|
||||
centerY,
|
||||
leftToRight,
|
||||
@@ -511,7 +500,6 @@ class FrameRenderer(private val context: Context) {
|
||||
is FrameElement.Logo -> drawLogoElement(
|
||||
canvas,
|
||||
element,
|
||||
showAppBranding,
|
||||
x,
|
||||
centerY,
|
||||
leftToRight,
|
||||
@@ -531,13 +519,12 @@ class FrameRenderer(private val context: Context) {
|
||||
canvas: Canvas,
|
||||
element: FrameElement.Text,
|
||||
metadata: PhotoMetadata,
|
||||
showAppBranding: Boolean,
|
||||
x: Float,
|
||||
centerY: Float,
|
||||
leftToRight: Boolean,
|
||||
scale: Float = 1f
|
||||
): Float {
|
||||
val text = getTextContent(element, metadata, showAppBranding) ?: return x
|
||||
val text = getTextContent(element, metadata) ?: return x
|
||||
|
||||
textPaint.color = element.color
|
||||
textPaint.textSize = spToPx(element.fontSizeSp) * scale
|
||||
@@ -560,7 +547,6 @@ class FrameRenderer(private val context: Context) {
|
||||
private fun getTextContent(
|
||||
element: FrameElement.Text,
|
||||
metadata: PhotoMetadata,
|
||||
showAppBranding: Boolean
|
||||
): String? {
|
||||
val content = when (element.textType) {
|
||||
TextType.DEVICE_MODEL -> metadata.deviceModel
|
||||
@@ -585,7 +571,7 @@ class FrameRenderer(private val context: Context) {
|
||||
TextType.APERTURE -> metadata.aperture
|
||||
TextType.RESOLUTION -> metadata.resolution
|
||||
TextType.CUSTOM -> element.format
|
||||
TextType.APP_NAME -> if (showAppBranding) context.getString(R.string.app_name) else null
|
||||
TextType.APP_NAME -> context.getString(R.string.app_name)
|
||||
} ?: return null
|
||||
|
||||
// 允许用户自定义覆盖内容
|
||||
@@ -639,7 +625,6 @@ class FrameRenderer(private val context: Context) {
|
||||
private fun drawLogoElement(
|
||||
canvas: Canvas,
|
||||
element: FrameElement.Logo,
|
||||
showAppBranding: Boolean,
|
||||
x: Float,
|
||||
centerY: Float,
|
||||
leftToRight: Boolean,
|
||||
@@ -647,9 +632,6 @@ class FrameRenderer(private val context: Context) {
|
||||
scale: Float = 1f
|
||||
): Float {
|
||||
// 如果是 App Logo 且不显示品牌,则跳过
|
||||
if (element.logoType == LogoType.APP && !showAppBranding) {
|
||||
return x
|
||||
}
|
||||
val margin = dpToPx(element.marginDp) * scale
|
||||
|
||||
val size = (dpToPx(element.sizeDp) * scale).toInt()
|
||||
@@ -779,7 +761,7 @@ class FrameRenderer(private val context: Context) {
|
||||
|
||||
// 渲染边框
|
||||
val metadata = PhotoMetadata.createDefault(scaledWidth, scaledHeight)
|
||||
return render(scaledBitmap, template, metadata, showAppBranding = true)
|
||||
return render(scaledBitmap, template, metadata)
|
||||
}
|
||||
|
||||
// 工具方法
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.utils.PLog
|
||||
import org.json.JSONObject
|
||||
import java.text.SimpleDateFormat
|
||||
@@ -17,15 +18,13 @@ import kotlin.text.toInt
|
||||
* 保存 LUT、边框水印、编辑信息和拍摄参数,用于非破坏性编辑和边框水印渲染
|
||||
*/
|
||||
data class PhotoMetadata(
|
||||
val version: Int = 4,
|
||||
val version: Int = 5, // 升级版本以支持色彩配方
|
||||
// 编辑配置
|
||||
val lutId: String? = null,
|
||||
val lutIntensity: Float = 1f,
|
||||
val brightness: Float = 1f,
|
||||
val rotation: Float = 0f,
|
||||
// 色彩配方配置
|
||||
val colorRecipeParams: ColorRecipeParams? = null,
|
||||
// 边框水印配置
|
||||
val frameId: String? = null,
|
||||
val showAppBranding: Boolean = true,
|
||||
// 图片尺寸
|
||||
val width: Int = 0,
|
||||
val height: Int = 0,
|
||||
@@ -55,11 +54,24 @@ data class PhotoMetadata(
|
||||
return JSONObject().apply {
|
||||
put("version", version)
|
||||
put("lutId", lutId ?: JSONObject.NULL)
|
||||
put("lutIntensity", lutIntensity.toDouble())
|
||||
put("brightness", brightness.toDouble())
|
||||
put("rotation", rotation.toDouble())
|
||||
// 色彩配方配置
|
||||
if (colorRecipeParams != null) {
|
||||
put("colorRecipeParams", JSONObject().apply {
|
||||
put("exposure", colorRecipeParams.exposure.toDouble())
|
||||
put("contrast", colorRecipeParams.contrast.toDouble())
|
||||
put("saturation", colorRecipeParams.saturation.toDouble())
|
||||
put("temperature", colorRecipeParams.temperature.toDouble())
|
||||
put("tint", colorRecipeParams.tint.toDouble())
|
||||
put("fade", colorRecipeParams.fade.toDouble())
|
||||
put("vibrance", colorRecipeParams.vibrance.toDouble())
|
||||
put("highlights", colorRecipeParams.highlights.toDouble())
|
||||
put("shadows", colorRecipeParams.shadows.toDouble())
|
||||
put("lutIntensity", colorRecipeParams.lutIntensity.toDouble())
|
||||
})
|
||||
} else {
|
||||
put("colorRecipeParams", JSONObject.NULL)
|
||||
}
|
||||
put("frameId", frameId ?: JSONObject.NULL)
|
||||
put("showAppBranding", showAppBranding)
|
||||
put("width", width)
|
||||
put("height", height)
|
||||
// 拍摄信息
|
||||
@@ -98,14 +110,30 @@ data class PhotoMetadata(
|
||||
}
|
||||
}
|
||||
|
||||
// 解析色彩配方参数
|
||||
val colorRecipeParamsObj = obj.optJSONObject("colorRecipeParams")
|
||||
val colorRecipeParams = if (colorRecipeParamsObj != null && !obj.isNull("colorRecipeParams")) {
|
||||
ColorRecipeParams(
|
||||
exposure = colorRecipeParamsObj.optDouble("exposure", 0.0).toFloat(),
|
||||
contrast = colorRecipeParamsObj.optDouble("contrast", 1.0).toFloat(),
|
||||
saturation = colorRecipeParamsObj.optDouble("saturation", 1.0).toFloat(),
|
||||
temperature = colorRecipeParamsObj.optDouble("temperature", 0.0).toFloat(),
|
||||
tint = colorRecipeParamsObj.optDouble("tint", 0.0).toFloat(),
|
||||
fade = colorRecipeParamsObj.optDouble("fade", 0.0).toFloat(),
|
||||
vibrance = colorRecipeParamsObj.optDouble("vibrance", 1.0).toFloat(),
|
||||
highlights = colorRecipeParamsObj.optDouble("highlights", 0.0).toFloat(),
|
||||
shadows = colorRecipeParamsObj.optDouble("shadows", 0.0).toFloat(),
|
||||
lutIntensity = colorRecipeParamsObj.optDouble("lutIntensity", 1.0).toFloat()
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
PhotoMetadata(
|
||||
version = obj.optInt("version", 1),
|
||||
lutId = if (obj.isNull("lutId")) null else obj.optString("lutId"),
|
||||
lutIntensity = obj.optDouble("lutIntensity", 1.0).toFloat(),
|
||||
brightness = obj.optDouble("brightness", 1.0).toFloat(),
|
||||
rotation = obj.optDouble("rotation", 0.0).toFloat(),
|
||||
colorRecipeParams = colorRecipeParams,
|
||||
frameId = if (obj.isNull("frameId")) null else obj.optString("frameId"),
|
||||
showAppBranding = obj.optBoolean("showAppBranding", true),
|
||||
width = obj.optInt("width", 0),
|
||||
height = obj.optInt("height", 0),
|
||||
// 拍摄信息
|
||||
|
||||
@@ -39,24 +39,16 @@ class PhotoProcessor(
|
||||
var result = input
|
||||
|
||||
// 1. 应用 LUT
|
||||
if (metadata.lutId != null && metadata.lutIntensity > 0f) {
|
||||
if (metadata.lutId != null) {
|
||||
val lutConfig = lutManager.loadLut(metadata.lutId)
|
||||
if (lutConfig != null) {
|
||||
val lutResult = lutImageProcessor.applyLut(result, lutConfig, metadata.lutIntensity)
|
||||
val colorRecipeParams = lutManager.loadColorRecipeParams(metadata.lutId)
|
||||
if (lutConfig != null && colorRecipeParams.lutIntensity > 0f) {
|
||||
val lutResult = lutImageProcessor.applyLut(result, lutConfig, colorRecipeParams)
|
||||
result = lutResult
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 应用旋转和亮度
|
||||
if (metadata.rotation != 0f || metadata.brightness != 1f) {
|
||||
val editedResult = applyEdits(result, metadata.rotation, metadata.brightness)
|
||||
if (editedResult != result && result != input) {
|
||||
result.recycle()
|
||||
}
|
||||
result = editedResult
|
||||
}
|
||||
|
||||
// 3. 应用边框水印
|
||||
// 2. 应用边框水印
|
||||
if (metadata.frameId != null) {
|
||||
val template = frameManager.loadTemplate(metadata.frameId)
|
||||
if (template != null) {
|
||||
@@ -98,7 +90,6 @@ class PhotoProcessor(
|
||||
result,
|
||||
template,
|
||||
finalMetadata,
|
||||
metadata.showAppBranding
|
||||
)
|
||||
if (framedResult != result && result != input) {
|
||||
result.recycle()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hinnka.mycamera.lut
|
||||
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import java.nio.FloatBuffer
|
||||
@@ -94,22 +95,6 @@ data class LutConfig(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* LUT 强度预设
|
||||
*/
|
||||
enum class LutIntensity(val value: Float, val displayRes: Int) {
|
||||
NONE(0f, com.hinnka.mycamera.R.string.lut_intensity_none),
|
||||
LOW(0.33f, com.hinnka.mycamera.R.string.lut_intensity_low),
|
||||
MEDIUM(0.66f, com.hinnka.mycamera.R.string.lut_intensity_medium),
|
||||
FULL(1.0f, com.hinnka.mycamera.R.string.lut_intensity_high);
|
||||
|
||||
companion object {
|
||||
fun fromValue(value: Float): LutIntensity {
|
||||
return entries.minByOrNull { kotlin.math.abs(it.value - value) } ?: FULL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* LUT 信息(用于列表展示)
|
||||
*/
|
||||
@@ -119,7 +104,7 @@ data class LutInfo(
|
||||
val fileName: String,
|
||||
val isBuiltIn: Boolean = true,
|
||||
val isDefault: Boolean = false, // 是否为默认 LUT
|
||||
val isVip: Boolean = false // 是否为 VIP LUT
|
||||
val isVip: Boolean = false, // 是否为 VIP LUT
|
||||
) {
|
||||
/**
|
||||
* 获取显示名称(优先当前系统语言)
|
||||
|
||||
@@ -7,7 +7,7 @@ import android.opengl.EGLContext
|
||||
import android.opengl.EGLDisplay
|
||||
import android.opengl.EGLSurface
|
||||
import android.opengl.GLES30
|
||||
import android.util.Log
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.utils.PLog
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -45,7 +45,7 @@ class LutImageProcessor {
|
||||
private var indexBuffer: ShortBuffer? = null
|
||||
|
||||
private var isInitialized = false
|
||||
|
||||
|
||||
// Uniform 位置
|
||||
private var uImageTextureLoc = 0
|
||||
private var uLutTextureLoc = 0
|
||||
@@ -53,6 +53,18 @@ class LutImageProcessor {
|
||||
private var uLutIntensityLoc = 0
|
||||
private var uLutEnabledLoc = 0
|
||||
private var uMVPMatrixLoc = 0
|
||||
|
||||
// 色彩配方 Uniform 位置
|
||||
private var uColorRecipeEnabledLoc = 0
|
||||
private var uExposureLoc = 0
|
||||
private var uContrastLoc = 0
|
||||
private var uSaturationLoc = 0
|
||||
private var uTemperatureLoc = 0
|
||||
private var uTintLoc = 0
|
||||
private var uFadeLoc = 0
|
||||
private var uVibranceLoc = 0
|
||||
private var uHighlightsLoc = 0
|
||||
private var uShadowsLoc = 0
|
||||
|
||||
/**
|
||||
* 初始化 EGL 环境
|
||||
@@ -144,13 +156,26 @@ class LutImageProcessor {
|
||||
suspend fun applyLut(
|
||||
bitmap: Bitmap,
|
||||
lutConfig: LutConfig?,
|
||||
intensity: Float
|
||||
colorRecipeParams: ColorRecipeParams?,
|
||||
): Bitmap = withContext(glDispatcher) {
|
||||
if (!isInitialized) {
|
||||
if (!initialize()) {
|
||||
return@withContext bitmap
|
||||
}
|
||||
}
|
||||
|
||||
// 提取色彩配方参数
|
||||
val colorRecipeEnabled = colorRecipeParams != null && !colorRecipeParams.isDefault()
|
||||
val exposure = colorRecipeParams?.exposure ?: 0f
|
||||
val contrast = colorRecipeParams?.contrast ?: 1f
|
||||
val saturation = colorRecipeParams?.saturation ?: 1f
|
||||
val temperature = colorRecipeParams?.temperature ?: 0f
|
||||
val tint = colorRecipeParams?.tint ?: 0f
|
||||
val fade = colorRecipeParams?.fade ?: 0f
|
||||
val vibrance = colorRecipeParams?.vibrance ?: 1f
|
||||
val highlights = colorRecipeParams?.highlights ?: 0f
|
||||
val shadows = colorRecipeParams?.shadows ?: 0f
|
||||
val intensity = colorRecipeParams?.lutIntensity ?: 1f
|
||||
|
||||
// 确保上下文激活
|
||||
EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)
|
||||
@@ -190,7 +215,21 @@ class LutImageProcessor {
|
||||
GLES30.glUniform1f(uLutSizeLoc, lutConfig?.size?.toFloat() ?: 0f)
|
||||
GLES30.glUniform1f(uLutIntensityLoc, if (lutConfig != null) intensity else 0f)
|
||||
GLES30.glUniform1i(uLutEnabledLoc, if (lutConfig != null) 1 else 0)
|
||||
|
||||
|
||||
// 设置色彩配方参数
|
||||
GLES30.glUniform1i(uColorRecipeEnabledLoc, if (colorRecipeEnabled) 1 else 0)
|
||||
if (colorRecipeEnabled) {
|
||||
GLES30.glUniform1f(uExposureLoc, exposure)
|
||||
GLES30.glUniform1f(uContrastLoc, contrast)
|
||||
GLES30.glUniform1f(uSaturationLoc, saturation)
|
||||
GLES30.glUniform1f(uTemperatureLoc, temperature)
|
||||
GLES30.glUniform1f(uTintLoc, tint)
|
||||
GLES30.glUniform1f(uFadeLoc, fade)
|
||||
GLES30.glUniform1f(uVibranceLoc, vibrance)
|
||||
GLES30.glUniform1f(uHighlightsLoc, highlights)
|
||||
GLES30.glUniform1f(uShadowsLoc, shadows)
|
||||
}
|
||||
|
||||
// 设置 MVP 矩阵(单位矩阵)
|
||||
val mvpMatrix = FloatArray(16)
|
||||
android.opengl.Matrix.setIdentityM(mvpMatrix, 0)
|
||||
@@ -319,13 +358,13 @@ class LutImageProcessor {
|
||||
|
||||
private fun initShaderProgram() {
|
||||
val vertexShader = compileShader(GLES30.GL_VERTEX_SHADER, IMAGE_VERTEX_SHADER)
|
||||
val fragmentShader = compileShader(GLES30.GL_FRAGMENT_SHADER, IMAGE_FRAGMENT_SHADER_LUT)
|
||||
|
||||
val fragmentShader = compileShader(GLES30.GL_FRAGMENT_SHADER, IMAGE_FRAGMENT_SHADER_COLOR_RECIPE)
|
||||
|
||||
shaderProgram = GLES30.glCreateProgram()
|
||||
GLES30.glAttachShader(shaderProgram, vertexShader)
|
||||
GLES30.glAttachShader(shaderProgram, fragmentShader)
|
||||
GLES30.glLinkProgram(shaderProgram)
|
||||
|
||||
|
||||
// 获取 uniform 位置
|
||||
uImageTextureLoc = GLES30.glGetUniformLocation(shaderProgram, "uImageTexture")
|
||||
uLutTextureLoc = GLES30.glGetUniformLocation(shaderProgram, "uLutTexture")
|
||||
@@ -333,6 +372,18 @@ class LutImageProcessor {
|
||||
uLutIntensityLoc = GLES30.glGetUniformLocation(shaderProgram, "uLutIntensity")
|
||||
uLutEnabledLoc = GLES30.glGetUniformLocation(shaderProgram, "uLutEnabled")
|
||||
uMVPMatrixLoc = GLES30.glGetUniformLocation(shaderProgram, "uMVPMatrix")
|
||||
|
||||
// 获取色彩配方 uniform 位置
|
||||
uColorRecipeEnabledLoc = GLES30.glGetUniformLocation(shaderProgram, "uColorRecipeEnabled")
|
||||
uExposureLoc = GLES30.glGetUniformLocation(shaderProgram, "uExposure")
|
||||
uContrastLoc = GLES30.glGetUniformLocation(shaderProgram, "uContrast")
|
||||
uSaturationLoc = GLES30.glGetUniformLocation(shaderProgram, "uSaturation")
|
||||
uTemperatureLoc = GLES30.glGetUniformLocation(shaderProgram, "uTemperature")
|
||||
uTintLoc = GLES30.glGetUniformLocation(shaderProgram, "uTint")
|
||||
uFadeLoc = GLES30.glGetUniformLocation(shaderProgram, "uFade")
|
||||
uVibranceLoc = GLES30.glGetUniformLocation(shaderProgram, "uVibrance")
|
||||
uHighlightsLoc = GLES30.glGetUniformLocation(shaderProgram, "uHighlights")
|
||||
uShadowsLoc = GLES30.glGetUniformLocation(shaderProgram, "uShadows")
|
||||
}
|
||||
|
||||
private fun compileShader(type: Int, source: String): Int {
|
||||
@@ -436,37 +487,103 @@ class LutImageProcessor {
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
// 2D 图片版本的片元着色器(带 LUT)
|
||||
private val IMAGE_FRAGMENT_SHADER_LUT = """
|
||||
// 2D 图片版本的片元着色器(带色彩配方和 LUT)
|
||||
private val IMAGE_FRAGMENT_SHADER_COLOR_RECIPE = """
|
||||
#version 300 es
|
||||
|
||||
precision mediump float;
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
in vec2 vTexCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
|
||||
uniform sampler2D uImageTexture;
|
||||
uniform mediump sampler3D uLutTexture;
|
||||
uniform float uLutSize;
|
||||
uniform float uLutIntensity;
|
||||
uniform bool uLutEnabled;
|
||||
|
||||
|
||||
// 色彩配方控制
|
||||
uniform bool uColorRecipeEnabled;
|
||||
|
||||
// 色彩配方参数
|
||||
uniform float uExposure; // -2.0 ~ +2.0 (EV)
|
||||
uniform float uContrast; // 0.5 ~ 1.5
|
||||
uniform float uSaturation; // 0.0 ~ 2.0
|
||||
uniform float uTemperature; // -1.0 ~ +1.0 (暖/冷色调)
|
||||
uniform float uTint; // -1.0 ~ +1.0 (绿/品红偏移)
|
||||
uniform float uFade; // 0.0 ~ 1.0 (褪色效果)
|
||||
uniform float uVibrance; // 0.0 ~ 2.0 (蓝色增强)
|
||||
uniform float uHighlights; // -1.0 ~ +1.0 (高光调整)
|
||||
uniform float uShadows; // -1.0 ~ +1.0 (阴影调整)
|
||||
|
||||
void main() {
|
||||
vec4 originalColor = texture(uImageTexture, vTexCoord);
|
||||
|
||||
if (!uLutEnabled || uLutIntensity <= 0.0) {
|
||||
fragColor = originalColor;
|
||||
// 从图片纹理采样原始颜色
|
||||
vec4 color = texture(uImageTexture, vTexCoord);
|
||||
|
||||
// Early exit 优化:无任何调整时直接输出
|
||||
if (!uColorRecipeEnabled && !uLutEnabled) {
|
||||
fragColor = color;
|
||||
return;
|
||||
}
|
||||
|
||||
// 3D LUT 查找
|
||||
float scale = (uLutSize - 1.0) / uLutSize;
|
||||
float offset = 1.0 / (2.0 * uLutSize);
|
||||
vec3 lutCoord = originalColor.rgb * scale + offset;
|
||||
vec4 lutColor = texture(uLutTexture, lutCoord);
|
||||
|
||||
vec3 finalColor = mix(originalColor.rgb, lutColor.rgb, uLutIntensity);
|
||||
fragColor = vec4(finalColor, originalColor.a);
|
||||
|
||||
// === 色彩配方处理(按专业后期流程顺序) ===
|
||||
if (uColorRecipeEnabled) {
|
||||
// 1. 曝光调整(线性空间,最先执行避免 clipping)
|
||||
color.rgb *= pow(2.0, uExposure);
|
||||
|
||||
// 2. 高光/阴影调整(分区调整,基于亮度 mask)
|
||||
float luma = dot(color.rgb, vec3(0.299, 0.587, 0.114));
|
||||
float highlightMask = smoothstep(0.5, 1.0, luma);
|
||||
float shadowMask = smoothstep(0.5, 0.0, luma);
|
||||
color.rgb *= 1.0 + uHighlights * highlightMask;
|
||||
color.rgb *= 1.0 + uShadows * shadowMask;
|
||||
|
||||
// 3. 对比度(围绕中灰点调整)
|
||||
color.rgb = (color.rgb - 0.5) * uContrast + 0.5;
|
||||
|
||||
// 4. 白平衡调整(色温 + 色调)
|
||||
color.r += uTemperature * 0.1;
|
||||
color.b -= uTemperature * 0.1;
|
||||
color.g += uTint * 0.05;
|
||||
|
||||
// 5. 饱和度(基于 Luma 的快速算法)
|
||||
float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
|
||||
color.rgb = mix(vec3(gray), color.rgb, uSaturation);
|
||||
|
||||
// 6. 蓝色增强(Vibrance)
|
||||
float blueness = color.b - max(color.r, color.g);
|
||||
if (blueness > 0.0) {
|
||||
color.b += blueness * (uVibrance - 1.0) * 0.5;
|
||||
}
|
||||
|
||||
// 7. 褪色效果
|
||||
if (uFade > 0.0) {
|
||||
float fadeAmount = uFade * 0.3;
|
||||
color.rgb = mix(color.rgb, vec3(0.5), fadeAmount);
|
||||
color.rgb += fadeAmount * 0.1;
|
||||
}
|
||||
|
||||
// Clamp 到合法范围
|
||||
color.rgb = clamp(color.rgb, 0.0, 1.0);
|
||||
}
|
||||
|
||||
// === LUT 处理(在色彩配方之后) ===
|
||||
if (uLutEnabled && uLutIntensity > 0.0) {
|
||||
// 3D LUT 查找
|
||||
float scale = (uLutSize - 1.0) / uLutSize;
|
||||
float offset = 1.0 / (2.0 * uLutSize);
|
||||
|
||||
// 将 RGB 值映射到 LUT 纹理坐标
|
||||
vec3 lutCoord = color.rgb * scale + offset;
|
||||
|
||||
// 从 3D LUT 纹理采样
|
||||
vec4 lutColor = texture(uLutTexture, lutCoord);
|
||||
|
||||
// 根据强度混合色彩配方处理后的颜色和 LUT 颜色
|
||||
color.rgb = mix(color.rgb, lutColor.rgb, uLutIntensity);
|
||||
}
|
||||
|
||||
fragColor = color;
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
@@ -1,15 +1,28 @@
|
||||
package com.hinnka.mycamera.lut
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.util.LruCache
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.core.edit
|
||||
import androidx.datastore.preferences.core.floatPreferencesKey
|
||||
import androidx.datastore.preferences.preferencesDataStore
|
||||
import com.hinnka.mycamera.data.CustomImportManager
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.utils.PLog
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
/**
|
||||
* DataStore 扩展属性
|
||||
*/
|
||||
private val Context.colorRecipeDataStore: DataStore<Preferences> by preferencesDataStore(name = "color_recipe_preferences")
|
||||
|
||||
/**
|
||||
* LUT 管理器
|
||||
*
|
||||
* 负责 LUT 的加载、缓存和管理
|
||||
* 负责 LUT 的加载、缓存和管理,以及色彩配方的持久化
|
||||
*/
|
||||
class LutManager(private val context: Context) {
|
||||
|
||||
@@ -21,6 +34,18 @@ class LutManager(private val context: Context) {
|
||||
|
||||
// 内置 LUT 目录
|
||||
private const val BUILT_IN_LUT_FOLDER = "luts"
|
||||
|
||||
// 色彩配方 DataStore Key 生成函数(每个 LUT ID 独立)
|
||||
private fun exposureKey(lutId: String) = floatPreferencesKey("${lutId}_exposure")
|
||||
private fun contrastKey(lutId: String) = floatPreferencesKey("${lutId}_contrast")
|
||||
private fun saturationKey(lutId: String) = floatPreferencesKey("${lutId}_saturation")
|
||||
private fun temperatureKey(lutId: String) = floatPreferencesKey("${lutId}_temperature")
|
||||
private fun tintKey(lutId: String) = floatPreferencesKey("${lutId}_tint")
|
||||
private fun fadeKey(lutId: String) = floatPreferencesKey("${lutId}_fade")
|
||||
private fun vibranceKey(lutId: String) = floatPreferencesKey("${lutId}_vibrance")
|
||||
private fun highlightsKey(lutId: String) = floatPreferencesKey("${lutId}_highlights")
|
||||
private fun shadowsKey(lutId: String) = floatPreferencesKey("${lutId}_shadows")
|
||||
private fun lutIntensityKey(lutId: String) = floatPreferencesKey("${lutId}_lutIntensity")
|
||||
}
|
||||
|
||||
// LUT 缓存
|
||||
@@ -32,6 +57,26 @@ class LutManager(private val context: Context) {
|
||||
// 自定义导入管理器
|
||||
private val customImportManager = CustomImportManager(context)
|
||||
|
||||
/**
|
||||
* 获取指定 LUT 的色彩配方参数 Flow
|
||||
*/
|
||||
fun getColorRecipeParams(lutId: String): Flow<ColorRecipeParams> {
|
||||
return context.colorRecipeDataStore.data.map { preferences ->
|
||||
ColorRecipeParams(
|
||||
exposure = preferences[exposureKey(lutId)] ?: 0f,
|
||||
contrast = preferences[contrastKey(lutId)] ?: 1f,
|
||||
saturation = preferences[saturationKey(lutId)] ?: 1f,
|
||||
temperature = preferences[temperatureKey(lutId)] ?: 0f,
|
||||
tint = preferences[tintKey(lutId)] ?: 0f,
|
||||
fade = preferences[fadeKey(lutId)] ?: 0f,
|
||||
vibrance = preferences[vibranceKey(lutId)] ?: 1f,
|
||||
highlights = preferences[highlightsKey(lutId)] ?: 0f,
|
||||
shadows = preferences[shadowsKey(lutId)] ?: 0f,
|
||||
lutIntensity = preferences[lutIntensityKey(lutId)] ?: 1f
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化,扫描可用的 LUT 文件(包括内置和自定义)
|
||||
*/
|
||||
@@ -145,4 +190,82 @@ class LutManager(private val context: Context) {
|
||||
fun getCacheInfo(): String {
|
||||
return "LUT Cache: ${lutCache.size()}/${CACHE_SIZE}, hits=${lutCache.hitCount()}, misses=${lutCache.missCount()}"
|
||||
}
|
||||
|
||||
// ========== 色彩配方持久化方法 ==========
|
||||
|
||||
/**
|
||||
* 保存指定 LUT 的色彩配方参数
|
||||
*
|
||||
* @param lutId LUT ID
|
||||
* @param params 色彩配方参数
|
||||
*/
|
||||
suspend fun saveColorRecipeParams(lutId: String, params: ColorRecipeParams) {
|
||||
context.colorRecipeDataStore.edit { preferences ->
|
||||
preferences[exposureKey(lutId)] = params.exposure
|
||||
preferences[contrastKey(lutId)] = params.contrast
|
||||
preferences[saturationKey(lutId)] = params.saturation
|
||||
preferences[temperatureKey(lutId)] = params.temperature
|
||||
preferences[tintKey(lutId)] = params.tint
|
||||
preferences[fadeKey(lutId)] = params.fade
|
||||
preferences[vibranceKey(lutId)] = params.vibrance
|
||||
preferences[highlightsKey(lutId)] = params.highlights
|
||||
preferences[shadowsKey(lutId)] = params.shadows
|
||||
preferences[lutIntensityKey(lutId)] = params.lutIntensity
|
||||
}
|
||||
PLog.d(TAG, "Color recipe params saved for LUT [$lutId]: $params")
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载指定 LUT 的色彩配方参数(同步方法)
|
||||
*
|
||||
* @param lutId LUT ID
|
||||
* @return 色彩配方参数,如果未设置则返回默认值
|
||||
*/
|
||||
suspend fun loadColorRecipeParams(lutId: String): ColorRecipeParams {
|
||||
return context.colorRecipeDataStore.data.map { preferences ->
|
||||
ColorRecipeParams(
|
||||
exposure = preferences[exposureKey(lutId)] ?: 0f,
|
||||
contrast = preferences[contrastKey(lutId)] ?: 1f,
|
||||
saturation = preferences[saturationKey(lutId)] ?: 1f,
|
||||
temperature = preferences[temperatureKey(lutId)] ?: 0f,
|
||||
tint = preferences[tintKey(lutId)] ?: 0f,
|
||||
fade = preferences[fadeKey(lutId)] ?: 0f,
|
||||
vibrance = preferences[vibranceKey(lutId)] ?: 1f,
|
||||
highlights = preferences[highlightsKey(lutId)] ?: 0f,
|
||||
shadows = preferences[shadowsKey(lutId)] ?: 0f,
|
||||
lutIntensity = preferences[lutIntensityKey(lutId)] ?: 1f
|
||||
)
|
||||
}.firstOrNull() ?: ColorRecipeParams.DEFAULT
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置指定 LUT 的色彩配方参数为默认值
|
||||
*
|
||||
* @param lutId LUT ID
|
||||
*/
|
||||
suspend fun resetColorRecipeParams(lutId: String) {
|
||||
saveColorRecipeParams(lutId, ColorRecipeParams.DEFAULT)
|
||||
PLog.d(TAG, "Color recipe params reset to default for LUT [$lutId]")
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定 LUT 的色彩配方参数
|
||||
*
|
||||
* @param lutId LUT ID
|
||||
*/
|
||||
suspend fun deleteColorRecipeParams(lutId: String) {
|
||||
context.colorRecipeDataStore.edit { preferences ->
|
||||
preferences.remove(exposureKey(lutId))
|
||||
preferences.remove(contrastKey(lutId))
|
||||
preferences.remove(saturationKey(lutId))
|
||||
preferences.remove(temperatureKey(lutId))
|
||||
preferences.remove(tintKey(lutId))
|
||||
preferences.remove(fadeKey(lutId))
|
||||
preferences.remove(vibranceKey(lutId))
|
||||
preferences.remove(highlightsKey(lutId))
|
||||
preferences.remove(shadowsKey(lutId))
|
||||
preferences.remove(lutIntensityKey(lutId))
|
||||
}
|
||||
PLog.d(TAG, "Color recipe params deleted for LUT [$lutId]")
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,18 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
private var uLutSizeLocation: Int = 0
|
||||
private var uLutIntensityLocation: Int = 0
|
||||
private var uLutEnabledLocation: Int = 0
|
||||
|
||||
// 色彩配方 Uniform 位置
|
||||
private var uColorRecipeEnabledLocation: Int = 0
|
||||
private var uExposureLocation: Int = 0
|
||||
private var uContrastLocation: Int = 0
|
||||
private var uSaturationLocation: Int = 0
|
||||
private var uTemperatureLocation: Int = 0
|
||||
private var uTintLocation: Int = 0
|
||||
private var uFadeLocation: Int = 0
|
||||
private var uVibranceLocation: Int = 0
|
||||
private var uHighlightsLocation: Int = 0
|
||||
private var uShadowsLocation: Int = 0
|
||||
|
||||
// Attribute 位置
|
||||
private var aPositionLocation: Int = 0
|
||||
@@ -81,7 +93,29 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
// LUT 是否启用
|
||||
@Volatile
|
||||
var lutEnabled: Boolean = false
|
||||
|
||||
|
||||
// 色彩配方参数
|
||||
@Volatile
|
||||
var colorRecipeEnabled: Boolean = false
|
||||
@Volatile
|
||||
var exposure: Float = 0f // -2.0 ~ +2.0
|
||||
@Volatile
|
||||
var contrast: Float = 1f // 0.5 ~ 1.5
|
||||
@Volatile
|
||||
var saturation: Float = 1f // 0.0 ~ 2.0
|
||||
@Volatile
|
||||
var temperature: Float = 0f // -1.0 ~ +1.0
|
||||
@Volatile
|
||||
var tint: Float = 0f // -1.0 ~ +1.0
|
||||
@Volatile
|
||||
var fade: Float = 0f // 0.0 ~ 1.0
|
||||
@Volatile
|
||||
var vibrance: Float = 1f // 0.0 ~ 2.0
|
||||
@Volatile
|
||||
var highlights: Float = 0f // -1.0 ~ +1.0
|
||||
@Volatile
|
||||
var shadows: Float = 0f // -1.0 ~ +1.0
|
||||
|
||||
// 渲染尺寸
|
||||
private var viewportWidth: Int = 0
|
||||
private var viewportHeight: Int = 0
|
||||
@@ -201,7 +235,21 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
GLES30.glUniform1f(uLutSizeLocation, lutSize)
|
||||
GLES30.glUniform1f(uLutIntensityLocation, lutIntensity)
|
||||
GLES30.glUniform1i(uLutEnabledLocation, if (lutEnabled && lutTextureId != 0) 1 else 0)
|
||||
|
||||
|
||||
// 设置色彩配方 Uniforms
|
||||
GLES30.glUniform1i(uColorRecipeEnabledLocation, if (colorRecipeEnabled) 1 else 0)
|
||||
if (colorRecipeEnabled) {
|
||||
GLES30.glUniform1f(uExposureLocation, exposure)
|
||||
GLES30.glUniform1f(uContrastLocation, contrast)
|
||||
GLES30.glUniform1f(uSaturationLocation, saturation)
|
||||
GLES30.glUniform1f(uTemperatureLocation, temperature)
|
||||
GLES30.glUniform1f(uTintLocation, tint)
|
||||
GLES30.glUniform1f(uFadeLocation, fade)
|
||||
GLES30.glUniform1f(uVibranceLocation, vibrance)
|
||||
GLES30.glUniform1f(uHighlightsLocation, highlights)
|
||||
GLES30.glUniform1f(uShadowsLocation, shadows)
|
||||
}
|
||||
|
||||
// 绑定顶点缓冲
|
||||
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, vertexBufferId)
|
||||
GLES30.glEnableVertexAttribArray(aPositionLocation)
|
||||
@@ -255,24 +303,24 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
*/
|
||||
private fun initShaderProgram() {
|
||||
val vertexShader = GlUtils.compileShader(GLES30.GL_VERTEX_SHADER, Shaders.VERTEX_SHADER)
|
||||
val fragmentShader = GlUtils.compileShader(GLES30.GL_FRAGMENT_SHADER, Shaders.FRAGMENT_SHADER_LUT)
|
||||
|
||||
val fragmentShader = GlUtils.compileShader(GLES30.GL_FRAGMENT_SHADER, Shaders.FRAGMENT_SHADER_COLOR_RECIPE)
|
||||
|
||||
if (vertexShader == 0 || fragmentShader == 0) {
|
||||
PLog.e(TAG, "Failed to compile shaders")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
programId = GlUtils.linkProgram(vertexShader, fragmentShader)
|
||||
|
||||
|
||||
// 着色器已链接到程序,可以删除
|
||||
GLES30.glDeleteShader(vertexShader)
|
||||
GLES30.glDeleteShader(fragmentShader)
|
||||
|
||||
|
||||
if (programId == 0) {
|
||||
PLog.e(TAG, "Failed to link program")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// 获取 Uniform 位置
|
||||
uMVPMatrixLocation = GLES30.glGetUniformLocation(programId, "uMVPMatrix")
|
||||
uSTMatrixLocation = GLES30.glGetUniformLocation(programId, "uSTMatrix")
|
||||
@@ -281,11 +329,23 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
uLutSizeLocation = GLES30.glGetUniformLocation(programId, "uLutSize")
|
||||
uLutIntensityLocation = GLES30.glGetUniformLocation(programId, "uLutIntensity")
|
||||
uLutEnabledLocation = GLES30.glGetUniformLocation(programId, "uLutEnabled")
|
||||
|
||||
|
||||
// 获取色彩配方 Uniform 位置
|
||||
uColorRecipeEnabledLocation = GLES30.glGetUniformLocation(programId, "uColorRecipeEnabled")
|
||||
uExposureLocation = GLES30.glGetUniformLocation(programId, "uExposure")
|
||||
uContrastLocation = GLES30.glGetUniformLocation(programId, "uContrast")
|
||||
uSaturationLocation = GLES30.glGetUniformLocation(programId, "uSaturation")
|
||||
uTemperatureLocation = GLES30.glGetUniformLocation(programId, "uTemperature")
|
||||
uTintLocation = GLES30.glGetUniformLocation(programId, "uTint")
|
||||
uFadeLocation = GLES30.glGetUniformLocation(programId, "uFade")
|
||||
uVibranceLocation = GLES30.glGetUniformLocation(programId, "uVibrance")
|
||||
uHighlightsLocation = GLES30.glGetUniformLocation(programId, "uHighlights")
|
||||
uShadowsLocation = GLES30.glGetUniformLocation(programId, "uShadows")
|
||||
|
||||
// 获取 Attribute 位置
|
||||
aPositionLocation = GLES30.glGetAttribLocation(programId, "aPosition")
|
||||
aTexCoordLocation = GLES30.glGetAttribLocation(programId, "aTexCoord")
|
||||
|
||||
|
||||
// PLog.d(TAG, "Shader program created: $programId")
|
||||
}
|
||||
|
||||
|
||||
@@ -101,24 +101,148 @@ object Shaders {
|
||||
|
||||
/**
|
||||
* 简单的直通片元着色器(无 LUT)
|
||||
*
|
||||
*
|
||||
* 用于调试或禁用 LUT 时
|
||||
*/
|
||||
val FRAGMENT_SHADER_PASSTHROUGH = """
|
||||
#version 300 es
|
||||
#extension GL_OES_EGL_image_external_essl3 : require
|
||||
|
||||
|
||||
precision mediump float;
|
||||
|
||||
|
||||
in vec2 vTexCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
|
||||
uniform samplerExternalOES uCameraTexture;
|
||||
|
||||
|
||||
void main() {
|
||||
fragColor = texture(uCameraTexture, vTexCoord);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
/**
|
||||
* 片元着色器 - 带色彩配方和 3D LUT 支持
|
||||
*
|
||||
* 处理流程:相机采样 → 色彩配方调整 → LUT处理(可选) → 输出
|
||||
*
|
||||
* 性能优化:
|
||||
* - 使用 highp float 提高色彩精度
|
||||
* - Early exit 优化(无调整时直接返回)
|
||||
* - 避免 HSL 转换,使用基于 Luma 的快速饱和度算法
|
||||
*/
|
||||
val FRAGMENT_SHADER_COLOR_RECIPE = """
|
||||
#version 300 es
|
||||
#extension GL_OES_EGL_image_external_essl3 : require
|
||||
|
||||
precision highp float;
|
||||
|
||||
// 从顶点着色器接收的纹理坐标
|
||||
in vec2 vTexCoord;
|
||||
|
||||
// 输出颜色
|
||||
out vec4 fragColor;
|
||||
|
||||
// 相机 OES 纹理
|
||||
uniform samplerExternalOES uCameraTexture;
|
||||
|
||||
// 3D LUT 纹理
|
||||
uniform mediump sampler3D uLutTexture;
|
||||
|
||||
// LUT 控制
|
||||
uniform float uLutSize;
|
||||
uniform float uLutIntensity;
|
||||
uniform bool uLutEnabled;
|
||||
|
||||
// 色彩配方控制
|
||||
uniform bool uColorRecipeEnabled;
|
||||
|
||||
// 色彩配方参数(阶段1:核心3参数)
|
||||
uniform float uExposure; // -2.0 ~ +2.0 (EV)
|
||||
uniform float uContrast; // 0.5 ~ 1.5
|
||||
uniform float uSaturation; // 0.0 ~ 2.0
|
||||
|
||||
// 色彩配方参数(阶段1:额外3参数)
|
||||
uniform float uTemperature; // -1.0 ~ +1.0 (暖/冷色调)
|
||||
uniform float uTint; // -1.0 ~ +1.0 (绿/品红偏移)
|
||||
uniform float uFade; // 0.0 ~ 1.0 (褪色效果)
|
||||
uniform float uVibrance; // 0.0 ~ 2.0 (蓝色增强 - vibrance)
|
||||
|
||||
// 色彩配方参数(阶段2:高级参数)
|
||||
uniform float uHighlights; // -1.0 ~ +1.0 (高光调整)
|
||||
uniform float uShadows; // -1.0 ~ +1.0 (阴影调整)
|
||||
|
||||
void main() {
|
||||
// 从相机纹理采样原始颜色
|
||||
vec4 color = texture(uCameraTexture, vTexCoord);
|
||||
|
||||
// Early exit 优化:无任何调整时直接输出
|
||||
if (!uColorRecipeEnabled && !uLutEnabled) {
|
||||
fragColor = color;
|
||||
return;
|
||||
}
|
||||
|
||||
// === 色彩配方处理(按专业后期流程顺序) ===
|
||||
if (uColorRecipeEnabled) {
|
||||
// 1. 曝光调整(线性空间,最先执行避免 clipping)
|
||||
color.rgb *= pow(2.0, uExposure);
|
||||
|
||||
// 2. 高光/阴影调整(分区调整,基于亮度 mask)
|
||||
float luma = dot(color.rgb, vec3(0.299, 0.587, 0.114));
|
||||
float highlightMask = smoothstep(0.5, 1.0, luma);
|
||||
float shadowMask = smoothstep(0.5, 0.0, luma);
|
||||
color.rgb *= 1.0 + uHighlights * highlightMask;
|
||||
color.rgb *= 1.0 + uShadows * shadowMask;
|
||||
|
||||
// 3. 对比度(围绕中灰点调整)
|
||||
color.rgb = (color.rgb - 0.5) * uContrast + 0.5;
|
||||
|
||||
// 4. 白平衡调整(色温 + 色调)
|
||||
// 色温:增加暖色调(偏红)或冷色调(偏蓝)
|
||||
color.r += uTemperature * 0.1;
|
||||
color.b -= uTemperature * 0.1;
|
||||
// 色调:绿-品红偏移
|
||||
color.g += uTint * 0.05;
|
||||
|
||||
// 5. 饱和度(基于 Luma 的快速算法,避免 HSL 转换)
|
||||
float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
|
||||
color.rgb = mix(vec3(gray), color.rgb, uSaturation);
|
||||
|
||||
// 6. 蓝色增强(Vibrance - 选择性增强蓝色,保护肤色)
|
||||
float blueness = color.b - max(color.r, color.g);
|
||||
if (blueness > 0.0) {
|
||||
color.b += blueness * (uVibrance - 1.0) * 0.5;
|
||||
}
|
||||
|
||||
// 7. 褪色效果(降低对比度 + 提升黑电平)
|
||||
if (uFade > 0.0) {
|
||||
float fadeAmount = uFade * 0.3;
|
||||
color.rgb = mix(color.rgb, vec3(0.5), fadeAmount);
|
||||
color.rgb += fadeAmount * 0.1;
|
||||
}
|
||||
|
||||
// Clamp 到合法范围
|
||||
color.rgb = clamp(color.rgb, 0.0, 1.0);
|
||||
}
|
||||
|
||||
// === LUT 处理(在色彩配方之后,保持 LUT 创作意图) ===
|
||||
if (uLutEnabled && uLutIntensity > 0.0) {
|
||||
// 3D LUT 查找
|
||||
float scale = (uLutSize - 1.0) / uLutSize;
|
||||
float offset = 1.0 / (2.0 * uLutSize);
|
||||
|
||||
// 将 RGB 值映射到 LUT 纹理坐标
|
||||
vec3 lutCoord = color.rgb * scale + offset;
|
||||
|
||||
// 从 3D LUT 纹理采样
|
||||
vec4 lutColor = texture(uLutTexture, lutCoord);
|
||||
|
||||
// 根据强度混合色彩配方处理后的颜色和 LUT 颜色
|
||||
color.rgb = mix(color.rgb, lutColor.rgb, uLutIntensity);
|
||||
}
|
||||
|
||||
fragColor = color;
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
/**
|
||||
* 全屏四边形的顶点坐标
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.hinnka.mycamera.model
|
||||
|
||||
/**
|
||||
* 色彩配方参数数据类
|
||||
*
|
||||
* 定义所有色彩调整参数的值
|
||||
*/
|
||||
data class ColorRecipeParams(
|
||||
val exposure: Float = 0f, // -2.0 ~ +2.0 (EV值,曝光调整)
|
||||
val contrast: Float = 1f, // 0.5 ~ 1.5 (对比度,1为无调整)
|
||||
val saturation: Float = 1f, // 0.0 ~ 2.0 (饱和度,1为无调整)
|
||||
val temperature: Float = 0f, // -1.0 ~ +1.0 (色温,负值偏冷,正值偏暖)
|
||||
val tint: Float = 0f, // -1.0 ~ +1.0 (色调,负值偏绿,正值偏品红)
|
||||
val fade: Float = 0f, // 0.0 ~ 1.0 (褪色效果,0为无褪色)
|
||||
val vibrance: Float = 1f, // 0.0 ~ 2.0 (蓝色增强/自然饱和度,1为无调整)
|
||||
val highlights: Float = 0f, // -1.0 ~ +1.0 (高光调整,0为无调整)
|
||||
val shadows: Float = 0f, // -1.0 ~ +1.0 (阴影调整,0为无调整)
|
||||
val lutIntensity: Float = 1f // 0.0 ~ 1.0 (LUT强度,1为完全应用)
|
||||
) {
|
||||
/**
|
||||
* 检查参数是否为默认值(无任何调整)
|
||||
*/
|
||||
fun isDefault(): Boolean {
|
||||
return exposure == 0f &&
|
||||
contrast == 1f &&
|
||||
saturation == 1f &&
|
||||
temperature == 0f &&
|
||||
tint == 0f &&
|
||||
fade == 0f &&
|
||||
vibrance == 1f &&
|
||||
highlights == 0f &&
|
||||
shadows == 0f &&
|
||||
lutIntensity == 1f
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查参数是否与另一个参数集相同
|
||||
*/
|
||||
fun isSameAs(other: ColorRecipeParams): Boolean {
|
||||
return exposure == other.exposure &&
|
||||
contrast == other.contrast &&
|
||||
saturation == other.saturation &&
|
||||
temperature == other.temperature &&
|
||||
tint == other.tint &&
|
||||
fade == other.fade &&
|
||||
vibrance == other.vibrance &&
|
||||
highlights == other.highlights &&
|
||||
shadows == other.shadows &&
|
||||
lutIntensity == other.lutIntensity
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* 默认参数(无调整)
|
||||
*/
|
||||
val DEFAULT = ColorRecipeParams()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 色彩配方预设
|
||||
*
|
||||
* 包含命名的预设配方,可以快速应用到照片
|
||||
*/
|
||||
data class ColorRecipe(
|
||||
val id: String, // 配方唯一ID
|
||||
val name: String, // 配方名称(用户可见)
|
||||
val description: String = "", // 配方描述
|
||||
val params: ColorRecipeParams, // 配方参数
|
||||
val thumbnailRes: Int? = null, // 缩略图资源ID(可选)
|
||||
val isVip: Boolean = false // 是否为VIP专享配方
|
||||
)
|
||||
|
||||
/**
|
||||
* 色彩配方参数枚举
|
||||
*
|
||||
* 用于标识不同的可调整参数
|
||||
*/
|
||||
enum class RecipeParam(
|
||||
val displayName: String, // 显示名称
|
||||
val minValue: Float, // 最小值
|
||||
val maxValue: Float, // 最大值
|
||||
val defaultValue: Float // 默认值
|
||||
) {
|
||||
EXPOSURE("曝光", -2.0f, 2.0f, 0f),
|
||||
CONTRAST("对比度", 0.5f, 1.5f, 1f),
|
||||
SATURATION("饱和度", 0.0f, 2.0f, 1f),
|
||||
TEMPERATURE("色温", -1.0f, 1.0f, 0f),
|
||||
TINT("色调", -1.0f, 1.0f, 0f),
|
||||
FADE("褪色", 0.0f, 1.0f, 0f),
|
||||
VIBRANCE("蓝色增强", 0.0f, 2.0f, 1f),
|
||||
HIGHLIGHTS("高光", -1.0f, 1.0f, 0f),
|
||||
SHADOWS("阴影", -1.0f, 1.0f, 0f),
|
||||
LUT_INTENSITY("滤镜强度", 0.0f, 1.0f, 1f);
|
||||
|
||||
/**
|
||||
* 将参数值限制在合法范围内
|
||||
*/
|
||||
fun clamp(value: Float): Float {
|
||||
return value.coerceIn(minValue, maxValue)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取参数在当前参数集中的值
|
||||
*/
|
||||
fun getValue(params: ColorRecipeParams): Float {
|
||||
return when (this) {
|
||||
EXPOSURE -> params.exposure
|
||||
CONTRAST -> params.contrast
|
||||
SATURATION -> params.saturation
|
||||
TEMPERATURE -> params.temperature
|
||||
TINT -> params.tint
|
||||
FADE -> params.fade
|
||||
VIBRANCE -> params.vibrance
|
||||
HIGHLIGHTS -> params.highlights
|
||||
SHADOWS -> params.shadows
|
||||
LUT_INTENSITY -> params.lutIntensity
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在参数集中设置此参数的值
|
||||
*/
|
||||
fun setValue(params: ColorRecipeParams, value: Float): ColorRecipeParams {
|
||||
val clampedValue = clamp(value)
|
||||
return when (this) {
|
||||
EXPOSURE -> params.copy(exposure = clampedValue)
|
||||
CONTRAST -> params.copy(contrast = clampedValue)
|
||||
SATURATION -> params.copy(saturation = clampedValue)
|
||||
TEMPERATURE -> params.copy(temperature = clampedValue)
|
||||
TINT -> params.copy(tint = clampedValue)
|
||||
FADE -> params.copy(fade = clampedValue)
|
||||
VIBRANCE -> params.copy(vibrance = clampedValue)
|
||||
HIGHLIGHTS -> params.copy(highlights = clampedValue)
|
||||
SHADOWS -> params.copy(shadows = clampedValue)
|
||||
LUT_INTENSITY -> params.copy(lutIntensity = clampedValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,16 +85,6 @@ class CameraGLSurfaceView @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 LUT 强度
|
||||
*
|
||||
* @param intensity 强度值 (0.0 - 1.0)
|
||||
*/
|
||||
fun setLutIntensity(intensity: Float) {
|
||||
renderer.lutIntensity = intensity.coerceIn(0f, 1f)
|
||||
requestRender()
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 LUT 是否启用
|
||||
*/
|
||||
@@ -112,7 +102,43 @@ class CameraGLSurfaceView @JvmOverloads constructor(
|
||||
* 获取 LUT 是否启用
|
||||
*/
|
||||
fun isLutEnabled(): Boolean = renderer.lutEnabled
|
||||
|
||||
|
||||
/**
|
||||
* 设置色彩配方是否启用
|
||||
*/
|
||||
fun setColorRecipeEnabled(enabled: Boolean) {
|
||||
renderer.colorRecipeEnabled = enabled
|
||||
requestRender()
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置色彩配方参数
|
||||
*/
|
||||
fun setColorRecipeParams(
|
||||
exposure: Float,
|
||||
contrast: Float,
|
||||
saturation: Float,
|
||||
temperature: Float,
|
||||
tint: Float,
|
||||
fade: Float,
|
||||
vibrance: Float,
|
||||
highlights: Float,
|
||||
shadows: Float,
|
||||
lutIntensity: Float,
|
||||
) {
|
||||
renderer.exposure = exposure
|
||||
renderer.contrast = contrast
|
||||
renderer.saturation = saturation
|
||||
renderer.temperature = temperature
|
||||
renderer.tint = tint
|
||||
renderer.fade = fade
|
||||
renderer.vibrance = vibrance
|
||||
renderer.highlights = highlights
|
||||
renderer.shadows = shadows
|
||||
renderer.lutIntensity = lutIntensity
|
||||
requestRender()
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求渲染帧
|
||||
*/
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.hinnka.mycamera.ui.camera
|
||||
|
||||
import android.graphics.SurfaceTexture
|
||||
import android.util.Size
|
||||
import android.view.Surface
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.*
|
||||
@@ -17,19 +16,20 @@ import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import com.hinnka.mycamera.camera.AspectRatio
|
||||
import com.hinnka.mycamera.lut.LutConfig
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.ui.components.FocusIndicator
|
||||
|
||||
/**
|
||||
* 相机预览组件 - OpenGL ES 版本(Camera2 适配)
|
||||
*
|
||||
* 使用 GLSurfaceView 渲染相机预览,支持实时 3D LUT 滤镜
|
||||
*
|
||||
* 使用 GLSurfaceView 渲染相机预览,支持实时 3D LUT 滤镜和色彩配方
|
||||
*/
|
||||
@Composable
|
||||
fun CameraPreviewGL(
|
||||
aspectRatio: AspectRatio,
|
||||
previewSize: Size,
|
||||
currentLut: LutConfig?,
|
||||
lutIntensity: Float,
|
||||
colorRecipeParams: ColorRecipeParams,
|
||||
focusPoint: Pair<Float, Float>?,
|
||||
isFocusing: Boolean,
|
||||
focusSuccess: Boolean?,
|
||||
@@ -124,15 +124,29 @@ fun CameraPreviewGL(
|
||||
onSurfaceTextureReady(surfaceTexture)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
val colorRecipeEnabled = !colorRecipeParams.isDefault()
|
||||
// 更新 LUT 设置
|
||||
if (currentLut != null) {
|
||||
glSurfaceView.setLut(currentLut)
|
||||
glSurfaceView.setLutEnabled(true)
|
||||
glSurfaceView.setColorRecipeEnabled(colorRecipeEnabled)
|
||||
glSurfaceView.setColorRecipeParams(
|
||||
exposure = colorRecipeParams.exposure,
|
||||
contrast = colorRecipeParams.contrast,
|
||||
saturation = colorRecipeParams.saturation,
|
||||
temperature = colorRecipeParams.temperature,
|
||||
tint = colorRecipeParams.tint,
|
||||
fade = colorRecipeParams.fade,
|
||||
vibrance = colorRecipeParams.vibrance,
|
||||
highlights = colorRecipeParams.highlights,
|
||||
shadows = colorRecipeParams.shadows,
|
||||
lutIntensity = colorRecipeParams.lutIntensity,
|
||||
)
|
||||
} else {
|
||||
glSurfaceView.setLutEnabled(false)
|
||||
glSurfaceView.setColorRecipeEnabled(false)
|
||||
}
|
||||
glSurfaceView.setLutIntensity(lutIntensity)
|
||||
},
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
|
||||
@@ -71,6 +71,8 @@ fun CameraScreen(
|
||||
val state by viewModel.state.collectAsState()
|
||||
val latestPhoto by galleryViewModel.latestPhoto.collectAsState()
|
||||
val showLevelIndicator by viewModel.showLevelIndicator.collectAsState(initial = false)
|
||||
val currentLutId by viewModel.currentLutId.collectAsState()
|
||||
val currentRecipeParams by viewModel.currentRecipeParams.collectAsState()
|
||||
|
||||
val backgroundColor = Color(0xFF434A5D)
|
||||
|
||||
@@ -162,7 +164,7 @@ fun CameraScreen(
|
||||
aspectRatio = state.aspectRatio,
|
||||
previewSize = previewSize,
|
||||
currentLut = viewModel.currentLutConfig,
|
||||
lutIntensity = state.lutIntensity,
|
||||
colorRecipeParams = currentRecipeParams,
|
||||
focusPoint = state.focusPoint,
|
||||
isFocusing = state.isFocusing,
|
||||
focusSuccess = state.focusSuccess,
|
||||
@@ -309,11 +311,9 @@ fun CameraScreen(
|
||||
if (activePanel == ActivePanel.FILTERS) {
|
||||
LutControlPanel(
|
||||
availableLuts = viewModel.availableLutList,
|
||||
currentLutId = viewModel.currentLutId,
|
||||
lutIntensity = state.lutIntensity,
|
||||
currentLutId = currentLutId,
|
||||
lutPreviewBitmaps = viewModel.lutPreviewBitmaps,
|
||||
onLutSelected = { viewModel.setLut(it) },
|
||||
onIntensityChange = { viewModel.setLutIntensity(it) },
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
.padding(horizontal = 8.dp)
|
||||
)
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.hinnka.mycamera.ui.camera
|
||||
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.ModalBottomSheet
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.rememberModalBottomSheetState
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.hinnka.mycamera.R
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.ui.components.ColorRecipePanel
|
||||
import com.hinnka.mycamera.ui.components.CustomSliderThinThumb
|
||||
import com.hinnka.mycamera.viewmodel.LutEditViewModel
|
||||
|
||||
/**
|
||||
* LUT编辑底部弹窗
|
||||
*
|
||||
* 为选中的LUT设置专属的色彩配方参数
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LutEditBottomSheet(
|
||||
lutId: String,
|
||||
onDismiss: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val viewModel: LutEditViewModel = viewModel()
|
||||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
||||
val backgroundColor = Color(0xFF434A5D)
|
||||
|
||||
var editingParams by remember { mutableStateOf(ColorRecipeParams.DEFAULT) }
|
||||
|
||||
LaunchedEffect(lutId) {
|
||||
editingParams = viewModel.getColorRecipe(lutId)
|
||||
}
|
||||
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = onDismiss,
|
||||
sheetState = sheetState,
|
||||
containerColor = backgroundColor,
|
||||
modifier = modifier,
|
||||
scrimColor = Color.Transparent
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.navigationBarsPadding()
|
||||
) {
|
||||
LutIntensitySlider(
|
||||
intensity = editingParams.lutIntensity,
|
||||
onIntensityChange = {
|
||||
editingParams = editingParams.copy(lutIntensity = it)
|
||||
viewModel.saveLutColorRecipe(lutId, editingParams)
|
||||
}
|
||||
)
|
||||
|
||||
// 底部色彩配方面板
|
||||
ColorRecipePanel(
|
||||
currentParams = editingParams,
|
||||
onParamChange = { param, value ->
|
||||
editingParams = param.setValue(editingParams, value)
|
||||
viewModel.saveLutColorRecipe(lutId, editingParams)
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 16.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* LUT 强度滑块组件
|
||||
*/
|
||||
@Composable
|
||||
fun LutIntensitySlider(
|
||||
intensity: Float,
|
||||
onIntensityChange: (Float) -> Unit,
|
||||
enabled: Boolean = true,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.filter_intensity),
|
||||
color = if (enabled) Color.White else Color.Gray,
|
||||
fontSize = 12.sp
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "${(intensity * 100).toInt()}%",
|
||||
color = if (enabled) Color.White else Color.Gray,
|
||||
fontSize = 10.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
|
||||
CustomSliderThinThumb(
|
||||
value = intensity,
|
||||
onValueChange = onIntensityChange,
|
||||
onDoubleTap = {
|
||||
if (enabled) onIntensityChange(1.0f)
|
||||
},
|
||||
enabled = enabled,
|
||||
valueRange = 0f..1f,
|
||||
thumbWidth = 3.dp,
|
||||
thumbHeight = 22.dp,
|
||||
trackHeight = 4.dp,
|
||||
activeTrackColor = Color.White,
|
||||
inactiveTrackColor = Color.Gray.copy(alpha = 0.5f),
|
||||
thumbColor = Color.White,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.AutoAwesome
|
||||
import androidx.compose.material.icons.filled.Palette
|
||||
import androidx.compose.material.icons.filled.SwapHoriz
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
@@ -69,7 +70,7 @@ fun ZoomControlBar(
|
||||
) {
|
||||
// Display Mode Toggle (Left)
|
||||
IconButton(
|
||||
onClick = {
|
||||
onClick = {
|
||||
displayMode = if (displayMode == ZoomDisplayMode.ZOOM_RATIO) {
|
||||
ZoomDisplayMode.FOCAL_LENGTH
|
||||
} else {
|
||||
@@ -89,8 +90,8 @@ fun ZoomControlBar(
|
||||
tint = Color.White
|
||||
)
|
||||
}
|
||||
|
||||
// Filter Button (Right)
|
||||
|
||||
// 右侧滤镜按钮
|
||||
IconButton(
|
||||
onClick = onFilterClick,
|
||||
modifier = Modifier
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
package com.hinnka.mycamera.ui.components
|
||||
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.animation.core.animateDpAsState
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.model.RecipeParam
|
||||
|
||||
/**
|
||||
* 色彩配方控制面板
|
||||
*
|
||||
* 使用顶部 Tab 切换不同参数组
|
||||
*/
|
||||
@Composable
|
||||
fun ColorRecipePanel(
|
||||
currentParams: ColorRecipeParams,
|
||||
onParamChange: (RecipeParam, Float) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var selectedTabIndex by remember { mutableIntStateOf(0) }
|
||||
|
||||
val tabs = listOf("基础", "色彩", "高级")
|
||||
val parameterGroups = listOf(
|
||||
listOf(
|
||||
RecipeParam.EXPOSURE,
|
||||
RecipeParam.CONTRAST,
|
||||
RecipeParam.SATURATION
|
||||
),
|
||||
listOf(
|
||||
RecipeParam.TEMPERATURE,
|
||||
RecipeParam.TINT,
|
||||
RecipeParam.VIBRANCE
|
||||
),
|
||||
listOf(
|
||||
RecipeParam.HIGHLIGHTS,
|
||||
RecipeParam.SHADOWS,
|
||||
RecipeParam.FADE
|
||||
)
|
||||
)
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(4.dp)
|
||||
) {
|
||||
// 自定义 Tab 选择器 (Pill style)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(36.dp)
|
||||
.clip(CircleShape)
|
||||
.background(Color.Black.copy(alpha = 0.4f))
|
||||
.padding(4.dp)
|
||||
) {
|
||||
Row(modifier = Modifier.fillMaxSize()) {
|
||||
tabs.forEachIndexed { index, title ->
|
||||
val isSelected = selectedTabIndex == index
|
||||
val backgroundColor by animateColorAsState(
|
||||
if (isSelected) Color.White.copy(alpha = 0.2f) else Color.Transparent,
|
||||
label = "tabBackground"
|
||||
)
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.fillMaxHeight()
|
||||
.clip(CircleShape)
|
||||
.background(backgroundColor)
|
||||
.clickable { selectedTabIndex = index },
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
fontSize = 12.sp,
|
||||
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal,
|
||||
color = if (isSelected) Color.White else Color.White.copy(alpha = 0.6f)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
// 当前选中的参数组
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
Color.Black.copy(alpha = 0.3f),
|
||||
RoundedCornerShape(8.dp)
|
||||
)
|
||||
.padding(8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
parameterGroups[selectedTabIndex].forEach { param ->
|
||||
key(param) {
|
||||
ColorRecipeSlider(
|
||||
param = param,
|
||||
value = param.getValue(currentParams),
|
||||
onValueChange = { newValue ->
|
||||
onParamChange(param, newValue)
|
||||
},
|
||||
onDoubleTap = {
|
||||
onParamChange(param, param.defaultValue)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 色彩配方参数滑块
|
||||
*/
|
||||
@Composable
|
||||
fun ColorRecipeSlider(
|
||||
param: RecipeParam,
|
||||
value: Float,
|
||||
onValueChange: (Float) -> Unit,
|
||||
onDoubleTap: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier.fillMaxWidth()
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = param.displayName,
|
||||
color = Color.White,
|
||||
fontSize = 11.sp,
|
||||
modifier = Modifier.width(64.dp)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = formatParamValue(param, value),
|
||||
color = Color.White.copy(alpha = 0.8f),
|
||||
fontSize = 10.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
textAlign = TextAlign.End,
|
||||
modifier = Modifier.width(50.dp)
|
||||
)
|
||||
}
|
||||
|
||||
CustomSliderThinThumb(
|
||||
value = value,
|
||||
onValueChange = onValueChange,
|
||||
onDoubleTap = onDoubleTap,
|
||||
valueRange = param.minValue..param.maxValue,
|
||||
thumbWidth = 3.dp,
|
||||
thumbHeight = 20.dp,
|
||||
trackHeight = 3.dp,
|
||||
activeTrackColor = getParamColor(param),
|
||||
inactiveTrackColor = Color.Gray.copy(alpha = 0.3f),
|
||||
thumbColor = Color.White,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化参数值显示
|
||||
*/
|
||||
private fun formatParamValue(param: RecipeParam, value: Float): String {
|
||||
return when (param) {
|
||||
RecipeParam.EXPOSURE -> String.format("%.1f EV", value)
|
||||
RecipeParam.CONTRAST,
|
||||
RecipeParam.SATURATION,
|
||||
RecipeParam.VIBRANCE -> String.format("%.2f", value)
|
||||
|
||||
RecipeParam.TEMPERATURE,
|
||||
RecipeParam.TINT,
|
||||
RecipeParam.HIGHLIGHTS,
|
||||
RecipeParam.SHADOWS,
|
||||
RecipeParam.FADE -> {
|
||||
if (value >= 0) {
|
||||
String.format("+%.2f", value)
|
||||
} else {
|
||||
String.format("%.2f", value)
|
||||
}
|
||||
}
|
||||
|
||||
RecipeParam.LUT_INTENSITY -> String.format("%.2f", value)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取参数对应的颜色(用于滑块)
|
||||
*/
|
||||
private fun getParamColor(param: RecipeParam): Color {
|
||||
return when (param) {
|
||||
RecipeParam.EXPOSURE -> Color(0xFFFFEB3B) // 黄色
|
||||
RecipeParam.CONTRAST -> Color(0xFF9C27B0) // 紫色
|
||||
RecipeParam.SATURATION -> Color(0xFFE91E63) // 粉色
|
||||
RecipeParam.TEMPERATURE -> Color(0xFFFF9800) // 橙色
|
||||
RecipeParam.TINT -> Color(0xFF4CAF50) // 绿色
|
||||
RecipeParam.FADE -> Color(0xFF607D8B) // 灰蓝色
|
||||
RecipeParam.VIBRANCE -> Color(0xFF2196F3) // 蓝色
|
||||
RecipeParam.HIGHLIGHTS -> Color(0xFFF44336) // 红色
|
||||
RecipeParam.SHADOWS -> Color(0xFF3F51B5) // 深蓝色
|
||||
RecipeParam.LUT_INTENSITY -> Color(0xFF9E9E9E) // 灰色
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ import kotlin.math.abs
|
||||
fun CustomSlider(
|
||||
value: Float,
|
||||
onValueChange: (Float) -> Unit,
|
||||
onDoubleTap: (() -> Unit)? = null,
|
||||
modifier: Modifier = Modifier,
|
||||
enabled: Boolean = true,
|
||||
valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
|
||||
@@ -47,17 +48,19 @@ fun CustomSlider(
|
||||
thumbColor: Color = Color.White
|
||||
) {
|
||||
var isDragging by remember { mutableStateOf(false) }
|
||||
|
||||
val currentOnValueChange by rememberUpdatedState(onValueChange)
|
||||
val currentOnDoubleTap by rememberUpdatedState(onDoubleTap)
|
||||
|
||||
val density = LocalDensity.current
|
||||
val thumbRadiusPx = with(density) { thumbRadius.toPx() }
|
||||
val trackHeightPx = with(density) { trackHeight.toPx() }
|
||||
|
||||
|
||||
// 确保值在范围内
|
||||
val coercedValue = value.coerceIn(valueRange.start, valueRange.endInclusive)
|
||||
|
||||
|
||||
// 计算归一化的值(0-1)
|
||||
val normalizedValue = (coercedValue - valueRange.start) / (valueRange.endInclusive - valueRange.start)
|
||||
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
@@ -66,50 +69,44 @@ fun CustomSlider(
|
||||
Canvas(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.pointerInput(enabled) {
|
||||
.pointerInput(enabled, valueRange, thumbRadiusPx) {
|
||||
if (!enabled) return@pointerInput
|
||||
|
||||
detectDragGestures(
|
||||
onDragStart = {
|
||||
isDragging = true
|
||||
},
|
||||
onDragEnd = {
|
||||
isDragging = false
|
||||
},
|
||||
onDragCancel = {
|
||||
isDragging = false
|
||||
}
|
||||
onDragStart = { isDragging = true },
|
||||
onDragEnd = { isDragging = false },
|
||||
onDragCancel = { isDragging = false }
|
||||
) { change, _ ->
|
||||
change.consume()
|
||||
|
||||
val trackWidth = size.width - thumbRadiusPx * 2
|
||||
val trackStart = thumbRadiusPx
|
||||
val x = change.position.x.coerceIn(trackStart, trackStart + trackWidth)
|
||||
|
||||
val fraction = (x - trackStart) / trackWidth
|
||||
val newValue = valueRange.start + fraction * (valueRange.endInclusive - valueRange.start)
|
||||
onValueChange(newValue.coerceIn(valueRange.start, valueRange.endInclusive))
|
||||
currentOnValueChange(newValue.coerceIn(valueRange.start, valueRange.endInclusive))
|
||||
}
|
||||
}
|
||||
.pointerInput(enabled) {
|
||||
.pointerInput(enabled, valueRange, thumbRadiusPx) {
|
||||
if (!enabled) return@pointerInput
|
||||
|
||||
detectTapGestures { offset ->
|
||||
val trackWidth = size.width - thumbRadiusPx * 2
|
||||
val trackStart = thumbRadiusPx
|
||||
val x = offset.x.coerceIn(trackStart, trackStart + trackWidth)
|
||||
|
||||
val fraction = (x - trackStart) / trackWidth
|
||||
val newValue = valueRange.start + fraction * (valueRange.endInclusive - valueRange.start)
|
||||
onValueChange(newValue.coerceIn(valueRange.start, valueRange.endInclusive))
|
||||
}
|
||||
detectTapGestures(
|
||||
onDoubleTap = {
|
||||
currentOnDoubleTap?.invoke()
|
||||
},
|
||||
onTap = { offset ->
|
||||
val trackWidth = size.width - thumbRadiusPx * 2
|
||||
val trackStart = thumbRadiusPx
|
||||
val x = offset.x.coerceIn(trackStart, trackStart + trackWidth)
|
||||
val fraction = (x - trackStart) / trackWidth
|
||||
val newValue = valueRange.start + fraction * (valueRange.endInclusive - valueRange.start)
|
||||
currentOnValueChange(newValue.coerceIn(valueRange.start, valueRange.endInclusive))
|
||||
}
|
||||
)
|
||||
}
|
||||
) {
|
||||
val trackWidth = size.width - thumbRadiusPx * 2
|
||||
val trackStart = thumbRadiusPx
|
||||
val trackEnd = trackStart + trackWidth
|
||||
val centerY = size.height / 2
|
||||
|
||||
|
||||
// 绘制未激活轨道
|
||||
drawTrack(
|
||||
start = Offset(trackStart, centerY),
|
||||
@@ -117,7 +114,7 @@ fun CustomSlider(
|
||||
color = if (enabled) inactiveTrackColor else inactiveTrackColor.copy(alpha = 0.3f),
|
||||
strokeWidth = trackHeightPx
|
||||
)
|
||||
|
||||
|
||||
// 绘制激活轨道
|
||||
val activeEnd = trackStart + trackWidth * normalizedValue
|
||||
drawTrack(
|
||||
@@ -126,7 +123,7 @@ fun CustomSlider(
|
||||
color = if (enabled) activeTrackColor else activeTrackColor.copy(alpha = 0.5f),
|
||||
strokeWidth = trackHeightPx
|
||||
)
|
||||
|
||||
|
||||
// 绘制 Thumb
|
||||
val thumbX = trackStart + trackWidth * normalizedValue
|
||||
drawThumb(
|
||||
@@ -176,14 +173,14 @@ private fun DrawScope.drawThumb(
|
||||
center = center
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
// 主圆圈
|
||||
drawCircle(
|
||||
color = color,
|
||||
radius = radius,
|
||||
center = center
|
||||
)
|
||||
|
||||
|
||||
// 内圈高光(增加立体感)
|
||||
drawCircle(
|
||||
color = Color.White.copy(alpha = if (enabled) 0.3f else 0.15f),
|
||||
@@ -201,6 +198,7 @@ private fun DrawScope.drawThumb(
|
||||
fun CustomSliderThinThumb(
|
||||
value: Float,
|
||||
onValueChange: (Float) -> Unit,
|
||||
onDoubleTap: (() -> Unit)? = null,
|
||||
modifier: Modifier = Modifier,
|
||||
enabled: Boolean = true,
|
||||
valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
|
||||
@@ -212,18 +210,20 @@ fun CustomSliderThinThumb(
|
||||
thumbColor: Color = Color.White
|
||||
) {
|
||||
var isDragging by remember { mutableStateOf(false) }
|
||||
|
||||
val currentOnValueChange by rememberUpdatedState(onValueChange)
|
||||
val currentOnDoubleTap by rememberUpdatedState(onDoubleTap)
|
||||
|
||||
val density = LocalDensity.current
|
||||
val thumbWidthPx = with(density) { thumbWidth.toPx() }
|
||||
val thumbHeightPx = with(density) { thumbHeight.toPx() }
|
||||
val trackHeightPx = with(density) { trackHeight.toPx() }
|
||||
|
||||
|
||||
// 确保值在范围内
|
||||
val coercedValue = value.coerceIn(valueRange.start, valueRange.endInclusive)
|
||||
|
||||
|
||||
// 计算归一化的值(0-1)
|
||||
val normalizedValue = (coercedValue - valueRange.start) / (valueRange.endInclusive - valueRange.start)
|
||||
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
@@ -232,50 +232,44 @@ fun CustomSliderThinThumb(
|
||||
Canvas(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.pointerInput(enabled) {
|
||||
.pointerInput(enabled, valueRange, thumbWidthPx) {
|
||||
if (!enabled) return@pointerInput
|
||||
|
||||
detectDragGestures(
|
||||
onDragStart = {
|
||||
isDragging = true
|
||||
},
|
||||
onDragEnd = {
|
||||
isDragging = false
|
||||
},
|
||||
onDragCancel = {
|
||||
isDragging = false
|
||||
}
|
||||
onDragStart = { isDragging = true },
|
||||
onDragEnd = { isDragging = false },
|
||||
onDragCancel = { isDragging = false }
|
||||
) { change, _ ->
|
||||
change.consume()
|
||||
|
||||
val trackWidth = size.width - thumbWidthPx
|
||||
val trackStart = thumbWidthPx / 2
|
||||
val x = change.position.x.coerceIn(trackStart, trackStart + trackWidth)
|
||||
|
||||
val fraction = (x - trackStart) / trackWidth
|
||||
val newValue = valueRange.start + fraction * (valueRange.endInclusive - valueRange.start)
|
||||
onValueChange(newValue.coerceIn(valueRange.start, valueRange.endInclusive))
|
||||
currentOnValueChange(newValue.coerceIn(valueRange.start, valueRange.endInclusive))
|
||||
}
|
||||
}
|
||||
.pointerInput(enabled) {
|
||||
.pointerInput(enabled, valueRange, thumbWidthPx) {
|
||||
if (!enabled) return@pointerInput
|
||||
|
||||
detectTapGestures { offset ->
|
||||
val trackWidth = size.width - thumbWidthPx
|
||||
val trackStart = thumbWidthPx / 2
|
||||
val x = offset.x.coerceIn(trackStart, trackStart + trackWidth)
|
||||
|
||||
val fraction = (x - trackStart) / trackWidth
|
||||
val newValue = valueRange.start + fraction * (valueRange.endInclusive - valueRange.start)
|
||||
onValueChange(newValue.coerceIn(valueRange.start, valueRange.endInclusive))
|
||||
}
|
||||
detectTapGestures(
|
||||
onDoubleTap = {
|
||||
currentOnDoubleTap?.invoke()
|
||||
},
|
||||
onTap = { offset ->
|
||||
val trackWidth = size.width - thumbWidthPx
|
||||
val trackStart = thumbWidthPx / 2
|
||||
val x = offset.x.coerceIn(trackStart, trackStart + trackWidth)
|
||||
val fraction = (x - trackStart) / trackWidth
|
||||
val newValue = valueRange.start + fraction * (valueRange.endInclusive - valueRange.start)
|
||||
currentOnValueChange(newValue.coerceIn(valueRange.start, valueRange.endInclusive))
|
||||
}
|
||||
)
|
||||
}
|
||||
) {
|
||||
val trackWidth = size.width - thumbWidthPx
|
||||
val trackStart = thumbWidthPx / 2
|
||||
val trackEnd = trackStart + trackWidth
|
||||
val centerY = size.height / 2
|
||||
|
||||
|
||||
// 绘制未激活轨道
|
||||
drawLine(
|
||||
color = if (enabled) inactiveTrackColor else inactiveTrackColor.copy(alpha = 0.3f),
|
||||
@@ -284,7 +278,7 @@ fun CustomSliderThinThumb(
|
||||
strokeWidth = trackHeightPx,
|
||||
cap = StrokeCap.Round
|
||||
)
|
||||
|
||||
|
||||
// 绘制激活轨道
|
||||
val activeEnd = trackStart + trackWidth * normalizedValue
|
||||
drawLine(
|
||||
@@ -294,12 +288,12 @@ fun CustomSliderThinThumb(
|
||||
strokeWidth = trackHeightPx,
|
||||
cap = StrokeCap.Round
|
||||
)
|
||||
|
||||
|
||||
// 绘制细长型 Thumb
|
||||
val thumbX = trackStart + trackWidth * normalizedValue
|
||||
val thumbTop = centerY - thumbHeightPx / 2
|
||||
val thumbBottom = centerY + thumbHeightPx / 2
|
||||
|
||||
|
||||
// 拖拽时的光晕效果
|
||||
if (isDragging && enabled) {
|
||||
drawRoundRect(
|
||||
@@ -309,7 +303,7 @@ fun CustomSliderThinThumb(
|
||||
cornerRadius = androidx.compose.ui.geometry.CornerRadius(thumbWidthPx * 1.5f, thumbWidthPx * 1.5f)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
// 主 Thumb 矩形
|
||||
drawRoundRect(
|
||||
color = if (enabled) thumbColor else thumbColor.copy(alpha = 0.5f),
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.hinnka.mycamera.ui.components
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
@@ -11,13 +12,17 @@ import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material.icons.filled.Edit
|
||||
import androidx.compose.material.icons.filled.FilterNone
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
@@ -33,6 +38,7 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.hinnka.mycamera.R
|
||||
import com.hinnka.mycamera.lut.LutInfo
|
||||
import com.hinnka.mycamera.ui.camera.LutEditBottomSheet
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
@@ -50,6 +56,7 @@ fun LutSelector(
|
||||
) {
|
||||
val scrollState = rememberLazyListState()
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
var showLutEditDialog by remember { mutableStateOf(false) }
|
||||
|
||||
// 在组件首次加载时滚动到当前选中的 LUT
|
||||
LaunchedEffect(currentLutId) {
|
||||
@@ -63,6 +70,16 @@ fun LutSelector(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 全局 LUT 编辑底部弹窗
|
||||
if (showLutEditDialog && currentLutId != null) {
|
||||
LutEditBottomSheet(
|
||||
lutId = currentLutId,
|
||||
onDismiss = {
|
||||
showLutEditDialog = false
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
LazyRow(
|
||||
modifier = modifier
|
||||
@@ -79,7 +96,13 @@ fun LutSelector(
|
||||
isSelected = currentLutId == lut.id,
|
||||
isVip = lut.isVip,
|
||||
isCustom = !lut.isBuiltIn, // 添加自定义标识
|
||||
onClick = { onLutSelected(lut.id) }
|
||||
onClick = {
|
||||
if (currentLutId == lut.id) {
|
||||
showLutEditDialog = true
|
||||
} else {
|
||||
onLutSelected(lut.id)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -88,6 +111,7 @@ fun LutSelector(
|
||||
/**
|
||||
* 单个 LUT 选项
|
||||
*/
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
private fun LutItem(
|
||||
name: String,
|
||||
@@ -121,7 +145,7 @@ private fun LutItem(
|
||||
color = borderColor,
|
||||
shape = RoundedCornerShape(8.dp)
|
||||
)
|
||||
.clickable(onClick = onClick)
|
||||
.clickable { onClick() }
|
||||
.padding(8.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
@@ -178,10 +202,10 @@ private fun LutItem(
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Check,
|
||||
contentDescription = stringResource(R.string.selected),
|
||||
tint = Color.White,
|
||||
modifier = Modifier.size(24.dp)
|
||||
imageVector = Icons.Default.Edit,
|
||||
contentDescription = stringResource(R.string.edit),
|
||||
tint = Color(0xFFD7E1F1),
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -244,59 +268,6 @@ private fun LutItem(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* LUT 强度滑块组件
|
||||
*/
|
||||
@Composable
|
||||
fun LutIntensitySlider(
|
||||
intensity: Float,
|
||||
onIntensityChange: (Float) -> Unit,
|
||||
enabled: Boolean = true,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
/*.background(
|
||||
Color.Black.copy(alpha = 0.6f),
|
||||
RoundedCornerShape(8.dp)
|
||||
)*/
|
||||
.padding(horizontal = 8.dp)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
/*Text(
|
||||
text = stringResource(R.string.filter_intensity),
|
||||
color = if (enabled) Color.White else Color.Gray,
|
||||
fontSize = 12.sp
|
||||
)*/
|
||||
|
||||
Text(
|
||||
text = "${(intensity * 100).toInt()}%",
|
||||
color = if (enabled) Color.White else Color.Gray,
|
||||
fontSize = 10.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
|
||||
CustomSliderThinThumb(
|
||||
value = intensity,
|
||||
onValueChange = onIntensityChange,
|
||||
enabled = enabled,
|
||||
valueRange = 0f..1f,
|
||||
thumbWidth = 3.dp,
|
||||
thumbHeight = 22.dp,
|
||||
trackHeight = 4.dp,
|
||||
activeTrackColor = Color.White,
|
||||
inactiveTrackColor = Color.Gray.copy(alpha = 0.5f),
|
||||
thumbColor = Color.White,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* LUT 控制面板
|
||||
@@ -307,10 +278,8 @@ fun LutIntensitySlider(
|
||||
fun LutControlPanel(
|
||||
availableLuts: List<LutInfo>,
|
||||
currentLutId: String?,
|
||||
lutIntensity: Float,
|
||||
lutPreviewBitmaps: Map<String, Bitmap> = emptyMap(),
|
||||
onLutSelected: (String?) -> Unit,
|
||||
onIntensityChange: (Float) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(
|
||||
@@ -319,13 +288,6 @@ fun LutControlPanel(
|
||||
.padding(4.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
// 强度滑块(LUT 始终可用)
|
||||
LutIntensitySlider(
|
||||
intensity = lutIntensity,
|
||||
onIntensityChange = onIntensityChange,
|
||||
enabled = true
|
||||
)
|
||||
|
||||
// LUT 选择器
|
||||
LutSelector(
|
||||
availableLuts = availableLuts,
|
||||
|
||||
@@ -13,7 +13,6 @@ import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyRow
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
@@ -38,7 +37,7 @@ import coil.compose.AsyncImage
|
||||
import coil.request.ImageRequest
|
||||
import com.hinnka.mycamera.R
|
||||
import com.hinnka.mycamera.frame.TextType
|
||||
import com.hinnka.mycamera.ui.components.CustomSlider
|
||||
import com.hinnka.mycamera.ui.components.LutSelector
|
||||
import com.hinnka.mycamera.ui.components.PaymentDialog
|
||||
import com.hinnka.mycamera.ui.theme.AccentOrange
|
||||
import com.hinnka.mycamera.viewmodel.GalleryViewModel
|
||||
@@ -60,10 +59,8 @@ fun PhotoEditScreen(
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val currentPhoto = viewModel.getCurrentPhoto()
|
||||
val rotation = viewModel.editRotation
|
||||
val brightness = viewModel.editBrightness
|
||||
val editLutId = viewModel.editLutId
|
||||
val editLutIntensity = viewModel.editLutIntensity
|
||||
val editLutId by viewModel.editLutId.collectAsState()
|
||||
val editLutRecipeParams by viewModel.editLutRecipeParams.collectAsState()
|
||||
val editLutConfig = viewModel.editLutConfig
|
||||
val availableLuts = viewModel.availableLuts
|
||||
val showPaymentDialog = viewModel.showPaymentDialog
|
||||
@@ -81,7 +78,7 @@ fun PhotoEditScreen(
|
||||
|
||||
// 预览 Bitmap 状态
|
||||
var previewBitmap by remember { mutableStateOf<Bitmap?>(null) }
|
||||
var lutPreviews by remember { mutableStateOf<List<Bitmap?>>(emptyList()) }
|
||||
var lutPreviews by remember { mutableStateOf<Map<String, Bitmap>>(emptyMap()) }
|
||||
|
||||
// 边框编辑状态
|
||||
val editFrameId = viewModel.editFrameId
|
||||
@@ -92,10 +89,8 @@ fun PhotoEditScreen(
|
||||
LaunchedEffect(
|
||||
currentPhoto,
|
||||
editLutId,
|
||||
editLutRecipeParams,
|
||||
editLutConfig,
|
||||
editLutIntensity,
|
||||
rotation,
|
||||
brightness,
|
||||
editFrameId,
|
||||
customPropertiesList
|
||||
) {
|
||||
@@ -248,25 +243,6 @@ fun PhotoEditScreen(
|
||||
modifier = Modifier.size(48.dp)
|
||||
)
|
||||
}
|
||||
|
||||
// LUT 指示器
|
||||
if (editLutId != null) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopEnd)
|
||||
.background(
|
||||
AccentOrange.copy(alpha = 0.8f),
|
||||
RoundedCornerShape(4.dp)
|
||||
)
|
||||
.padding(horizontal = 8.dp, vertical = 4.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "LUT ${(editLutIntensity * 100).toInt()}%",
|
||||
color = Color.White,
|
||||
fontSize = 12.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑控制区域
|
||||
@@ -287,51 +263,12 @@ fun PhotoEditScreen(
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
LazyRow(
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
state = lutScrollState
|
||||
) {
|
||||
// LUT 选项
|
||||
itemsIndexed(availableLuts) { index, lut ->
|
||||
LutOption(
|
||||
name = lut.getName(),
|
||||
previewBitmap = lutPreviews.getOrNull(index),
|
||||
isSelected = editLutId == lut.id,
|
||||
isVip = lut.isVip,
|
||||
isCustom = !lut.isBuiltIn, // 添加自定义标识
|
||||
onClick = { viewModel.setEditLut(lut.id) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// LUT 强度滑块(LUT 始终可用)
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.intensity),
|
||||
color = Color.White,
|
||||
fontSize = 14.sp,
|
||||
modifier = Modifier.width(60.dp)
|
||||
)
|
||||
|
||||
CustomSlider(
|
||||
value = editLutIntensity,
|
||||
onValueChange = { viewModel.updateEditLutIntensity(it) },
|
||||
valueRange = 0f..1f,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "${(editLutIntensity * 100).toInt()}%",
|
||||
color = Color.White.copy(alpha = 0.7f),
|
||||
fontSize = 12.sp,
|
||||
modifier = Modifier.width(40.dp)
|
||||
)
|
||||
}
|
||||
LutSelector(
|
||||
availableLuts = viewModel.availableLuts,
|
||||
currentLutId = editLutId,
|
||||
lutPreviewBitmaps = lutPreviews,
|
||||
onLutSelected = { viewModel.setEditLut(it) }
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
@@ -351,7 +288,7 @@ fun PhotoEditScreen(
|
||||
) {
|
||||
// 无边框选项
|
||||
item {
|
||||
LutOption(
|
||||
FrameOption(
|
||||
name = stringResource(R.string.none),
|
||||
isSelected = editFrameId == null,
|
||||
isCustom = false, // 无边框不是自定义
|
||||
@@ -361,7 +298,7 @@ fun PhotoEditScreen(
|
||||
|
||||
// 边框选项
|
||||
items(availableFrames) { frame ->
|
||||
LutOption(
|
||||
FrameOption(
|
||||
name = frame.name,
|
||||
isSelected = editFrameId == frame.id,
|
||||
isCustom = !frame.isBuiltIn, // 添加自定义标识
|
||||
@@ -458,7 +395,7 @@ private fun Context.findActivity(): Activity? {
|
||||
* LUT 选项
|
||||
*/
|
||||
@Composable
|
||||
private fun LutOption(
|
||||
private fun FrameOption(
|
||||
name: String,
|
||||
previewBitmap: Bitmap? = null,
|
||||
isSelected: Boolean,
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.graphics.SurfaceTexture
|
||||
import android.hardware.camera2.CameraCharacteristics
|
||||
import android.media.Image
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -26,6 +27,7 @@ import com.hinnka.mycamera.gallery.PhotoProcessor
|
||||
import com.hinnka.mycamera.lut.LutConfig
|
||||
import com.hinnka.mycamera.lut.LutImageProcessor
|
||||
import com.hinnka.mycamera.lut.LutInfo
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.utils.OrientationObserver
|
||||
import com.hinnka.mycamera.utils.PLog
|
||||
import com.hinnka.mycamera.utils.ShutterSoundPlayer
|
||||
@@ -82,9 +84,18 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
var currentLutConfig: LutConfig? by mutableStateOf(null)
|
||||
private set
|
||||
|
||||
var currentLutId: String? by mutableStateOf(null)
|
||||
var currentLutId = MutableStateFlow("standard")
|
||||
private set
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
var currentRecipeParams = currentLutId.flatMapLatest { id ->
|
||||
contentRepository.lutManager.getColorRecipeParams(id)
|
||||
}.stateIn(
|
||||
scope = viewModelScope,
|
||||
started = SharingStarted.WhileSubscribed(5000),
|
||||
initialValue = ColorRecipeParams.DEFAULT
|
||||
)
|
||||
|
||||
var availableLutList: List<LutInfo> by mutableStateOf(emptyList())
|
||||
private set
|
||||
|
||||
@@ -116,6 +127,13 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
// 付费弹窗状态
|
||||
var showPaymentDialog by mutableStateOf(false)
|
||||
|
||||
// LUT编辑底部弹窗状态
|
||||
var showLutEditSheet by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
var editingLutInfo: LutInfo? by mutableStateOf(null)
|
||||
private set
|
||||
|
||||
// 新增设置项 StateFlow
|
||||
val showLevelIndicator: Flow<Boolean> = userPreferencesRepository.userPreferences.map { it.showLevelIndicator }
|
||||
val shutterSoundEnabled: Flow<Boolean> = userPreferencesRepository.userPreferences.map { it.shutterSoundEnabled }
|
||||
@@ -161,9 +179,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化内容仓库
|
||||
contentRepository.initialize()
|
||||
|
||||
// 订阅 ContentRepository 的 StateFlow,实现自动更新
|
||||
viewModelScope.launch {
|
||||
contentRepository.availableLuts.collect { luts ->
|
||||
@@ -199,7 +214,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
val defaultLut = availableLutList.firstOrNull { it.isDefault }
|
||||
defaultLut?.let { setLut(it.id) }
|
||||
}
|
||||
setLutIntensity(prefs.lutIntensity)
|
||||
|
||||
// 应用保存的边框配置
|
||||
if (prefs.frameId != null) {
|
||||
@@ -253,7 +267,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
val timerSeconds = state.value.timerSeconds
|
||||
|
||||
// 检查 VIP 权限
|
||||
val currentLut = getLutInfo(currentLutId ?: "")
|
||||
val currentLut = getLutInfo(currentLutId.value)
|
||||
if (currentLut?.isVip == true && !isPurchased.value) {
|
||||
showPaymentDialog = true
|
||||
return
|
||||
@@ -264,7 +278,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
viewModelScope.launch {
|
||||
for (i in timerSeconds downTo 1) {
|
||||
cameraController.setCountdownValue(i)
|
||||
kotlinx.coroutines.delay(1000)
|
||||
delay(1000)
|
||||
}
|
||||
// 倒计时结束,拍照
|
||||
cameraController.setCountdownValue(0)
|
||||
@@ -441,7 +455,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
* 设置当前 LUT
|
||||
*/
|
||||
fun setLut(lutId: String?) {
|
||||
currentLutId = lutId
|
||||
currentLutId.value = lutId ?: currentLutId.value
|
||||
if (lutId == null) {
|
||||
currentLutConfig = null
|
||||
// LUT 已禁用,通知相机控制器
|
||||
@@ -451,6 +465,11 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
currentLutConfig = withContext(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadLut(lutId)
|
||||
}
|
||||
currentRecipeParams = contentRepository.lutManager.getColorRecipeParams(lutId).stateIn(
|
||||
viewModelScope,
|
||||
started = SharingStarted.Lazily,
|
||||
initialValue = ColorRecipeParams.DEFAULT,
|
||||
)
|
||||
}
|
||||
// LUT 已启用,通知相机控制器
|
||||
cameraController.setLutEnabled(true)
|
||||
@@ -458,19 +477,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
// 保存到用户偏好设置
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.saveLutConfig(lutId, state.value.lutIntensity)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 LUT 强度
|
||||
*/
|
||||
fun setLutIntensity(intensity: Float) {
|
||||
cameraController.setLutIntensity(intensity)
|
||||
cameraController.setLutEnabled(intensity > 0f)
|
||||
// 保存到用户偏好设置
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.saveLutIntensity(intensity)
|
||||
userPreferencesRepository.saveLutConfig(lutId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -516,11 +523,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
|
||||
if (lutConfig != null) {
|
||||
val colorRecipeParams = contentRepository.lutManager.loadColorRecipeParams(lutInfo.id)
|
||||
// 直接使用原始 bitmap,不创建副本以避免内存溢出
|
||||
val previewBitmap = lutImageProcessor.applyLut(
|
||||
bitmap = bitmap,
|
||||
lutConfig = lutConfig,
|
||||
intensity = 1.0f
|
||||
colorRecipeParams = colorRecipeParams
|
||||
)
|
||||
newPreviews[lutInfo.id] = previewBitmap
|
||||
}
|
||||
@@ -721,8 +729,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
val context = getApplication<Application>()
|
||||
|
||||
// 保存当前 LUT 信息用于元数据
|
||||
val lutIdToSave = currentLutId
|
||||
val lutIntensityToSave = state.value.lutIntensity
|
||||
val lutIdToSave = currentLutId.value
|
||||
|
||||
val aspectRatio = state.value.aspectRatio
|
||||
|
||||
@@ -757,9 +764,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
val metadata = PhotoMetadata(
|
||||
// 编辑配置
|
||||
lutId = lutIdToSave,
|
||||
lutIntensity = lutIntensityToSave,
|
||||
frameId = frameIdToSave,
|
||||
showAppBranding = showAppBrandingToSave,
|
||||
// 拍摄信息 (来自 captureInfo)
|
||||
deviceModel = captureInfo.model,
|
||||
brand = captureInfo.make.replaceFirstChar { it.uppercase() },
|
||||
|
||||
@@ -20,13 +20,21 @@ import com.hinnka.mycamera.frame.FrameInfo
|
||||
import com.hinnka.mycamera.frame.FrameRenderer
|
||||
import com.hinnka.mycamera.gallery.*
|
||||
import com.hinnka.mycamera.lut.*
|
||||
import com.hinnka.mycamera.model.ColorRecipe
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.model.RecipeParam
|
||||
import com.hinnka.mycamera.utils.PLog
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
@@ -96,17 +104,23 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
var isEditing by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
// 编辑参数
|
||||
var editRotation by mutableFloatStateOf(0f)
|
||||
private set
|
||||
var editBrightness by mutableFloatStateOf(1f)
|
||||
// LUT 编辑状态
|
||||
var editLutId = MutableStateFlow<String?>(null)
|
||||
private set
|
||||
|
||||
// LUT 编辑状态
|
||||
var editLutId: String? by mutableStateOf(null)
|
||||
private set
|
||||
var editLutIntensity by mutableFloatStateOf(1f)
|
||||
private set
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
var editLutRecipeParams = editLutId.flatMapLatest { id ->
|
||||
if (id == null) {
|
||||
flowOf(ColorRecipeParams.DEFAULT)
|
||||
} else {
|
||||
contentRepository.lutManager.getColorRecipeParams(id)
|
||||
}
|
||||
}.stateIn(
|
||||
scope = viewModelScope,
|
||||
started = SharingStarted.WhileSubscribed(5000),
|
||||
initialValue = ColorRecipeParams.DEFAULT
|
||||
)
|
||||
|
||||
var editLutConfig: LutConfig? by mutableStateOf(null)
|
||||
private set
|
||||
|
||||
@@ -121,8 +135,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
// 边框编辑状态
|
||||
var editFrameId: String? by mutableStateOf(null)
|
||||
private set
|
||||
var editShowAppBranding by mutableStateOf(true)
|
||||
private set
|
||||
|
||||
// 可用的边框列表
|
||||
var availableFrames: List<FrameInfo> by mutableStateOf(emptyList())
|
||||
@@ -151,7 +163,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
init {
|
||||
loadPhotos()
|
||||
contentRepository.initialize()
|
||||
|
||||
// 订阅 ContentRepository 的 StateFlow,实现自动更新
|
||||
viewModelScope.launch {
|
||||
@@ -327,15 +338,11 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
// 更新编辑状态
|
||||
currentPhotoMetadata?.let { metadata ->
|
||||
editLutId = metadata.lutId
|
||||
editLutIntensity = metadata.lutIntensity
|
||||
editBrightness = metadata.brightness
|
||||
editRotation = metadata.rotation
|
||||
editLutId.value = metadata.lutId
|
||||
editFrameId = metadata.frameId
|
||||
editShowAppBranding = metadata.showAppBranding
|
||||
|
||||
// 加载 LUT 配置
|
||||
editLutId?.let { id ->
|
||||
editLutId.value?.let { id ->
|
||||
editLutConfig = withContext(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadLut(id)
|
||||
}
|
||||
@@ -344,7 +351,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun loadLutPreviews(photo: PhotoData): List<Bitmap?> {
|
||||
suspend fun loadLutPreviews(photo: PhotoData): Map<String, Bitmap> {
|
||||
val context = getApplication<Application>()
|
||||
val inputStream = context.contentResolver.openInputStream(photo.uri)
|
||||
val options = BitmapFactory.Options().apply {
|
||||
@@ -353,21 +360,30 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
val bitmap = BitmapFactory.decodeStream(inputStream, null, options)
|
||||
inputStream?.close()
|
||||
|
||||
if (bitmap == null) return emptyList()
|
||||
if (bitmap == null) return emptyMap()
|
||||
|
||||
return availableLuts.map { lutInfo ->
|
||||
val previews = mutableMapOf<String, Bitmap>()
|
||||
|
||||
availableLuts.forEach { lutInfo ->
|
||||
val lutConfig = withContext(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadLut(lutInfo.id)
|
||||
}
|
||||
|
||||
if (lutConfig != null) {
|
||||
val colorRecipeParams = withContext(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadColorRecipeParams(lutInfo.id)
|
||||
}
|
||||
lutImageProcessor.applyLut(
|
||||
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false),
|
||||
lutConfig = lutConfig,
|
||||
intensity = 1.0f
|
||||
)
|
||||
} else null
|
||||
colorRecipeParams = colorRecipeParams
|
||||
).let { preview ->
|
||||
previews[lutInfo.id] = preview
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return previews
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -757,26 +773,18 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
isEditing = true
|
||||
// 从当前元数据恢复编辑状态
|
||||
currentPhotoMetadata?.let { metadata ->
|
||||
editLutId = metadata.lutId
|
||||
editLutIntensity = metadata.lutIntensity
|
||||
editBrightness = metadata.brightness
|
||||
editRotation = metadata.rotation
|
||||
editLutId.value = metadata.lutId
|
||||
editFrameId = metadata.frameId
|
||||
editShowAppBranding = metadata.showAppBranding
|
||||
editCustomProperties.clear()
|
||||
editCustomProperties.putAll(metadata.customProperties)
|
||||
} ?: run {
|
||||
editLutId = null
|
||||
editLutIntensity = 1f
|
||||
editBrightness = 1f
|
||||
editRotation = 0f
|
||||
editLutId.value = null
|
||||
editFrameId = null
|
||||
editShowAppBranding = true
|
||||
editCustomProperties.clear()
|
||||
}
|
||||
|
||||
// 加载当前编辑的 LUT 配置
|
||||
editLutId?.let { id ->
|
||||
editLutId.value?.let { id ->
|
||||
viewModelScope.launch {
|
||||
editLutConfig = withContext(Dispatchers.IO) {
|
||||
contentRepository.lutManager.loadLut(id)
|
||||
@@ -790,35 +798,17 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
*/
|
||||
fun exitEditMode() {
|
||||
isEditing = false
|
||||
editRotation = 0f
|
||||
editBrightness = 1f
|
||||
editLutId = null
|
||||
editLutIntensity = 1f
|
||||
editLutId.value = null
|
||||
editLutConfig = null
|
||||
editFrameId = null
|
||||
editShowAppBranding = true
|
||||
editCustomProperties.clear()
|
||||
}
|
||||
|
||||
/**
|
||||
* 旋转90度
|
||||
*/
|
||||
fun rotate90() {
|
||||
editRotation = (editRotation + 90f) % 360f
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置亮度
|
||||
*/
|
||||
fun setBrightness(value: Float) {
|
||||
editBrightness = value.coerceIn(0.5f, 2f)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 LUT
|
||||
*/
|
||||
fun setEditLut(lutId: String?) {
|
||||
editLutId = lutId
|
||||
editLutId.value = lutId
|
||||
if (lutId == null) {
|
||||
editLutConfig = null
|
||||
return
|
||||
@@ -831,13 +821,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 LUT 强度
|
||||
*/
|
||||
fun updateEditLutIntensity(intensity: Float) {
|
||||
editLutIntensity = intensity.coerceIn(0f, 1f)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置边框
|
||||
*/
|
||||
@@ -845,13 +828,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editFrameId = frameId
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否显示 App 品牌
|
||||
*/
|
||||
fun setShowAppBranding(show: Boolean) {
|
||||
editShowAppBranding = show
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新水印自定义属性
|
||||
*/
|
||||
@@ -886,12 +862,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
if (bitmap == null) return@withContext null
|
||||
|
||||
val metadata = (photo.metadata ?: PhotoMetadata()).copy(
|
||||
lutId = editLutId,
|
||||
lutIntensity = editLutIntensity,
|
||||
brightness = editBrightness,
|
||||
rotation = editRotation,
|
||||
lutId = editLutId.value,
|
||||
frameId = editFrameId,
|
||||
showAppBranding = editShowAppBranding,
|
||||
customProperties = editCustomProperties.toMap()
|
||||
)
|
||||
|
||||
@@ -908,7 +880,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
*/
|
||||
fun saveEditMetadata(photo: PhotoData, onComplete: (Boolean) -> Unit = {}) {
|
||||
// 检查 VIP 权限
|
||||
val currentLut = availableLuts.find { it.id == editLutId }
|
||||
val currentLut = availableLuts.find { it.id == editLutId.value }
|
||||
if (currentLut?.isVip == true && !isPurchased.value) {
|
||||
showPaymentDialog = true
|
||||
onComplete(false)
|
||||
@@ -919,12 +891,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
try {
|
||||
val context = getApplication<Application>()
|
||||
val metadata = (currentPhotoMetadata ?: PhotoMetadata()).copy(
|
||||
lutId = editLutId,
|
||||
lutIntensity = editLutIntensity,
|
||||
brightness = editBrightness,
|
||||
rotation = editRotation,
|
||||
lutId = editLutId.value,
|
||||
frameId = editFrameId,
|
||||
showAppBranding = editShowAppBranding,
|
||||
customProperties = editCustomProperties.toMap()
|
||||
)
|
||||
val success = PhotoManager.saveMetadata(context, photo.id, metadata)
|
||||
@@ -962,19 +930,15 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
*/
|
||||
fun saveEdit(photo: PhotoData, onComplete: (Boolean) -> Unit = {}) {
|
||||
// 检查 VIP 权限
|
||||
val currentLut = availableLuts.find { it.id == editLutId }
|
||||
val currentLut = availableLuts.find { it.id == editLutId.value }
|
||||
if (currentLut?.isVip == true && !isPurchased.value) {
|
||||
showPaymentDialog = true
|
||||
return
|
||||
}
|
||||
|
||||
val metadata = (photo.metadata ?: PhotoMetadata()).copy(
|
||||
lutId = editLutId,
|
||||
lutIntensity = editLutIntensity,
|
||||
brightness = editBrightness,
|
||||
rotation = editRotation,
|
||||
lutId = editLutId.value,
|
||||
frameId = editFrameId,
|
||||
showAppBranding = editShowAppBranding,
|
||||
customProperties = editCustomProperties.toMap()
|
||||
)
|
||||
exportPhotoInternal(
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.hinnka.mycamera.viewmodel
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.hinnka.mycamera.data.ContentRepository
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class LutEditViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
private val contentRepository = ContentRepository.getInstance(application)
|
||||
|
||||
suspend fun getColorRecipe(lutId: String) = contentRepository.lutManager.loadColorRecipeParams(lutId)
|
||||
|
||||
/**
|
||||
* 保存LUT的色彩配方参数
|
||||
*/
|
||||
fun saveLutColorRecipe(lutId: String, params: ColorRecipeParams) {
|
||||
viewModelScope.launch {
|
||||
contentRepository.lutManager.saveColorRecipeParams(lutId, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,6 +143,9 @@
|
||||
<string name="name">名称</string>
|
||||
<string name="confirm">确认</string>
|
||||
|
||||
<!-- Color Recipe -->
|
||||
<string name="color_recipe">色彩配方</string>
|
||||
|
||||
<!-- Developer Options -->
|
||||
<string name="settings_section_developer">开发者选项</string>
|
||||
<string name="settings_log_viewer">日志收集</string>
|
||||
|
||||
@@ -144,6 +144,9 @@
|
||||
<string name="name">Name</string>
|
||||
<string name="confirm">Confirm</string>
|
||||
|
||||
<!-- Color Recipe -->
|
||||
<string name="color_recipe">Color Recipe</string>
|
||||
|
||||
<!-- Developer Options -->
|
||||
<string name="settings_section_developer">Developer Options</string>
|
||||
<string name="settings_log_viewer">Log Viewer</string>
|
||||
|
||||
Reference in new issue
Block a user