diff --git a/app/src/main/java/com/hinnka/mycamera/lut/creator/AiImagePreprocessor.kt b/app/src/main/java/com/hinnka/mycamera/lut/creator/AiImagePreprocessor.kt deleted file mode 100644 index 72a99e6d..00000000 --- a/app/src/main/java/com/hinnka/mycamera/lut/creator/AiImagePreprocessor.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.hinnka.mycamera.lut.creator - -import android.graphics.Bitmap -import androidx.core.graphics.scale - -object AiImagePreprocessor { - private const val VISION_MAX_EDGE = 1024 - private const val IMAGE_EDIT_MAX_EDGE = 1024 - - fun prepareForVisionAnalysis(bitmap: Bitmap): Bitmap { - if (bitmap.width <= VISION_MAX_EDGE && bitmap.height <= VISION_MAX_EDGE) { - return bitmap - } - - val scale = VISION_MAX_EDGE.toFloat() / maxOf(bitmap.width, bitmap.height) - val width = (bitmap.width * scale).toInt().coerceAtLeast(1) - val height = (bitmap.height * scale).toInt().coerceAtLeast(1) - return bitmap.scale(width, height) - } - - fun prepareForImageToImage(bitmap: Bitmap): Bitmap { - val squareBitmap = cropBitmapToSquare(bitmap) - if (squareBitmap.width <= IMAGE_EDIT_MAX_EDGE && squareBitmap.height <= IMAGE_EDIT_MAX_EDGE) { - return squareBitmap - } - - return squareBitmap.scale(IMAGE_EDIT_MAX_EDGE, IMAGE_EDIT_MAX_EDGE) - } - - private fun cropBitmapToSquare(bitmap: Bitmap): Bitmap { - if (bitmap.width == bitmap.height) { - return bitmap - } - - val size = minOf(bitmap.width, bitmap.height) - val x = (bitmap.width - size) / 2 - val y = (bitmap.height - size) / 2 - return Bitmap.createBitmap(bitmap, x, y, size, size) - } -} diff --git a/app/src/main/java/com/hinnka/mycamera/lut/creator/LutCreatorScreen.kt b/app/src/main/java/com/hinnka/mycamera/lut/creator/LutCreatorScreen.kt index 74b4640e..20424c03 100644 --- a/app/src/main/java/com/hinnka/mycamera/lut/creator/LutCreatorScreen.kt +++ b/app/src/main/java/com/hinnka/mycamera/lut/creator/LutCreatorScreen.kt @@ -1,8 +1,5 @@ package com.hinnka.mycamera.lut.creator -import android.app.Activity -import android.content.Context -import android.content.ContextWrapper import android.net.Uri import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts @@ -22,10 +19,7 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll -import androidx.compose.ui.graphics.asImageBitmap -import androidx.compose.ui.platform.LocalContext import com.hinnka.mycamera.R -import com.hinnka.mycamera.ui.components.PaymentDialog import com.hinnka.mycamera.ui.icons.AppIcons private data class LocalImagePairDraft( @@ -33,11 +27,6 @@ private data class LocalImagePairDraft( val targetUri: Uri ) -private enum class LutCreatorMode { - AI, - LOCAL -} - @OptIn(ExperimentalMaterial3Api::class) @Composable fun LutCreatorScreen( @@ -46,28 +35,11 @@ fun LutCreatorScreen( onSuccess: (String) -> Unit ) { val uiState by viewModel.uiState.collectAsState() - val context = LocalContext.current - val isPurchased by viewModel.isPurchased.collectAsState() - val openAIKey by viewModel.openAIApiKey.collectAsState() - val canUseLutCreator = isPurchased || !openAIKey.isNullOrBlank() - var lutName by remember { mutableStateOf("My AI LUT") } - var customPrompt by remember { mutableStateOf("") } - var selectedMode by remember { mutableStateOf(LutCreatorMode.AI) } + var lutName by remember { mutableStateOf("My LUT") } var pendingSourceUri by remember { mutableStateOf(null) } var localPairs by remember { mutableStateOf(listOf()) } val idleScrollState = rememberScrollState() - val aiImageLauncher = rememberLauncherForActivityResult( - contract = ActivityResultContracts.GetContent() - ) { uri: Uri? -> - uri ?: return@rememberLauncherForActivityResult - if (!canUseLutCreator) { - viewModel.showPaymentDialog = true - return@rememberLauncherForActivityResult - } - viewModel.analyzeAiImage(uri, customPrompt) - } - val localSourceLauncher = rememberLauncherForActivityResult( contract = ActivityResultContracts.GetContent() ) { uri: Uri? -> @@ -114,194 +86,130 @@ fun LutCreatorScreen( verticalArrangement = Arrangement.Top, horizontalAlignment = Alignment.Start ) { - if (!canUseLutCreator) { - LutCreatorPremiumRequiredCard( - onPurchase = { viewModel.showPaymentDialog = true } - ) - Spacer(modifier = Modifier.height(24.dp)) - return@Column - } - - PrimaryTabRow( - selectedTabIndex = selectedMode.ordinal, - containerColor = Color.Transparent, - contentColor = Color(0xFFE5A324) - ) { - Tab( - selected = selectedMode == LutCreatorMode.AI, - onClick = { selectedMode = LutCreatorMode.AI }, - text = { Text(stringResource(R.string.lut_creator_tab_ai)) } - ) - Tab( - selected = selectedMode == LutCreatorMode.LOCAL, - onClick = { selectedMode = LutCreatorMode.LOCAL }, - text = { Text(stringResource(R.string.lut_creator_tab_local)) } - ) - } - - Spacer(modifier = Modifier.height(16.dp)) - Surface( color = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.4f), shape = RoundedCornerShape(20.dp), modifier = Modifier.fillMaxWidth() ) { Column(modifier = Modifier.padding(20.dp)) { - when (selectedMode) { - LutCreatorMode.AI -> { + val isSelectingTarget = pendingSourceUri != null + + Text( + text = stringResource(R.string.lut_creator_tab_local), + style = MaterialTheme.typography.titleMedium, + fontWeight = androidx.compose.ui.text.font.FontWeight.SemiBold + ) + Spacer(modifier = Modifier.height(6.dp)) + Text( + text = stringResource(R.string.lut_creator_local_mode_desc), + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + Spacer(modifier = Modifier.height(16.dp)) + HorizontalDivider(color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.1f)) + Spacer(modifier = Modifier.height(16.dp)) + Text( + text = stringResource(R.string.lut_creator_local_pairs_hint), + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + Spacer(modifier = Modifier.height(16.dp)) + Surface( + modifier = Modifier.fillMaxWidth(), + shape = RoundedCornerShape(14.dp), + color = MaterialTheme.colorScheme.surface.copy(alpha = 0.55f) + ) { + Column(modifier = Modifier.padding(14.dp)) { Text( - text = stringResource(R.string.lut_creator_tab_ai), - style = MaterialTheme.typography.titleMedium, + text = if (isSelectingTarget) { + stringResource(R.string.lut_creator_local_step_select_target) + } else { + stringResource(R.string.lut_creator_local_step_select_source) + }, + style = MaterialTheme.typography.titleSmall, fontWeight = androidx.compose.ui.text.font.FontWeight.SemiBold ) - Spacer(modifier = Modifier.height(6.dp)) + Spacer(modifier = Modifier.height(4.dp)) Text( - text = stringResource(R.string.lut_creator_ai_mode_desc), - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurfaceVariant - ) - Spacer(modifier = Modifier.height(16.dp)) - OutlinedTextField( - value = customPrompt, - onValueChange = { customPrompt = it }, - label = { Text(stringResource(R.string.lut_creator_custom_ai_instructions)) }, - placeholder = { Text(stringResource(R.string.lut_creator_custom_ai_hint)) }, - modifier = Modifier.fillMaxWidth(), - shape = RoundedCornerShape(12.dp), - colors = OutlinedTextFieldDefaults.colors( - unfocusedBorderColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.2f), - focusedBorderColor = Color(0xFFE5A324) - ) - ) - Spacer(modifier = Modifier.height(12.dp)) - Text( - text = stringResource(R.string.lut_creator_use_ai), + text = if (isSelectingTarget) { + stringResource(R.string.lut_creator_local_step_select_target_desc) + } else { + stringResource(R.string.lut_creator_local_step_select_source_desc) + }, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant ) } - - LutCreatorMode.LOCAL -> { - val isSelectingTarget = pendingSourceUri != null - - Text( - text = stringResource(R.string.lut_creator_tab_local), - style = MaterialTheme.typography.titleMedium, - fontWeight = androidx.compose.ui.text.font.FontWeight.SemiBold - ) - Spacer(modifier = Modifier.height(6.dp)) - Text( - text = stringResource(R.string.lut_creator_local_mode_desc), - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurfaceVariant - ) - Spacer(modifier = Modifier.height(16.dp)) - HorizontalDivider(color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.1f)) - Spacer(modifier = Modifier.height(16.dp)) - Text( - text = stringResource(R.string.lut_creator_local_pairs_hint), - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurfaceVariant - ) - Spacer(modifier = Modifier.height(16.dp)) - Surface( - modifier = Modifier.fillMaxWidth(), - shape = RoundedCornerShape(14.dp), - color = MaterialTheme.colorScheme.surface.copy(alpha = 0.55f) - ) { - Column(modifier = Modifier.padding(14.dp)) { - Text( - text = if (isSelectingTarget) { - stringResource(R.string.lut_creator_local_step_select_target) - } else { - stringResource(R.string.lut_creator_local_step_select_source) - }, - style = MaterialTheme.typography.titleSmall, - fontWeight = androidx.compose.ui.text.font.FontWeight.SemiBold - ) - Spacer(modifier = Modifier.height(4.dp)) - Text( - text = if (isSelectingTarget) { - stringResource(R.string.lut_creator_local_step_select_target_desc) - } else { - stringResource(R.string.lut_creator_local_step_select_source_desc) - }, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant - ) - } + } + Spacer(modifier = Modifier.height(14.dp)) + Button( + onClick = { + if (isSelectingTarget) { + localTargetLauncher.launch("image/*") + } else { + localSourceLauncher.launch("image/*") } - Spacer(modifier = Modifier.height(14.dp)) - Button( - onClick = { - if (isSelectingTarget) { - localTargetLauncher.launch("image/*") - } else { - localSourceLauncher.launch("image/*") - } - }, - modifier = Modifier.fillMaxWidth(), - shape = RoundedCornerShape(12.dp) - ) { + }, + modifier = Modifier.fillMaxWidth(), + shape = RoundedCornerShape(12.dp) + ) { + Text( + if (isSelectingTarget) { + stringResource(R.string.lut_creator_select_effect_image) + } else { + stringResource(R.string.lut_creator_select_source_image) + } + ) + } + Spacer(modifier = Modifier.height(12.dp)) + OutlinedButton( + onClick = { + pendingSourceUri = null + localPairs = emptyList() + }, + enabled = isSelectingTarget || localPairs.isNotEmpty(), + modifier = Modifier.fillMaxWidth(), + shape = RoundedCornerShape(12.dp) + ) { + Text(stringResource(R.string.lut_creator_reset_local_selection)) + } + Spacer(modifier = Modifier.height(16.dp)) + Surface( + modifier = Modifier.fillMaxWidth(), + shape = RoundedCornerShape(14.dp), + color = MaterialTheme.colorScheme.surface.copy(alpha = 0.55f) + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 14.dp, vertical = 12.dp), + verticalAlignment = Alignment.CenterVertically + ) { + Icon( + imageVector = Icons.Default.CheckCircle, + contentDescription = null, + tint = Color(0xFFE5A324), + modifier = Modifier.size(20.dp) + ) + Spacer(modifier = Modifier.width(10.dp)) + Column(modifier = Modifier.weight(1f)) { Text( - if (isSelectingTarget) { - stringResource(R.string.lut_creator_select_effect_image) + text = stringResource( + R.string.lut_creator_local_pairs_count, + localPairs.size + ), + style = MaterialTheme.typography.titleSmall + ) + Spacer(modifier = Modifier.height(2.dp)) + Text( + text = if (isSelectingTarget) { + stringResource(R.string.lut_creator_local_pending_target) } else { - stringResource(R.string.lut_creator_select_source_image) - } + stringResource(R.string.lut_creator_local_ready_status) + }, + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant ) - } - Spacer(modifier = Modifier.height(12.dp)) - OutlinedButton( - onClick = { - pendingSourceUri = null - localPairs = emptyList() - }, - enabled = isSelectingTarget || localPairs.isNotEmpty(), - modifier = Modifier.fillMaxWidth(), - shape = RoundedCornerShape(12.dp) - ) { - Text(stringResource(R.string.lut_creator_reset_local_selection)) - } - Spacer(modifier = Modifier.height(16.dp)) - Surface( - modifier = Modifier.fillMaxWidth(), - shape = RoundedCornerShape(14.dp), - color = MaterialTheme.colorScheme.surface.copy(alpha = 0.55f) - ) { - Row( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 14.dp, vertical = 12.dp), - verticalAlignment = Alignment.CenterVertically - ) { - Icon( - imageVector = Icons.Default.CheckCircle, - contentDescription = null, - tint = Color(0xFFE5A324), - modifier = Modifier.size(20.dp) - ) - Spacer(modifier = Modifier.width(10.dp)) - Column(modifier = Modifier.weight(1f)) { - Text( - text = stringResource( - R.string.lut_creator_local_pairs_count, - localPairs.size - ), - style = MaterialTheme.typography.titleSmall - ) - Spacer(modifier = Modifier.height(2.dp)) - Text( - text = if (isSelectingTarget) { - stringResource(R.string.lut_creator_local_pending_target) - } else { - stringResource(R.string.lut_creator_local_ready_status) - }, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant - ) - } - } } } } @@ -310,19 +218,11 @@ fun LutCreatorScreen( Spacer(modifier = Modifier.height(20.dp)) Button( onClick = { - if (!canUseLutCreator) { - viewModel.showPaymentDialog = true - return@Button - } - if (selectedMode == LutCreatorMode.AI) { - aiImageLauncher.launch("image/*") - } else { - viewModel.analyzeLocalImagePairs( - localPairs.map { LocalImagePairInput(it.sourceUri, it.targetUri) } - ) - } + viewModel.analyzeLocalImagePairs( + localPairs.map { LocalImagePairInput(it.sourceUri, it.targetUri) } + ) }, - enabled = selectedMode == LutCreatorMode.AI || localPairs.isNotEmpty(), + enabled = localPairs.isNotEmpty(), modifier = Modifier .fillMaxWidth() .height(60.dp), @@ -333,11 +233,7 @@ fun LutCreatorScreen( ) ) { Text( - if (selectedMode == LutCreatorMode.AI) { - stringResource(R.string.lut_creator_select_images) - } else { - stringResource(R.string.lut_creator_start_local_analysis) - }, + stringResource(R.string.lut_creator_start_local_analysis), style = MaterialTheme.typography.titleLarge, fontWeight = androidx.compose.ui.text.font.FontWeight.Medium ) @@ -385,28 +281,6 @@ fun LutCreatorScreen( fontWeight = androidx.compose.ui.text.font.FontWeight.Bold ) - state.generatedSourceBitmap?.let { bitmap -> - Spacer(modifier = Modifier.height(24.dp)) - Text( - text = stringResource(R.string.lut_creator_ai_restored_preview), - style = MaterialTheme.typography.titleSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant - ) - Spacer(modifier = Modifier.height(12.dp)) - Surface( - shape = RoundedCornerShape(16.dp), - shadowElevation = 4.dp, - modifier = Modifier.sizeIn(maxHeight = 300.dp) - ) { - androidx.compose.foundation.Image( - bitmap = bitmap.asImageBitmap(), - contentDescription = "AI Generated Original", - modifier = Modifier.fillMaxWidth(), - contentScale = androidx.compose.ui.layout.ContentScale.Fit - ) - } - } - Spacer(modifier = Modifier.height(32.dp)) OutlinedTextField( value = lutName, @@ -512,71 +386,4 @@ fun LutCreatorScreen( } } } - - if (viewModel.showPaymentDialog) { - val activity = context.findActivity() - PaymentDialog( - onDismiss = { viewModel.showPaymentDialog = false }, - onPurchase = { - if (activity != null) { - viewModel.purchase(activity) - } - viewModel.showPaymentDialog = false - } - ) - } -} - -@Composable -private fun LutCreatorPremiumRequiredCard( - onPurchase: () -> Unit -) { - Surface( - color = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.4f), - shape = RoundedCornerShape(20.dp), - modifier = Modifier - .fillMaxWidth() - .padding(top = 16.dp) - ) { - Column( - modifier = Modifier.padding(20.dp), - horizontalAlignment = Alignment.Start - ) { - Text( - text = stringResource(R.string.lut_creator_premium_required_title), - style = MaterialTheme.typography.titleMedium, - fontWeight = androidx.compose.ui.text.font.FontWeight.SemiBold - ) - Spacer(modifier = Modifier.height(8.dp)) - Text( - text = stringResource(R.string.lut_creator_premium_required_desc), - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurfaceVariant - ) - Spacer(modifier = Modifier.height(20.dp)) - Button( - onClick = onPurchase, - modifier = Modifier.fillMaxWidth(), - shape = RoundedCornerShape(12.dp), - colors = ButtonDefaults.buttonColors( - containerColor = Color(0xFFE5A324), - contentColor = Color.White - ) - ) { - Text( - text = stringResource(R.string.billing_premium_get_access), - fontWeight = androidx.compose.ui.text.font.FontWeight.Bold - ) - } - } - } -} - -private fun Context.findActivity(): Activity? { - var current = this - while (current is ContextWrapper) { - if (current is Activity) return current - current = current.baseContext - } - return null } diff --git a/app/src/main/java/com/hinnka/mycamera/lut/creator/LutCreatorViewModel.kt b/app/src/main/java/com/hinnka/mycamera/lut/creator/LutCreatorViewModel.kt index eed7a545..8b31deff 100644 --- a/app/src/main/java/com/hinnka/mycamera/lut/creator/LutCreatorViewModel.kt +++ b/app/src/main/java/com/hinnka/mycamera/lut/creator/LutCreatorViewModel.kt @@ -3,119 +3,25 @@ package com.hinnka.mycamera.lut.creator import android.app.Application import android.graphics.BitmapFactory import android.net.Uri -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.setValue import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.viewModelScope import com.hinnka.mycamera.data.CustomImportManager -import com.hinnka.mycamera.data.ContentRepository import com.hinnka.mycamera.lut.LutManager import com.hinnka.mycamera.utils.PLog import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import java.io.File class LutCreatorViewModel(application: Application) : AndroidViewModel(application) { - private val contentRepository = ContentRepository.getInstance(application) - private val userPreferencesRepository = contentRepository.userPreferencesRepository - private val billingManager = com.hinnka.mycamera.billing.BillingManagerImpl(application) private val importManager = CustomImportManager(application) private val lutManager = LutManager(application) private val _uiState = MutableStateFlow(LutCreatorUiState.Idle) val uiState: StateFlow = _uiState - val aiAnalysisEnabled: MutableStateFlow = MutableStateFlow(false) - val isPurchased = billingManager.isPurchased - val openAIApiKey = userPreferencesRepository.userPreferences.map { it.openAIApiKey } - .stateIn(viewModelScope, SharingStarted.Eagerly, "") - var showPaymentDialog by mutableStateOf(false) - - fun purchase(activity: android.app.Activity) { - billingManager.purchase(activity) - } - - fun analyzeAiImage(uri: Uri, customPrompt: String = "") { - viewModelScope.launch(Dispatchers.IO) { - _uiState.value = LutCreatorUiState.Analyzing - - try { - val bitmap = loadBitmapFromUri(uri) - if (bitmap == null) { - _uiState.value = LutCreatorUiState.Error("Failed to decode image(s)") - return@launch - } - - val context = getApplication() - val client = OpenAIApiClient() - client.initialize(context) - val preparedBitmap = AiImagePreprocessor.prepareForVisionAnalysis(bitmap) - - PLog.d( - "LutCreatorViewModel", - "Calling AI text recipe generation for single-image LUT creation..." - ) - - val recipe = client.generateLutRecipeFromImage( - bitmap = preparedBitmap, - customPrompt = customPrompt - ).getOrThrow() - - PLog.d("LutCreatorViewModel", "AI text recipe: $recipe") - - _uiState.value = LutCreatorUiState.AnalysisComplete(recipe) - } catch (e: Exception) { - _uiState.value = LutCreatorUiState.Error("Analysis failed: ${e.message}") - } - } - } - - fun analyzeAiImageWithImageEdit(uri: Uri, customPrompt: String = "") { - viewModelScope.launch(Dispatchers.IO) { - _uiState.value = LutCreatorUiState.Analyzing - - try { - val bitmap = loadBitmapFromUri(uri) - if (bitmap == null) { - _uiState.value = LutCreatorUiState.Error("Failed to decode image(s)") - return@launch - } - - val context = getApplication() - val client = OpenAIApiClient() - client.initialize(context) - - PLog.d( - "LutCreatorViewModel", - "Calling Gemini 3.1 for direct image-to-image restoration..." - ) - - val preparedBitmap = AiImagePreprocessor.prepareForImageToImage(bitmap) - val sourceBitmap = client.generateOriginalImage( - bitmap = preparedBitmap, - model = OpenAIApiClient.BUILT_IN_IMAGE_MODEL, - customPrompt = customPrompt - ).getOrThrow() - - PLog.d("LutCreatorViewModel", "AI generated original image, analyzing pair locally...") - val recipe = LocalImageAnalyzer.analyzeSourceTargetImages(sourceBitmap, preparedBitmap) - - PLog.d("LutCreatorViewModel", "Recipe: $recipe") - - _uiState.value = LutCreatorUiState.AnalysisComplete(recipe, sourceBitmap) - } catch (e: Exception) { - _uiState.value = LutCreatorUiState.Error("Analysis failed: ${e.message}") - } - } - } - fun analyzeLocalImagePairs(pairs: List) { viewModelScope.launch(Dispatchers.IO) { _uiState.value = LutCreatorUiState.Analyzing @@ -215,10 +121,7 @@ data class LocalImagePairInput( sealed class LutCreatorUiState { object Idle : LutCreatorUiState() object Analyzing : LutCreatorUiState() - data class AnalysisComplete( - val recipe: LutRecipe, - val generatedSourceBitmap: android.graphics.Bitmap? = null - ) : LutCreatorUiState() + data class AnalysisComplete(val recipe: LutRecipe) : LutCreatorUiState() object Generating : LutCreatorUiState() data class Success(val lutId: String) : LutCreatorUiState() data class Error(val message: String) : LutCreatorUiState() diff --git a/app/src/main/java/com/hinnka/mycamera/ui/components/ApertureScaleSettingItem.kt b/app/src/main/java/com/hinnka/mycamera/ui/components/ApertureScaleSettingItem.kt index 59e6776f..5bc809d9 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/components/ApertureScaleSettingItem.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/components/ApertureScaleSettingItem.kt @@ -11,7 +11,6 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Switch @@ -22,7 +21,6 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.rememberUpdatedState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.scale import androidx.compose.ui.graphics.Color import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.input.pointer.pointerInput @@ -75,23 +73,45 @@ fun ApertureScaleSettingItem( .fillMaxWidth() .padding(vertical = 8.dp) ) { + // 与 SwitchSettingItem 保持一致的头部:左侧标题 + 描述,右侧开关 Row( modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { - Text( - text = title, - color = if (enabled) Color.White else Color.White.copy(alpha = 0.45f), - fontSize = 16.sp, - fontWeight = FontWeight.Normal - ) + Column(modifier = Modifier.weight(1f)) { + Row(verticalAlignment = Alignment.CenterVertically) { + Text( + text = title, + color = Color.White, + fontSize = 16.sp, + fontWeight = FontWeight.Normal + ) + if (shouldShowScale) { + Spacer(modifier = Modifier.width(8.dp)) + Text( + text = "f/${formatApertureStop(ApertureScaleStops[selectedIndex])}", + color = AccentColor, + fontSize = 14.sp, + fontWeight = FontWeight.Medium + ) + } + } + description?.let { + Spacer(modifier = Modifier.height(2.dp)) + Text( + text = it, + color = Color.White.copy(alpha = 0.6f), + fontSize = 13.sp, + lineHeight = 18.sp + ) + } + } if (toggleValue != null) { - Spacer(modifier = Modifier.width(8.dp)) Switch( checked = toggleValue, onCheckedChange = onToggleChange, - modifier = Modifier.scale(0.7f).size(40.dp, 24.dp), colors = SwitchDefaults.colors( checkedThumbColor = OnAccentColor, checkedTrackColor = AccentColor, @@ -101,27 +121,6 @@ fun ApertureScaleSettingItem( ) ) } - - Spacer(modifier = Modifier.weight(1f)) - - if (shouldShowScale) { - Text( - text = "f/${formatApertureStop(ApertureScaleStops[selectedIndex])}", - color = Color.White.copy(alpha = if (enabled) 0.8f else 0.35f), - fontSize = 14.sp, - fontWeight = FontWeight.Medium - ) - } - } - - description?.let { - Spacer(modifier = Modifier.height(4.dp)) - Text( - text = it, - color = Color.White.copy(alpha = if (enabled) 0.6f else 0.35f), - fontSize = 13.sp, - lineHeight = 18.sp - ) } if (shouldShowScale) { diff --git a/app/src/main/res/values-b+zh+Hant/strings.xml b/app/src/main/res/values-b+zh+Hant/strings.xml index 0f1e0163..b2555aeb 100644 --- a/app/src/main/res/values-b+zh+Hant/strings.xml +++ b/app/src/main/res/values-b+zh+Hant/strings.xml @@ -1015,19 +1015,12 @@ 深色 - AI 仿色 - 選擇圖片分析色彩風格,并生成專屬 LUT。 - 需要會員 - 未在設定中配置自己的 OpenAI API Key 時,LUT 創建功能需要購買會員后才能使用。 - AI 分析 - 本地分析 - AI 會根據所選效果圖生成文字版 LUT 配方。 - 自訂 AI 提示詞(選填) - 例如:讓畫面更有氛圍感,加深對比度 + 仿色 + 用原圖和效果圖配對,複刻色彩風格並生成專屬 LUT。 + 原圖 / 效果圖配對 選擇圖片 - 上傳一張效果圖,AI 會直接推斷文字版 LUT 配方,不再調用圖片編輯能力。 - 上傳多組圖片,每組包含一張原圖和一張效果圖,且應盡量是完全相同的場景。 - 本地分析支援多組原圖/效果圖配對。構圖、曝光和場景越一致,合并后的控制點越穩定。 + 添加一組或多組圖片,每組包含同一場景的一張原圖和一張調色後的效果圖。 + 配對越多,構圖和曝光越一致,生成的 LUT 越準確。 選擇原圖 選擇效果圖 清空已選內容 @@ -1038,10 +1031,9 @@ 已添加 %1$d 組圖片 當前有 1 組還差效果圖 可以繼續添加圖片組,或直接開始分析 - 開始本地分析 + 開始分析 正在分析圖片風格… 分析完成! - AI 還原的原圖預覽 LUT 預設名稱 生成并儲存 正在生成 3D LUT 資料… @@ -1092,7 +1084,7 @@ 開啟后,拍攝及匯入相片將自動應用所選光圈值的虛化效果。 使用目前已安裝的相容深度模型。首次使用時可下載預設模型,或匯入其他相容的 TFLite 模型。 大光圈虛化 - 使用目前已安裝的相容深度模型估計畫面深度,模擬大光圈的淺景深、背景虛化和柔和散景光斑。輕點畫面可改變對焦位置;光圈值越小,虛化越強。首次使用時可下載預設模型,或匯入其他相容的 TFLite 模型。 + 模擬大光圈的淺景深背景虛化效果 光斑風格 虛化處理中… 降噪處理中… diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index d938ebcf..d9094a1f 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -1225,18 +1225,11 @@ Clair Sombre Créateur de LUT - Sélectionnez des images pour analyser le style et générer un LUT personnalisé. - Premium requis - Le Créateur de LUT nécessite Premium, sauf si vous avez configuré votre propre clé API OpenAI dans les Paramètres. - Analyse IA - Analyse locale - L\'IA générera une recette de LUT sous forme de texte à partir de l\'image stylisée sélectionnée. - Instructions IA personnalisées (facultatif) - ex. plus sombre, accentuer les rouges + Associez des originaux à des images stylisées pour reproduire un style colorimétrique dans un LUT personnalisé. + Paires original / stylisée Sélectionner des images - Importez une image stylisée. L\'IA déduira directement une recette de LUT sous forme de texte, sans retouche d\'image. - Importez plusieurs paires d\'images. Chaque paire doit comprendre une image originale et une image stylisée de la même scène. - Pour l\'analyse locale, ajoutez plusieurs paires original/stylisée. Plus le cadrage et l\'exposition se ressemblent, meilleurs seront les points de contrôle fusionnés. + Ajoutez une ou plusieurs paires d\'images. Chaque paire comprend un original et une version étalonnée de la même scène. + Plus les paires sont nombreuses et proches en cadrage et en exposition, plus le LUT sera précis. Sélectionner l\'image originale Sélectionner l\'image stylisée Effacer la sélection @@ -1247,10 +1240,9 @@ %1$d paire(s) d\'images ajoutée(s) 1 paire attend encore son image stylisée Vous pouvez ajouter d\'autres paires ou lancer l\'analyse maintenant - Analyser les paires locales + Lancer l\'analyse Analyse du style de l\'image… Analyse terminée ! - Aperçu d\'origine restauré par l\'IA Nom du LUT Générer et enregistrer Génération du LUT 3D interpolé… @@ -1275,7 +1267,7 @@ Active automatiquement l\'ouverture virtuelle avec la valeur d\'ouverture choisie pour les nouvelles photos. Utilise le modèle de profondeur compatible installé. Téléchargez le modèle par défaut ou importez un autre modèle TFLite compatible lors de la première utilisation. Flou à grande ouverture - Utilise le modèle de profondeur compatible installé pour estimer la profondeur de la scène et simuler une faible profondeur de champ, un flou d\'arrière-plan et des bokehs doux. Touchez l\'image pour changer le point de mise au point. Plus le nombre f est bas, plus le flou est marqué. Téléchargez le modèle par défaut ou importez un autre modèle TFLite compatible lors de la première utilisation. + Simule la faible profondeur de champ et le flou d\'arrière-plan d\'une grande ouverture Style de bokeh Tourbillon Naturel diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 76fd2624..ac26d039 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -884,18 +884,11 @@ ライト ダーク LUTクリエイター - 画像のスタイルを解析し、カスタムLUTを生成 - Premiumが必要です - 設定で独自のOpenAI APIキーを指定していない場合、LUT CreatorにはPremiumが必要です。 - AI解析 - ローカル解析 - AIが選択したスタイル画像からテキスト形式のLUTレシピを生成します。 - カスタムAI指示(任意) - 例:もっとムーディーに、赤を強調 + オリジナルと仕上がり画像のペアから色調を再現し、カスタムLUTを生成 + オリジナル/仕上がりペア 画像を選択 - スタイル適用済み画像を1枚アップロードします。画像編集は行わず、AIが直接テキストLUTレシピを推定します。 - 複数の画像ペアをアップロードします。各ペアには同一シーンのオリジナル画像とスタイル適用済み画像を含めてください。 - ローカル解析では複数のオリジナル/スタイル済みペアを追加します。構図と露出が近いほど、統合されるコントロールポイントの精度が上がります。 + 1組以上の画像ペアを追加します。各ペアは同じシーンのオリジナル画像とカラーグレーディング済み画像です。 + ペアが多く、構図と露出が近いほど、より正確なLUTが生成されます。 オリジナル画像を選択 スタイル画像を選択 選択を解除 @@ -906,10 +899,9 @@ %1$d 組の画像ペアを追加 1組がスタイル画像持ちです さらにペアを追加するか、このまま解析を開始できます - ローカルペアを解析 + 解析を開始 画像スタイルを解析中... 解析完了 - AIがオリジナルプレビューを復元しました LUT名 生成して保存 @@ -943,7 +935,7 @@ 新しい写真で、選択したF値の仮想絞りを自動有効化 インストール済みの対応深度モデルを使用します。初回使用時に既定モデルをダウンロードするか、別の対応TFLiteモデルを読み込んでください。 大口径ボケ - 対応深度モデルでシーン深度を推定し、浅い被写界深度、背景ボケ、柔らかな玉ボケをシミュレートします。画像をタップして合焦点を変更できます。F値が小さいほどボケは強くなります。初回使用時に既定モデルをダウンロードするか、別の対応TFLiteモデルを読み込んでください。 + 大口径レンズの浅い被写界深度と背景ボケを再現します ボケ味 ボケ処理中… ノイズ低減を処理中… diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index 53210df5..e42c0608 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -741,19 +741,12 @@ มืด - AI กำลังทำสี - เลือกสไตล์สีการวิเคราะห์ภาพและสร้าง LUT ของคุณเอง - จำเป็นต้องสมัครสมาชิก - เมื่อไม่ได้กำหนดค่าคีย์ OpenAI API ของคุณเองในการตั้งค่า ฟังก์ชันการสร้าง LUT จำเป็นต้องซื้อการเป็นสมาชิกก่อนจึงจะสามารถใช้งานได้ - การวิเคราะห์เอไอ - การวิเคราะห์ในท้องถิ่น - AI จะสร้างเวอร์ชันข้อความของสูตร LUT ตามการเรนเดอร์ที่เลือก - คำพร้อมท์ AI ที่กำหนดเอง (ไม่บังคับ) - ตัวอย่างเช่น: ทำให้ภาพมีบรรยากาศมากขึ้นและเพิ่มคอนทราสต์ให้ลึกซึ้งยิ่งขึ้น + เลียนแบบสี + จับคู่ภาพต้นฉบับกับภาพที่แต่งสีแล้ว เพื่อเลียนแบบโทนสีและสร้าง LUT ของคุณเอง + คู่ภาพต้นฉบับ / ภาพแต่งสี เลือกรูปภาพ - อัปโหลดการเรนเดอร์ แล้ว AI จะอนุมานเวอร์ชันข้อความของสูตร LUT โดยตรง โดยไม่ต้องเรียกใช้ความสามารถในการแก้ไขรูปภาพ - อัปโหลดรูปภาพหลายชุด โดยแต่ละชุดประกอบด้วยรูปภาพต้นฉบับและรูปภาพเอฟเฟกต์ และรูปภาพเหล่านั้นควรอยู่ในฉากเดียวกันที่สุดเท่าที่จะเป็นไปได้ - การวิเคราะห์เฉพาะที่รองรับการจับคู่รูปภาพ/เอฟเฟกต์ต้นฉบับหลายชุด ยิ่งองค์ประกอบภาพ ค่าแสง และฉากมีความสอดคล้องกันมากเท่าใด จุดควบคุมที่รวมกันก็จะยิ่งมีความเสถียรมากขึ้นเท่านั้น + เพิ่มคู่ภาพหนึ่งคู่หรือมากกว่า แต่ละคู่ประกอบด้วยภาพต้นฉบับและภาพที่แต่งสีแล้วของฉากเดียวกัน + ยิ่งมีคู่ภาพมากและองค์ประกอบภาพกับค่าแสงใกล้เคียงกัน LUT ที่ได้ก็จะยิ่งแม่นยำ เลือกภาพต้นฉบับ เลือกการเรนเดอร์ ล้างเนื้อหาที่เลือก @@ -764,10 +757,9 @@ เพิ่มรูปภาพกลุ่ม %1$d แล้ว ขณะนี้ยังมีการเรนเดอร์อีก 1 ชุดที่ยังขาดอยู่ คุณสามารถเพิ่มกลุ่มรูปภาพต่อไปหรือเริ่มการวิเคราะห์ได้โดยตรง - เริ่มการวิเคราะห์ในพื้นที่ + เริ่มวิเคราะห์ กำลังวิเคราะห์สไตล์ภาพ... วิเคราะห์เสร็จแล้ว! - ดูตัวอย่างภาพต้นฉบับที่กู้คืนโดย AI ชื่อเริ่มต้นของ LUT สร้างและบันทึก กำลังสร้างข้อมูล 3D LUT... diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 4129232d..1db76b66 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -1036,19 +1036,12 @@ 深色 - AI 仿色 - 选择图片分析色彩风格,并生成专属 LUT。 - 需要会员 - 未在设置中配置自己的 OpenAI API Key 时,LUT 创建功能需要购买会员后才能使用。 - AI 分析 - 本地分析 - AI 会根据所选效果图生成文字版 LUT 配方。 - 自定义 AI 提示词(选填) - 例如:让画面更有氛围感,加深对比度 + 仿色 + 用原图和效果图配对,复刻色彩风格并生成专属 LUT。 + 原图 / 效果图配对 选择图片 - 上传一张效果图,AI 会直接推断文字版 LUT 配方,不再调用图片编辑能力。 - 上传多组图片,每组包含一张原图和一张效果图,且应尽量是完全相同的场景。 - 本地分析支持多组原图/效果图配对。构图、曝光和场景越一致,合并后的控制点越稳定。 + 添加一组或多组图片,每组包含同一场景的一张原图和一张调色后的效果图。 + 配对越多,构图和曝光越一致,生成的 LUT 越准确。 选择原图 选择效果图 清空已选内容 @@ -1059,10 +1052,9 @@ 已添加 %1$d 组图片 当前有 1 组还差效果图 可以继续添加图片组,或直接开始分析 - 开始本地分析 + 开始分析 正在分析图片风格… 分析完成! - AI 还原的原图预览 LUT 预设名称 生成并保存 正在生成 3D LUT 数据… @@ -1113,7 +1105,7 @@ 开启后,拍摄及导入照片将自动应用所选光圈值的虚化效果。 使用当前已安装的兼容深度模型。首次使用时可下载默认模型,或导入其他兼容的 TFLite 模型。 大光圈虚化 - 使用当前已安装的兼容深度模型估计画面深度,模拟大光圈的浅景深、背景虚化和柔和散景光斑。轻点画面可改变对焦位置;光圈值越小,虚化越强。首次使用时可下载默认模型,或导入其他兼容的 TFLite 模型。 + 模拟大光圈的浅景深背景虚化效果 光斑风格 虚化处理中… 降噪处理中… diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index ac39a195..e21cf4c0 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1015,19 +1015,12 @@ 深色 - AI 仿色 - 選擇圖片分析色彩風格,并生成專屬 LUT。 - 需要會員 - 未在設定中配置自己的 OpenAI API Key 時,LUT 創建功能需要購買會員后才能使用。 - AI 分析 - 本地分析 - AI 會根據所選效果圖生成文字版 LUT 配方。 - 自訂 AI 提示詞(選填) - 例如:讓畫面更有氛圍感,加深對比度 + 仿色 + 用原圖和效果圖配對,複刻色彩風格並生成專屬 LUT。 + 原圖 / 效果圖配對 選擇圖片 - 上傳一張效果圖,AI 會直接推斷文字版 LUT 配方,不再調用圖片編輯能力。 - 上傳多組圖片,每組包含一張原圖和一張效果圖,且應盡量是完全相同的場景。 - 本地分析支援多組原圖/效果圖配對。構圖、曝光和場景越一致,合并后的控制點越穩定。 + 添加一組或多組圖片,每組包含同一場景的一張原圖和一張調色後的效果圖。 + 配對越多,構圖和曝光越一致,生成的 LUT 越準確。 選擇原圖 選擇效果圖 清空已選內容 @@ -1038,10 +1031,9 @@ 已添加 %1$d 組圖片 當前有 1 組還差效果圖 可以繼續添加圖片組,或直接開始分析 - 開始本地分析 + 開始分析 正在分析圖片風格… 分析完成! - AI 還原的原圖預覽 LUT 預設名稱 生成并儲存 正在生成 3D LUT 資料… @@ -1092,7 +1084,7 @@ 開啟后,拍攝及匯入相片將自動應用所選光圈值的虛化效果。 使用目前已安裝的兼容深度模型。首次使用時可下載預設模型,或匯入其他兼容的 TFLite 模型。 大光圈虛化 - 使用目前已安裝的兼容深度模型估計畫面深度,模擬大光圈的淺景深、背景虛化和柔和散景光斑。輕點畫面可改變對焦位置;光圈值越小,虛化越強。首次使用時可下載預設模型,或匯入其他兼容的 TFLite 模型。 + 模擬大光圈的淺景深背景虛化效果 編輯面板 展開編輯面板 最小化編輯面板 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 764f2f09..7717231b 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1015,19 +1015,12 @@ 深色 - AI 仿色 - 選擇圖片分析色彩風格,并生成專屬 LUT。 - 需要會員 - 未在設定中配置自己的 OpenAI API Key 時,LUT 創建功能需要購買會員后才能使用。 - AI 分析 - 本地分析 - AI 會根據所選效果圖生成文字版 LUT 配方。 - 自訂 AI 提示詞(選填) - 例如:讓畫面更有氛圍感,加深對比度 + 仿色 + 用原圖和效果圖配對,複刻色彩風格並生成專屬 LUT。 + 原圖 / 效果圖配對 選擇圖片 - 上傳一張效果圖,AI 會直接推斷文字版 LUT 配方,不再調用圖片編輯能力。 - 上傳多組圖片,每組包含一張原圖和一張效果圖,且應盡量是完全相同的場景。 - 本地分析支援多組原圖/效果圖配對。構圖、曝光和場景越一致,合并后的控制點越穩定。 + 添加一組或多組圖片,每組包含同一場景的一張原圖和一張調色後的效果圖。 + 配對越多,構圖和曝光越一致,生成的 LUT 越準確。 選擇原圖 選擇效果圖 清空已選內容 @@ -1038,10 +1031,9 @@ 已添加 %1$d 組圖片 當前有 1 組還差效果圖 可以繼續添加圖片組,或直接開始分析 - 開始本地分析 + 開始分析 正在分析圖片風格… 分析完成! - AI 還原的原圖預覽 LUT 預設名稱 生成并儲存 正在生成 3D LUT 資料… @@ -1092,7 +1084,7 @@ 開啟后,拍攝及匯入相片將自動應用所選光圈值的虛化效果。 使用目前已安裝的相容深度模型。首次使用時可下載預設模型,或匯入其他相容的 TFLite 模型。 大光圈虛化 - 使用目前已安裝的相容深度模型估計畫面深度,模擬大光圈的淺景深、背景虛化和柔和散景光斑。輕點畫面可改變對焦位置;光圈值越小,虛化越強。首次使用時可下載預設模型,或匯入其他相容的 TFLite 模型。 + 模擬大光圈的淺景深背景虛化效果 光斑風格 虛化處理中… 降噪處理中… diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1c45f690..2e87c7ea 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1049,18 +1049,11 @@ LUT Creator - Select images to analyze style and generate a custom LUT. - Premium required - LUT Creator requires Premium unless you have configured your own OpenAI API key in Settings. - AI Analysis - Local Analysis - AI will generate a text LUT recipe from the selected styled image. - Custom AI Instructions (Optional) - e.g., make it moodier, enhance reds + Pair originals with styled images to recreate a color style as a custom LUT. + Original / Styled Pairs Select Images - Upload one styled image. AI will infer a text LUT recipe directly, without using image editing. - Upload multiple image pairs. Each pair should include an original image and a styled image of the same scene. - For local analysis, add multiple original/styled pairs. The closer the framing and exposure match, the better the merged control points will be. + Add one or more image pairs. Each pair is an original and a color-graded version of the same scene. + More pairs with closely matching framing and exposure give a more accurate LUT. Select Original Image Select Styled Image Clear Selection @@ -1071,10 +1064,9 @@ %1$d image pair(s) added 1 pair is still waiting for its styled image You can add more pairs or start analysis now - Analyze Local Pairs + Start Analysis Analyzing image style... Analysis Complete! - AI restored original preview LUT Name Generate & Save Generating 3D Interpolated LUT... @@ -1125,7 +1117,7 @@ Automatically enable virtual aperture with the selected f-stop value for new photos. Uses the installed compatible depth model. Download the default model or import another compatible TFLite model on first use. Wide-Aperture Blur - Uses the installed compatible depth model to estimate scene depth and simulate a shallow depth of field, background blur, and soft bokeh highlights. Tap the image to change the focus point. Lower f-numbers produce stronger blur. Download the default model or import another compatible TFLite model on first use. + Simulates the shallow depth of field and background blur of a wide aperture Bokeh style Applying bokeh… Applying noise reduction…