Implement 34_FIX_BG.md: restore high-quality AI background replacement and blur blending for captured photos in the background thread, while maintaining lag-free early bypass for viewfinder preview

This commit is contained in:
2026-07-06 21:53:29 +07:00
parent 2cf5a91557
commit 2de7fc4c0f
2 changed files with 196 additions and 3 deletions
@@ -1722,9 +1722,17 @@ class MainActivity : AppCompatActivity() {
capturedImage: android.graphics.Bitmap,
isStreamMode: Boolean = false
): android.graphics.Bitmap {
// Chỉ chạy các thuật toán xử lý phân đoạn AI hoặc mờ phần mềm khi bật chế độ AI_BLUR
if (currentBackgroundMode != BackgroundMode.AI_BLUR) {
return capturedImage
if (isStreamMode) {
// Khi xem trước (Viewfinder stream): chỉ chạy AI khi thực sự thay nền (AI_BLUR) để tránh lag
if (currentBackgroundMode != BackgroundMode.AI_BLUR) {
return capturedImage
}
} else {
// Khi chụp lưu ảnh (isStreamMode = false): chạy AI khi chèn hình nền HOẶC khi có xóa phông (blurIntensity > 0)
val isBgActive = (selectedBgAssetPath != null) || (blurIntensity > 0f)
if (!isBgActive) {
return capturedImage
}
}
if (!isAiSupported) {