Android
AuraScore 79/100

Android CameraX to Diffusion Realtime Generation Engine

Build a zero-copy CameraX to on-device diffusion pipeline script for realtime multimodal Android generation.

Use this template when implementing high-performance camera frame capture and on-device diffusion inference in an Android app. It bridges CameraX buffers directly into native neural processing delegates.

Template

Role: Principal Android Graphics & Computer Vision Engineer

Context

  • Target Android package identifier: {{app_package_name}}
  • Hardware acceleration backend target: {{target_npu_backend}}
  • Embedded generative model artifact: {{diffusion_model_version}}
  • CameraX image stream resolution preset: {{frame_resolution_preset}}
  • Diffusion generation inference step budget: {{sampling_step_count}}
  • Real-time conditioning modality configuration: {{multimodal_conditioning_mode}}

Task

Write an end-to-end Kotlin and NDK integration script that captures image frames from CameraX, performs zero-copy hardware buffer transformations, constructs multimodal conditioning tensors, and executes on-device image synthesis pipeline without dropping frames.

Method

  1. Initialize the CameraX ImageAnalysis stream binding configured with {{frame_resolution_preset}} and YUV_420_888 output format.
  2. Establish an AHardwareBuffer bridge to route raw frame buffers directly to native C++ code without JVM memory copies.
  3. Convert color planes to RGB floating-point tensors utilizing Vulkan compute shaders or NDK hardware accelerators.
  4. Normalize and pack tensor buffers according to the input specifications of {{diffusion_model_version}}.
  5. Bind the target acceleration context using {{target_npu_backend}} via Android NNAPI or Qualcomm QNN runtime delegates.
  6. Inject multimodal context embeddings matching {{multimodal_conditioning_mode}} into the visual conditioning cross-attention layers.
  7. Execute the iterative diffusion loop capped strictly at {{sampling_step_count}} steps on a dedicated background coroutine dispatcher.
  8. Stream intermediate latent decodes to a SurfaceView using Android HardwareRenderer for progressive UI visualization.

Constraints

  • The solution MUST implement zero-copy memory transfers via AHardwareBuffer or GraphicBuffer between camera capture and inference.
  • The code MUST NOT block the Android Main UI thread during tensor quantization, compilation, or inference execution.
  • Handle thermal throttling state callbacks and adapt sampling steps dynamically when device temperatures elevate.
  • Include explicit memory reclamation logic for intermediate native buffers to avoid OOM crashes on memory-constrained devices.

Output format

Provide a production-ready Kotlin source file with companion C++ NDK bindings, structured in three parts:

  1. Architecture & Threading Plan (2-3 paragraphs)
  2. Kotlin Pipeline Controller (CameraDiffusionEngine.kt)
  3. Native JNI Bridge (native_tensor_bridge.cpp)

Self-review

  • Does the CameraX pipeline eliminate unnecessary Bitmap allocations?
  • Are all {{target_npu_backend}} delegate initializations properly guarded by runtime availability checks?
  • Is memory freed deterministically in native JNI methods?
AuraScore breakdown
79/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering10/12 · Adequate

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency5/10 · Thin

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness3/5 · Adequate

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

developers
developers-android
image-multimodal-prompting
android
camerax
diffusion