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.
- package/README.md +50 -0
- package/dist/src/an2ktool.d.ts +12 -0
- package/dist/src/an2ktool.js +40 -0
- package/dist/src/bozorth3.d.ts +16 -0
- package/dist/src/bozorth3.js +152 -2
- package/dist/src/chkan2k.d.ts +2 -0
- package/dist/src/chkan2k.js +30 -0
- package/dist/src/cjp2k.d.ts +10 -0
- package/dist/src/cjp2k.js +51 -0
- package/dist/src/cjpeg.d.ts +8 -0
- package/dist/src/cjpeg.js +61 -0
- package/dist/src/cjpegb.d.ts +8 -0
- package/dist/src/cjpegb.js +25 -0
- package/dist/src/cjpegl.d.ts +8 -0
- package/dist/src/cjpegl.js +28 -0
- package/dist/src/cwsq.d.ts +8 -0
- package/dist/src/cwsq.js +22 -0
- package/dist/src/datainfo.d.ts +2 -0
- package/dist/src/datainfo.js +12 -0
- package/dist/src/djp2k.d.ts +10 -0
- package/dist/src/djp2k.js +52 -0
- package/dist/src/djpeg.d.ts +8 -0
- package/dist/src/djpeg.js +64 -0
- package/dist/src/djpegb.d.ts +9 -0
- package/dist/src/djpegb.js +26 -0
- package/dist/src/djpegl.d.ts +9 -0
- package/dist/src/djpegl.js +26 -0
- package/dist/src/dwsq.d.ts +9 -0
- package/dist/src/dwsq.js +23 -0
- package/dist/src/image-convert.d.ts +17 -0
- package/dist/src/image-convert.js +118 -0
- package/dist/src/intr2not.d.ts +8 -0
- package/dist/src/intr2not.js +22 -0
- package/dist/src/jpegtran.d.ts +8 -0
- package/dist/src/jpegtran.js +82 -0
- package/dist/src/mindtct.d.ts +18 -0
- package/dist/src/mindtct.js +80 -25
- package/dist/src/nfiq.d.ts +14 -0
- package/dist/src/nfiq.js +71 -21
- package/dist/src/not2intr.d.ts +13 -0
- package/dist/src/not2intr.js +22 -0
- package/dist/src/rdjpgcom.d.ts +3 -0
- package/dist/src/rdjpgcom.js +17 -0
- package/dist/src/rdwsqcom.d.ts +2 -0
- package/dist/src/rdwsqcom.js +12 -0
- package/dist/src/rgb2ycc.d.ts +8 -0
- package/dist/src/rgb2ycc.js +25 -0
- package/dist/src/temp-io.d.ts +15 -0
- package/dist/src/temp-io.js +102 -0
- package/dist/src/wrjpgcom.d.ts +7 -0
- package/dist/src/wrjpgcom.js +26 -0
- package/dist/src/wrwsqcom.d.ts +8 -0
- package/dist/src/wrwsqcom.js +21 -0
- package/dist/src/ycc2rgb.d.ts +13 -0
- package/dist/src/ycc2rgb.js +25 -0
- package/package.json +5 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.withTempDir = withTempDir;
|
|
7
|
+
exports.writeTempInput = writeTempInput;
|
|
8
|
+
exports.deliverTempOutput = deliverTempOutput;
|
|
9
|
+
exports.readFileIfExists = readFileIfExists;
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const os_1 = __importDefault(require("os"));
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const stream_1 = require("stream");
|
|
14
|
+
const promises_1 = require("stream/promises");
|
|
15
|
+
function isReadableStream(value) {
|
|
16
|
+
return typeof value.pipe === 'function';
|
|
17
|
+
}
|
|
18
|
+
function normalizeExtension(extension) {
|
|
19
|
+
if (!extension) {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
return extension.startsWith('.') ? extension : `.${extension}`;
|
|
23
|
+
}
|
|
24
|
+
function resolveInputName(input, nameOrOptions) {
|
|
25
|
+
if (!nameOrOptions) {
|
|
26
|
+
if (isReadableStream(input)) {
|
|
27
|
+
const streamPath = input.path;
|
|
28
|
+
if (typeof streamPath === 'string') {
|
|
29
|
+
return path_1.default.basename(streamPath);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return 'input';
|
|
33
|
+
}
|
|
34
|
+
if (typeof nameOrOptions === 'string') {
|
|
35
|
+
return nameOrOptions;
|
|
36
|
+
}
|
|
37
|
+
const extension = normalizeExtension(nameOrOptions.inputExtension);
|
|
38
|
+
if (nameOrOptions.inputName) {
|
|
39
|
+
if (extension && nameOrOptions.inputName.endsWith(extension)) {
|
|
40
|
+
return nameOrOptions.inputName;
|
|
41
|
+
}
|
|
42
|
+
return `${nameOrOptions.inputName}${extension}`;
|
|
43
|
+
}
|
|
44
|
+
if (extension) {
|
|
45
|
+
return `input${extension}`;
|
|
46
|
+
}
|
|
47
|
+
if (isReadableStream(input)) {
|
|
48
|
+
const streamPath = input.path;
|
|
49
|
+
if (typeof streamPath === 'string') {
|
|
50
|
+
return path_1.default.basename(streamPath);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return 'input';
|
|
54
|
+
}
|
|
55
|
+
async function withTempDir(fn) {
|
|
56
|
+
const tempDir = await fs_1.default.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'nbis-'));
|
|
57
|
+
try {
|
|
58
|
+
return await fn(tempDir);
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
await fs_1.default.promises.rm(tempDir, { recursive: true, force: true });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function writeTempInput(tempDir, input, nameOrOptions) {
|
|
65
|
+
const resolvedName = resolveInputName(input, nameOrOptions);
|
|
66
|
+
const safeName = path_1.default.basename(resolvedName) || 'input';
|
|
67
|
+
const inputPath = path_1.default.join(tempDir, safeName);
|
|
68
|
+
if (isReadableStream(input)) {
|
|
69
|
+
await (0, promises_1.pipeline)(input, fs_1.default.createWriteStream(inputPath));
|
|
70
|
+
return inputPath;
|
|
71
|
+
}
|
|
72
|
+
const buffer = Buffer.isBuffer(input) ? input : Buffer.from(input);
|
|
73
|
+
await fs_1.default.promises.writeFile(inputPath, buffer);
|
|
74
|
+
return inputPath;
|
|
75
|
+
}
|
|
76
|
+
async function deliverTempOutput(outputPath, options = {}) {
|
|
77
|
+
if (options.output) {
|
|
78
|
+
if (options.outputToBuffer) {
|
|
79
|
+
const buffer = await fs_1.default.promises.readFile(outputPath);
|
|
80
|
+
await (0, promises_1.pipeline)(stream_1.Readable.from(buffer), options.output);
|
|
81
|
+
return buffer;
|
|
82
|
+
}
|
|
83
|
+
await (0, promises_1.pipeline)(fs_1.default.createReadStream(outputPath), options.output);
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
if (options.outputToBuffer === false) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
return fs_1.default.promises.readFile(outputPath);
|
|
90
|
+
}
|
|
91
|
+
async function readFileIfExists(filePath) {
|
|
92
|
+
try {
|
|
93
|
+
return await fs_1.default.promises.readFile(filePath);
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
const code = err.code;
|
|
97
|
+
if (code === 'ENOENT') {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
}
|
package/dist/src/wrjpgcom.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StreamInput, StreamIoOptions } from './temp-io';
|
|
1
2
|
export type WrjpgcomOptions = {
|
|
2
3
|
replace?: boolean;
|
|
3
4
|
commentFile: string;
|
|
@@ -14,7 +15,13 @@ export type WrjpgcomResult = {
|
|
|
14
15
|
outputPath?: string;
|
|
15
16
|
stderr: string;
|
|
16
17
|
};
|
|
18
|
+
export type WrjpgcomStreamOptions = Omit<WrjpgcomOptions, 'outputPath'> & StreamIoOptions;
|
|
19
|
+
export type WrjpgcomStreamResult = {
|
|
20
|
+
outputBuffer?: Buffer;
|
|
21
|
+
stderr: string;
|
|
22
|
+
};
|
|
17
23
|
export declare class Wrjpgcom {
|
|
18
24
|
version(): string;
|
|
19
25
|
write(imagePath: string, options: WrjpgcomOptions): WrjpgcomResult;
|
|
26
|
+
writeStream(input: StreamInput, options: WrjpgcomStreamOptions): Promise<WrjpgcomStreamResult>;
|
|
20
27
|
}
|
package/dist/src/wrjpgcom.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.Wrjpgcom = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const nbis_runtime_1 = require("./nbis-runtime");
|
|
9
|
+
const temp_io_1 = require("./temp-io");
|
|
9
10
|
class Wrjpgcom {
|
|
10
11
|
version() {
|
|
11
12
|
const result = (0, nbis_runtime_1.runNbisBinary)('wrjpgcom', ['-version']);
|
|
@@ -37,5 +38,30 @@ class Wrjpgcom {
|
|
|
37
38
|
stderr: result.stderr.toString('utf8')
|
|
38
39
|
};
|
|
39
40
|
}
|
|
41
|
+
async writeStream(input, options) {
|
|
42
|
+
return (0, temp_io_1.withTempDir)(async (tempDir) => {
|
|
43
|
+
const imagePath = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
|
|
44
|
+
const args = [];
|
|
45
|
+
if (options.replace) {
|
|
46
|
+
args.push('-replace');
|
|
47
|
+
}
|
|
48
|
+
if (options.commentFile) {
|
|
49
|
+
args.push('-cfile', options.commentFile);
|
|
50
|
+
}
|
|
51
|
+
if (options.commentText) {
|
|
52
|
+
args.push('-comment', options.commentText);
|
|
53
|
+
}
|
|
54
|
+
args.push(imagePath);
|
|
55
|
+
const result = (0, nbis_runtime_1.runNbisBinary)('wrjpgcom', args);
|
|
56
|
+
(0, nbis_runtime_1.assertSuccess)(result, 'wrjpgcom');
|
|
57
|
+
const outputPath = `${imagePath}.out`;
|
|
58
|
+
await fs_1.default.promises.writeFile(outputPath, result.stdout);
|
|
59
|
+
const outputBuffer = await (0, temp_io_1.deliverTempOutput)(outputPath, options);
|
|
60
|
+
return {
|
|
61
|
+
outputBuffer,
|
|
62
|
+
stderr: result.stderr.toString('utf8')
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
40
66
|
}
|
|
41
67
|
exports.Wrjpgcom = Wrjpgcom;
|
package/dist/src/wrwsqcom.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StreamInput, StreamIoOptions } from './temp-io';
|
|
1
2
|
export type WrwsqcomOptions = {
|
|
2
3
|
commentFile: string;
|
|
3
4
|
commentText?: never;
|
|
@@ -9,7 +10,14 @@ export type WrwsqcomResult = {
|
|
|
9
10
|
stdout: string;
|
|
10
11
|
stderr: string;
|
|
11
12
|
};
|
|
13
|
+
export type WrwsqcomStreamOptions = WrwsqcomOptions & StreamIoOptions;
|
|
14
|
+
export type WrwsqcomStreamResult = {
|
|
15
|
+
stdout: string;
|
|
16
|
+
stderr: string;
|
|
17
|
+
outputBuffer?: Buffer;
|
|
18
|
+
};
|
|
12
19
|
export declare class Wrwsqcom {
|
|
13
20
|
version(): string;
|
|
14
21
|
write(imagePath: string, options: WrwsqcomOptions): WrwsqcomResult;
|
|
22
|
+
writeStream(input: StreamInput, options: WrwsqcomStreamOptions): Promise<WrwsqcomStreamResult>;
|
|
15
23
|
}
|
package/dist/src/wrwsqcom.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Wrwsqcom = void 0;
|
|
4
4
|
const nbis_runtime_1 = require("./nbis-runtime");
|
|
5
|
+
const temp_io_1 = require("./temp-io");
|
|
5
6
|
class Wrwsqcom {
|
|
6
7
|
version() {
|
|
7
8
|
const result = (0, nbis_runtime_1.runNbis)('wrwsqcom', ['-version']);
|
|
@@ -23,5 +24,25 @@ class Wrwsqcom {
|
|
|
23
24
|
stderr: result.stderr
|
|
24
25
|
};
|
|
25
26
|
}
|
|
27
|
+
async writeStream(input, options) {
|
|
28
|
+
return (0, temp_io_1.withTempDir)(async (tempDir) => {
|
|
29
|
+
const imagePath = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
|
|
30
|
+
const args = [imagePath];
|
|
31
|
+
if (options.commentFile) {
|
|
32
|
+
args.push('-f', options.commentFile);
|
|
33
|
+
}
|
|
34
|
+
if (options.commentText) {
|
|
35
|
+
args.push('-t', options.commentText);
|
|
36
|
+
}
|
|
37
|
+
const result = (0, nbis_runtime_1.runNbis)('wrwsqcom', args);
|
|
38
|
+
(0, nbis_runtime_1.assertSuccess)(result, 'wrwsqcom');
|
|
39
|
+
const outputBuffer = await (0, temp_io_1.deliverTempOutput)(imagePath, options);
|
|
40
|
+
return {
|
|
41
|
+
stdout: result.stdout,
|
|
42
|
+
stderr: result.stderr,
|
|
43
|
+
outputBuffer
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
}
|
|
26
47
|
}
|
|
27
48
|
exports.Wrwsqcom = Wrwsqcom;
|
package/dist/src/ycc2rgb.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StreamInput, StreamIoOptions } from './temp-io';
|
|
1
2
|
export type Ycc2rgbOptions = {
|
|
2
3
|
rawOut?: boolean;
|
|
3
4
|
nonInterleaved?: boolean;
|
|
@@ -12,6 +13,12 @@ export type Ycc2rgbResult = {
|
|
|
12
13
|
stdout: string;
|
|
13
14
|
stderr: string;
|
|
14
15
|
};
|
|
16
|
+
export type Ycc2rgbStreamOptions = Ycc2rgbOptions & StreamIoOptions;
|
|
17
|
+
export type Ycc2rgbStreamResult = {
|
|
18
|
+
stdout: string;
|
|
19
|
+
stderr: string;
|
|
20
|
+
outputBuffer?: Buffer;
|
|
21
|
+
};
|
|
15
22
|
export declare class Ycc2rgb {
|
|
16
23
|
version(): string;
|
|
17
24
|
convert(outputExtension: string, imagePath: string, rawIn: {
|
|
@@ -20,4 +27,10 @@ export declare class Ycc2rgb {
|
|
|
20
27
|
depth: number;
|
|
21
28
|
ppi?: number;
|
|
22
29
|
}, options?: Ycc2rgbOptions): Ycc2rgbResult;
|
|
30
|
+
convertStream(outputExtension: string, input: StreamInput, rawIn: {
|
|
31
|
+
width: number;
|
|
32
|
+
height: number;
|
|
33
|
+
depth: number;
|
|
34
|
+
ppi?: number;
|
|
35
|
+
}, options?: Ycc2rgbStreamOptions): Promise<Ycc2rgbStreamResult>;
|
|
23
36
|
}
|
package/dist/src/ycc2rgb.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.Ycc2rgb = 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) {
|
|
@@ -47,5 +48,29 @@ class Ycc2rgb {
|
|
|
47
48
|
stderr: result.stderr
|
|
48
49
|
};
|
|
49
50
|
}
|
|
51
|
+
async convertStream(outputExtension, input, rawIn, options = {}) {
|
|
52
|
+
return (0, temp_io_1.withTempDir)(async (tempDir) => {
|
|
53
|
+
const inputPath = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
|
|
54
|
+
const args = [outputExtension, inputPath, buildRawAttr(rawIn)];
|
|
55
|
+
if (options.rawOut) {
|
|
56
|
+
args.push('-raw_out');
|
|
57
|
+
}
|
|
58
|
+
if (options.nonInterleaved) {
|
|
59
|
+
args.push('-nonintrlv');
|
|
60
|
+
}
|
|
61
|
+
if (options.yCbCr) {
|
|
62
|
+
args.push('-YCbCr', buildYCbCr(options.yCbCr));
|
|
63
|
+
}
|
|
64
|
+
const result = (0, nbis_runtime_1.runNbis)('ycc2rgb', args);
|
|
65
|
+
(0, nbis_runtime_1.assertSuccess)(result, 'ycc2rgb');
|
|
66
|
+
const outputPath = replaceExtension(inputPath, outputExtension);
|
|
67
|
+
const outputBuffer = await (0, temp_io_1.deliverTempOutput)(outputPath, options);
|
|
68
|
+
return {
|
|
69
|
+
stdout: result.stdout,
|
|
70
|
+
stderr: result.stderr,
|
|
71
|
+
outputBuffer
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
}
|
|
50
75
|
}
|
|
51
76
|
exports.Ycc2rgb = Ycc2rgb;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nbis-wrapper-js",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Node.js wrappers for NBIS 5.0.0 binaries",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -44,6 +44,10 @@
|
|
|
44
44
|
"test:nbis-versions": "npm run build && node dist/scripts/test-nbis-versions.js",
|
|
45
45
|
"test": "npm run build && node dist/test/nbis-versions.test.js"
|
|
46
46
|
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"jpeg-js": "^0.4.4",
|
|
49
|
+
"pngjs": "^7.0.0"
|
|
50
|
+
},
|
|
47
51
|
"devDependencies": {
|
|
48
52
|
"@types/node": "^20.14.10",
|
|
49
53
|
"typescript": "^5.4.5"
|