This document details the architecture of the RawPipeline iOS application, designed to capture unadulterated RAW (Bayer) data directly from the camera sensor, bypassing Apple's standard Image Signal Processor (ISP) pipeline (Deep Fusion, Smart HDR, etc.).
The application follows a MVVM (Model-View-ViewModel) pattern:
-
View (
ContentView.swift):- A SwiftUI interface that displays the camera preview, lens controls, and status indicators.
- Directly observes
CameraManagerfor state updates (e.g.,isProcessing,sensorResolution). - Handles user interactions and permissions.
-
ViewModel / Manager (
CameraManager.swift):- The core engine responsible for
AVCaptureSessionmanagement. - Handles device discovery, format negotiation, and photo capture.
- Executes heavy camera operations on a dedicated serial background queue (
com.rawpipeline.session) to keep the UI responsive. - Publishes state changes to the main thread via
@MainActor.
- The core engine responsible for
The primary goal of this application is to retrieve raw sensor data without the computational photography enhancements applied by the Apple ISP (Image Signal Processor).
The CameraManager achieves this through a specific format selection strategy in configureHighestResFormat(for:):
- Format Iteration: The app iterates through all available
AVCaptureDevice.Formats supported by the hardware. - Resolution Priority: formats are sorted by their maximum photo dimensions to ensure the highest fidelity capture.
- Raw Format Selection (The Bypass):
- For each format, the app checks
photoOutput.availableRawPhotoPixelFormatTypes. - Priority 1 (Pure Bayer): It explicitly searches for a pixel format type that is NOT recognized as Apple ProRAW.
- Standard Apple ProRAW formats are processed linear DNGs (
kCVPixelFormatType_420YpCbCr8BiPlanarFullRangewrapped). - By selecting formats like
kCVPixelFormatType_14Bayer_RGGB(or similar Bayer patterns), we force the system to return the raw data straight from the sensor's analog-to-digital converter, before demosaicing or multi-frame fusion occurs.
- Standard Apple ProRAW formats are processed linear DNGs (
- Priority 2 (Fallback): If no pure Bayer format is available (rare on modern devices for the main sensor, but possible on secondary lenses), it falls back to ProRAW.
- For each format, the app checks
// From CameraManager.swift
if let rawType = tryConfigureFormat(device: device, format: format, photoOutput: photoOutput, enableProRAW: false) {
// Found a Non-ProRAW (Pure Bayer) format
selectedFormat = format
bestRawType = rawType
usesProRAW = false
// ...
}By setting isAppleProRAWEnabled = false and selecting a non-ProRAW pixel format, we effectively disable the computational pipeline.
- Capture Request: User taps the shutter button.
- Configuration:
AVCapturePhotoSettingsis configured with the pre-determinedrawPixelFormatType(e.g.,kCVPixelFormatType_14Bayer_RGGB). - Sensor Readout: The sensor captures the image. The ISP performs minimal processing (black level subtraction, defective pixel correction) but skips multi-exposure blending.
- Data Delivery: The
AVCapturePhotoOutputdelegate receives aAVCapturePhotoobject. - DNG Extraction:
photo.fileDataRepresentation()is called to generate a standard DNG file containing the raw sensor data and metadata. - Direct File Storage:
- The DNG data is written directly to the app's
Documents/CapturedRAWsdirectory. - This bypasses the system
PHPhotoLibrary, giving the user direct file access via the iOS Files app or iTunes File Sharing.
- The DNG data is written directly to the app's
- Session Queue: A dedicated serial queue protects the
AVCaptureSessionfrom thread safety issues and UI blocking. - Lens Switching: Dynamically reconfigures inputs between Ultra Wide (
.builtInUltraWideCamera), Wide (.builtInWideAngleCamera), and Telephoto (.builtInTelephotoCamera). - Error Handling: internal errors are propagated to the UI via the
errorMessagepublished property.
- Preview: Uses
CameraPreviewView(aUIViewRepresentablewrappingAVCaptureVideoPreviewLayer) to render the live feed. - Feedback: Provides haptic feedback and visual flash animation during capture.