Skip to content

Add offline App Bokeh for people and objects - #339

Merged
TTolsun merged 4 commits into
mainfrom
codex/app-bokeh
Oct 24, 2026
Merged

TTolsun merged 4 commits into
mainfrom
codex/app-bokeh

Conversation

@TTolsun

@TTolsun TTolsun commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

제조사 Bokeh나 센서 Depth를 제공하지 않는 기기에서도 일반 JPEG 한 장으로 사물과 인물의 상대 깊이를 추정해 배경 흐림을 적용할 수 있도록 LIVE → Depth → App Bokeh를 추가합니다.

Camera2 Preview+JPEG만 구성하며 분석 YUV·DEPTH16·제조사 확장 세션은 사용하지 않습니다. 촬영 원본을 저장한 뒤 MiDaS v2.1과 LiteRT CPU로 깊이를 추정하고, 편집기에서 피사체 지점·강도·원본/깊이/결과 비교를 제공합니다. 복사본 JPEG, 깊이 PNG, 메타데이터를 저장하며 원본은 보존합니다. 모델은 공식 릴리스의 SHA-256을 확인해 APK에 포함하고 MIT 라이선스를 함께 배포합니다.

검증

  • 앱 및 검사 APK 빌드, JVM 테스트 916개, Android lint 통과.
  • SM-S936N / Android 16(API 36): 실제 마우스 장면의 동일 원본으로 강도 0·50·80·100 비교. 가까운 사물·책상 보존과 먼 배경의 추가 흐림 확인, 강도 0 픽셀 동일성 및 저장 결과 재디코딩 통과.
  • 서비스 덤프에서 PRIVATE Preview 1280×720 + BLOB JPEG 1920×1080 확인. 로드·방향 보정·축소·깊이 추론은 관찰 시 332–541 ms.
  • UI 저장, 원본/깊이 비교, 기준면 선택, Home 복귀, 일반 Photo 및 카메라 변경 확인. 리뷰에서 카메라 전환 시 App Bokeh 상태가 남는 문제와 Original 버튼 줄바꿈을 수정.
  • 문서 코드 대조 리뷰 후 최신성 기록 갱신, docflow check --build, docflow check --ci, 문서 회귀 검사 37개 통과.

실기기 기록: docs/validation/app-bokeh.md. 스트림·모델·저장 계약: docs/design/APP-BOKEH.md.

제약

현재는 촬영 후 편집이며 실시간 효과가 아닙니다. 출력 긴 변은 최대 1600픽셀, 깊이는 256×256 상대 역깊이입니다. 책상 뒤쪽 경계 등에는 흐림 번짐이 남아 있으며 모든 피사체·기기에서 품질을 보장하지 않습니다. 이번 새 장면의 품질 검증은 후면 사물 한 장입니다. 첫 빌드에는 약 66 MB 모델 다운로드가 필요하고 실행은 오프라인입니다.

검증 사진과 화면 캡처는 사용자와 합의한 로컬 전용 자료여서 PR에 첨부하지 않았습니다. 제조사 Portrait와 센서 Depth 메뉴는 유지합니다.

Summary by Sourcery

Add an offline App Bokeh workflow that captures a standard JPEG, estimates relative depth on-device, and lets users apply and save adjustable background blur without modifying the original.

New Features:

  • Add an offline App Bokeh capture and editing flow that estimates relative depth from standard JPEG photos and applies adjustable background blur to people and objects.
  • Save the original photo alongside the generated Bokeh JPEG, depth PNG, and processing metadata.

Bug Fixes:

  • Clear App Bokeh state when changing cameras or leaving the mode, and preserve editor behavior across activity interruptions.

Enhancements:

  • Add an on-device MiDaS v2.1 LiteRT CPU pipeline with verified model packaging and MIT license attribution.
  • Provide accessible Bokeh, Original, and Depth comparisons with subject selection, blur-strength control, and consistent Live/Gallery styling.

Build:

  • Package the verified MiDaS model as an application asset and add the LiteRT runtime dependency.

Documentation:

  • Document the App Bokeh workflow, processing contract, limitations, architecture, and device validation results.

