Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add support for a number of exposure-related options
  • Loading branch information
darrylhodgins committed Jul 14, 2020
commit b2da56e1a369a119d2864ca32bccf3ec8cad5b10
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ const stillCamera = new StillCamera({
- [`rotation: Rotation`](#rotation) - *Default: `Rotation.Rotate0`*
- [`flip: Flip`](#flip) - *Default: `Flip.None`*
- `delay: number` - *Default: 1 ms*
- `shutter: number` - *Default: Auto calculated based on framerate (1000000µs/fps). Number is in microseconds*
- `iso: number` - *Default: Auto*
- `exposureCompensation: number` - *Default: `0`*
- [`exposureMode: ExposureMode`](#exposuremode) - *Default: Auto*
- [`awbMode: AwbMode`](#awbmode) - *Default: Auto*
- `analoggain: number` - *Default: 0*
- `digitalgain: number` - *Default: 0*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `analoggain: number` - *Default: 0*
- `digitalgain: number` - *Default: 0*
- `analogGain: number` - *Default: 0*
- `digitalGain: number` - *Default: 0*

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

Expand Down Expand Up @@ -271,6 +278,13 @@ const streamCamera = new StreamCamera({
- `fps: number` - *Default: 30 fps*
- [`codec: Codec`](#codec) - *Default: `Codec.H264`*
- [`sensorMode: SensorMode`](#sensormode) - *Default: `SensorMode.AutoSelect`*
- `shutter: number` - *Default: Auto calculated based on framerate (1000000µs/fps). Number is in microseconds*
- `iso: number` - *Default: Auto*
- `exposureCompensation: number` - *Default: `0`*
- [`exposureMode: ExposureMode`](#exposuremode) - *Default: Auto*
- [`awbMode: AwbMode`](#awbmode) - *Default: Auto*
- `analoggain: number` - *Default: 0*
- `digitalgain: number` - *Default: 0*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `analoggain: number` - *Default: 0*
- `digitalgain: number` - *Default: 0*
- `analogGain: number` - *Default: 0*
- `digitalGain: number` - *Default: 0*

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

## `ExposureMode`
Exposure mode options.
- `ExposureMode.Off`
- `ExposureMode.Auto`
- `ExposureMode.Night`
- `ExposureMode.NightPreview`
- `ExposureMode.Backlight`
- `ExposureMode.Spotlight`
- `ExposureMode.Sports`
- `ExposureMode.Snow`
- `ExposureMode.Beach`
- `ExposureMode.VeryLong`
- `ExposureMode.FixedFps`
- `ExposureMode.AntiShake`
- `ExposureMode.Fireworks`

```javascript
import { ExposureMode } from "pi-camera-connect";
```

## `AwbMode`
White balance mode options.
- `Off`
- `Auto`
- `Sun`
- `Cloud`
- `Shade`
- `Tungsten`
- `Fluorescent`
- `Incandescent`
- `Flash`
- `Horizon`
- `GreyWorld`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `Off`
- `Auto`
- `Sun`
- `Cloud`
- `Shade`
- `Tungsten`
- `Fluorescent`
- `Incandescent`
- `Flash`
- `Horizon`
- `GreyWorld`
- `AwbMode.Off`
- `AwbMode.Auto`
- `AwbMode.Sun`
- `AwbMode.Cloud`
- `AwbMode.Shade`
- `AwbMode.Tungsten`
- `AwbMode.Fluorescent`
- `AwbMode.Incandescent`
- `AwbMode.Flash`
- `AwbMode.Horizon`
- `AwbMode.GreyWorld`

```javascript
import { AwbMode } from "pi-camera-connect";
```

## `Codec`
Stream codec options.
- `Codec.H264`
Expand Down
30 changes: 30 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,33 @@ export enum Flip {
Vertical = 'vertical',
Both = 'both',
}

export enum ExposureMode {
Off = 'off',
Auto = 'auto',
Night = 'night',
NightPreview = 'nightpreview',
Backlight = 'backlight',
Spotlight = 'spotlight',
Sports = 'sports',
Snow = 'snow',
Beach = 'beach',
VeryLong = 'verylong',
FixedFps = 'fixedfps',
AntiShake = 'antishake',
Fireworks = 'fireworks'
}

export enum AwbMode {
Off = 'off',
Auto = 'auto',
Sun = 'sun',
Cloud = 'cloud',
Shade = 'shade',
Tungsten = 'tungsten',
Fluorescent = 'fluorescent',
Incandescent = 'incandescent',
Flash = 'flash',
Horizon = 'horizon',
GreyWorld = 'greyworld'
}
81 changes: 81 additions & 0 deletions src/lib/shared-args.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { StillOptions } from "./still-camera";
import { StreamOptions } from "./stream-camera";
import { Flip } from '..';

/**
* Get the command line arguments for `raspistill` or `raspivid` that are common among both
*
* These are: `--width`, `--height`, `--rotation`, `--hflip`, `--vflip`, `--shutter`,
* `--ISO`, `--exposure`, `--ev`, and `--awb`
* @param options Camera options
*/
export function getSharedArgs(options: StillOptions | StreamOptions): string[] {
return [

/**
* Width
*/
...(options.width ? ['--width', options.width.toString()] : []),

/**
* Height
*/
...(options.height ? ['--height', options.height.toString()] : []),

/**
* Rotation
*/
...(options.rotation ? ['--rotation', options.rotation.toString()] : []),

/**
* Horizontal flip
*/
...(options.flip &&
(options.flip === Flip.Horizontal || options.flip === Flip.Both)
? ['--hflip']
: []),

/**
* Vertical flip
*/
...(options.flip &&
(options.flip === Flip.Vertical || options.flip === Flip.Both)
? ['--vflip']
: []),

/**
* Shutter Speed
*/
...(options.shutter ? ["--shutter", options.shutter.toString()] : []),

/**
* ISO
*/
...(options.iso ? ['--ISO', options.iso.toString()] : []),

/**
* EV Compensation
*/
...(options.exposureCompensation ? ['--ev', options.exposureCompensation.toString()] : []),

/**
* Exposure Mode
*/
...(options.exposureMode ? ['--exposure', options.exposureMode.toString()] : []),

/**
* Auto White Balance Mode
*/
...(options.awbMode ? ['--awb', options.awbMode.toString()] : []),

/**
* Analog Gain
*/
...(options.analoggain ? ['--analoggain', options.analoggain.toString()] : []),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's stay consistent with this lib's camel case convention (even though the underlying arg isn't camel cased)

Suggested change
...(options.analoggain ? ['--analoggain', options.analoggain.toString()] : []),
...(options.analogGain ? ['--analoggain', options.analogGain.toString()] : []),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that was a copy-paste/multi-line edit thing. I'll fix that.


/**
* Digital Gain
*/
...(options.digitalgain ? ['--digitalgain', options.digitalgain.toString()] : [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
...(options.digitalgain ? ['--digitalgain', options.digitalgain.toString()] : [])
...(options.digitalGain ? ['--digitalgain', options.digitalGain.toString()] : [])
];
}
40 changes: 11 additions & 29 deletions src/lib/still-camera.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import * as si from 'systeminformation';
import { Flip, Rotation } from '..';
import { AwbMode, ExposureMode, Flip, Rotation } from '..';
import { spawnPromise } from '../util';
import { getSharedArgs } from './shared-args';

export interface StillOptions {
width?: number;
height?: number;
rotation?: Rotation;
flip?: Flip;
delay?: number;
shutter?: number;
iso?: number;
exposureCompensation?: number;
exposureMode?: ExposureMode;
awbMode?: AwbMode;
analoggain?: number;
digitalgain?: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
analoggain?: number;
digitalgain?: number;
analogGain?: number;
digitalGain?: number;
}

export default class StillCamera {
Expand Down Expand Up @@ -42,35 +50,9 @@ export default class StillCamera {
try {
return await spawnPromise('raspistill', [
/**
* Width
* Add the command-line arguments that are common to both `raspivid` and `raspistill`
*/
...(this.options.width ? ['--width', this.options.width.toString()] : []),

/**
* Height
*/
...(this.options.height ? ['--height', this.options.height.toString()] : []),

/**
* Rotation
*/
...(this.options.rotation ? ['--rotation', this.options.rotation.toString()] : []),

/**
* Horizontal flip
*/
...(this.options.flip &&
(this.options.flip === Flip.Horizontal || this.options.flip === Flip.Both)
? ['--hflip']
: []),

/**
* Vertical flip
*/
...(this.options.flip &&
(this.options.flip === Flip.Vertical || this.options.flip === Flip.Both)
? ['--vflip']
: []),
...getSharedArgs(this.options),

/**
* Capture delay (ms)
Expand Down
40 changes: 11 additions & 29 deletions src/lib/stream-camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
import { EventEmitter } from 'events';
import * as stream from 'stream';
import * as si from 'systeminformation';
import { Flip, Rotation } from '..';
import { AwbMode, ExposureMode, Flip, Rotation } from '..';
import { getSharedArgs } from './shared-args';

export enum Codec {
H264 = 'H264',
Expand All @@ -29,6 +30,13 @@ export interface StreamOptions {
fps?: number;
codec?: Codec;
sensorMode?: SensorMode;
shutter?: number;
iso?: number;
exposureCompensation?: number;
exposureMode?: ExposureMode;
awbMode?: AwbMode;
analoggain?: number;
digitalgain?: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
analoggain?: number;
digitalgain?: number;
analogGain?: number;
digitalGain?: number;
}

declare interface StreamCamera {
Expand Down Expand Up @@ -79,35 +87,9 @@ class StreamCamera extends EventEmitter {
try {
const args: Array<string> = [
/**
* Width
* Add the command-line arguments that are common to both `raspivid` and `raspistill`
*/
...(this.options.width ? ['--width', this.options.width.toString()] : []),

/**
* Height
*/
...(this.options.height ? ['--height', this.options.height.toString()] : []),

/**
* Rotation
*/
...(this.options.rotation ? ['--rotation', this.options.rotation.toString()] : []),

/**
* Horizontal flip
*/
...(this.options.flip &&
(this.options.flip === Flip.Horizontal || this.options.flip === Flip.Both)
? ['--hflip']
: []),

/**
* Vertical flip
*/
...(this.options.flip &&
(this.options.flip === Flip.Vertical || this.options.flip === Flip.Both)
? ['--vflip']
: []),
...getSharedArgs(this.options),

/**
* Bit rate
Expand Down