From b5d7311447bdf5b79bc339b75c0788c91c89e9c2 Mon Sep 17 00:00:00 2001 From: 3dtours Date: Sun, 5 Jul 2026 18:20:46 +0700 Subject: [PATCH] Fix: Enable real-time ARGB color overlay preview updates by bypassing hardcoded colors in edit mode --- .../java/com/photobooth/app/MainActivity.kt | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/android-project/app/src/main/java/com/photobooth/app/MainActivity.kt b/android-project/app/src/main/java/com/photobooth/app/MainActivity.kt index 16f43bd..e75574d 100644 --- a/android-project/app/src/main/java/com/photobooth/app/MainActivity.kt +++ b/android-project/app/src/main/java/com/photobooth/app/MainActivity.kt @@ -219,28 +219,40 @@ class MainActivity : AppCompatActivity() { binding.imgFilterOverlay.visibility = android.view.View.GONE } else { binding.imgFilterOverlay.visibility = android.view.View.VISIBLE - val filterColor = when (preset.id) { - "instax_faded_warm_01" -> android.graphics.Color.argb(55, 255, 152, 0) - "instax_bw_cool" -> android.graphics.Color.argb(80, 128, 128, 128) - "instax_cool_summer" -> android.graphics.Color.argb(45, 0, 188, 212) - else -> { - // Sophisticated ARGB mapping to simulate film filters using adjustment parameters - // Vibrance and Saturation increase opacity of the filter color - val alpha = (((preset.basic.vibrance + preset.basic.saturation) / 2f + 1.0f) * 40 + 20).toInt().coerceIn(10, 120) - - // Temperature (+ is warm/red-yellow), Brightness, Clarity, and ShadowsTintR affect red - val tempWarmth = if (preset.basic.temperature > 0) preset.basic.temperature * 50f else 0f - val r = (((preset.advanced.clarity + preset.basic.brightness) / 2f + 1.0f) * 100 + 30 + tempWarmth + (preset.toneCurve.shadowsTintR * 30)).toInt().coerceIn(0, 255) - - // Contrast, Tint (- is green), and ShadowsTintG affect green - val tintGreen = if (preset.basic.tint < 0) -preset.basic.tint * 50f else 0f - val g = ((preset.basic.contrast + 1.0f) * 90 + 20 + tintGreen + (preset.toneCurve.shadowsTintG * 30)).toInt().coerceIn(0, 255) - - // Dehaze, cool Temperature (- is blue), and ShadowsTintB affect blue - val tempCoolness = if (preset.basic.temperature < 0) -preset.basic.temperature * 60f else 0f - val b = (((preset.advanced.dehaze + 1.0f) * 80) + 20 + tempCoolness + (preset.toneCurve.shadowsTintB * 30)).toInt().coerceIn(0, 255) - - android.graphics.Color.argb(alpha, r, g, b) + val isBeingEdited = editingPreset != null + val filterColor = if (isBeingEdited) { + // Sophisticated ARGB mapping to simulate film filters using adjustment parameters + // Vibrance and Saturation increase opacity of the filter color + val alpha = (((preset.basic.vibrance + preset.basic.saturation) / 2f + 1.0f) * 40 + 20).toInt().coerceIn(10, 120) + + // Temperature (+ is warm/red-yellow), Brightness, Clarity, and ShadowsTintR affect red + val tempWarmth = if (preset.basic.temperature > 0) preset.basic.temperature * 50f else 0f + val r = (((preset.advanced.clarity + preset.basic.brightness) / 2f + 1.0f) * 100 + 30 + tempWarmth + (preset.toneCurve.shadowsTintR * 30)).toInt().coerceIn(0, 255) + + // Contrast, Tint (- is green), and ShadowsTintG affect green + val tintGreen = if (preset.basic.tint < 0) -preset.basic.tint * 50f else 0f + val g = ((preset.basic.contrast + 1.0f) * 90 + 20 + tintGreen + (preset.toneCurve.shadowsTintG * 30)).toInt().coerceIn(0, 255) + + // Dehaze, cool Temperature (- is blue), and ShadowsTintB affect blue + val tempCoolness = if (preset.basic.temperature < 0) -preset.basic.temperature * 60f else 0f + val b = (((preset.advanced.dehaze + 1.0f) * 80) + 20 + tempCoolness + (preset.toneCurve.shadowsTintB * 30)).toInt().coerceIn(0, 255) + + android.graphics.Color.argb(alpha, r, g, b) + } else { + when (preset.id) { + "instax_faded_warm_01" -> android.graphics.Color.argb(55, 255, 152, 0) + "instax_bw_cool" -> android.graphics.Color.argb(80, 128, 128, 128) + "instax_cool_summer" -> android.graphics.Color.argb(45, 0, 188, 212) + else -> { + val alpha = (((preset.basic.vibrance + preset.basic.saturation) / 2f + 1.0f) * 40 + 20).toInt().coerceIn(10, 120) + val tempWarmth = if (preset.basic.temperature > 0) preset.basic.temperature * 50f else 0f + val r = (((preset.advanced.clarity + preset.basic.brightness) / 2f + 1.0f) * 100 + 30 + tempWarmth + (preset.toneCurve.shadowsTintR * 30)).toInt().coerceIn(0, 255) + val tintGreen = if (preset.basic.tint < 0) -preset.basic.tint * 50f else 0f + val g = ((preset.basic.contrast + 1.0f) * 90 + 20 + tintGreen + (preset.toneCurve.shadowsTintG * 30)).toInt().coerceIn(0, 255) + val tempCoolness = if (preset.basic.temperature < 0) -preset.basic.temperature * 60f else 0f + val b = (((preset.advanced.dehaze + 1.0f) * 80) + 20 + tempCoolness + (preset.toneCurve.shadowsTintB * 30)).toInt().coerceIn(0, 255) + android.graphics.Color.argb(alpha, r, g, b) + } } } binding.imgFilterOverlay.setBackgroundColor(filterColor) @@ -596,6 +608,7 @@ class MainActivity : AppCompatActivity() { .setDuration(200) .withEndAction { binding.cardAdvancedSliders.visibility = android.view.View.GONE + editingPreset = null currentSelectedPreset?.let { applyPresetFilter(it) } } .start()