Tests:

  • Add unit, instrumentation, UI, and real-device validation coverage for depth processing, blur rendering, artifact saving, and editor interactions.

Chores:

  • Update architecture and documentation evidence metadata for the new camera flow.

UI/UX 리뷰 후 보완

Live 선택창의 제목·닫기 아이콘·흰색 선택 표시와 Gallery의 저장 버튼 스타일을 재사용했습니다. Bokeh/Original/Depth의 선택 상태를 시각·접근성 정보로 표시하고, 강도 변경 시 Bokeh 결과로 돌아갑니다. 저장 버튼은 Save Bokeh로 명확히 했으며 슬라이더 터치 높이를 48dp로 확보했습니다. 큰 글씨에서 잘리던 Original 버튼은 기존 앱에서 사용하는 자동 글자 크기 조절 방식으로 수정했습니다.

SM-S936N에서 기존 사진을 재사용한 UI 검사와 115%·200% 글꼴 화면 확인을 통과했습니다. 기기 글꼴 배율은 원래 값으로 복원했습니다. 수정 APK 빌드·lint, 문서 회귀 검사 37개와 문서 최신성/산출물 검사를 다시 통과했습니다.

@sourcery-ai

sourcery-ai Bot commented Oct 24, 2026

Copy link
Copy Markdown

Sorry @TTolsun, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 6 days and 12 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

일반 Camera2 JPEG 한 장을 보존한 채 MiDaS v2.1/LiteRT CPU로 상대 깊이를 추정하고, 사용자가 선택한 피사체를 기준으로 오프라인 배경 흐림을 편집·저장하는 App Bokeh 경로를 추가했으며 UI 상태 전이, 모델 무결성, 테스트와 아키텍처·사용자 문서를 함께 갱신했습니다.

Sequence diagram for offline App Bokeh capture and editing

sequenceDiagram
    actor User
    participant MainActivity
    participant Camera2
    participant AppBokehEditor
    participant AppBokehProcessor
    participant MiDaS
    participant MediaLibrary

    User->>MainActivity: chooseAppBokeh()
    MainActivity->>Camera2: configure Preview + JPEG
    User->>MainActivity: captureAppBokeh()
    MainActivity->>Camera2: capturePhoto()
    Camera2-->>MainActivity: JPEG URI
    MainActivity->>MediaLibrary: save original JPEG
    MainActivity->>AppBokehEditor: openAppBokehEditor(uri)
    AppBokehEditor->>AppBokehProcessor: load(uri)
    AppBokehProcessor->>MiDaS: infer RGB image
    MiDaS-->>AppBokehProcessor: 256x256 relative depth
    AppBokehProcessor-->>AppBokehEditor: Scene
    User->>AppBokehEditor: select focus and strength
    AppBokehEditor->>AppBokehProcessor: render(scene, focusX, focusY, strength)
    AppBokehProcessor-->>AppBokehEditor: bokeh bitmap
    User->>AppBokehEditor: saveCopy()
    AppBokehEditor->>AppBokehProcessor: save(scene, result, source, focusX, focusY, strength)
    AppBokehProcessor->>MediaLibrary: save JPEG, depth PNG, metadata
Loading

Entity relationship diagram for App Bokeh output artifacts

