nbis-wrapper-js 0.0.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +50 -0
  2. package/dist/src/an2ktool.d.ts +12 -0
  3. package/dist/src/an2ktool.js +40 -0
  4. package/dist/src/bozorth3.d.ts +16 -0
  5. package/dist/src/bozorth3.js +152 -2
  6. package/dist/src/chkan2k.d.ts +2 -0
  7. package/dist/src/chkan2k.js +30 -0
  8. package/dist/src/cjp2k.d.ts +10 -0
  9. package/dist/src/cjp2k.js +51 -0
  10. package/dist/src/cjpeg.d.ts +8 -0
  11. package/dist/src/cjpeg.js +61 -0
  12. package/dist/src/cjpegb.d.ts +8 -0
  13. package/dist/src/cjpegb.js +25 -0
  14. package/dist/src/cjpegl.d.ts +8 -0
  15. package/dist/src/cjpegl.js +28 -0
  16. package/dist/src/cwsq.d.ts +8 -0
  17. package/dist/src/cwsq.js +22 -0
  18. package/dist/src/datainfo.d.ts +2 -0
  19. package/dist/src/datainfo.js +12 -0
  20. package/dist/src/djp2k.d.ts +10 -0
  21. package/dist/src/djp2k.js +52 -0
  22. package/dist/src/djpeg.d.ts +8 -0
  23. package/dist/src/djpeg.js +64 -0
  24. package/dist/src/djpegb.d.ts +9 -0
  25. package/dist/src/djpegb.js +26 -0
  26. package/dist/src/djpegl.d.ts +9 -0
  27. package/dist/src/djpegl.js +26 -0
  28. package/dist/src/dwsq.d.ts +9 -0
  29. package/dist/src/dwsq.js +23 -0
  30. package/dist/src/image-convert.d.ts +17 -0
  31. package/dist/src/image-convert.js +118 -0
  32. package/dist/src/intr2not.d.ts +8 -0
  33. package/dist/src/intr2not.js +22 -0
  34. package/dist/src/jpegtran.d.ts +8 -0
  35. package/dist/src/jpegtran.js +82 -0
  36. package/dist/src/mindtct.d.ts +18 -0
  37. package/dist/src/mindtct.js +80 -25
  38. package/dist/src/nfiq.d.ts +14 -0
  39. package/dist/src/nfiq.js +71 -21
  40. package/dist/src/not2intr.d.ts +13 -0
  41. package/dist/src/not2intr.js +22 -0
  42. package/dist/src/rdjpgcom.d.ts +3 -0
  43. package/dist/src/rdjpgcom.js +17 -0
  44. package/dist/src/rdwsqcom.d.ts +2 -0
  45. package/dist/src/rdwsqcom.js +12 -0
  46. package/dist/src/rgb2ycc.d.ts +8 -0
  47. package/dist/src/rgb2ycc.js +25 -0
  48. package/dist/src/temp-io.d.ts +15 -0
  49. package/dist/src/temp-io.js +102 -0
  50. package/dist/src/wrjpgcom.d.ts +7 -0
  51. package/dist/src/wrjpgcom.js +26 -0
  52. package/dist/src/wrwsqcom.d.ts +8 -0
  53. package/dist/src/wrwsqcom.js +21 -0
  54. package/dist/src/ycc2rgb.d.ts +13 -0
  55. package/dist/src/ycc2rgb.js +25 -0
  56. package/package.json +5 -1
package/README.md CHANGED
@@ -37,6 +37,56 @@ const score = nfiq.score('sample.wsq');
37
37
  console.log(score.scores);
