node-libcamera 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- require('child_process');
5
+ var child_process = require('child_process');
6
6
 
7
7
  var optionConverterMap = {
8
8
  preview: function preview(val) {
@@ -14,6 +14,14 @@ function cmd(base, args) {
14
14
  if (base && !args) return base;
15
15
  return base + " " + (args == null ? void 0 : args.join(' '));
16
16
  }
17
+ function run(command, options) {
18
+ return new Promise(function (resolve, reject) {
19
+ child_process.exec(command, options, function (error, stdout, stderr) {
20
+ if (stderr || error) reject(stderr || error);
21
+ resolve(stdout);
22
+ });
23
+ });
24
+ }
17
25
  function convertOptionsToCmdArgs(options) {
18
26
  var args = [];
19
27
  Object.entries(options).forEach(function (_ref) {
@@ -35,10 +43,7 @@ function runLibCamera(bin, options) {
35
43
  var args = convertOptionsToCmdArgs(options);
36
44
  var command = cmd(bin, args);
37
45
 
38
- {
39
- console.log(command);
40
- return command;
41
- }
46
+ return run(command);
42
47
  }
43
48
 
44
49
  function jpeg(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"node-libcamera.cjs.development.js","sources":["../src/options.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["export namespace LibCamera {\n export interface CommandLineOptions {\n /**\n * Print help information for the application\n *\n * The `--help` option causes every application to print its full set of command line options with a brief synopsis of each, and then quit.\n **/\n help: boolean\n /**\n * Print out a software version number\n *\n * All `libcamera-apps` will, when they see the `--version` option, print out a version string both for `libcamera` and `libcamera-apps` and then quit.\n */\n version: boolean\n /**\n * Delay before application stops automatically <milliseconds>\n *\n * The `--timeout` option specifies how long the application runs before it stops, whether it is recording a video or showing a preview. In the case of still image capture, the application will show the preview window for this long before capturing the output image.\n *\n * If unspecified, the default value is 5000 (5 seconds). The value zero causes the application to run indefinitely.\n */\n timeout: number\n }\n\n export interface PreviewWindowOptions {\n /**\n * Preview window settings\n *\n * Sets the size and location of the preview window (both X Windows and DRM versions). It does not affect the resolution or aspect ratio of images being requested from the camera. The camera images will be scaled to the size of the preview window for display, and will be pillar/letter-boxed to fit.\n *\n * Example:\n * ```json\n * { \"x\": 100, \"y\": 100, \"width\": 500, \"height\": 500 }\n * ```\n */\n preview: PreviewOption\n /**\n * Fullscreen preview mode\n *\n * Forces the preview window to use the whole screen, and the window will have no border or title bar. Again the image may be pillar/letter-boxed.\n */\n fullscreen: boolean\n /**\n * Use Qt-based preview window\n *\n * The preview window is switched to use the Qt-based implementation. This option is not normally recommended because it no longer uses zero-copy buffer sharing nor GPU acceleration and is therefore very expensive, however, it does support X forwarding (which the other preview implementations do not).\n *\n * The Qt preview window does not support the `--fullscreen` option. Generally it is advised to try and keep the preview window small.\n */\n 'qt-preview': boolean\n /**\n * Do not display a preview window\n *\n * The preview window is suppressed entirely.\n */\n nopreview: boolean\n /**\n * Set window title bar text <string>\n *\n * The supplied string is set as the title of the preview window (when running under X Windows). Additionally the string may contain a number of `%` directives which are substituted with information from the image metadata. The permitted directives are:\n *\n * | Directive | Substitution |\n * | :--------------- | :------------------ |\n * | `%frame` | The sequence number of the frame |\n * | `%fps` | The instantaneous frame rate |\n * | `%exp` | The shutter speed used to capture the image, in microseconds |\n * | `%ag` | The analogue gain applied to the image in the sensor |\n * | `%dg` | The digital gain applied to the image by the ISP |\n * | `%rg` | The gain applied to the red component of each pixel |\n * | `%bg` | The gain applied to the blue component of each pixel |\n * | `%focus` | The focus metric for the image, where a larger value implies a sharper image |\n *\n * When not provided, the `--info-text` string defaults to `\"#%frame (%fps fps) exp %exp ag %ag dg %dg\"`.\n */\n 'info-text': string\n }\n\n export interface CameraResolutionOptions {\n /**\n * Capture image width <width>\n *\n * This number specifies the output resolution of the camera images captured by libcamera-still, libcamera-jpeg and libcamera-vid.\n *\n * For libcamera-raw, it affects the size of the raw frames captured. Where a camera has a 2x2 binned readout mode, specifying a resolution not larger than this binned mode will result in the capture of 2x2 binned raw frames.\n *\n * For libcamera-hello these parameters have no effect.\n */\n width: number\n /**\n * Capture image height <height>\n *\n * This number specifies the output resolution of the camera images captured by libcamera-still, libcamera-jpeg and libcamera-vid.\n *\n * For libcamera-raw, it affects the size of the raw frames captured. Where a camera has a 2x2 binned readout mode, specifying a resolution not larger than this binned mode will result in the capture of 2x2 binned raw frames.\n *\n * For libcamera-hello these parameters have no effect.\n */\n height: number\n }\n\n export interface OutputFileOptions {\n /**\n * Output file name <string>\n *\n * `--output` sets the name of the output file to which the output image or video is written. Besides regular file names, this may take the following special values:\n *\n * `-` - write to stdout\n *\n * `udp://` - a string starting with this is taken as a network address for streaming\n *\n * `tcp://` - a string starting with this is taken as a network address for streaming\n *\n * a string containing a `%d` directive is taken as a file name where the format directive is replaced with a count that increments for each file that is opened. Standard C format directive modifiers are permitted.\n */\n output: string\n }\n\n export interface VideoOptions {\n /**\n * Saves timestamp information to the specified file. Useful as an input file to `mkvmerge`.\n */\n 'save-pts': string\n }\n\n export type OptionsObject = CommandLineOptions &\n PreviewWindowOptions &\n CameraResolutionOptions &\n OutputFileOptions &\n VideoOptions\n\n export type OptionKeys = keyof OptionsObject\n export type OptionConverter = (val: any) => string\n\n export interface PreviewOption {\n x: number\n y: number\n width: number\n height: number\n }\n}\n\nexport const optionConverterMap: Partial<Record<\n LibCamera.OptionKeys,\n LibCamera.OptionConverter\n>> = {\n preview(val: LibCamera.PreviewOption) {\n return `${val.x},${val.y},${val.width},${val.height}`\n },\n} as const\n","import { exec, ExecOptionsWithBufferEncoding } from 'child_process'\nimport { optionConverterMap, LibCamera } from './options'\n\nexport function cmd(base: string, args?: string[]): string {\n if (base && !args) return base\n return `${base} ${args?.join(' ')}`\n}\n\nexport function run(command: string, options?: ExecOptionsWithBufferEncoding) {\n return new Promise((resolve, reject) => {\n exec(command, options, (error, stdout, stderr) => {\n if (stderr || error) reject(stderr || error)\n resolve(stdout)\n })\n })\n}\n\nexport function convertOptionsToCmdArgs(\n options: Partial<LibCamera.OptionsObject>\n): string[] {\n const args: string[] = []\n Object.entries(options).forEach(([key, val]) => {\n const converter = optionConverterMap[key as LibCamera.OptionKeys]\n const value = typeof converter === 'function' ? converter(val) : val\n if (value) args.push(`--${key}`)\n if (value !== true && value?.toString()) args.push(value?.toString())\n }, true)\n return args\n}\n","import { LibCamera } from './options'\nimport { run, cmd, convertOptionsToCmdArgs } from './utils'\n\nfunction runLibCamera(\n bin: string = 'libcamera-still',\n options: Partial<LibCamera.OptionsObject>\n) {\n const args = convertOptionsToCmdArgs(options)\n const command = cmd(bin, args)\n if (__DEV__) {\n console.log(command)\n return command\n }\n return run(command)\n}\n\nexport function jpeg(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-jpeg', options)\n}\n\nexport function still(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-still', options)\n}\n\nexport function vid(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-vid', options)\n}\n"],"names":["optionConverterMap","preview","val","x","y","width","height","cmd","base","args","join","convertOptionsToCmdArgs","options","Object","entries","forEach","key","converter","value","push","toString","runLibCamera","bin","command","console","log","jpeg","still","vid"],"mappings":";;;;;;AA6IO,IAAMA,kBAAkB,GAG1B;AACHC,EAAAA,OADG,mBACKC,GADL;AAED,WAAUA,GAAG,CAACC,CAAd,SAAmBD,GAAG,CAACE,CAAvB,SAA4BF,GAAG,CAACG,KAAhC,SAAyCH,GAAG,CAACI,MAA7C;AACD;AAHE,CAHE;;SC1ISC,IAAIC,MAAcC;AAChC,MAAID,IAAI,IAAI,CAACC,IAAb,EAAmB,OAAOD,IAAP;AACnB,SAAUA,IAAV,UAAkBC,IAAlB,oBAAkBA,IAAI,CAAEC,IAAN,CAAW,GAAX,CAAlB;AACD;AAED,SASgBC,wBACdC;AAEA,MAAMH,IAAI,GAAa,EAAvB;AACAI,EAAAA,MAAM,CAACC,OAAP,CAAeF,OAAf,EAAwBG,OAAxB,CAAgC;QAAEC;QAAKd;AACrC,QAAMe,SAAS,GAAGjB,kBAAkB,CAACgB,GAAD,CAApC;AACA,QAAME,KAAK,GAAG,OAAOD,SAAP,KAAqB,UAArB,GAAkCA,SAAS,CAACf,GAAD,CAA3C,GAAmDA,GAAjE;AACA,QAAIgB,KAAJ,EAAWT,IAAI,CAACU,IAAL,QAAeH,GAAf;AACX,QAAIE,KAAK,KAAK,IAAV,IAAkBA,KAAlB,YAAkBA,KAAK,CAAEE,QAAP,EAAtB,EAAyCX,IAAI,CAACU,IAAL,CAAUD,KAAV,oBAAUA,KAAK,CAAEE,QAAP,EAAV;AAC1C,GALD,EAKG,IALH;AAMA,SAAOX,IAAP;AACD;;ACzBD,SAASY,YAAT,CACEC,GADF,EAEEV,OAFF;MACEU;AAAAA,IAAAA,MAAc;;;AAGd,MAAMb,IAAI,GAAGE,uBAAuB,CAACC,OAAD,CAApC;AACA,MAAMW,OAAO,GAAGhB,GAAG,CAACe,GAAD,EAAMb,IAAN,CAAnB;;AACA,EAAa;AACXe,IAAAA,OAAO,CAACC,GAAR,CAAYF,OAAZ;AACA,WAAOA,OAAP;AACD;AAEF;;AAED,SAAgBG,KAAKd;AACnB,SAAOS,YAAY,CAAC,gBAAD,EAAmBT,OAAnB,CAAnB;AACD;AAED,SAAgBe,MAAMf;AACpB,SAAOS,YAAY,CAAC,iBAAD,EAAoBT,OAApB,CAAnB;AACD;AAED,SAAgBgB,IAAIhB;AAClB,SAAOS,YAAY,CAAC,eAAD,EAAkBT,OAAlB,CAAnB;AACD;;;;;;"}
1
+ {"version":3,"file":"node-libcamera.cjs.development.js","sources":["../src/options.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["export namespace LibCamera {\n export interface CommandLineOptions {\n /**\n * Print help information for the application\n *\n * The `--help` option causes every application to print its full set of command line options with a brief synopsis of each, and then quit.\n **/\n help: boolean\n /**\n * Print out a software version number\n *\n * All `libcamera-apps` will, when they see the `--version` option, print out a version string both for `libcamera` and `libcamera-apps` and then quit.\n */\n version: boolean\n /**\n * Delay before application stops automatically <milliseconds>\n *\n * The `--timeout` option specifies how long the application runs before it stops, whether it is recording a video or showing a preview. In the case of still image capture, the application will show the preview window for this long before capturing the output image.\n *\n * If unspecified, the default value is 5000 (5 seconds). The value zero causes the application to run indefinitely.\n */\n timeout: number\n }\n\n export interface PreviewWindowOptions {\n /**\n * Preview window settings\n *\n * Sets the size and location of the preview window (both X Windows and DRM versions). It does not affect the resolution or aspect ratio of images being requested from the camera. The camera images will be scaled to the size of the preview window for display, and will be pillar/letter-boxed to fit.\n *\n * Example:\n * ```json\n * { \"x\": 100, \"y\": 100, \"width\": 500, \"height\": 500 }\n * ```\n */\n preview: PreviewOption\n /**\n * Fullscreen preview mode\n *\n * Forces the preview window to use the whole screen, and the window will have no border or title bar. Again the image may be pillar/letter-boxed.\n */\n fullscreen: boolean\n /**\n * Use Qt-based preview window\n *\n * The preview window is switched to use the Qt-based implementation. This option is not normally recommended because it no longer uses zero-copy buffer sharing nor GPU acceleration and is therefore very expensive, however, it does support X forwarding (which the other preview implementations do not).\n *\n * The Qt preview window does not support the `--fullscreen` option. Generally it is advised to try and keep the preview window small.\n */\n 'qt-preview': boolean\n /**\n * Do not display a preview window\n *\n * The preview window is suppressed entirely.\n */\n nopreview: boolean\n /**\n * Set window title bar text <string>\n *\n * The supplied string is set as the title of the preview window (when running under X Windows). Additionally the string may contain a number of `%` directives which are substituted with information from the image metadata. The permitted directives are:\n *\n * | Directive | Substitution |\n * | :--------------- | :------------------ |\n * | `%frame` | The sequence number of the frame |\n * | `%fps` | The instantaneous frame rate |\n * | `%exp` | The shutter speed used to capture the image, in microseconds |\n * | `%ag` | The analogue gain applied to the image in the sensor |\n * | `%dg` | The digital gain applied to the image by the ISP |\n * | `%rg` | The gain applied to the red component of each pixel |\n * | `%bg` | The gain applied to the blue component of each pixel |\n * | `%focus` | The focus metric for the image, where a larger value implies a sharper image |\n *\n * When not provided, the `--info-text` string defaults to `\"#%frame (%fps fps) exp %exp ag %ag dg %dg\"`.\n */\n 'info-text': string\n }\n\n export interface CameraResolutionOptions {\n /**\n * Capture image width <width>\n *\n * This number specifies the output resolution of the camera images captured by libcamera-still, libcamera-jpeg and libcamera-vid.\n *\n * For libcamera-raw, it affects the size of the raw frames captured. Where a camera has a 2x2 binned readout mode, specifying a resolution not larger than this binned mode will result in the capture of 2x2 binned raw frames.\n *\n * For libcamera-hello these parameters have no effect.\n */\n width: number\n /**\n * Capture image height <height>\n *\n * This number specifies the output resolution of the camera images captured by libcamera-still, libcamera-jpeg and libcamera-vid.\n *\n * For libcamera-raw, it affects the size of the raw frames captured. Where a camera has a 2x2 binned readout mode, specifying a resolution not larger than this binned mode will result in the capture of 2x2 binned raw frames.\n *\n * For libcamera-hello these parameters have no effect.\n */\n height: number\n }\n\n export interface OutputFileOptions {\n /**\n * Output file name <string>\n *\n * `--output` sets the name of the output file to which the output image or video is written. Besides regular file names, this may take the following special values:\n *\n * `-` - write to stdout\n *\n * `udp://` - a string starting with this is taken as a network address for streaming\n *\n * `tcp://` - a string starting with this is taken as a network address for streaming\n *\n * a string containing a `%d` directive is taken as a file name where the format directive is replaced with a count that increments for each file that is opened. Standard C format directive modifiers are permitted.\n */\n output: string\n }\n\n export interface VideoOptions {\n /**\n * Saves timestamp information to the specified file. Useful as an input file to `mkvmerge`.\n */\n 'save-pts': string\n }\n\n export type OptionsObject = CommandLineOptions &\n PreviewWindowOptions &\n CameraResolutionOptions &\n OutputFileOptions &\n VideoOptions\n\n export type OptionKeys = keyof OptionsObject\n export type OptionConverter = (val: any) => string\n\n export interface PreviewOption {\n x: number\n y: number\n width: number\n height: number\n }\n}\n\nexport const optionConverterMap: Partial<Record<\n LibCamera.OptionKeys,\n LibCamera.OptionConverter\n>> = {\n preview(val: LibCamera.PreviewOption) {\n return `${val.x},${val.y},${val.width},${val.height}`\n },\n} as const\n","import { exec, ExecOptionsWithBufferEncoding } from 'child_process'\nimport { optionConverterMap, LibCamera } from './options'\n\nexport function cmd(base: string, args?: string[]): string {\n if (base && !args) return base\n return `${base} ${args?.join(' ')}`\n}\n\nexport function run(command: string, options?: ExecOptionsWithBufferEncoding) {\n return new Promise((resolve, reject) => {\n exec(command, options, (error, stdout, stderr) => {\n if (stderr || error) reject(stderr || error)\n resolve(stdout)\n })\n })\n}\n\nexport function convertOptionsToCmdArgs(\n options: Partial<LibCamera.OptionsObject>\n): string[] {\n const args: string[] = []\n Object.entries(options).forEach(([key, val]) => {\n const converter = optionConverterMap[key as LibCamera.OptionKeys]\n const value = typeof converter === 'function' ? converter(val) : val\n if (value) args.push(`--${key}`)\n if (value !== true && value?.toString()) args.push(value?.toString())\n }, true)\n return args\n}\n","import { LibCamera } from './options'\nimport { run, cmd, convertOptionsToCmdArgs } from './utils'\n\nfunction runLibCamera(\n bin: string = 'libcamera-still',\n options: Partial<LibCamera.OptionsObject>\n) {\n const args = convertOptionsToCmdArgs(options)\n const command = cmd(bin, args)\n if (process.env.NODE_ENV === 'test') {\n console.log(command)\n return command\n }\n return run(command)\n}\n\nexport function jpeg(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-jpeg', options)\n}\n\nexport function still(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-still', options)\n}\n\nexport function vid(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-vid', options)\n}\n"],"names":["optionConverterMap","preview","val","x","y","width","height","cmd","base","args","join","run","command","options","Promise","resolve","reject","exec","error","stdout","stderr","convertOptionsToCmdArgs","Object","entries","forEach","key","converter","value","push","toString","runLibCamera","bin","jpeg","still","vid"],"mappings":";;;;;;AA6IO,IAAMA,kBAAkB,GAG1B;AACHC,EAAAA,OADG,mBACKC,GADL;AAED,WAAUA,GAAG,CAACC,CAAd,SAAmBD,GAAG,CAACE,CAAvB,SAA4BF,GAAG,CAACG,KAAhC,SAAyCH,GAAG,CAACI,MAA7C;AACD;AAHE,CAHE;;SC1ISC,IAAIC,MAAcC;AAChC,MAAID,IAAI,IAAI,CAACC,IAAb,EAAmB,OAAOD,IAAP;AACnB,SAAUA,IAAV,UAAkBC,IAAlB,oBAAkBA,IAAI,CAAEC,IAAN,CAAW,GAAX,CAAlB;AACD;AAED,SAAgBC,IAAIC,SAAiBC;AACnC,SAAO,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV;AACjBC,IAAAA,kBAAI,CAACL,OAAD,EAAUC,OAAV,EAAmB,UAACK,KAAD,EAAQC,MAAR,EAAgBC,MAAhB;AACrB,UAAIA,MAAM,IAAIF,KAAd,EAAqBF,MAAM,CAACI,MAAM,IAAIF,KAAX,CAAN;AACrBH,MAAAA,OAAO,CAACI,MAAD,CAAP;AACD,KAHG,CAAJ;AAID,GALM,CAAP;AAMD;AAED,SAAgBE,wBACdR;AAEA,MAAMJ,IAAI,GAAa,EAAvB;AACAa,EAAAA,MAAM,CAACC,OAAP,CAAeV,OAAf,EAAwBW,OAAxB,CAAgC;QAAEC;QAAKvB;AACrC,QAAMwB,SAAS,GAAG1B,kBAAkB,CAACyB,GAAD,CAApC;AACA,QAAME,KAAK,GAAG,OAAOD,SAAP,KAAqB,UAArB,GAAkCA,SAAS,CAACxB,GAAD,CAA3C,GAAmDA,GAAjE;AACA,QAAIyB,KAAJ,EAAWlB,IAAI,CAACmB,IAAL,QAAeH,GAAf;AACX,QAAIE,KAAK,KAAK,IAAV,IAAkBA,KAAlB,YAAkBA,KAAK,CAAEE,QAAP,EAAtB,EAAyCpB,IAAI,CAACmB,IAAL,CAAUD,KAAV,oBAAUA,KAAK,CAAEE,QAAP,EAAV;AAC1C,GALD,EAKG,IALH;AAMA,SAAOpB,IAAP;AACD;;ACzBD,SAASqB,YAAT,CACEC,GADF,EAEElB,OAFF;MACEkB;AAAAA,IAAAA,MAAc;;;AAGd,MAAMtB,IAAI,GAAGY,uBAAuB,CAACR,OAAD,CAApC;AACA,MAAMD,OAAO,GAAGL,GAAG,CAACwB,GAAD,EAAMtB,IAAN,CAAnB;;AAKA,SAAOE,GAAG,CAACC,OAAD,CAAV;AACD;;AAED,SAAgBoB,KAAKnB;AACnB,SAAOiB,YAAY,CAAC,gBAAD,EAAmBjB,OAAnB,CAAnB;AACD;AAED,SAAgBoB,MAAMpB;AACpB,SAAOiB,YAAY,CAAC,iBAAD,EAAoBjB,OAApB,CAAnB;AACD;AAED,SAAgBqB,IAAIrB;AAClB,SAAOiB,YAAY,CAAC,eAAD,EAAkBjB,OAAlB,CAAnB;AACD;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"node-libcamera.cjs.production.min.js","sources":["../src/options.ts","../src/index.ts","../src/utils.ts"],"sourcesContent":["export namespace LibCamera {\n export interface CommandLineOptions {\n /**\n * Print help information for the application\n *\n * The `--help` option causes every application to print its full set of command line options with a brief synopsis of each, and then quit.\n **/\n help: boolean\n /**\n * Print out a software version number\n *\n * All `libcamera-apps` will, when they see the `--version` option, print out a version string both for `libcamera` and `libcamera-apps` and then quit.\n */\n version: boolean\n /**\n * Delay before application stops automatically <milliseconds>\n *\n * The `--timeout` option specifies how long the application runs before it stops, whether it is recording a video or showing a preview. In the case of still image capture, the application will show the preview window for this long before capturing the output image.\n *\n * If unspecified, the default value is 5000 (5 seconds). The value zero causes the application to run indefinitely.\n */\n timeout: number\n }\n\n export interface PreviewWindowOptions {\n /**\n * Preview window settings\n *\n * Sets the size and location of the preview window (both X Windows and DRM versions). It does not affect the resolution or aspect ratio of images being requested from the camera. The camera images will be scaled to the size of the preview window for display, and will be pillar/letter-boxed to fit.\n *\n * Example:\n * ```json\n * { \"x\": 100, \"y\": 100, \"width\": 500, \"height\": 500 }\n * ```\n */\n preview: PreviewOption\n /**\n * Fullscreen preview mode\n *\n * Forces the preview window to use the whole screen, and the window will have no border or title bar. Again the image may be pillar/letter-boxed.\n */\n fullscreen: boolean\n /**\n * Use Qt-based preview window\n *\n * The preview window is switched to use the Qt-based implementation. This option is not normally recommended because it no longer uses zero-copy buffer sharing nor GPU acceleration and is therefore very expensive, however, it does support X forwarding (which the other preview implementations do not).\n *\n * The Qt preview window does not support the `--fullscreen` option. Generally it is advised to try and keep the preview window small.\n */\n 'qt-preview': boolean\n /**\n * Do not display a preview window\n *\n * The preview window is suppressed entirely.\n */\n nopreview: boolean\n /**\n * Set window title bar text <string>\n *\n * The supplied string is set as the title of the preview window (when running under X Windows). Additionally the string may contain a number of `%` directives which are substituted with information from the image metadata. The permitted directives are:\n *\n * | Directive | Substitution |\n * | :--------------- | :------------------ |\n * | `%frame` | The sequence number of the frame |\n * | `%fps` | The instantaneous frame rate |\n * | `%exp` | The shutter speed used to capture the image, in microseconds |\n * | `%ag` | The analogue gain applied to the image in the sensor |\n * | `%dg` | The digital gain applied to the image by the ISP |\n * | `%rg` | The gain applied to the red component of each pixel |\n * | `%bg` | The gain applied to the blue component of each pixel |\n * | `%focus` | The focus metric for the image, where a larger value implies a sharper image |\n *\n * When not provided, the `--info-text` string defaults to `\"#%frame (%fps fps) exp %exp ag %ag dg %dg\"`.\n */\n 'info-text': string\n }\n\n export interface CameraResolutionOptions {\n /**\n * Capture image width <width>\n *\n * This number specifies the output resolution of the camera images captured by libcamera-still, libcamera-jpeg and libcamera-vid.\n *\n * For libcamera-raw, it affects the size of the raw frames captured. Where a camera has a 2x2 binned readout mode, specifying a resolution not larger than this binned mode will result in the capture of 2x2 binned raw frames.\n *\n * For libcamera-hello these parameters have no effect.\n */\n width: number\n /**\n * Capture image height <height>\n *\n * This number specifies the output resolution of the camera images captured by libcamera-still, libcamera-jpeg and libcamera-vid.\n *\n * For libcamera-raw, it affects the size of the raw frames captured. Where a camera has a 2x2 binned readout mode, specifying a resolution not larger than this binned mode will result in the capture of 2x2 binned raw frames.\n *\n * For libcamera-hello these parameters have no effect.\n */\n height: number\n }\n\n export interface OutputFileOptions {\n /**\n * Output file name <string>\n *\n * `--output` sets the name of the output file to which the output image or video is written. Besides regular file names, this may take the following special values:\n *\n * `-` - write to stdout\n *\n * `udp://` - a string starting with this is taken as a network address for streaming\n *\n * `tcp://` - a string starting with this is taken as a network address for streaming\n *\n * a string containing a `%d` directive is taken as a file name where the format directive is replaced with a count that increments for each file that is opened. Standard C format directive modifiers are permitted.\n */\n output: string\n }\n\n export interface VideoOptions {\n /**\n * Saves timestamp information to the specified file. Useful as an input file to `mkvmerge`.\n */\n 'save-pts': string\n }\n\n export type OptionsObject = CommandLineOptions &\n PreviewWindowOptions &\n CameraResolutionOptions &\n OutputFileOptions &\n VideoOptions\n\n export type OptionKeys = keyof OptionsObject\n export type OptionConverter = (val: any) => string\n\n export interface PreviewOption {\n x: number\n y: number\n width: number\n height: number\n }\n}\n\nexport const optionConverterMap: Partial<Record<\n LibCamera.OptionKeys,\n LibCamera.OptionConverter\n>> = {\n preview(val: LibCamera.PreviewOption) {\n return `${val.x},${val.y},${val.width},${val.height}`\n },\n} as const\n","import { LibCamera } from './options'\nimport { run, cmd, convertOptionsToCmdArgs } from './utils'\n\nfunction runLibCamera(\n bin: string = 'libcamera-still',\n options: Partial<LibCamera.OptionsObject>\n) {\n const args = convertOptionsToCmdArgs(options)\n const command = cmd(bin, args)\n if (__DEV__) {\n console.log(command)\n return command\n }\n return run(command)\n}\n\nexport function jpeg(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-jpeg', options)\n}\n\nexport function still(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-still', options)\n}\n\nexport function vid(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-vid', options)\n}\n","import { exec, ExecOptionsWithBufferEncoding } from 'child_process'\nimport { optionConverterMap, LibCamera } from './options'\n\nexport function cmd(base: string, args?: string[]): string {\n if (base && !args) return base\n return `${base} ${args?.join(' ')}`\n}\n\nexport function run(command: string, options?: ExecOptionsWithBufferEncoding) {\n return new Promise((resolve, reject) => {\n exec(command, options, (error, stdout, stderr) => {\n if (stderr || error) reject(stderr || error)\n resolve(stdout)\n })\n })\n}\n\nexport function convertOptionsToCmdArgs(\n options: Partial<LibCamera.OptionsObject>\n): string[] {\n const args: string[] = []\n Object.entries(options).forEach(([key, val]) => {\n const converter = optionConverterMap[key as LibCamera.OptionKeys]\n const value = typeof converter === 'function' ? converter(val) : val\n if (value) args.push(`--${key}`)\n if (value !== true && value?.toString()) args.push(value?.toString())\n }, true)\n return args\n}\n"],"names":["optionConverterMap","preview","val","x","y","width","height","runLibCamera","bin","options","command","base","args","join","cmd","Object","entries","forEach","key","converter","value","push","toString","convertOptionsToCmdArgs","Promise","resolve","reject","exec","run","error","stdout","stderr"],"mappings":"mGA6IaA,EAGR,CACHC,iBAAQC,UACIA,EAAIC,MAAKD,EAAIE,MAAKF,EAAIG,UAASH,EAAII,SC/IjD,SAASC,EACPC,EACAC,mBADAD,IAAAA,EAAc,mBCIIE,WALAC,EAAcC,UAC5BD,IAASC,EAAaD,EAChBA,aAAQC,SAAAA,EAAMC,KAAK,MDGbC,CAAIN,WCUpBC,OAEMG,EAAiB,UACvBG,OAAOC,QAAQP,GAASQ,SAAQ,gBAAEC,OAAKhB,OAC/BiB,EAAYnB,EAAmBkB,GAC/BE,EAA6B,mBAAdD,EAA2BA,EAAUjB,GAAOA,EAC7DkB,GAAOR,EAAKS,UAAUH,IACZ,IAAVE,SAAkBA,GAAAA,EAAOE,YAAYV,EAAKS,WAAKD,SAAAA,EAAOE,eACzD,GACIV,EDpBMW,CAAwBd,ICE9B,IAAIe,SAAQ,SAACC,EAASC,GAC3BC,OAAKjB,ODGAkB,GCHkB,SAACC,EAAOC,EAAQC,IACjCA,GAAUF,IAAOH,EAAOK,GAAUF,GACtCJ,EAAQK,aAJMpB,wBDQCD,UACZF,EAAa,iBAAkBE,2BAGlBA,UACbF,EAAa,kBAAmBE,yBAGrBA,UACXF,EAAa,gBAAiBE"}
1
+ {"version":3,"file":"node-libcamera.cjs.production.min.js","sources":["../src/options.ts","../src/index.ts","../src/utils.ts"],"sourcesContent":["export namespace LibCamera {\n export interface CommandLineOptions {\n /**\n * Print help information for the application\n *\n * The `--help` option causes every application to print its full set of command line options with a brief synopsis of each, and then quit.\n **/\n help: boolean\n /**\n * Print out a software version number\n *\n * All `libcamera-apps` will, when they see the `--version` option, print out a version string both for `libcamera` and `libcamera-apps` and then quit.\n */\n version: boolean\n /**\n * Delay before application stops automatically <milliseconds>\n *\n * The `--timeout` option specifies how long the application runs before it stops, whether it is recording a video or showing a preview. In the case of still image capture, the application will show the preview window for this long before capturing the output image.\n *\n * If unspecified, the default value is 5000 (5 seconds). The value zero causes the application to run indefinitely.\n */\n timeout: number\n }\n\n export interface PreviewWindowOptions {\n /**\n * Preview window settings\n *\n * Sets the size and location of the preview window (both X Windows and DRM versions). It does not affect the resolution or aspect ratio of images being requested from the camera. The camera images will be scaled to the size of the preview window for display, and will be pillar/letter-boxed to fit.\n *\n * Example:\n * ```json\n * { \"x\": 100, \"y\": 100, \"width\": 500, \"height\": 500 }\n * ```\n */\n preview: PreviewOption\n /**\n * Fullscreen preview mode\n *\n * Forces the preview window to use the whole screen, and the window will have no border or title bar. Again the image may be pillar/letter-boxed.\n */\n fullscreen: boolean\n /**\n * Use Qt-based preview window\n *\n * The preview window is switched to use the Qt-based implementation. This option is not normally recommended because it no longer uses zero-copy buffer sharing nor GPU acceleration and is therefore very expensive, however, it does support X forwarding (which the other preview implementations do not).\n *\n * The Qt preview window does not support the `--fullscreen` option. Generally it is advised to try and keep the preview window small.\n */\n 'qt-preview': boolean\n /**\n * Do not display a preview window\n *\n * The preview window is suppressed entirely.\n */\n nopreview: boolean\n /**\n * Set window title bar text <string>\n *\n * The supplied string is set as the title of the preview window (when running under X Windows). Additionally the string may contain a number of `%` directives which are substituted with information from the image metadata. The permitted directives are:\n *\n * | Directive | Substitution |\n * | :--------------- | :------------------ |\n * | `%frame` | The sequence number of the frame |\n * | `%fps` | The instantaneous frame rate |\n * | `%exp` | The shutter speed used to capture the image, in microseconds |\n * | `%ag` | The analogue gain applied to the image in the sensor |\n * | `%dg` | The digital gain applied to the image by the ISP |\n * | `%rg` | The gain applied to the red component of each pixel |\n * | `%bg` | The gain applied to the blue component of each pixel |\n * | `%focus` | The focus metric for the image, where a larger value implies a sharper image |\n *\n * When not provided, the `--info-text` string defaults to `\"#%frame (%fps fps) exp %exp ag %ag dg %dg\"`.\n */\n 'info-text': string\n }\n\n export interface CameraResolutionOptions {\n /**\n * Capture image width <width>\n *\n * This number specifies the output resolution of the camera images captured by libcamera-still, libcamera-jpeg and libcamera-vid.\n *\n * For libcamera-raw, it affects the size of the raw frames captured. Where a camera has a 2x2 binned readout mode, specifying a resolution not larger than this binned mode will result in the capture of 2x2 binned raw frames.\n *\n * For libcamera-hello these parameters have no effect.\n */\n width: number\n /**\n * Capture image height <height>\n *\n * This number specifies the output resolution of the camera images captured by libcamera-still, libcamera-jpeg and libcamera-vid.\n *\n * For libcamera-raw, it affects the size of the raw frames captured. Where a camera has a 2x2 binned readout mode, specifying a resolution not larger than this binned mode will result in the capture of 2x2 binned raw frames.\n *\n * For libcamera-hello these parameters have no effect.\n */\n height: number\n }\n\n export interface OutputFileOptions {\n /**\n * Output file name <string>\n *\n * `--output` sets the name of the output file to which the output image or video is written. Besides regular file names, this may take the following special values:\n *\n * `-` - write to stdout\n *\n * `udp://` - a string starting with this is taken as a network address for streaming\n *\n * `tcp://` - a string starting with this is taken as a network address for streaming\n *\n * a string containing a `%d` directive is taken as a file name where the format directive is replaced with a count that increments for each file that is opened. Standard C format directive modifiers are permitted.\n */\n output: string\n }\n\n export interface VideoOptions {\n /**\n * Saves timestamp information to the specified file. Useful as an input file to `mkvmerge`.\n */\n 'save-pts': string\n }\n\n export type OptionsObject = CommandLineOptions &\n PreviewWindowOptions &\n CameraResolutionOptions &\n OutputFileOptions &\n VideoOptions\n\n export type OptionKeys = keyof OptionsObject\n export type OptionConverter = (val: any) => string\n\n export interface PreviewOption {\n x: number\n y: number\n width: number\n height: number\n }\n}\n\nexport const optionConverterMap: Partial<Record<\n LibCamera.OptionKeys,\n LibCamera.OptionConverter\n>> = {\n preview(val: LibCamera.PreviewOption) {\n return `${val.x},${val.y},${val.width},${val.height}`\n },\n} as const\n","import { LibCamera } from './options'\nimport { run, cmd, convertOptionsToCmdArgs } from './utils'\n\nfunction runLibCamera(\n bin: string = 'libcamera-still',\n options: Partial<LibCamera.OptionsObject>\n) {\n const args = convertOptionsToCmdArgs(options)\n const command = cmd(bin, args)\n if (process.env.NODE_ENV === 'test') {\n console.log(command)\n return command\n }\n return run(command)\n}\n\nexport function jpeg(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-jpeg', options)\n}\n\nexport function still(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-still', options)\n}\n\nexport function vid(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-vid', options)\n}\n","import { exec, ExecOptionsWithBufferEncoding } from 'child_process'\nimport { optionConverterMap, LibCamera } from './options'\n\nexport function cmd(base: string, args?: string[]): string {\n if (base && !args) return base\n return `${base} ${args?.join(' ')}`\n}\n\nexport function run(command: string, options?: ExecOptionsWithBufferEncoding) {\n return new Promise((resolve, reject) => {\n exec(command, options, (error, stdout, stderr) => {\n if (stderr || error) reject(stderr || error)\n resolve(stdout)\n })\n })\n}\n\nexport function convertOptionsToCmdArgs(\n options: Partial<LibCamera.OptionsObject>\n): string[] {\n const args: string[] = []\n Object.entries(options).forEach(([key, val]) => {\n const converter = optionConverterMap[key as LibCamera.OptionKeys]\n const value = typeof converter === 'function' ? converter(val) : val\n if (value) args.push(`--${key}`)\n if (value !== true && value?.toString()) args.push(value?.toString())\n }, true)\n return args\n}\n"],"names":["optionConverterMap","preview","val","x","y","width","height","runLibCamera","bin","options","command","base","args","join","cmd","Object","entries","forEach","key","converter","value","push","toString","convertOptionsToCmdArgs","Promise","resolve","reject","exec","run","error","stdout","stderr"],"mappings":"mGA6IaA,EAGR,CACHC,iBAAQC,UACIA,EAAIC,MAAKD,EAAIE,MAAKF,EAAIG,UAASH,EAAII,SC/IjD,SAASC,EACPC,EACAC,mBADAD,IAAAA,EAAc,mBCIIE,WALAC,EAAcC,UAC5BD,IAASC,EAAaD,EAChBA,aAAQC,SAAAA,EAAMC,KAAK,MDGbC,CAAIN,WCUpBC,OAEMG,EAAiB,UACvBG,OAAOC,QAAQP,GAASQ,SAAQ,gBAAEC,OAAKhB,OAC/BiB,EAAYnB,EAAmBkB,GAC/BE,EAA6B,mBAAdD,EAA2BA,EAAUjB,GAAOA,EAC7DkB,GAAOR,EAAKS,UAAUH,IACZ,IAAVE,SAAkBA,GAAAA,EAAOE,YAAYV,EAAKS,WAAKD,SAAAA,EAAOE,eACzD,GACIV,EDpBMW,CAAwBd,ICE9B,IAAIe,SAAQ,SAACC,EAASC,GAC3BC,OAAKjB,ODGAkB,GCHkB,SAACC,EAAOC,EAAQC,IACjCA,GAAUF,IAAOH,EAAOK,GAAUF,GACtCJ,EAAQK,aAJMpB,wBDQCD,UACZF,EAAa,iBAAkBE,2BAGlBA,UACbF,EAAa,kBAAmBE,yBAGrBA,UACXF,EAAa,gBAAiBE"}
@@ -39,7 +39,7 @@ function runLibCamera(bin, options) {
39
39
  var args = convertOptionsToCmdArgs(options);
40
40
  var command = cmd(bin, args);
41
41
 
42
- if (process.env.NODE_ENV !== "production") {
42
+ if (process.env.NODE_ENV === 'test') {
43
43
  console.log(command);
44
44
  return command;
45
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"node-libcamera.esm.js","sources":["../src/options.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["export namespace LibCamera {\n export interface CommandLineOptions {\n /**\n * Print help information for the application\n *\n * The `--help` option causes every application to print its full set of command line options with a brief synopsis of each, and then quit.\n **/\n help: boolean\n /**\n * Print out a software version number\n *\n * All `libcamera-apps` will, when they see the `--version` option, print out a version string both for `libcamera` and `libcamera-apps` and then quit.\n */\n version: boolean\n /**\n * Delay before application stops automatically <milliseconds>\n *\n * The `--timeout` option specifies how long the application runs before it stops, whether it is recording a video or showing a preview. In the case of still image capture, the application will show the preview window for this long before capturing the output image.\n *\n * If unspecified, the default value is 5000 (5 seconds). The value zero causes the application to run indefinitely.\n */\n timeout: number\n }\n\n export interface PreviewWindowOptions {\n /**\n * Preview window settings\n *\n * Sets the size and location of the preview window (both X Windows and DRM versions). It does not affect the resolution or aspect ratio of images being requested from the camera. The camera images will be scaled to the size of the preview window for display, and will be pillar/letter-boxed to fit.\n *\n * Example:\n * ```json\n * { \"x\": 100, \"y\": 100, \"width\": 500, \"height\": 500 }\n * ```\n */\n preview: PreviewOption\n /**\n * Fullscreen preview mode\n *\n * Forces the preview window to use the whole screen, and the window will have no border or title bar. Again the image may be pillar/letter-boxed.\n */\n fullscreen: boolean\n /**\n * Use Qt-based preview window\n *\n * The preview window is switched to use the Qt-based implementation. This option is not normally recommended because it no longer uses zero-copy buffer sharing nor GPU acceleration and is therefore very expensive, however, it does support X forwarding (which the other preview implementations do not).\n *\n * The Qt preview window does not support the `--fullscreen` option. Generally it is advised to try and keep the preview window small.\n */\n 'qt-preview': boolean\n /**\n * Do not display a preview window\n *\n * The preview window is suppressed entirely.\n */\n nopreview: boolean\n /**\n * Set window title bar text <string>\n *\n * The supplied string is set as the title of the preview window (when running under X Windows). Additionally the string may contain a number of `%` directives which are substituted with information from the image metadata. The permitted directives are:\n *\n * | Directive | Substitution |\n * | :--------------- | :------------------ |\n * | `%frame` | The sequence number of the frame |\n * | `%fps` | The instantaneous frame rate |\n * | `%exp` | The shutter speed used to capture the image, in microseconds |\n * | `%ag` | The analogue gain applied to the image in the sensor |\n * | `%dg` | The digital gain applied to the image by the ISP |\n * | `%rg` | The gain applied to the red component of each pixel |\n * | `%bg` | The gain applied to the blue component of each pixel |\n * | `%focus` | The focus metric for the image, where a larger value implies a sharper image |\n *\n * When not provided, the `--info-text` string defaults to `\"#%frame (%fps fps) exp %exp ag %ag dg %dg\"`.\n */\n 'info-text': string\n }\n\n export interface CameraResolutionOptions {\n /**\n * Capture image width <width>\n *\n * This number specifies the output resolution of the camera images captured by libcamera-still, libcamera-jpeg and libcamera-vid.\n *\n * For libcamera-raw, it affects the size of the raw frames captured. Where a camera has a 2x2 binned readout mode, specifying a resolution not larger than this binned mode will result in the capture of 2x2 binned raw frames.\n *\n * For libcamera-hello these parameters have no effect.\n */\n width: number\n /**\n * Capture image height <height>\n *\n * This number specifies the output resolution of the camera images captured by libcamera-still, libcamera-jpeg and libcamera-vid.\n *\n * For libcamera-raw, it affects the size of the raw frames captured. Where a camera has a 2x2 binned readout mode, specifying a resolution not larger than this binned mode will result in the capture of 2x2 binned raw frames.\n *\n * For libcamera-hello these parameters have no effect.\n */\n height: number\n }\n\n export interface OutputFileOptions {\n /**\n * Output file name <string>\n *\n * `--output` sets the name of the output file to which the output image or video is written. Besides regular file names, this may take the following special values:\n *\n * `-` - write to stdout\n *\n * `udp://` - a string starting with this is taken as a network address for streaming\n *\n * `tcp://` - a string starting with this is taken as a network address for streaming\n *\n * a string containing a `%d` directive is taken as a file name where the format directive is replaced with a count that increments for each file that is opened. Standard C format directive modifiers are permitted.\n */\n output: string\n }\n\n export interface VideoOptions {\n /**\n * Saves timestamp information to the specified file. Useful as an input file to `mkvmerge`.\n */\n 'save-pts': string\n }\n\n export type OptionsObject = CommandLineOptions &\n PreviewWindowOptions &\n CameraResolutionOptions &\n OutputFileOptions &\n VideoOptions\n\n export type OptionKeys = keyof OptionsObject\n export type OptionConverter = (val: any) => string\n\n export interface PreviewOption {\n x: number\n y: number\n width: number\n height: number\n }\n}\n\nexport const optionConverterMap: Partial<Record<\n LibCamera.OptionKeys,\n LibCamera.OptionConverter\n>> = {\n preview(val: LibCamera.PreviewOption) {\n return `${val.x},${val.y},${val.width},${val.height}`\n },\n} as const\n","import { exec, ExecOptionsWithBufferEncoding } from 'child_process'\nimport { optionConverterMap, LibCamera } from './options'\n\nexport function cmd(base: string, args?: string[]): string {\n if (base && !args) return base\n return `${base} ${args?.join(' ')}`\n}\n\nexport function run(command: string, options?: ExecOptionsWithBufferEncoding) {\n return new Promise((resolve, reject) => {\n exec(command, options, (error, stdout, stderr) => {\n if (stderr || error) reject(stderr || error)\n resolve(stdout)\n })\n })\n}\n\nexport function convertOptionsToCmdArgs(\n options: Partial<LibCamera.OptionsObject>\n): string[] {\n const args: string[] = []\n Object.entries(options).forEach(([key, val]) => {\n const converter = optionConverterMap[key as LibCamera.OptionKeys]\n const value = typeof converter === 'function' ? converter(val) : val\n if (value) args.push(`--${key}`)\n if (value !== true && value?.toString()) args.push(value?.toString())\n }, true)\n return args\n}\n","import { LibCamera } from './options'\nimport { run, cmd, convertOptionsToCmdArgs } from './utils'\n\nfunction runLibCamera(\n bin: string = 'libcamera-still',\n options: Partial<LibCamera.OptionsObject>\n) {\n const args = convertOptionsToCmdArgs(options)\n const command = cmd(bin, args)\n if (__DEV__) {\n console.log(command)\n return command\n }\n return run(command)\n}\n\nexport function jpeg(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-jpeg', options)\n}\n\nexport function still(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-still', options)\n}\n\nexport function vid(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-vid', options)\n}\n"],"names":["optionConverterMap","preview","val","x","y","width","height","cmd","base","args","join","run","command","options","Promise","resolve","reject","exec","error","stdout","stderr","convertOptionsToCmdArgs","Object","entries","forEach","key","converter","value","push","toString","runLibCamera","bin","console","log","jpeg","still","vid"],"mappings":";;AA6IO,IAAMA,kBAAkB,GAG1B;AACHC,EAAAA,OADG,mBACKC,GADL;AAED,WAAUA,GAAG,CAACC,CAAd,SAAmBD,GAAG,CAACE,CAAvB,SAA4BF,GAAG,CAACG,KAAhC,SAAyCH,GAAG,CAACI,MAA7C;AACD;AAHE,CAHE;;SC1ISC,IAAIC,MAAcC;AAChC,MAAID,IAAI,IAAI,CAACC,IAAb,EAAmB,OAAOD,IAAP;AACnB,SAAUA,IAAV,UAAkBC,IAAlB,oBAAkBA,IAAI,CAAEC,IAAN,CAAW,GAAX,CAAlB;AACD;AAED,SAAgBC,IAAIC,SAAiBC;AACnC,SAAO,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV;AACjBC,IAAAA,IAAI,CAACL,OAAD,EAAUC,OAAV,EAAmB,UAACK,KAAD,EAAQC,MAAR,EAAgBC,MAAhB;AACrB,UAAIA,MAAM,IAAIF,KAAd,EAAqBF,MAAM,CAACI,MAAM,IAAIF,KAAX,CAAN;AACrBH,MAAAA,OAAO,CAACI,MAAD,CAAP;AACD,KAHG,CAAJ;AAID,GALM,CAAP;AAMD;AAED,SAAgBE,wBACdR;AAEA,MAAMJ,IAAI,GAAa,EAAvB;AACAa,EAAAA,MAAM,CAACC,OAAP,CAAeV,OAAf,EAAwBW,OAAxB,CAAgC;QAAEC;QAAKvB;AACrC,QAAMwB,SAAS,GAAG1B,kBAAkB,CAACyB,GAAD,CAApC;AACA,QAAME,KAAK,GAAG,OAAOD,SAAP,KAAqB,UAArB,GAAkCA,SAAS,CAACxB,GAAD,CAA3C,GAAmDA,GAAjE;AACA,QAAIyB,KAAJ,EAAWlB,IAAI,CAACmB,IAAL,QAAeH,GAAf;AACX,QAAIE,KAAK,KAAK,IAAV,IAAkBA,KAAlB,YAAkBA,KAAK,CAAEE,QAAP,EAAtB,EAAyCpB,IAAI,CAACmB,IAAL,CAAUD,KAAV,oBAAUA,KAAK,CAAEE,QAAP,EAAV;AAC1C,GALD,EAKG,IALH;AAMA,SAAOpB,IAAP;AACD;;ACzBD,SAASqB,YAAT,CACEC,GADF,EAEElB,OAFF;MACEkB;AAAAA,IAAAA,MAAc;;;AAGd,MAAMtB,IAAI,GAAGY,uBAAuB,CAACR,OAAD,CAApC;AACA,MAAMD,OAAO,GAAGL,GAAG,CAACwB,GAAD,EAAMtB,IAAN,CAAnB;;AACA,6CAAa;AACXuB,IAAAA,OAAO,CAACC,GAAR,CAAYrB,OAAZ;AACA,WAAOA,OAAP;AACD;;AACD,SAAOD,GAAG,CAACC,OAAD,CAAV;AACD;;AAED,SAAgBsB,KAAKrB;AACnB,SAAOiB,YAAY,CAAC,gBAAD,EAAmBjB,OAAnB,CAAnB;AACD;AAED,SAAgBsB,MAAMtB;AACpB,SAAOiB,YAAY,CAAC,iBAAD,EAAoBjB,OAApB,CAAnB;AACD;AAED,SAAgBuB,IAAIvB;AAClB,SAAOiB,YAAY,CAAC,eAAD,EAAkBjB,OAAlB,CAAnB;AACD;;;;"}
1
+ {"version":3,"file":"node-libcamera.esm.js","sources":["../src/options.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["export namespace LibCamera {\n export interface CommandLineOptions {\n /**\n * Print help information for the application\n *\n * The `--help` option causes every application to print its full set of command line options with a brief synopsis of each, and then quit.\n **/\n help: boolean\n /**\n * Print out a software version number\n *\n * All `libcamera-apps` will, when they see the `--version` option, print out a version string both for `libcamera` and `libcamera-apps` and then quit.\n */\n version: boolean\n /**\n * Delay before application stops automatically <milliseconds>\n *\n * The `--timeout` option specifies how long the application runs before it stops, whether it is recording a video or showing a preview. In the case of still image capture, the application will show the preview window for this long before capturing the output image.\n *\n * If unspecified, the default value is 5000 (5 seconds). The value zero causes the application to run indefinitely.\n */\n timeout: number\n }\n\n export interface PreviewWindowOptions {\n /**\n * Preview window settings\n *\n * Sets the size and location of the preview window (both X Windows and DRM versions). It does not affect the resolution or aspect ratio of images being requested from the camera. The camera images will be scaled to the size of the preview window for display, and will be pillar/letter-boxed to fit.\n *\n * Example:\n * ```json\n * { \"x\": 100, \"y\": 100, \"width\": 500, \"height\": 500 }\n * ```\n */\n preview: PreviewOption\n /**\n * Fullscreen preview mode\n *\n * Forces the preview window to use the whole screen, and the window will have no border or title bar. Again the image may be pillar/letter-boxed.\n */\n fullscreen: boolean\n /**\n * Use Qt-based preview window\n *\n * The preview window is switched to use the Qt-based implementation. This option is not normally recommended because it no longer uses zero-copy buffer sharing nor GPU acceleration and is therefore very expensive, however, it does support X forwarding (which the other preview implementations do not).\n *\n * The Qt preview window does not support the `--fullscreen` option. Generally it is advised to try and keep the preview window small.\n */\n 'qt-preview': boolean\n /**\n * Do not display a preview window\n *\n * The preview window is suppressed entirely.\n */\n nopreview: boolean\n /**\n * Set window title bar text <string>\n *\n * The supplied string is set as the title of the preview window (when running under X Windows). Additionally the string may contain a number of `%` directives which are substituted with information from the image metadata. The permitted directives are:\n *\n * | Directive | Substitution |\n * | :--------------- | :------------------ |\n * | `%frame` | The sequence number of the frame |\n * | `%fps` | The instantaneous frame rate |\n * | `%exp` | The shutter speed used to capture the image, in microseconds |\n * | `%ag` | The analogue gain applied to the image in the sensor |\n * | `%dg` | The digital gain applied to the image by the ISP |\n * | `%rg` | The gain applied to the red component of each pixel |\n * | `%bg` | The gain applied to the blue component of each pixel |\n * | `%focus` | The focus metric for the image, where a larger value implies a sharper image |\n *\n * When not provided, the `--info-text` string defaults to `\"#%frame (%fps fps) exp %exp ag %ag dg %dg\"`.\n */\n 'info-text': string\n }\n\n export interface CameraResolutionOptions {\n /**\n * Capture image width <width>\n *\n * This number specifies the output resolution of the camera images captured by libcamera-still, libcamera-jpeg and libcamera-vid.\n *\n * For libcamera-raw, it affects the size of the raw frames captured. Where a camera has a 2x2 binned readout mode, specifying a resolution not larger than this binned mode will result in the capture of 2x2 binned raw frames.\n *\n * For libcamera-hello these parameters have no effect.\n */\n width: number\n /**\n * Capture image height <height>\n *\n * This number specifies the output resolution of the camera images captured by libcamera-still, libcamera-jpeg and libcamera-vid.\n *\n * For libcamera-raw, it affects the size of the raw frames captured. Where a camera has a 2x2 binned readout mode, specifying a resolution not larger than this binned mode will result in the capture of 2x2 binned raw frames.\n *\n * For libcamera-hello these parameters have no effect.\n */\n height: number\n }\n\n export interface OutputFileOptions {\n /**\n * Output file name <string>\n *\n * `--output` sets the name of the output file to which the output image or video is written. Besides regular file names, this may take the following special values:\n *\n * `-` - write to stdout\n *\n * `udp://` - a string starting with this is taken as a network address for streaming\n *\n * `tcp://` - a string starting with this is taken as a network address for streaming\n *\n * a string containing a `%d` directive is taken as a file name where the format directive is replaced with a count that increments for each file that is opened. Standard C format directive modifiers are permitted.\n */\n output: string\n }\n\n export interface VideoOptions {\n /**\n * Saves timestamp information to the specified file. Useful as an input file to `mkvmerge`.\n */\n 'save-pts': string\n }\n\n export type OptionsObject = CommandLineOptions &\n PreviewWindowOptions &\n CameraResolutionOptions &\n OutputFileOptions &\n VideoOptions\n\n export type OptionKeys = keyof OptionsObject\n export type OptionConverter = (val: any) => string\n\n export interface PreviewOption {\n x: number\n y: number\n width: number\n height: number\n }\n}\n\nexport const optionConverterMap: Partial<Record<\n LibCamera.OptionKeys,\n LibCamera.OptionConverter\n>> = {\n preview(val: LibCamera.PreviewOption) {\n return `${val.x},${val.y},${val.width},${val.height}`\n },\n} as const\n","import { exec, ExecOptionsWithBufferEncoding } from 'child_process'\nimport { optionConverterMap, LibCamera } from './options'\n\nexport function cmd(base: string, args?: string[]): string {\n if (base && !args) return base\n return `${base} ${args?.join(' ')}`\n}\n\nexport function run(command: string, options?: ExecOptionsWithBufferEncoding) {\n return new Promise((resolve, reject) => {\n exec(command, options, (error, stdout, stderr) => {\n if (stderr || error) reject(stderr || error)\n resolve(stdout)\n })\n })\n}\n\nexport function convertOptionsToCmdArgs(\n options: Partial<LibCamera.OptionsObject>\n): string[] {\n const args: string[] = []\n Object.entries(options).forEach(([key, val]) => {\n const converter = optionConverterMap[key as LibCamera.OptionKeys]\n const value = typeof converter === 'function' ? converter(val) : val\n if (value) args.push(`--${key}`)\n if (value !== true && value?.toString()) args.push(value?.toString())\n }, true)\n return args\n}\n","import { LibCamera } from './options'\nimport { run, cmd, convertOptionsToCmdArgs } from './utils'\n\nfunction runLibCamera(\n bin: string = 'libcamera-still',\n options: Partial<LibCamera.OptionsObject>\n) {\n const args = convertOptionsToCmdArgs(options)\n const command = cmd(bin, args)\n if (process.env.NODE_ENV === 'test') {\n console.log(command)\n return command\n }\n return run(command)\n}\n\nexport function jpeg(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-jpeg', options)\n}\n\nexport function still(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-still', options)\n}\n\nexport function vid(options: Partial<LibCamera.OptionsObject>) {\n return runLibCamera('libcamera-vid', options)\n}\n"],"names":["optionConverterMap","preview","val","x","y","width","height","cmd","base","args","join","run","command","options","Promise","resolve","reject","exec","error","stdout","stderr","convertOptionsToCmdArgs","Object","entries","forEach","key","converter","value","push","toString","runLibCamera","bin","process","env","NODE_ENV","console","log","jpeg","still","vid"],"mappings":";;AA6IO,IAAMA,kBAAkB,GAG1B;AACHC,EAAAA,OADG,mBACKC,GADL;AAED,WAAUA,GAAG,CAACC,CAAd,SAAmBD,GAAG,CAACE,CAAvB,SAA4BF,GAAG,CAACG,KAAhC,SAAyCH,GAAG,CAACI,MAA7C;AACD;AAHE,CAHE;;SC1ISC,IAAIC,MAAcC;AAChC,MAAID,IAAI,IAAI,CAACC,IAAb,EAAmB,OAAOD,IAAP;AACnB,SAAUA,IAAV,UAAkBC,IAAlB,oBAAkBA,IAAI,CAAEC,IAAN,CAAW,GAAX,CAAlB;AACD;AAED,SAAgBC,IAAIC,SAAiBC;AACnC,SAAO,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV;AACjBC,IAAAA,IAAI,CAACL,OAAD,EAAUC,OAAV,EAAmB,UAACK,KAAD,EAAQC,MAAR,EAAgBC,MAAhB;AACrB,UAAIA,MAAM,IAAIF,KAAd,EAAqBF,MAAM,CAACI,MAAM,IAAIF,KAAX,CAAN;AACrBH,MAAAA,OAAO,CAACI,MAAD,CAAP;AACD,KAHG,CAAJ;AAID,GALM,CAAP;AAMD;AAED,SAAgBE,wBACdR;AAEA,MAAMJ,IAAI,GAAa,EAAvB;AACAa,EAAAA,MAAM,CAACC,OAAP,CAAeV,OAAf,EAAwBW,OAAxB,CAAgC;QAAEC;QAAKvB;AACrC,QAAMwB,SAAS,GAAG1B,kBAAkB,CAACyB,GAAD,CAApC;AACA,QAAME,KAAK,GAAG,OAAOD,SAAP,KAAqB,UAArB,GAAkCA,SAAS,CAACxB,GAAD,CAA3C,GAAmDA,GAAjE;AACA,QAAIyB,KAAJ,EAAWlB,IAAI,CAACmB,IAAL,QAAeH,GAAf;AACX,QAAIE,KAAK,KAAK,IAAV,IAAkBA,KAAlB,YAAkBA,KAAK,CAAEE,QAAP,EAAtB,EAAyCpB,IAAI,CAACmB,IAAL,CAAUD,KAAV,oBAAUA,KAAK,CAAEE,QAAP,EAAV;AAC1C,GALD,EAKG,IALH;AAMA,SAAOpB,IAAP;AACD;;ACzBD,SAASqB,YAAT,CACEC,GADF,EAEElB,OAFF;MACEkB;AAAAA,IAAAA,MAAc;;;AAGd,MAAMtB,IAAI,GAAGY,uBAAuB,CAACR,OAAD,CAApC;AACA,MAAMD,OAAO,GAAGL,GAAG,CAACwB,GAAD,EAAMtB,IAAN,CAAnB;;AACA,MAAIuB,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,MAA7B,EAAqC;AACnCC,IAAAA,OAAO,CAACC,GAAR,CAAYxB,OAAZ;AACA,WAAOA,OAAP;AACD;;AACD,SAAOD,GAAG,CAACC,OAAD,CAAV;AACD;;AAED,SAAgByB,KAAKxB;AACnB,SAAOiB,YAAY,CAAC,gBAAD,EAAmBjB,OAAnB,CAAnB;AACD;AAED,SAAgByB,MAAMzB;AACpB,SAAOiB,YAAY,CAAC,iBAAD,EAAoBjB,OAApB,CAAnB;AACD;AAED,SAAgB0B,IAAI1B;AAClB,SAAOiB,YAAY,CAAC,eAAD,EAAkBjB,OAAlB,CAAnB;AACD;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-libcamera",
3
3
  "author": "Hussain Abbas",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "typings": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -7,7 +7,7 @@ function runLibCamera(
7
7
  ) {
8
8
  const args = convertOptionsToCmdArgs(options)
9
9
  const command = cmd(bin, args)
10
- if (__DEV__) {
10
+ if (process.env.NODE_ENV === 'test') {
11
11
  console.log(command)
12
12
  return command
13
13
  }