crabcamera 0.4.0

Advanced cross-platform camera integration for Tauri applications
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# πŸ¦€ CrabCamera: The Desktop Camera Plugin for Tauri πŸ“·

```
     __________________________
    < Hello fellow Rustaceans! >
     --------------------------
            \
             \
                _~^~^~_
            \) /  o o  \ (/
              '_   -   _'
              / '-----' \
```

[![Crates.io](https://img.shields.io/crates/v/crabcamera.svg)](https://crates.io/crates/crabcamera)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Rust](https://img.shields.io/badge/rust-stable-brightgreen.svg)](https://rustup.rs/)
[![Sponsor](https://img.shields.io/badge/❀️-Sponsor-ea4aaa?logo=github)](https://github.com/sponsors/Michael-A-Kuykendall)

**πŸ¦€ CrabCamera will be free forever. πŸ¦€** No asterisks. No "free for now." No pivot to paid.

## πŸ¦€ What is CrabCamera?

πŸ¦€ CrabCamera is the **first production-ready desktop camera plugin** for Tauri applications. It provides unified camera access across Windows, macOS, and Linux with professional controls and zero-config setup. It's designed to be the **invisible infrastructure** that makes desktop camera apps just work.

| Feature | CrabCamera | Web APIs | Other Plugins |
|---------|------------|----------|---------------|
| **Desktop Native** | Windows/macOS/Linux πŸ† | Limited browser | Mobile-only |
| **Hardware Access** | Direct camera control πŸ† | Browser restricted | Basic access |
| **Professional Controls** | Auto-focus, exposure πŸ† | Limited | Basic |
| **Cross-Platform** | Unified API πŸ† | Platform dependent | Single platform |
| **Production Ready** | 63 comprehensive tests πŸ† | No guarantees | Proof-of-concept |
| **Memory Safety** | Zero unsafe code πŸ† | N/A | Manual management |

## 🎯 Perfect for Desktop Applications πŸ¦€

- **Photography**: Photo booth apps, image editors, content creation tools
- **Security**: Surveillance systems, access control, monitoring dashboards  
- **Medical**: Imaging interfaces, patient documentation, diagnostic tools
- **Industrial**: Quality control, inspection systems, documentation cameras
- **Education**: Interactive learning tools, virtual labs, presentation software
- **Communication**: Video chat apps, streaming tools, conference software

**BONUS:** Professional camera controls with platform-optimized settings for maximum image quality.

## πŸ¦€ Quick Start (30 seconds) πŸ“·

### Installation

```toml
[dependencies]
crabcamera = "0.3.0"
tauri = { version = "2.0", features = ["protocol-asset"] }
```

### Tauri Integration

```rust
// src-tauri/src/main.rs
use crabcamera;

fn main() {
    tauri::Builder::default()
        .plugin(crabcamera::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
```

```json
// tauri.conf.json
{
  "plugins": {
    "crabcamera": {}
  }
}
```

### Frontend Usage

```javascript
import { invoke } from '@tauri-apps/api/tauri';

// Initialize camera system
await invoke('initialize_camera_system');

// Get available cameras
const cameras = await invoke('get_available_cameras');
console.log('Available cameras:', cameras);

// Get recommended format for high quality
const format = await invoke('get_recommended_format');

// Capture a photo
const photo = await invoke('capture_single_photo', {
  deviceId: cameras[0].id,
  format: format
});
```

## πŸ“¦ Professional Camera Features πŸ¦€

### πŸ”§ Hardware Control πŸ¦€
- **Device Enumeration**: Automatic discovery of all connected cameras
- **Format Negotiation**: Resolution, FPS, and color format selection
- **Professional Settings**: Auto-focus, auto-exposure, white balance
- **Multi-camera Support**: Switch between multiple cameras seamlessly
- **Error Recovery**: Robust handling of device disconnection and errors

### πŸ–₯️ Cross-Platform Native πŸ¦€
- **Windows**: DirectShow/MediaFoundation with advanced camera controls
- **macOS**: AVFoundation with Metal acceleration support
- **Linux**: V4L2 with comprehensive device support
- **Unified API**: Same code works across all platforms
- **Professional Controls**: Focus, exposure, white balance on all platforms

### ⚑ Performance & Memory πŸ¦€
- **Zero-Copy Operations**: Minimal memory allocations where possible
- **Async/Await**: Non-blocking operations throughout
- **Resource Management**: Automatic cleanup and device release
- **Memory Safety**: Built with Rust's memory safety guarantees
- **Thread Safety**: Concurrent access with proper synchronization

## πŸ”§ Available Commands πŸ¦€

### Initialization & Discovery
```rust
// Initialize the camera system
initialize_camera_system() -> Result<String>

// Get all available cameras with capabilities
get_available_cameras() -> Result<Vec<CameraDeviceInfo>>

// Get platform-specific information
get_platform_info() -> Result<PlatformInfo>

// Test camera system functionality
test_camera_system() -> Result<SystemTestResult>
```

### Camera Operations
```rust
// Check if specific camera is available
check_camera_availability(device_id: String) -> Result<bool>

// Get supported formats for a camera
get_camera_formats(device_id: String) -> Result<Vec<CameraFormat>>

// Get recommended settings for quality photography
get_recommended_format() -> Result<CameraFormat>
get_optimal_settings() -> Result<CameraInitParams>
```

### Capture & Streaming
```rust
// Single photo capture
capture_single_photo(device_id: String, format: CameraFormat) -> Result<CameraFrame>

// Photo sequence for burst mode
capture_photo_sequence(params: SequenceParams) -> Result<Vec<CameraFrame>>

// Real-time streaming
start_camera_preview(device_id: String) -> Result<()>
stop_camera_preview() -> Result<()>

// Save frames to disk
save_frame_to_disk(frame: CameraFrame, path: String) -> Result<()>
```

### Professional Camera Controls (NEW in v0.3.0!)
```rust
// Apply camera controls (focus, exposure, white balance, etc.)
apply_camera_controls(device_id: String, controls: CameraControls) -> Result<()>

// Get current camera control values
get_camera_controls(device_id: String) -> Result<CameraControls>

// Test what controls are supported by camera
test_camera_capabilities(device_id: String) -> Result<CameraCapabilities>

// Get performance metrics
get_camera_performance(device_id: String) -> Result<CameraPerformanceMetrics>
```

### Permissions & Security
```rust
// Handle camera permissions properly
request_camera_permission() -> Result<bool>
check_camera_permission_status() -> Result<PermissionStatus>
```

## πŸ¦€ Why CrabCamera Will Always Be Free πŸ“·

I built CrabCamera because desktop applications deserve native camera access without the limitations of web APIs or mobile-only plugins.

**This is my commitment**: CrabCamera stays MIT licensed, forever. If you want to support development, [sponsor it](https://github.com/sponsors/Michael-A-Kuykendall). If you don't, just build something incredible with it.

> πŸ¦€ CrabCamera saves developers weeks of cross-platform camera integration. If it's useful, consider sponsoring for $5/month β€” less than a coffee, infinitely more valuable than web API limitations. πŸ¦€

## πŸ“Š Performance Comparison πŸ¦€

| Metric | CrabCamera | Web APIs | Mobile Plugins |
|--------|------------|----------|----------------|
| **Desktop Support** | **Full native** | Browser dependent | None |
| **Camera Access** | **Direct hardware** | getUserMedia limited | N/A |
| **Image Quality** | **Professional controls** | Basic settings | Basic |
| **Cross-Platform** | **Windows/macOS/Linux** | Browser variation | iOS/Android only |
| **Performance** | **Native speed** | Browser overhead | N/A |
| **Reliability** | **63 tests passing** | No guarantees | Varies |

## πŸ—οΈ Technical Architecture πŸ¦€

### Hybrid Capture + Controls Architecture
```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   nokhwa        β”‚    β”‚ Platform Controlsβ”‚    β”‚  CrabCamera     β”‚
β”‚   (Capture)     β”‚    β”‚ (Advanced)       β”‚    β”‚  (Unified API)  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ Frame capture β”‚    β”‚ β€’ Focus control  β”‚    β”‚ β€’ Generic types β”‚
β”‚ β€’ Resolution    β”‚    β”‚ β€’ Exposure       β”‚    β”‚ β€’ Error handlingβ”‚
β”‚ β€’ Format        β”‚    β”‚ β€’ White balance  β”‚    β”‚ β€’ Cross-platformβ”‚
β”‚ β€’ Start/Stop    β”‚    β”‚ β€’ Brightness     β”‚    β”‚ β€’ Thread safety β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Platform-Specific Implementations
- **Windows**: nokhwa capture + MediaFoundation controls (NEW in v0.3.0!)
- **macOS**: AVFoundation for both capture and controls
- **Linux**: nokhwa capture + V4L2 controls
- **Unified API**: Same control interface across all platforms

### Key Technologies
- **Rust + Tokio**: Memory-safe, async performance
- **Tauri 2.0 Plugin**: Modern plugin architecture  
- **Platform Backends**: MediaFoundation, AVFoundation, V4L2
- **COM Interface Management**: Thread-safe Windows controls
- **Zero unsafe code**: Memory safety guaranteed (except platform COM interfaces)

## πŸ“š API Reference πŸ¦€

### Core Types
```rust
pub struct CameraDeviceInfo {
    pub id: String,
    pub name: String,
    pub description: String,
    pub is_available: bool,
    pub supports_formats: Vec<CameraFormat>,
}

pub struct CameraFormat {
    pub width: u32,
    pub height: u32,
    pub fps: f32,
    pub format_type: String, // "RGB8", "JPEG", etc.
}

pub struct CameraFrame {
    pub data: Vec<u8>,
    pub width: u32,
    pub height: u32,
    pub format: String,
    pub timestamp: DateTime<Utc>,
}

pub struct CameraControls {
    pub auto_focus: Option<bool>,
    pub focus_distance: Option<f32>,     // 0.0 = infinity, 1.0 = closest
    pub auto_exposure: Option<bool>,
    pub exposure_time: Option<f32>,      // seconds
    pub white_balance: Option<WhiteBalance>,
    pub brightness: Option<f32>,         // -1.0 to 1.0
    pub contrast: Option<f32>,           // -1.0 to 1.0
    pub saturation: Option<f32>,         // -1.0 to 1.0
}

pub struct CameraCapabilities {
    pub supports_auto_focus: bool,
    pub supports_manual_focus: bool,
    pub supports_auto_exposure: bool,
    pub supports_manual_exposure: bool,
    pub supports_white_balance: bool,
    pub focus_range: Option<(f32, f32)>,
    pub exposure_range: Option<(f32, f32)>,
}
```

### Platform Detection
```rust
pub enum Platform {
    Windows,
    MacOS,
    Linux,
    Unknown,
}

// Automatic platform detection
let platform = Platform::current();
```

## πŸ¦€ Community & Support πŸ“·

- **πŸ› Bug Reports**: [GitHub Issues]https://github.com/Michael-A-Kuykendall/crabcamera/issues
- **πŸ’¬ Discussions**: [GitHub Discussions]https://github.com/Michael-A-Kuykendall/crabcamera/discussions
- **πŸ“– Documentation**: [docs.rs/crabcamera]https://docs.rs/crabcamera
- **πŸ’ Sponsorship**: [GitHub Sponsors]https://github.com/sponsors/Michael-A-Kuykendall

### Sponsors

See our amazing [sponsors](SPONSORS.md) who make πŸ¦€ CrabCamera possible! πŸ™

**Sponsorship Tiers:**
- **$5/month**: Coffee tier - My eternal gratitude + sponsor badge
- **$25/month**: Developer supporter - Priority support + name in SPONSORS.md  
- **$100/month**: Corporate backer - Logo on README + monthly office hours
- **$500/month**: Enterprise partner - Direct support + feature requests

**Companies**: Need invoicing? Email [michaelallenkuykendall@gmail.com](mailto:michaelallenkuykendall@gmail.com)

## πŸš€ Production Usage πŸ¦€

**βœ… Ready for production:**
- Memory-safe Rust implementation
- 63 comprehensive tests passing
- Zero unsafe code
- Comprehensive error handling
- Async/await throughout
- Cross-platform compatibility verified

**βœ… Use cases in production:**
- Desktop photography applications
- Security and surveillance systems
- Medical imaging interfaces
- Industrial inspection tools
- Educational software platforms
- Communication and streaming apps

## πŸ’‘ Examples & Integration πŸ¦€

### Photo Booth Application
```javascript
// Simple photo booth with camera selection
const cameras = await invoke('get_available_cameras');
const selectedCamera = cameras[0];
const format = await invoke('get_recommended_format');

// Take photo when user clicks
document.getElementById('capture').onclick = async () => {
    const photo = await invoke('capture_single_photo', {
        deviceId: selectedCamera.id,
        format: format
    });
    // Display photo in UI
    displayPhoto(photo);
};
```

### Multi-Camera Security System
```javascript
// Monitor multiple cameras
const cameras = await invoke('get_available_cameras');
for (const camera of cameras) {
    await invoke('start_camera_preview', { deviceId: camera.id });
    // Set up streaming handlers for each camera
    setupCameraStream(camera);
}
```

## πŸ“œ License & Philosophy πŸ¦€

MIT License - forever and always.

**Philosophy**: Desktop applications deserve native camera access. πŸ¦€ CrabCamera is camera infrastructure. πŸ“·

## πŸš€ What's New in v0.3.0

### πŸŽ‰ **Major Feature: Windows MediaFoundation Camera Controls**
- **Professional Windows Controls**: Full focus, exposure, white balance, brightness, contrast, and saturation control
- **Hybrid Architecture**: nokhwa capture + MediaFoundation controls for best of both worlds
- **Thread-Safe COM**: Proper Windows COM interface management for Tauri async commands
- **Capability Detection**: Runtime testing of which controls each camera supports
- **Unified API**: Same control interface across Windows, macOS, and Linux

### πŸ”§ **Technical Improvements**
- **WindowsCamera Struct**: Combines nokhwa capture with MediaFoundation controls
- **MediaFoundationControls**: Full COM interface wrapper with resource management
- **Platform Integration**: Updated PlatformCamera enum to use Windows-specific implementation
- **Error Handling**: Graceful degradation when controls aren't supported
- **Documentation**: Comprehensive technical architecture documentation

### πŸ† **Cross-Platform Parity Achieved**
Windows users now get the same professional camera control experience as macOS and Linux users!

---

**Forever maintainer**: Michael A. Kuykendall  
**Promise**: This will never become a paid product  
**Mission**: Making desktop camera development effortless

*"πŸ¦€ Native performance. Cross-platform compatibility. Zero hassle. πŸ“·"*

```
       πŸ¦€πŸ¦€πŸ¦€ Happy Coding! πŸ¦€πŸ¦€πŸ¦€
          Made with ❀️ and Rust
           πŸ“· Capture the moment πŸ“·
```