dcmnorm 0.0.0 → 0.12.1
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/LICENSE +201 -0
- package/README.md +231 -2
- package/index.d.ts +785 -0
- package/index.js +866 -0
- package/package.json +57 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,232 @@
|
|
|
1
|
-
# dcmnorm
|
|
1
|
+
# dcmnorm (Node.js binding)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Native Node.js bindings for dcmnorm, built with [napi-rs](https://napi.rs). Calls
|
|
4
|
+
straight into the `dcmnorm` lib crate in-process (no CLI subprocess, no stdio/JSON
|
|
5
|
+
round trip) with the blocking work offloaded to libuv's threadpool so it doesn't
|
|
6
|
+
block the JS event loop.
|
|
7
|
+
|
|
8
|
+
## Demo / test website
|
|
9
|
+
|
|
10
|
+
**Live demo: https://dcmnorm-test-website-spzcbrdjlq-uc.a.run.app**
|
|
11
|
+
|
|
12
|
+
`examples/test-website` is a small Express app that exercises these bindings end to end through
|
|
13
|
+
a browser UI: upload a `.dcm` file (or pick one of five bundled samples) and it renders the
|
|
14
|
+
file's JSON metadata, a JPEG of every frame, and per-step timings back on the page. See
|
|
15
|
+
[`examples/test-website/README.md`](examples/test-website/README.md) for how to run it locally,
|
|
16
|
+
build its Docker image, and deploy it to Cloud Run.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm i dcmnorm
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
const dcmnorm = require("dcmnorm");
|
|
26
|
+
const json = await dcmnorm.readJson("image.dcm");
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Prebuilt for Linux x64 and arm64 (glibc 2.31+: Ubuntu 20.04+, Debian 11+), macOS arm64 (11+) and
|
|
30
|
+
x64 (10.15+), and Windows x64, with every codec linked in (FFmpeg included, so the video transfer
|
|
31
|
+
syntaxes need no `ffmpeg` command). npm installs only your platform's addon; see Packaging below.
|
|
32
|
+
Node.js 18 or newer.
|
|
33
|
+
|
|
34
|
+
## Build
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
npm install
|
|
38
|
+
npm run build # release build -> dcmnorm-node.<platform>.node + index.js/index.d.ts
|
|
39
|
+
npm run build:debug # debug build, faster to iterate
|
|
40
|
+
npm run build:docker # Linux release build inside node:22-bullseye-slim (glibc 2.31) - see Packaging below
|
|
41
|
+
npm test # runs test/smoke.js against the fixtures in ../../test/files
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## API
|
|
45
|
+
|
|
46
|
+
- `readTags(filePath, tags: string[]): Promise<string>` — JSON (flat, hex-keyed,
|
|
47
|
+
bulk data as a URI reference) containing only the requested tags. Stops
|
|
48
|
+
parsing right after the highest requested tag, same fast path as `dcmnorm
|
|
49
|
+
--filter`. Filtering for a bulk-data-eligible tag (e.g. `PixelData`) falls
|
|
50
|
+
back to inlining it rather than a URI reference, unlike `readJson` below -
|
|
51
|
+
see the comment on `ReadTagsTask` in `src/lib.rs`.
|
|
52
|
+
- `readJson(filePath, options?: { format?: 'flat'|'standard', keyStyle?: 'name'|'hex', bulkData?: 'uri'|'inline', omitKeywordVm?: boolean }): Promise<string>`
|
|
53
|
+
— full-file JSON dump. `bulkData` defaults to `'uri'`, matching the CLI's own
|
|
54
|
+
default (`--bulk-data uri`) - not the Rust library's own default, which is
|
|
55
|
+
`'inline'`. Getting this wrong makes a huge difference: `'inline'`
|
|
56
|
+
base64-embeds elements like `PixelData` directly, ~1000x larger output for a
|
|
57
|
+
typical image, instead of a small `"?offset=..&length=.."` reference.
|
|
58
|
+
`omitKeywordVm: true` drops the non-standard `Keyword` and `VM` members from
|
|
59
|
+
`format: 'standard'` output, leaving only what PS3.18 Annex F defines.
|
|
60
|
+
- `editTags(filePath, options?: { outputPath?, set?: Record<string,string>, remove?: string[], removePrivateTags?: boolean }): Promise<void>`
|
|
61
|
+
— set/remove attributes; writes back in place unless `outputPath` is given.
|
|
62
|
+
- `transcode(filePath, outputPath, transferSyntaxUid): Promise<void>`.
|
|
63
|
+
- `checkDicom(filePath): Promise<boolean>`.
|
|
64
|
+
- `writeDicomdir(entries: { fileId: string[], json?: string, format?: 'flat'|'standard', path?: string, transferSyntaxUid?: string }[], outputPath, options?: { fileSetId?, sopInstanceUid? }): Promise<{ records, recordTypes: { recordType, count }[], synthesized: { recordType, entity, attribute, value, source? }[], warnings: string[] }>`
|
|
65
|
+
— writes a DICOMDIR (Media Storage Directory, Explicit VR Little Endian) for a File-set, the
|
|
66
|
+
in-process form of `dcmnorm dicomdir ROOT`. Each entry is one file of the File-set: its File ID
|
|
67
|
+
components (1-8 of 1-8 characters from `A-Z 0-9 _`, PS3.10 8.2) and its header, either as the
|
|
68
|
+
DICOM JSON `readJson` returns (`json`; BulkDataURI elements are ignored, so the default `'uri'`
|
|
69
|
+
output is fine) or a file to read it from (`path`; pixel data isn't loaded). With `json`, the
|
|
70
|
+
referenced file's transfer syntax is `transferSyntaxUid`, else the JSON's TransferSyntaxUID,
|
|
71
|
+
else Explicit VR Little Endian. Records are PATIENT > STUDY > SERIES > one per entry, typed by
|
|
72
|
+
SOP Class (IMAGE, SR DOCUMENT, KEY OBJECT DOC, PRESENTATION, ENCAP DOC, ...; PS3.3 F.5).
|
|
73
|
+
`synthesized` lists the Type 1 keys the instances lacked and the values written (IHE PDI
|
|
74
|
+
Table 4.47.4-1: Patient ID, Study ID, Study Date/Time, Modality, Series Number, Instance
|
|
75
|
+
Number), with `source` naming the attribute a value was copied from, if any. Rejects a bad File
|
|
76
|
+
ID or File-set ID (at most 16 of `A-Z 0-9 _`), a Patient ID shared by two patients, a study
|
|
77
|
+
under two patients, a series in two studies, and duplicate files or SOP Instance UIDs.
|
|
78
|
+
- `renderFrame(filePath, options?: { format?: 'jpeg'|'png', outputWidth?, outputHeight?, windowCenter?, windowWidth?, frameIndex?, jpegQuality?, showOverlays?: boolean, overlayIndex?: number, overlayColor?: string }): Promise<{ mimeType, width, height, data: Buffer, overlays: OverlaySummary[], selectedOverlayIndex?: number }>`
|
|
79
|
+
— renders a single frame to JPEG or PNG. If the instance has one or more DICOM overlay planes
|
|
80
|
+
(group `60xx`), the first available overlay composites onto the image by default; `overlayIndex`
|
|
81
|
+
selects a different one (0-based, by `OverlaySummary.index`, matching the CLI's
|
|
82
|
+
`--overlay-index`), `showOverlays: false` disables overlay rendering, and `overlayColor` (`"R,G,B"`
|
|
83
|
+
or `"#RRGGBB"`, default green) sets the fill color. `overlays` in the result always lists every
|
|
84
|
+
overlay present on the instance (even when none was rendered), so a caller can offer overlay
|
|
85
|
+
selection without a separate metadata call; `selectedOverlayIndex` says which one (if any) is
|
|
86
|
+
actually in `data`. `OverlaySummary` is `{ index, group, rows, columns, overlayType?, label? }`.
|
|
87
|
+
- `renderMovie(filePath, options?: { outputWidth?, outputHeight?, windowCenter?, windowWidth?, fps? }): Promise<{ mimeType, data: Buffer }>`
|
|
88
|
+
— renders every frame of a multiframe instance to an MP4 (requires `ffmpeg` on `PATH`). Does not
|
|
89
|
+
currently support the overlay options `renderFrame` does.
|
|
90
|
+
- `computeHistogram(filePath, options?: { binCount?, frameIndex?, minValue?, maxValue? }): Promise<FrameHistogram[]>`
|
|
91
|
+
— computes a pixel-value histogram per frame, over the same modality-LUT-applied grayscale
|
|
92
|
+
values `renderFrame` decodes from (so e.g. a CT frame's bins are in Hounsfield units). Mirrors
|
|
93
|
+
the CLI's `--histogram`/`--histogram-bins`/`--histogram-frame`/`--histogram-min`/`--histogram-max`
|
|
94
|
+
— see the main [README](../../README.md#compute-a-pixel-histogram-with---histogram) for the
|
|
95
|
+
field-by-field output shape. `binCount` defaults to 256; `frameIndex` (0-based) restricts the
|
|
96
|
+
result to one frame instead of every frame in the instance (and, like `renderFrame`, reads only
|
|
97
|
+
that frame's bytes of a native multi-frame file, and decodes only that frame of a compressed
|
|
98
|
+
one); `minValue`/`maxValue` (must be set
|
|
99
|
+
together) pin the bin range instead of defaulting to each frame's own observed min/max.
|
|
100
|
+
`FrameHistogram` is `{ frameIndex, channel: 'red'|'green'|'blue'|null, binCount, rangeMin,
|
|
101
|
+
rangeMax, binWidth, counts: number[], pixelCount, minValue, maxValue, mean, stdDev }`.
|
|
102
|
+
`channel` is `null` for a grayscale frame; an RGB/color frame (YBR variants converted to RGB
|
|
103
|
+
first) instead resolves to **three** entries per frame index, one per channel, each over that
|
|
104
|
+
channel's own 8-bit (0-255) samples with the bin range defaulted to the full 0-255 domain
|
|
105
|
+
rather than each channel's own min/max.
|
|
106
|
+
|
|
107
|
+
### MPR (Multiplanar Reformation)
|
|
108
|
+
|
|
109
|
+
- `buildVolume(filePaths: string[]): Promise<DicomVolumeHandle>` — reads and decodes every slice
|
|
110
|
+
of a parallel stack (e.g. one CT/MR/PT series), spatially re-sorted by `ImagePositionPatient`
|
|
111
|
+
regardless of input order. Rejects fewer than 2 files, mismatched Rows/Columns, or a
|
|
112
|
+
non-parallel/gantry-tilt-inconsistent stack. This is the expensive step — build once per series
|
|
113
|
+
and keep the returned handle resident (e.g. in a volume cache) so every subsequent `reformat()`
|
|
114
|
+
call is cheap.
|
|
115
|
+
- `DicomVolumeHandle` — an opaque, read-only handle around the built volume:
|
|
116
|
+
- getters: `rows`, `cols`, `numSlices`, `nativeBasis` (`[rowDir(3), colDir(3)]`, the volume's own
|
|
117
|
+
acquisition-native orientation — a reasonable seed for an "axial" reformat), `center`
|
|
118
|
+
(`[x,y,z]` LPS mm, the volume's physical center), `minSpacingMm` (its smallest voxel
|
|
119
|
+
dimension, a reasonable default output spacing)
|
|
120
|
+
- `reformat(options): Promise<RenderedFrame>` — resamples one plane through the volume and
|
|
121
|
+
encodes it exactly like `renderFrame`'s output shape, so callers reuse their existing
|
|
122
|
+
image-display code path. `options`: `{ origin: number[3], rowDir: number[3], colDir: number[3],
|
|
123
|
+
outputWidth, outputHeight, spacingMm, windowCenter?, windowWidth?, format?: 'jpeg'|'png',
|
|
124
|
+
jpegQuality?, interpolation?: 'trilinear'|'nearest', slabThicknessMm?, slabProjection?:
|
|
125
|
+
'mip'|'minip'|'average' }`. `interpolation` defaults to `'trilinear'`; use `'nearest'` (faster)
|
|
126
|
+
for a live-drag preview frame. `slabThicknessMm` (default 0, an infinitely-thin plane) turns on
|
|
127
|
+
a thick-slab reformat centered on `origin`, combined per `slabProjection` (default `'mip'`).
|
|
128
|
+
- `exportTexture(options?): Promise<TextureExportResult>` — see
|
|
129
|
+
[Texture export](#texture-export) below.
|
|
130
|
+
|
|
131
|
+
### Texture export
|
|
132
|
+
|
|
133
|
+
Packs a volume, a single frame, or several independent frames as a lossless, GPU-upload-ready
|
|
134
|
+
payload (16-bit samples, row-major, optionally gzip-compressed) instead of an 8-bit windowed
|
|
135
|
+
render — the client does its own window/level and oblique reslicing in a GPU shader instead of
|
|
136
|
+
round-tripping to the server per interaction. Mirrors the CLI's `--output-type texture`/`.gputex`
|
|
137
|
+
(`exportTexture`/`exportFrameTexture`) — see the main [README](../../README.md#export-a-gpu-texture-gputex)
|
|
138
|
+
and `dcmnorm::dicom_io::texture_export`'s own module doc for the full format contract.
|
|
139
|
+
|
|
140
|
+
- `DicomVolumeHandle.exportTexture(options?: { targetMaxDim?, compression?: 'gzip'|'none', windowCenter?, windowWidth? }): Promise<TextureExportResult>`
|
|
141
|
+
— packs the volume's own NATIVE voxel lattice (not a resampled oblique plane — that's
|
|
142
|
+
`reformat()`). `targetMaxDim` caps the longest of width/height/depth, proportionally
|
|
143
|
+
downsampling (trilinear) if the native volume exceeds it; omitted means full native resolution.
|
|
144
|
+
`compression` defaults to `'gzip'`. `windowCenter`/`windowWidth` are purely informational,
|
|
145
|
+
carried through to the result for the client's initial render — the exported samples are never
|
|
146
|
+
windowed.
|
|
147
|
+
- `exportFrameTexture(filePath, options?: { frameIndex?, targetMaxDim?, compression?, windowCenter?, windowWidth? }): Promise<TextureExportResult>`
|
|
148
|
+
— packs one decoded 2D frame as a depth-1 "1-slice volume" texture, so a large diagnostic 2D
|
|
149
|
+
image (DX/CR/mammography) can reuse the same client GPU texture/shader pipeline as an MPR
|
|
150
|
+
volume. `frameIndex` defaults to 0.
|
|
151
|
+
- `exportFrameStackTexture(sources: FrameStackSource[], options?: { compression?, windowCenter?, windowWidth? }): Promise<TextureExportResult>`
|
|
152
|
+
— packs several independent original frames (no resampling, no cross-layer interpolation, no
|
|
153
|
+
physical geometry) as one texture-array upload: a cine/multiframe instance supplies one source
|
|
154
|
+
with several `frameIndices` (its file is parsed once), a multi-image series supplies one source
|
|
155
|
+
per instance file (`frameIndices` defaulting to `[0]`). `FrameStackSource` is `{ filePath,
|
|
156
|
+
frameIndices?: number[] }`. The result's layer order is the flattened source order followed by
|
|
157
|
+
each source's own `frameIndices` order — callers must supply sources in the exact order the
|
|
158
|
+
client's own frame/instance index expects. This has no CLI equivalent — it's Node-bindings-only.
|
|
159
|
+
- `TextureExportResult`: `{ contentKind: 'volume'|'image2d'|'framestack', sampleFormat:
|
|
160
|
+
'int16'|'uint16', compression: 'none'|'gzip', lossless, width, height, depth, rescaleSlope,
|
|
161
|
+
rescaleIntercept, rowSpacingMm, colSpacingMm, sliceSpacingMm, origin: number[3], rowDir:
|
|
162
|
+
number[3], colDir: number[3], normalDir: number[3], defaultWindowCenter?, defaultWindowWidth?,
|
|
163
|
+
nativeWidth, nativeHeight, nativeDepth, downsampled, payloadBytesRaw, payloadBytesStored, data:
|
|
164
|
+
Buffer }`. `texel * rescaleSlope + rescaleIntercept` recovers the physical value (e.g. HU).
|
|
165
|
+
Geometry fields (`rowSpacingMm`/`origin`/`rowDir`/etc.) carry no meaning for `contentKind:
|
|
166
|
+
'framestack'` — only `'volume'` makes a real spatial claim.
|
|
167
|
+
|
|
168
|
+
All return values that carry data are JSON strings — parse them JS-side. This
|
|
169
|
+
sidesteps a napi-rs constraint (`Task::JsValue` requires `TypeName`, which
|
|
170
|
+
`serde_json::Value` doesn't implement) and matches how the CLI already talks
|
|
171
|
+
JSON everywhere else in this project.
|
|
172
|
+
|
|
173
|
+
Every entry point runs through `catch_unwind` (see `guarded()` in `src/lib.rs`):
|
|
174
|
+
DICOM files come from arbitrary, sometimes-malformed vendor equipment, and unlike
|
|
175
|
+
a subprocess call, a panic in an in-process addon takes the whole host process
|
|
176
|
+
down unless it's caught at the FFI boundary.
|
|
177
|
+
|
|
178
|
+
## Packaging
|
|
179
|
+
|
|
180
|
+
Published to npm by the [`Build and release`](../../.github/workflows/release.yml) workflow on
|
|
181
|
+
every `v*.*.*` release tag, with the release version, in the per-platform layout esbuild and the
|
|
182
|
+
napi-rs projects use:
|
|
183
|
+
|
|
184
|
+
| Package | Contents |
|
|
185
|
+
| --- | --- |
|
|
186
|
+
| `dcmnorm` | `index.js` (the loader), `index.d.ts`, README, LICENSE; `optionalDependencies` on the five below |
|
|
187
|
+
| `@dcmnorm/linux-x64-gnu` | `dcmnorm-node.linux-x64-gnu.node` only (`os: linux`, `cpu: x64`, `libc: glibc`) |
|
|
188
|
+
| `@dcmnorm/linux-arm64-gnu` | `dcmnorm-node.linux-arm64-gnu.node` only (`os: linux`, `cpu: arm64`, `libc: glibc`) |
|
|
189
|
+
| `@dcmnorm/darwin-arm64` | `dcmnorm-node.darwin-arm64.node` only (`os: darwin`, `cpu: arm64`) |
|
|
190
|
+
| `@dcmnorm/darwin-x64` | `dcmnorm-node.darwin-x64.node` only (`os: darwin`, `cpu: x64`) |
|
|
191
|
+
| `@dcmnorm/win32-x64-msvc` | `dcmnorm-node.win32-x64-msvc.node` only (`os: win32`, `cpu: x64`) |
|
|
192
|
+
|
|
193
|
+
npm skips the optional dependencies whose `os`/`cpu`/`libc` don't match, so an install downloads
|
|
194
|
+
one addon (about 12 MB packed, 31 MB unpacked on Linux x64). `index.js` (generated by napi-rs)
|
|
195
|
+
first tries a `dcmnorm-node.<platform>.node` next to itself, which is what a local build produces,
|
|
196
|
+
then `@dcmnorm/<platform>`. napi-rs names platform packages `<name>-<platform>`, so
|
|
197
|
+
`npm run build` (and `build-in-docker.sh`) runs `node prepare-npm.js --fix-loader` to rewrite the
|
|
198
|
+
generated requires to the `@dcmnorm` scope; CI fails if a committed `index.js` misses that.
|
|
199
|
+
|
|
200
|
+
`prepare-npm.js` lays the packages out for a release (`--artifacts <dir>` with every platform's
|
|
201
|
+
`.node`) and checks them with `npm pack --dry-run`: exact file lists, versions and
|
|
202
|
+
`optionalDependencies` in step. Pull requests run it with `--placeholder` (empty stand-in addons),
|
|
203
|
+
so the package metadata can't drift between releases. No `.node` file is committed; `npm/`,
|
|
204
|
+
`artifacts/` and the copied `LICENSE` are build outputs (`.gitignore`).
|
|
205
|
+
|
|
206
|
+
How each addon is built (all with FFmpeg linked in statically and the same codec set; a codec that
|
|
207
|
+
fails to build fails the release, there is no fallback to a smaller feature set):
|
|
208
|
+
|
|
209
|
+
- **Linux** (x64 on `ubuntu-24.04`, arm64 on `ubuntu-24.04-arm`): `build-in-docker.sh` builds in a
|
|
210
|
+
`node:22-bullseye-slim` container (glibc 2.31, GCC 10), so the addon needs at most GLIBC 2.31 /
|
|
211
|
+
GLIBCXX 3.4.28; the script fails if a newer symbol version or a dynamically linked FFmpeg sneaks
|
|
212
|
+
in, then runs `test/smoke.js` and `load-check.js` inside the container. A plain `npm run build`
|
|
213
|
+
links the host's glibc and is for local iteration only.
|
|
214
|
+
- **macOS** (arm64 on `macos-15`, deployment target 11.0; x64 on `macos-15-intel`, 10.15):
|
|
215
|
+
`napi build` with `packaging/macos-link.py` as the linker (ffmpeg-sys-next emits GNU-only link
|
|
216
|
+
flags there) and `packaging/portable-cc` on `PATH`, then `load-check.js`.
|
|
217
|
+
- **Windows** (`windows-latest`, MSVC): MSVC can't run FFmpeg's `./configure` + `make`, so the
|
|
218
|
+
workflow installs a pinned vcpkg `ffmpeg` (`x64-windows-static-md`: static, LGPL-only, native
|
|
219
|
+
codecs; `.github/actions/ffmpeg-vcpkg`) and builds with `ffmpeg-codec-linked`. The job fails if
|
|
220
|
+
the `.node` imports any FFmpeg DLL, then runs `load-check.js`. By hand: install that vcpkg
|
|
221
|
+
package, set `VCPKG_ROOT` and `VCPKGRS_TRIPLET=x64-windows-static-md`, then
|
|
222
|
+
|
|
223
|
+
```sh
|
|
224
|
+
npx napi build --platform --release --target x86_64-pc-windows-msvc --no-default-features --features "ffmpeg-codec-linked,jpeg-ls-codec,jpeg-xl-codec,jpeg2000-openjpeg-encode"
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Every Linux and macOS build compiles FFmpeg through `packaging/portable-cc`, which drops the
|
|
228
|
+
`-march=native` ffmpeg-sys-next would otherwise configure (it tunes FFmpeg's C code for the build
|
|
229
|
+
machine's CPU, which then crashes on older CPUs).
|
|
230
|
+
|
|
231
|
+
Publishing setup (npm org, trusted publisher, the `NPM_PUBLISH` variable):
|
|
232
|
+
[`packaging/README.md`](../../packaging/README.md).
|