erDiagram
    ORIGINAL_JPEG ||--o{ BOKEH_JPEG : produces
    ORIGINAL_JPEG ||--o| DEPTH_PNG : derives
    ORIGINAL_JPEG ||--o| PROCESS_METADATA : describes
    ORIGINAL_JPEG {
        string uri
    }
    BOKEH_JPEG {
        string uri
        int width
        int height
    }
    DEPTH_PNG {
        string uri
        int width
        int height
    }
    PROCESS_METADATA {
        string model
        string modelSha256
        float focusX
        float focusY
        int strength
    }
Loading

File-Level Changes

Change Details Files
일반 Camera2 Preview+JPEG 촬영을 App Bokeh 편집 흐름에 연결했다.
  • Depth 메뉴에 App Bokeh 모드를 추가하고 모드 전환·카메라 변경·Activity 재생성 상태를 관리
  • 촬영 후 원본 JPEG URI를 편집기로 전달하고 캡처·편집 중 중복 작업과 외부 전환을 차단
  • 원본 저장 실패와 편집기 수명주기, 오래된 worker 결과를 안전하게 처리
app/src/main/java/dev/halcamera/MainActivity.kt
app/src/main/java/dev/halcamera/MainAppBokehBridge.kt
app/src/main/java/dev/halcamera/MainDepthBridge.kt
app/src/main/java/dev/halcamera/MainCameraPicker.kt
app/src/main/java/dev/halcamera/MainCliBridge.kt
app/src/main/java/dev/halcamera/ui/AppBokehEditor.kt
MiDaS v2.1과 CPU LiteRT를 이용한 오프라인 상대 깊이 추정 및 배경 흐림 처리를 구현했다.
  • EXIF 방향 보정과 최대 1600픽셀 축소 후 RGB JPEG를 256×256 모델 입력으로 변환
  • 상대 역깊이를 정규화하고 선택 지점 주변 깊이를 기준으로 배경 가중치와 분리형 blur를 계산
  • 강도 0 identity, 전경 보존, 평탄하거나 잘못된 모델 출력 거부를 순수 Kotlin 로직과 테스트로 검증
app/src/main/java/dev/halcamera/camera/AppBokehProcessor.kt
app/src/main/java/dev/halcamera/camera/RelativeDepth.kt
app/src/test/java/dev/halcamera/camera/DepthBokehTest.kt
편집 결과와 모델 산출물을 원본과 분리해 저장하고 모델 공급망을 검증했다.
  • Bokeh JPEG, 256×256 깊이 PNG, 원본 URI·선택 위치·강도·모델 해시를 포함한 메타데이터를 transaction으로 저장
  • 빌드 시 공식 MiDaS 모델을 다운로드하고 SHA-256 검증 후 APK assets에 포함
  • MiDaS MIT 라이선스와 저장·처리 계약을 문서화
app/build.gradle.kts
app/src/main/assets/licenses/MiDaS.txt
docs/design/APP-BOKEH.md
docs/validation/app-bokeh.md
App Bokeh의 카메라 계약, 상태 전이, 사용 방법 및 검증 근거를 아키텍처 문서에 반영했다.
  • Preview+JPEG만 사용하고 분석 YUV·DEPTH16·제조사 확장 세션을 사용하지 않는 흐름을 기록
  • Live 가이드와 엔진 비교 문서에 촬영 후 편집·저장 제약을 추가
  • 구조 원본, evidence binding, 생성 문서 및 회귀 기대치를 갱신
.omm/data-flow/description.md
.omm/overall-architecture/camera-engines/app-bokeh/description.md
.omm/overall-architecture/camera-engines/meta.yaml
.omm/overall-architecture/camera-engines/description.md
.omm/state-transitions/description.md
.omm/state-transitions/engine-lifecycle/description.md
.omm/state-transitions/engine-lifecycle/portrait-lifecycle/description.md
.omm/ui-tool-handoff/description.md
docs/architecture.html
docs/live.html
guide/_bindings.yaml
guide/_content/_reference/engine/camera2.md
guide/_content/_reference/engine/comparison.md
guide/_content/_reference/engine/contract.md
guide/_content/architecture/constraints.md
guide/_content/architecture/module-roles.md
guide/_content/architecture/overview.md
guide/_content/architecture/runtime-flow.md
guide/_reference/engine.md
guide/architecture.md
guide/live.md
guide/_reference/evidence.md
guide/_reference/troubleshooting.md
tools/docgen/regression.test.mjs
tools/docgen/state/evidence.json
검사 APK에서 실제 JPEG를 처리하는 기기 검증 경로를 추가했다.
  • CLI instrumentation 인자로 소스 이미지와 초점 좌표를 받아 추론·렌더·저장 검사를 실행
  • 출력 크기, 깊이 크기, 강도 0 동일성, 산출물 재디코딩과 저장 개수를 확인
app/src/androidTest/java/dev/halcamera/camera/AppBokehChecks.kt
app/src/androidTest/java/dev/halcamera/cli/CliStoreInstrumentation.kt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@TTolsun
TTolsun merged commit 2157ebe into main Oct 24, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant