Shutter Priority Mode: Building a Custom Camera Mode for Android

By Henil J. Chhipani · 2025-03-15 · 6 min read

How I designed and implemented a custom Shutter Priority Mode for the Oasis Camera App, enabling real-time ISO adjustments based on scene luminosity for underwater photography.

## The Challenge

When I joined PlayPower Labs to build the Oasis Camera App, one of the most exciting features I got to implement was a custom **Shutter Priority Mode**. This isn't something you find in typical camera apps — it's a feature that professional photographers rely on, and we needed it for research-grade underwater photography.

## What is Shutter Priority Mode?

In photography, Shutter Priority (often labeled 'S' or 'Tv') is a semi-automatic mode where:
- **You control** the shutter speed
- **The camera automatically adjusts** the ISO to maintain proper exposure

This is crucial for underwater photography where light conditions change rapidly as you move through different depths.

## Technical Implementation

### Using CameraX and Camera2Interop

Android's CameraX library provides a high-level API for camera operations, but for manual controls, we needed to drop down to Camera2Interop:

```kotlin
val camera2Interop = Camera2Interop.Extender(previewBuilder)
camera2Interop.setCaptureRequestOption(
CaptureRequest.CONTROL_AE_MODE,
CaptureRequest.CONTROL_AE_MODE_OFF
)
```

### Real-time ISO Calculation

The core algorithm monitors the scene's luminosity through the camera's metering data and calculates the optimal ISO value:

```kotlin
fun calculateOptimalISO(
shutterSpeed: Long,
targetExposure: Float,
currentLuminosity: Float
): Int {
val exposureDiff = targetExposure - currentLuminosity
val isoAdjustment = (exposureDiff * ISO_SENSITIVITY_FACTOR).toInt()
return (currentISO + isoAdjustment).coerceIn(minISO, maxISO)
}
```

### Smooth Transitions

One challenge was making ISO transitions smooth rather than jumpy. I implemented an exponential moving average to dampen rapid changes:

```kotlin
val smoothedISO = (SMOOTHING_FACTOR * newISO +
(1 - SMOOTHING_FACTOR) * previousISO).toInt()
```

## Results

The Shutter Priority Mode became one of the most-used features by the research team. Professional underwater researchers could now:
- Lock their desired shutter speed for motion control
- Let the app handle exposure automatically
- Focus on capturing the perfect shot

## Key Takeaways

1. **Camera2Interop** bridges the gap between CameraX's simplicity and Camera2's power
2. **Smoothing algorithms** are essential for real-time adjustments
3. **Domain expertise matters** — understanding photography principles made the implementation much better
4. Building for **professional users** requires attention to details that consumer apps skip

This project taught me that the best mobile apps aren't just about code — they're about understanding the domain deeply and translating that understanding into a great user experience.

Tags: Android, CameraX, Kotlin, Photography

Back to all posts