Skip to content

Commit d97f4fb

Browse files
authored
Merge pull request #14 from darrylhodgins/exposure-opts
feat: add support for a number of exposure-related options
2 parents b0f9a82 + 80cadff commit d97f4fb

File tree

5 files changed

+187
-58
lines changed

5 files changed

+187
-58
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ Note that this example produces a raw H264 video. Wrapping it in a video contain
219219
- [`Flip`](#flip)
220220
- [`Codec`](#codec)
221221
- [`SensorMode`](#sensormode)
222+
- [`ExposureMode`](#exposuremode)
223+
- [`AwbMode`](#awbmode)
222224

223225
## `StillCamera`
224226
A class for taking still images. Equivalent to running the `raspistill` command.
@@ -239,6 +241,13 @@ const stillCamera = new StillCamera({
239241
- [`rotation: Rotation`](#rotation) - *Default: `Rotation.Rotate0`*
240242
- [`flip: Flip`](#flip) - *Default: `Flip.None`*
241243
- `delay: number` - *Default: 1 ms*
244+
- `shutter: number` - *Default: Auto calculated based on framerate (1000000µs/fps). Number is in microseconds*
245+
- `iso: number` - *Default: Auto*
246+
- `exposureCompensation: number` - *Default: `0`*
247+
- [`exposureMode: ExposureMode`](#exposuremode) - *Default: Auto*
248+
- [`awbMode: AwbMode`](#awbmode) - *Default: Auto*
249+
- `analogGain: number` - *Default: 0*
250+
- `digitalGain: number` - *Default: 0*
242251

243252
### `StillCamera.takeImage(): Promise<Buffer>`
244253

@@ -271,6 +280,13 @@ const streamCamera = new StreamCamera({
271280
- `fps: number` - *Default: 30 fps*
272281
- [`codec: Codec`](#codec) - *Default: `Codec.H264`*
273282
- [`sensorMode: SensorMode`](#sensormode) - *Default: `SensorMode.AutoSelect`*
283+
- `shutter: number` - *Default: Auto calculated based on framerate (1000000µs/fps). Number is in microseconds*
284+
- `iso: number` - *Default: Auto*
285+
- `exposureCompensation: number` - *Default: `0`*
286+
- [`exposureMode: ExposureMode`](#exposuremode) - *Default: Auto*
287+
- [`awbMode: AwbMode`](#awbmode) - *Default: Auto*
288+
- `analogGain: number` - *Default: 0*
289+
- `digitalGain: number` - *Default: 0*
274290

275291
### `startCapture(): Promise<void>`
276292
Begins the camera stream. Returns a `Promise` that is resolved when the capture has started.
@@ -345,6 +361,44 @@ Image flip options.
345361
import { Flip } from "pi-camera-connect";
346362
```
347363

364+
## `ExposureMode`
365+
Exposure mode options.
366+
- `ExposureMode.Off`
367+
- `ExposureMode.Auto`
368+
- `ExposureMode.Night`
369+
- `ExposureMode.NightPreview`
370+
- `ExposureMode.Backlight`
371+
- `ExposureMode.Spotlight`
372+
- `ExposureMode.Sports`
373+
- `ExposureMode.Snow`
374+
- `ExposureMode.Beach`
375+
- `ExposureMode.VeryLong`
376+
- `ExposureMode.FixedFps`
377+
- `ExposureMode.AntiShake`
378+
- `ExposureMode.Fireworks`
379+
380+
```javascript
381+
import { ExposureMode } from "pi-camera-connect";
382+
```
383+
384+
## `AwbMode`
385+
White balance mode options.
386+
- `AwbMode.Off`
387+
- `AwbMode.Auto`
388+
- `AwbMode.Sun`
389+
- `AwbMode.Cloud`
390+
- `AwbMode.Shade`
391+
- `AwbMode.Tungsten`
392+
- `AwbMode.Fluorescent`
393+
- `AwbMode.Incandescent`
394+
- `AwbMode.Flash`
395+
- `AwbMode.Horizon`
396+
- `AwbMode.GreyWorld`
397+
398+
```javascript
399+
import { AwbMode } from "pi-camera-connect";
400+
```
401+
348402
## `Codec`
349403
Stream codec options.
350404
- `Codec.H264`

src/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,33 @@ export enum Flip {
1414
Vertical = 'vertical',
1515
Both = 'both',
1616
}
17+
18+
export enum ExposureMode {
19+
Off = 'off',
20+
Auto = 'auto',
21+
Night = 'night',
22+
NightPreview = 'nightpreview',
23+
Backlight = 'backlight',
24+
Spotlight = 'spotlight',
25+
Sports = 'sports',
26+
Snow = 'snow',
27+
Beach = 'beach',
28+
VeryLong = 'verylong',
29+
FixedFps = 'fixedfps',
30+
AntiShake = 'antishake',
31+
Fireworks = 'fireworks'
32+
}
33+
34+
export enum AwbMode {
35+
Off = 'off',
36+
Auto = 'auto',
37+
Sun = 'sun',
38+
Cloud = 'cloud',
39+
Shade = 'shade',
40+
Tungsten = 'tungsten',
41+
Fluorescent = 'fluorescent',
42+
Incandescent = 'incandescent',
43+
Flash = 'flash',
44+
Horizon = 'horizon',
45+
GreyWorld = 'greyworld'
46+
}

src/lib/shared-args.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { StillOptions } from "./still-camera";
2+
import { StreamOptions } from "./stream-camera";
3+
import { Flip } from '..';
4+
5+
/**
6+
* Get the command line arguments for `raspistill` or `raspivid` that are common among both
7+
*
8+
* These are: `--width`, `--height`, `--rotation`, `--hflip`, `--vflip`, `--shutter`,
9+
* `--ISO`, `--exposure`, `--ev`, and `--awb`
10+
* @param options Camera options
11+
*/
12+
export function getSharedArgs(options: StillOptions | StreamOptions): string[] {
13+
return [
14+
15+
/**
16+
* Width
17+
*/
18+
...(options.width ? ['--width', options.width.toString()] : []),
19+
20+
/**
21+
* Height
22+
*/
23+
...(options.height ? ['--height', options.height.toString()] : []),
24+
25+
/**
26+
* Rotation
27+
*/
28+
...(options.rotation ? ['--rotation', options.rotation.toString()] : []),
29+
30+
/**
31+
* Horizontal flip
32+
*/
33+
...(options.flip &&
34+
(options.flip === Flip.Horizontal || options.flip === Flip.Both)
35+
? ['--hflip']
36+
: []),
37+
38+
/**
39+
* Vertical flip
40+
*/
41+
...(options.flip &&
42+
(options.flip === Flip.Vertical || options.flip === Flip.Both)
43+
? ['--vflip']
44+
: []),
45+
46+
/**
47+
* Shutter Speed
48+
*/
49+
...(options.shutter ? ["--shutter", options.shutter.toString()] : []),
50+
51+
/**
52+
* ISO
53+
*/
54+
...(options.iso ? ['--ISO', options.iso.toString()] : []),
55+
56+
/**
57+
* EV Compensation
58+
*/
59+
...(options.exposureCompensation ? ['--ev', options.exposureCompensation.toString()] : []),
60+
61+
/**
62+
* Exposure Mode
63+
*/
64+
...(options.exposureMode ? ['--exposure', options.exposureMode.toString()] : []),
65+
66+
/**
67+
* Auto White Balance Mode
68+
*/
69+
...(options.awbMode ? ['--awb', options.awbMode.toString()] : []),
70+
71+
/**
72+
* Analog Gain
73+
*/
74+
...(options.analogGain ? ['--analoggain', options.analogGain.toString()] : []),
75+
76+
/**
77+
* Digital Gain
78+
*/
79+
...(options.digitalGain ? ['--digitalgain', options.digitalGain.toString()] : [])
80+
];
81+
}

src/lib/still-camera.ts

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import * as si from 'systeminformation';
2-
import { Flip, Rotation } from '..';
2+
import { AwbMode, ExposureMode, Flip, Rotation } from '..';
33
import { spawnPromise } from '../util';
4+
import { getSharedArgs } from './shared-args';
45

56
export interface StillOptions {
67
width?: number;
78
height?: number;
89
rotation?: Rotation;
910
flip?: Flip;
1011
delay?: number;
12+
shutter?: number;
13+
iso?: number;
14+
exposureCompensation?: number;
15+
exposureMode?: ExposureMode;
16+
awbMode?: AwbMode;
17+
analogGain?: number;
18+
digitalGain?: number;
1119
}
1220

1321
export default class StillCamera {
@@ -42,35 +50,9 @@ export default class StillCamera {
4250
try {
4351
return await spawnPromise('raspistill', [
4452
/**
45-
* Width
53+
* Add the command-line arguments that are common to both `raspivid` and `raspistill`
4654
*/
47-
...(this.options.width ? ['--width', this.options.width.toString()] : []),
48-
49-
/**
50-
* Height
51-
*/
52-
...(this.options.height ? ['--height', this.options.height.toString()] : []),
53-
54-
/**
55-
* Rotation
56-
*/
57-
...(this.options.rotation ? ['--rotation', this.options.rotation.toString()] : []),
58-
59-
/**
60-
* Horizontal flip
61-
*/
62-
...(this.options.flip &&
63-
(this.options.flip === Flip.Horizontal || this.options.flip === Flip.Both)
64-
? ['--hflip']
65-
: []),
66-
67-
/**
68-
* Vertical flip
69-
*/
70-
...(this.options.flip &&
71-
(this.options.flip === Flip.Vertical || this.options.flip === Flip.Both)
72-
? ['--vflip']
73-
: []),
55+
...getSharedArgs(this.options),
7456

7557
/**
7658
* Capture delay (ms)

src/lib/stream-camera.ts

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
22
import { EventEmitter } from 'events';
33
import * as stream from 'stream';
44
import * as si from 'systeminformation';
5-
import { Flip, Rotation } from '..';
5+
import { AwbMode, ExposureMode, Flip, Rotation } from '..';
6+
import { getSharedArgs } from './shared-args';
67

78
export enum Codec {
89
H264 = 'H264',
@@ -29,6 +30,13 @@ export interface StreamOptions {
2930
fps?: number;
3031
codec?: Codec;
3132
sensorMode?: SensorMode;
33+
shutter?: number;
34+
iso?: number;
35+
exposureCompensation?: number;
36+
exposureMode?: ExposureMode;
37+
awbMode?: AwbMode;
38+
analogGain?: number;
39+
digitalGain?: number;
3240
}
3341

3442
declare interface StreamCamera {
@@ -79,35 +87,9 @@ class StreamCamera extends EventEmitter {
7987
try {
8088
const args: Array<string> = [
8189
/**
82-
* Width
90+
* Add the command-line arguments that are common to both `raspivid` and `raspistill`
8391
*/
84-
...(this.options.width ? ['--width', this.options.width.toString()] : []),
85-
86-
/**
87-
* Height
88-
*/
89-
...(this.options.height ? ['--height', this.options.height.toString()] : []),
90-
91-
/**
92-
* Rotation
93-
*/
94-
...(this.options.rotation ? ['--rotation', this.options.rotation.toString()] : []),
95-
96-
/**
97-
* Horizontal flip
98-
*/
99-
...(this.options.flip &&
100-
(this.options.flip === Flip.Horizontal || this.options.flip === Flip.Both)
101-
? ['--hflip']
102-
: []),
103-
104-
/**
105-
* Vertical flip
106-
*/
107-
...(this.options.flip &&
108-
(this.options.flip === Flip.Vertical || this.options.flip === Flip.Both)
109-
? ['--vflip']
110-
: []),
92+
...getSharedArgs(this.options),
11193

11294
/**
11395
* Bit rate

0 commit comments

Comments
 (0)