38
38
  ```
39
39
 
40
+ ## Stream IO (optional)
41
+
42
+ For file-based commands, async `*Stream` methods accept a stream or buffer and use
43
+ temporary files under the hood. Outputs can be returned as a buffer or piped to a
44
+ stream.
45
+
46
+ Most wrappers that take file paths now have `*Stream` counterparts. Commands with
47
+ multiple outputs (e.g., `mindtct`) return an `outputBuffers` map unless you provide
48
+ per-output streams. `mindtct.detectStream` only returns buffers when `outputToBuffer`
49
+ is set.
50
+
51
+ Stream inputs also accept `inputName`/`inputExtension` (for tools that infer format
52
+ from filenames). For `Bozorth3`, you can pass `{ input, label }` to keep stable
53
+ `probe`/`gallery` identifiers in results.
54
+
55
+ ## Image Auto-Convert (default on)
56
+
57
+ `Mindtct` and `Nfiq` can auto-convert PNG/JPEG inputs into WSQ before invoking NBIS.
58
+ This is enabled by default and can be disabled via the constructor.
59
+
60
+ ```ts
61
+ import { Mindtct } from 'nbis-wrapper-js';
62
+
63
+ const mindtct = new Mindtct({ autoConvert: false });
64
+
65
+ // Or tune WSQ conversion:
66
+ const tuned = new Mindtct({
67
+ autoConvert: { wsqBitrate: 0.75, ppi: 500 }
68
+ });
69
+ ```
70
+
71
+ ```ts
72
+ import fs from 'fs';
73
+ import { Cwsq } from 'nbis-wrapper-js';
74
+
75
+ const cwsq = new Cwsq();
76
+ const inputStream = fs.createReadStream('sample.raw');
77
+
78
+ const result = await cwsq.compressStream(0.75, 'wsq', inputStream, {
79
+ rawIn: { width: 500, height: 500, depth: 8 },
80
+ output: fs.createWriteStream('out.wsq')
81
+ });
82
+
83
+ // Or return a buffer instead of piping:
84
+ const { outputBuffer } = await cwsq.compressStream(0.75, 'wsq', inputStream, {
85
+ rawIn: { width: 500, height: 500, depth: 8 },
86
+ outputToBuffer: true
87
+ });
88
+ ```
89
+
40
90
  ## API Overview
41
91
 
42
92
  ### Fingerprint
@@ -1,7 +1,12 @@
1
+ import type { StreamInput, StreamIoOptions } from './temp-io';
1
2
  export type An2kToolResult = {
2
3
  stdout: string;
3
4
  stderr: string;
4
5
  };
6
+ export type An2kToolStreamResult = An2kToolResult & {
7
+ outputBuffer?: Buffer;
8
+ };
9
+ export type An2kToolStreamOptions = StreamIoOptions;
5
10
  export declare class An2kTool {
6
11
  version(): string;
7
12
  printAll(fileIn: string, fileOut?: string): An2kToolResult;
@@ -11,4 +16,11 @@ export declare class An2kTool {
11
16
  substituteFormatted(selection: string, fmtFile: string, fileIn: string, fileOut?: string): An2kToolResult;
12
17
  insertValue(selection: string, newValue: string, fileIn: string, fileOut?: string): An2kToolResult;
13
18
  insertFormatted(selection: string, fmtFile: string, fileIn: string, fileOut?: string): An2kToolResult;
19
+ printAllStream(input: StreamInput, options?: An2kToolStreamOptions): Promise<An2kToolStreamResult>;
20
+ printSelectionStream(selection: string, input: StreamInput, options?: An2kToolStreamOptions): Promise<An2kToolStreamResult>;
21
+ deleteSelectionStream(selection: string, input: StreamInput, options?: An2kToolStreamOptions): Promise<An2kToolStreamResult>;
22
+ substituteValueStream(selection: string, newValue: string, input: StreamInput, options?: An2kToolStreamOptions): Promise<An2kToolStreamResult>;
23
+ substituteFormattedStream(selection: string, fmtFile: string, input: StreamInput, options?: An2kToolStreamOptions): Promise<An2kToolStreamResult>;
24
+ insertValueStream(selection: string, newValue: string, input: StreamInput, options?: An2kToolStreamOptions): Promise<An2kToolStreamResult>;
25
+ insertFormattedStream(selection: string, fmtFile: string, input: StreamInput, options?: An2kToolStreamOptions): Promise<An2kToolStreamResult>;
14
26
  }
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.An2kTool = void 0;
7
+ const path_1 = __importDefault(require("path"));
4
8
  const nbis_runtime_1 = require("./nbis-runtime");
9
+ const temp_io_1 = require("./temp-io");
5
10
  function runAn2kTool(args, context) {
6
11
  const result = (0, nbis_runtime_1.runNbis)('an2ktool', args);
7
12
  (0, nbis_runtime_1.assertSuccess)(result, context);
@@ -17,6 +22,20 @@ function buildFileArgs(fileIn, fileOut) {
17
22
  }
18
23
  return args;
19
24
  }
25
+ async function runAn2kToolStream(argsBuilder, context, input, options = {}) {
26
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
27
+ const fileIn = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
28
+ const fileOut = path_1.default.join(tempDir, 'output.an2k');
29
+ const result = (0, nbis_runtime_1.runNbis)('an2ktool', argsBuilder(fileIn, fileOut));
30
+ (0, nbis_runtime_1.assertSuccess)(result, context);
31
+ const outputBuffer = await (0, temp_io_1.deliverTempOutput)(fileOut, options);
32
+ return {
33
+ stdout: result.stdout,
34
+ stderr: result.stderr,
35
+ outputBuffer
36
+ };
37
+ });
38
+ }
20
39
  class An2kTool {
21
40
  version() {
22
41
  const result = (0, nbis_runtime_1.runNbis)('an2ktool', ['-version']);
@@ -44,5 +63,26 @@ class An2kTool {
44
63
  insertFormatted(selection, fmtFile, fileIn, fileOut) {
45
64
  return runAn2kTool(['-insert', selection, fmtFile, ...buildFileArgs(fileIn, fileOut)], 'an2ktool insert');
46
65
  }
66
+ printAllStream(input, options = {}) {
67
+ return runAn2kToolStream((fileIn, fileOut) => ['-print', 'all', ...buildFileArgs(fileIn, fileOut)], 'an2ktool print', input, options);
68
+ }
69
+ printSelectionStream(selection, input, options = {}) {
70
+ return runAn2kToolStream((fileIn, fileOut) => ['-print', selection, ...buildFileArgs(fileIn, fileOut)], 'an2ktool print', input, options);
71
+ }
72
+ deleteSelectionStream(selection, input, options = {}) {
73
+ return runAn2kToolStream((fileIn, fileOut) => ['-delete', selection, ...buildFileArgs(fileIn, fileOut)], 'an2ktool delete', input, options);
74
+ }
75
+ substituteValueStream(selection, newValue, input, options = {}) {
76
+ return runAn2kToolStream((fileIn, fileOut) => ['-substitute', selection, newValue, ...buildFileArgs(fileIn, fileOut)], 'an2ktool substitute', input, options);
77
+ }
78
+ substituteFormattedStream(selection, fmtFile, input, options = {}) {
79
+ return runAn2kToolStream((fileIn, fileOut) => ['-substitute', selection, fmtFile, ...buildFileArgs(fileIn, fileOut)], 'an2ktool substitute', input, options);
80
+ }
81
+ insertValueStream(selection, newValue, input, options = {}) {
82
+ return runAn2kToolStream((fileIn, fileOut) => ['-insert', selection, newValue, ...buildFileArgs(fileIn, fileOut)], 'an2ktool insert', input, options);
83
+ }
84
+ insertFormattedStream(selection, fmtFile, input, options = {}) {
85
+ return runAn2kToolStream((fileIn, fileOut) => ['-insert', selection, fmtFile, ...buildFileArgs(fileIn, fileOut)], 'an2ktool insert', input, options);
86
+ }
47
87
  }
48
88
  exports.An2kTool = An2kTool;
@@ -1,3 +1,4 @@
1
+ import type { StreamInput } from './temp-io';
1
2
  export type BozorthOptions = {
2
3
  m1?: boolean;
3
4
  maxMinutiae?: number;
@@ -28,6 +29,10 @@ export type BozorthResult = {
28
29
  stdout: string;
29
30
  stderr: string;
30
31
  };
32
+ export type BozorthStreamInput = StreamInput | {
33
+ input: StreamInput;
34
+ label?: string;
35
+ };
31
36
  export declare class Bozorth3 {
32
37
  version(): string;
33
38
  matchPair(probeFile: string, galleryFile: string, options?: BozorthOptions): BozorthResult;
@@ -38,6 +43,17 @@ export declare class Bozorth3 {
38
43
  matchWithFixedProbeList(probeFile: string, galleryListFile: string, options?: BozorthOptions): BozorthResult;
39
44
  matchWithFixedGallery(galleryFile: string, probeFiles?: string[], options?: BozorthOptions): BozorthResult;
40
45
  matchWithFixedGalleryList(galleryFile: string, probeListFile: string, options?: BozorthOptions): BozorthResult;
46
+ matchPairStream(probeInput: BozorthStreamInput, galleryInput: BozorthStreamInput, options?: BozorthOptions): Promise<BozorthResult>;
47
+ matchMatesListStream(mates: Array<{
48
+ probe: BozorthStreamInput;
49
+ gallery: BozorthStreamInput;
50
+ }>, options?: BozorthOptions): Promise<BozorthResult>;
51
+ matchProbeListStream(probeInputs: BozorthStreamInput[], galleryInputs?: BozorthStreamInput[], options?: BozorthOptions): Promise<BozorthResult>;
52
+ matchGalleryListStream(galleryInputs: BozorthStreamInput[], probeInputs?: BozorthStreamInput[], options?: BozorthOptions): Promise<BozorthResult>;
53
+ matchWithFixedProbeStream(probeInput: BozorthStreamInput, galleryInputs?: BozorthStreamInput[], options?: BozorthOptions): Promise<BozorthResult>;
54
+ matchWithFixedProbeListStream(probeInput: BozorthStreamInput, galleryInputs: BozorthStreamInput[], options?: BozorthOptions): Promise<BozorthResult>;
55
+ matchWithFixedGalleryStream(galleryInput: BozorthStreamInput, probeInputs?: BozorthStreamInput[], options?: BozorthOptions): Promise<BozorthResult>;
56
+ matchWithFixedGalleryListStream(galleryInput: BozorthStreamInput, probeInputs: BozorthStreamInput[], options?: BozorthOptions): Promise<BozorthResult>;
41
57
  private withDefaultFormat;
42
58
  private runMatch;
43
59
  }
@@ -1,7 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Bozorth3 = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
4
9
  const nbis_runtime_1 = require("./nbis-runtime");
10
+ const temp_io_1 = require("./temp-io");
5
11
  function buildBozorthArgs(options = {}) {
6
12
  const args = [];
7
13
  if (options.m1) {
@@ -92,6 +98,45 @@ function parseBozorthOutput(output, outFormat) {
92
98
  return entry;
93
99
  });
94
100
  }
101
+ function normalizeStreamInput(entry) {
102
+ if (typeof entry === 'object' && entry != null && 'input' in entry) {
103
+ return entry;
104
+ }
105
+ return { input: entry };
106
+ }
107
+ function applyLabelMap(results, labelMap) {
108
+ if (!labelMap || labelMap.size === 0) {
109
+ return results;
110
+ }
111
+ return results.map((result) => {
112
+ const updated = { ...result };
113
+ if (updated.probe && labelMap.has(updated.probe)) {
114
+ updated.probe = labelMap.get(updated.probe);
115
+ }
116
+ if (updated.gallery && labelMap.has(updated.gallery)) {
117
+ updated.gallery = labelMap.get(updated.gallery);
118
+ }
119
+ return updated;
120
+ });
121
+ }
122
+ async function writeInputFiles(tempDir, inputs, prefix, labelMap) {
123
+ const paths = [];
124
+ for (let i = 0; i < inputs.length; i += 1) {
125
+ const { input, label } = normalizeStreamInput(inputs[i]);
126
+ const filePath = await (0, temp_io_1.writeTempInput)(tempDir, input, `${prefix}-${i}.xyt`);
127
+ if (label) {
128
+ labelMap.set(filePath, label);
129
+ }
130
+ paths.push(filePath);
131
+ }
132
+ return paths;
133
+ }
134
+ async function writeListFile(tempDir, name, lines) {
135
+ const listPath = path_1.default.join(tempDir, name);
136
+ const content = lines.length ? `${lines.join('\n')}\n` : '';
137
+ await fs_1.default.promises.writeFile(listPath, content);
138
+ return listPath;
139
+ }
95
140
  class Bozorth3 {
96
141
  version() {
97
142
  const result = (0, nbis_runtime_1.runNbis)('bozorth3', ['-version']);
@@ -122,6 +167,111 @@ class Bozorth3 {
122
167
  matchWithFixedGalleryList(galleryFile, probeListFile, options = {}) {
123
168
  return this.runMatch([...buildBozorthArgs(this.withDefaultFormat(options)), '-g', galleryFile, '-P', probeListFile], options);
124
169
  }
170
+ async matchPairStream(probeInput, galleryInput, options = {}) {
171
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
172
+ const labelMap = new Map();
173
+ const probeEntry = normalizeStreamInput(probeInput);
174
+ const galleryEntry = normalizeStreamInput(galleryInput);
175
+ const probeFile = await (0, temp_io_1.writeTempInput)(tempDir, probeEntry.input, 'probe.xyt');
176
+ const galleryFile = await (0, temp_io_1.writeTempInput)(tempDir, galleryEntry.input, 'gallery.xyt');
177
+ if (probeEntry.label) {
178
+ labelMap.set(probeFile, probeEntry.label);
179
+ }
180
+ if (galleryEntry.label) {
181
+ labelMap.set(galleryFile, galleryEntry.label);
182
+ }
183
+ return this.runMatch([...buildBozorthArgs(this.withDefaultFormat(options)), probeFile, galleryFile], options, labelMap);
184
+ });
185
+ }
186
+ async matchMatesListStream(mates, options = {}) {
187
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
188
+ const labelMap = new Map();
189
+ const lines = [];
190
+ for (let i = 0; i < mates.length; i += 1) {
191
+ const probeEntry = normalizeStreamInput(mates[i].probe);
192
+ const galleryEntry = normalizeStreamInput(mates[i].gallery);
193
+ const probeFile = await (0, temp_io_1.writeTempInput)(tempDir, probeEntry.input, `probe-${i}.xyt`);
194
+ const galleryFile = await (0, temp_io_1.writeTempInput)(tempDir, galleryEntry.input, `gallery-${i}.xyt`);
195
+ if (probeEntry.label) {
196
+ labelMap.set(probeFile, probeEntry.label);
197
+ }
198
+ if (galleryEntry.label) {
199
+ labelMap.set(galleryFile, galleryEntry.label);
200
+ }
201
+ lines.push(probeFile, galleryFile);
202
+ }
203
+ const matesListFile = await writeListFile(tempDir, 'mates.lis', lines);
204
+ return this.runMatch([...buildBozorthArgs(this.withDefaultFormat(options)), '-M', matesListFile], options, labelMap);
205
+ });
206
+ }
207
+ async matchProbeListStream(probeInputs, galleryInputs = [], options = {}) {
208
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
209
+ const labelMap = new Map();
210
+ const probeFiles = await writeInputFiles(tempDir, probeInputs, 'probe', labelMap);
211
+ const galleryFiles = await writeInputFiles(tempDir, galleryInputs, 'gallery', labelMap);
212
+ const probeListFile = await writeListFile(tempDir, 'probe.lis', probeFiles);
213
+ return this.runMatch([...buildBozorthArgs(this.withDefaultFormat(options)), '-P', probeListFile, ...galleryFiles], options, labelMap);
214
+ });
215
+ }
216
+ async matchGalleryListStream(galleryInputs, probeInputs = [], options = {}) {
217
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
218
+ const labelMap = new Map();
219
+ const galleryFiles = await writeInputFiles(tempDir, galleryInputs, 'gallery', labelMap);
220
+ const probeFiles = await writeInputFiles(tempDir, probeInputs, 'probe', labelMap);
221
+ const galleryListFile = await writeListFile(tempDir, 'gallery.lis', galleryFiles);
222
+ return this.runMatch([...buildBozorthArgs(this.withDefaultFormat(options)), '-G', galleryListFile, ...probeFiles], options, labelMap);
223
+ });
224
+ }
225
+ async matchWithFixedProbeStream(probeInput, galleryInputs = [], options = {}) {
226
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
227
+ const labelMap = new Map();
228
+ const probeEntry = normalizeStreamInput(probeInput);
229
+ const probeFile = await (0, temp_io_1.writeTempInput)(tempDir, probeEntry.input, 'probe.xyt');
230
+ if (probeEntry.label) {
231
+ labelMap.set(probeFile, probeEntry.label);
232
+ }
233
+ const galleryFiles = await writeInputFiles(tempDir, galleryInputs, 'gallery', labelMap);
234
+ return this.runMatch([...buildBozorthArgs(this.withDefaultFormat(options)), '-p', probeFile, ...galleryFiles], options, labelMap);
235
+ });
236
+ }
237
+ async matchWithFixedProbeListStream(probeInput, galleryInputs, options = {}) {
238
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
239
+ const labelMap = new Map();
240
+ const probeEntry = normalizeStreamInput(probeInput);
241
+ const probeFile = await (0, temp_io_1.writeTempInput)(tempDir, probeEntry.input, 'probe.xyt');
242
+ if (probeEntry.label) {
243
+ labelMap.set(probeFile, probeEntry.label);
244
+ }
245
+ const galleryFiles = await writeInputFiles(tempDir, galleryInputs, 'gallery', labelMap);
246
+ const galleryListFile = await writeListFile(tempDir, 'gallery.lis', galleryFiles);
247
+ return this.runMatch([...buildBozorthArgs(this.withDefaultFormat(options)), '-p', probeFile, '-G', galleryListFile], options, labelMap);
248
+ });
249
+ }
250
+ async matchWithFixedGalleryStream(galleryInput, probeInputs = [], options = {}) {
251
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
252
+ const labelMap = new Map();
253
+ const galleryEntry = normalizeStreamInput(galleryInput);
254
+ const galleryFile = await (0, temp_io_1.writeTempInput)(tempDir, galleryEntry.input, 'gallery.xyt');
255
+ if (galleryEntry.label) {
256
+ labelMap.set(galleryFile, galleryEntry.label);
257
+ }
258
+ const probeFiles = await writeInputFiles(tempDir, probeInputs, 'probe', labelMap);
259
+ return this.runMatch([...buildBozorthArgs(this.withDefaultFormat(options)), '-g', galleryFile, ...probeFiles], options, labelMap);
260
+ });
261
+ }
262
+ async matchWithFixedGalleryListStream(galleryInput, probeInputs, options = {}) {
263
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
264
+ const labelMap = new Map();
265
+ const galleryEntry = normalizeStreamInput(galleryInput);
266
+ const galleryFile = await (0, temp_io_1.writeTempInput)(tempDir, galleryEntry.input, 'gallery.xyt');
267
+ if (galleryEntry.label) {
268
+ labelMap.set(galleryFile, galleryEntry.label);
269
+ }
270
+ const probeFiles = await writeInputFiles(tempDir, probeInputs, 'probe', labelMap);
271
+ const probeListFile = await writeListFile(tempDir, 'probe.lis', probeFiles);
272
+ return this.runMatch([...buildBozorthArgs(this.withDefaultFormat(options)), '-g', galleryFile, '-P', probeListFile], options, labelMap);
273
+ });
274
+ }
125
275
  withDefaultFormat(options) {
126
276
  if (options.outFormat) {
127
277
  return options;
@@ -131,12 +281,12 @@ class Bozorth3 {
131
281
  outFormat: 'spg'
132
282
  };
133
283
  }
134
- runMatch(args, options) {
284
+ runMatch(args, options, labelMap) {
135
285
  const result = (0, nbis_runtime_1.runNbis)('bozorth3', args);
136
286
  (0, nbis_runtime_1.assertSuccess)(result, 'bozorth3');
137
287
  const format = options.outFormat || 'spg';
138
288
  return {
139
- results: parseBozorthOutput(result.stdout, format),
289
+ results: applyLabelMap(parseBozorthOutput(result.stdout, format), labelMap),
140
290
  stdout: result.stdout,
141
291
  stderr: result.stderr
142
292
  };
@@ -1,3 +1,4 @@
1
+ import type { StreamInput } from './temp-io';
1
2
  export type Chkan2kOptions = {
2
3
  baseConfigFile?: string;
3
4
  extraConfigFiles?: string[];
@@ -11,4 +12,5 @@ export type Chkan2kResult = {
11
12
  export declare class Chkan2k {
12
13
  version(): string;
13
14
  check(files: string[], options?: Chkan2kOptions): Chkan2kResult;
15
+ checkStream(inputs: StreamInput[], options?: Chkan2kOptions): Promise<Chkan2kResult>;
14
16
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Chkan2k = void 0;
4
4
  const nbis_runtime_1 = require("./nbis-runtime");
5
+ const temp_io_1 = require("./temp-io");
5
6
  class Chkan2k {
6
7
  version() {
7
8
  const result = (0, nbis_runtime_1.runNbis)('chkan2k', ['-version']);
@@ -30,5 +31,34 @@ class Chkan2k {
30
31
  stderr: result.stderr
31
32
  };
32
33
  }
34
+ async checkStream(inputs, options = {}) {
35
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
36
+ const files = [];
37
+ for (let i = 0; i < inputs.length; i += 1) {
38
+ const filePath = await (0, temp_io_1.writeTempInput)(tempDir, inputs[i], `input-${i}.an2k`);
39
+ files.push(filePath);
40
+ }
41
+ const args = [];
42
+ if (options.baseConfigFile) {
43
+ args.push('-b', options.baseConfigFile);
44
+ }
45
+ if (options.extraConfigFiles) {
46
+ options.extraConfigFiles.forEach((file) => args.push('-c', file));
47
+ }
48
+ if (options.logLevel) {
49
+ args.push('-l', options.logLevel);
50
+ }
51
+ if (options.help) {
52
+ args.push('-h');
53
+ }
54
+ args.push(...files);
55
+ const result = (0, nbis_runtime_1.runNbis)('chkan2k', args);
56
+ (0, nbis_runtime_1.assertSuccess)(result, 'chkan2k');
57
+ return {
58
+ stdout: result.stdout,
59
+ stderr: result.stderr
60
+ };
61
+ });
62
+ }
33
63
  }
34
64
  exports.Chkan2k = Chkan2k;
@@ -1,3 +1,4 @@
1
+ import type { StreamInput, StreamIoOptions } from './temp-io';
1
2
  export type Cjp2kOptions = {
2
3
  inputPath?: string;
3
4
  outputPath?: string;
@@ -15,7 +16,16 @@ export type Cjp2kResult = {
15
16
  stdout: string;
16
17
  stderr: string;
17
18
  };
19
+ export type Cjp2kStreamOptions = Omit<Cjp2kOptions, 'inputPath' | 'outputPath' | 'imageDir'> & StreamIoOptions & {
20
+ outputExtension?: string;
21
+ };
22
+ export type Cjp2kStreamResult = {
23
+ stdout: string;
24
+ stderr: string;
25
+ outputBuffer?: Buffer;
26
+ };
18
27
  export declare class Cjp2k {
19
28
  version(): string;
20
29
  compress(options: Cjp2kOptions): Cjp2kResult;
30
+ compressStream(input: StreamInput, options?: Cjp2kStreamOptions): Promise<Cjp2kStreamResult>;
21
31
  }
package/dist/src/cjp2k.js CHANGED
@@ -1,7 +1,18 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Cjp2k = void 0;
7
+ const path_1 = __importDefault(require("path"));
4
8
  const nbis_runtime_1 = require("./nbis-runtime");
9
+ const temp_io_1 = require("./temp-io");
10
+ function normalizeExtension(extension) {
11
+ if (!extension) {
12
+ return '';
13
+ }
14
+ return extension.startsWith('.') ? extension : `.${extension}`;
15
+ }
5
16
  class Cjp2k {
6
17
  version() {
7
18
  const result = (0, nbis_runtime_1.runNbis)('cjp2k', ['-version']);
@@ -50,5 +61,45 @@ class Cjp2k {
50
61
  stderr: result.stderr
51
62
  };
52
63
  }
64
+ async compressStream(input, options = {}) {
65
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
66
+ const inputPath = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
67
+ const extension = normalizeExtension(options.outputExtension || 'jp2');
68
+ const outputPath = path_1.default.join(tempDir, `output${extension}`);
69
+ const args = ['-i', inputPath, '-o', outputPath];
70
+ if (options.outputFormat) {
71
+ args.push('-OutFor', options.outputFormat);
72
+ }
73
+ if (options.rawFormat) {
74
+ args.push('-F', options.rawFormat);
75
+ }
76
+ if (options.nistLossy) {
77
+ args.push('-NIST-fingerprint-lossy');
78
+ }
79
+ if (options.nistLossless) {
80
+ args.push('-NIST-fingerprint-lossless');
81
+ }
82
+ if (options.compressionRatios && options.compressionRatios.length) {
83
+ args.push('-r', options.compressionRatios.join(','));
84
+ }
85
+ if (options.psnr && options.psnr.length) {
86
+ args.push('-q', options.psnr.join(','));
87
+ }
88
+ if (options.ppi != null) {
89
+ args.push('-PPI', String(options.ppi));
90
+ }
91
+ if (options.extraArgs) {
92
+ args.push(...options.extraArgs);
93
+ }
94
+ const result = (0, nbis_runtime_1.runNbis)('cjp2k', args);
95
+ (0, nbis_runtime_1.assertSuccess)(result, 'cjp2k');
96
+ const outputBuffer = await (0, temp_io_1.deliverTempOutput)(outputPath, options);
97
+ return {
98
+ stdout: result.stdout,
99
+ stderr: result.stderr,
100
+ outputBuffer
101
+ };
102
+ });
103
+ }
53
104
  }
54
105
  exports.Cjp2k = Cjp2k;
@@ -1,3 +1,4 @@
1
+ import type { StreamInput, StreamIoOptions } from './temp-io';
1
2
  export type CjpegOptions = {
2
3
  quality?: number;
3
4
  grayscale?: boolean;
@@ -19,6 +20,13 @@ export type CjpegResult = {
19
20
  stderr: string;
20
21
  outputPath?: string;
21
22
  };
23
+ export type CjpegStreamOptions = Omit<CjpegOptions, 'outputPath'> & StreamIoOptions;
24
+ export type CjpegStreamResult = {
25
+ stdout: string;
26
+ stderr: string;
27
+ outputBuffer?: Buffer;
28
+ };
22
29
  export declare class Cjpeg {
23
30
  compress(inputPath: string, options?: CjpegOptions): CjpegResult;
31
+ compressStream(input: StreamInput, options?: CjpegStreamOptions): Promise<CjpegStreamResult>;
24
32
  }
package/dist/src/cjpeg.js CHANGED
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Cjpeg = void 0;
7
+ const path_1 = __importDefault(require("path"));
4
8
  const nbis_runtime_1 = require("./nbis-runtime");
9
+ const temp_io_1 = require("./temp-io");
5
10
  class Cjpeg {
6
11
  compress(inputPath, options = {}) {
7
12
  const args = [];
@@ -56,5 +61,61 @@ class Cjpeg {
56
61
  outputPath: options.outputPath
57
62
  };
58
63
  }
64
+ async compressStream(input, options = {}) {
65
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
66
+ const inputPath = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
67
+ const outputPath = path_1.default.join(tempDir, 'output.jpg');
68
+ const args = [];
69
+ if (options.quality != null) {
70
+ args.push('-quality', String(options.quality));
71
+ }
72
+ if (options.grayscale) {
73
+ args.push('-grayscale');
74
+ }
75
+ if (options.optimize) {
76
+ args.push('-optimize');
77
+ }
78
+ if (options.progressive) {
79
+ args.push('-progressive');
80
+ }
81
+ if (options.targa) {
82
+ args.push('-targa');
83
+ }
84
+ if (options.dct) {
85
+ args.push('-dct', options.dct);
86
+ }
87
+ if (options.restart != null) {
88
+ args.push('-restart', String(options.restart));
89
+ }
90
+ if (options.smooth != null) {
91
+ args.push('-smooth', String(options.smooth));
92
+ }
93
+ if (options.maxMemory) {
94
+ args.push('-maxmemory', options.maxMemory);
95
+ }
96
+ args.push('-outfile', outputPath);
97
+ if (options.verbose) {
98
+ args.push('-verbose');
99
+ }
100
+ if (options.debug) {
101
+ args.push('-debug');
102
+ }
103
+ if (options.baseline) {
104
+ args.push('-baseline');
105
+ }
106
+ if (options.extraArgs) {
107
+ args.push(...options.extraArgs);
108
+ }
109
+ args.push(inputPath);
110
+ const result = (0, nbis_runtime_1.runNbis)('cjpeg', args);
111
+ (0, nbis_runtime_1.assertSuccess)(result, 'cjpeg');
112
+ const outputBuffer = await (0, temp_io_1.deliverTempOutput)(outputPath, options);
113
+ return {
114
+ stdout: result.stdout,
115
+ stderr: result.stderr,
116
+ outputBuffer
117
+ };
118
+ });
119
+ }
59
120
  }
60
121
  exports.Cjpeg = Cjpeg;
@@ -1,3 +1,4 @@
1
+ import type { StreamInput, StreamIoOptions } from './temp-io';
1
2
  export type CjpegbOptions = {
2
3
  rawIn?: {
3
4
  width: number;
@@ -13,7 +14,14 @@ export type CjpegbResult = {
13
14
  stdout: string;
14
15
  stderr: string;
15
16
  };
17
+ export type CjpegbStreamOptions = CjpegbOptions & StreamIoOptions;
18
+ export type CjpegbStreamResult = {
19
+ stdout: string;
20
+ stderr: string;
21
+ outputBuffer?: Buffer;
22
+ };
16
23
  export declare class Cjpegb {
17
24
  version(): string;
18
25
  compress(quality: number, outputExtension: string, imagePath: string, options?: CjpegbOptions): CjpegbResult;
26
+ compressStream(quality: number, outputExtension: string, input: StreamInput, options?: CjpegbStreamOptions): Promise<CjpegbStreamResult>;
19
27
  }
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Cjpegb = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const nbis_runtime_1 = require("./nbis-runtime");
9
+ const temp_io_1 = require("./temp-io");
9
10
  function buildRawAttr(raw) {
10
11
  const attrs = [raw.width, raw.height, raw.depth];
11
12
  if (raw.ppi != null) {
@@ -43,5 +44,29 @@ class Cjpegb {
43
44
  stderr: result.stderr
44
45
  };
45
46
  }
47
+ async compressStream(quality, outputExtension, input, options = {}) {
48
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
49
+ const inputPath = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
50
+ const args = [String(quality), outputExtension, inputPath];
51
+ if (options.rawIn) {
52
+ args.push('-raw_in', buildRawAttr(options.rawIn));
53
+ }
54
+ if (options.nonInterleaved) {
55
+ args.push('-nonintrlv');
56
+ }
57
+ if (options.commentFile) {
58
+ args.push(options.commentFile);
59
+ }
60
+ const result = (0, nbis_runtime_1.runNbis)('cjpegb', args);
61
+ (0, nbis_runtime_1.assertSuccess)(result, 'cjpegb');
62
+ const outputPath = replaceExtension(inputPath, outputExtension);
63
+ const outputBuffer = await (0, temp_io_1.deliverTempOutput)(outputPath, options);
64
+ return {
65
+ stdout: result.stdout,
66
+ stderr: result.stderr,
67
+ outputBuffer
68
+ };
69
+ });
70
+ }
46
71
  }
47
72
  exports.Cjpegb = Cjpegb;