Skip to content

Commit c2ef59f

Browse files
committed
feat(dcm2pdf): generate TS wrapper (bindgen) for read-dicom-encapsulated-pdf
Generate typescript bindings for read-dicom-encapsulated-pdf operation.
1 parent 9cb3553 commit c2ef59f

File tree

7 files changed

+289
-0
lines changed

7 files changed

+289
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface ReadDicomEncapsulatedPdfNodeResult {
2+
/** Output pdf file */
3+
pdfBinaryOutput: Uint8Array
4+
5+
}
6+
7+
export default ReadDicomEncapsulatedPdfNodeResult
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
interface ReadDicomEncapsulatedPdfOptions {
2+
/** read file format only */
3+
readFileOnly?: boolean
4+
5+
/** read data set without file meta information */
6+
readDataset?: boolean
7+
8+
/** use TS recognition (default) */
9+
readXferAuto?: boolean
10+
11+
/** ignore TS specified in the file meta header */
12+
readXferDetect?: boolean
13+
14+
/** read with explicit VR little endian TS */
15+
readXferLittle?: boolean
16+
17+
/** read with explicit VR big endian TS */
18+
readXferBig?: boolean
19+
20+
/** read with implicit VR little endian TS */
21+
readXferImplicit?: boolean
22+
23+
/** accept odd length attributes (default) */
24+
acceptOddLength?: boolean
25+
26+
/** assume real length is one byte larger */
27+
assumeEvenLength?: boolean
28+
29+
/** read undefined len UN as implicit VR (default) */
30+
enableCp246?: boolean
31+
32+
/** read undefined len UN as explicit VR */
33+
disableCp246?: boolean
34+
35+
/** retain elements as UN (default) */
36+
retainUn?: boolean
37+
38+
/** convert to real VR if known */
39+
convertUn?: boolean
40+
41+
/** enable automatic data correction (default) */
42+
enableCorrection?: boolean
43+
44+
/** disable automatic data correction */
45+
disableCorrection?: boolean
46+
47+
}
48+
49+
export default ReadDicomEncapsulatedPdfOptions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
interface ReadDicomEncapsulatedPdfResult {
2+
/** WebWorker used for computation */
3+
webWorker: Worker | null
4+
5+
/** Output pdf file */
6+
pdfBinaryOutput: Uint8Array
7+
8+
}
9+
10+
export default ReadDicomEncapsulatedPdfResult

dist/dicom/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11

22

3+
import ReadDicomEncapsulatedPdfResult from './ReadDicomEncapsulatedPdfResult.js'
4+
export type { ReadDicomEncapsulatedPdfResult }
5+
6+
import ReadDicomEncapsulatedPdfOptions from './ReadDicomEncapsulatedPdfOptions.js'
7+
export type { ReadDicomEncapsulatedPdfOptions }
8+
9+
import readDicomEncapsulatedPdf from './readDicomEncapsulatedPdf.js'
10+
export { readDicomEncapsulatedPdf }
11+
12+
313
import StructuredReportToHtmlResult from './StructuredReportToHtmlResult.js'
414
export type { StructuredReportToHtmlResult }
515

dist/dicom/src/indexNode.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11

22

3+
import ReadDicomEncapsulatedPdfNodeResult from './ReadDicomEncapsulatedPdfNodeResult.js'
4+
export type { ReadDicomEncapsulatedPdfNodeResult }
5+
6+
import ReadDicomEncapsulatedPdfOptions from './ReadDicomEncapsulatedPdfOptions.js'
7+
export type { ReadDicomEncapsulatedPdfOptions }
8+
9+
import readDicomEncapsulatedPdfNode from './readDicomEncapsulatedPdfNode.js'
10+
export { readDicomEncapsulatedPdfNode }
11+
12+
313
import StructuredReportToHtmlNodeResult from './StructuredReportToHtmlNodeResult.js'
414
export type { StructuredReportToHtmlNodeResult }
515

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import {
2+
BinaryStream,
3+
InterfaceTypes,
4+
runPipeline
5+
} from 'itk-wasm'
6+
7+
import ReadDicomEncapsulatedPdfOptions from './ReadDicomEncapsulatedPdfOptions.js'
8+
import ReadDicomEncapsulatedPdfResult from './ReadDicomEncapsulatedPdfResult.js'
9+
10+
/**
11+
* Extract PDF file from DICOM encapsulated PDF.
12+
*
13+
* @param {Uint8Array} dicomFile - Input DICOM file
14+
*
15+
* @returns {Promise<ReadDicomEncapsulatedPdfResult>} - result object
16+
*/
17+
async function readDicomEncapsulatedPdf(
18+
webWorker: null | Worker,
19+
dicomFile: Uint8Array,
20+
options: ReadDicomEncapsulatedPdfOptions = {})
21+
: Promise<ReadDicomEncapsulatedPdfResult> {
22+
23+
const desiredOutputs = [
24+
{ type: InterfaceTypes.BinaryStream },
25+
]
26+
const inputs = [
27+
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } },
28+
]
29+
30+
const args = []
31+
// Inputs
32+
args.push('file0')
33+
// Outputs
34+
args.push('0')
35+
// Options
36+
args.push('--memory-io')
37+
if (options.readFileOnly) {
38+
args.push('--read-file-only')
39+
}
40+
if (options.readDataset) {
41+
args.push('--read-dataset')
42+
}
43+
if (options.readXferAuto) {
44+
args.push('--read-xfer-auto')
45+
}
46+
if (options.readXferDetect) {
47+
args.push('--read-xfer-detect')
48+
}
49+
if (options.readXferLittle) {
50+
args.push('--read-xfer-little')
51+
}
52+
if (options.readXferBig) {
53+
args.push('--read-xfer-big')
54+
}
55+
if (options.readXferImplicit) {
56+
args.push('--read-xfer-implicit')
57+
}
58+
if (options.acceptOddLength) {
59+
args.push('--accept-odd-length')
60+
}
61+
if (options.assumeEvenLength) {
62+
args.push('--assume-even-length')
63+
}
64+
if (options.enableCp246) {
65+
args.push('--enable-cp246')
66+
}
67+
if (options.disableCp246) {
68+
args.push('--disable-cp246')
69+
}
70+
if (options.retainUn) {
71+
args.push('--retain-un')
72+
}
73+
if (options.convertUn) {
74+
args.push('--convert-un')
75+
}
76+
if (options.enableCorrection) {
77+
args.push('--enable-correction')
78+
}
79+
if (options.disableCorrection) {
80+
args.push('--disable-correction')
81+
}
82+
83+
const pipelinePath = 'read-dicom-encapsulated-pdf'
84+
85+
const {
86+
webWorker: usedWebWorker,
87+
returnValue,
88+
stderr,
89+
outputs
90+
} = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs)
91+
if (returnValue !== 0) {
92+
throw new Error(stderr)
93+
}
94+
95+
const result = {
96+
webWorker: usedWebWorker as Worker,
97+
pdfBinaryOutput: (outputs[0].data as BinaryStream).data,
98+
}
99+
return result
100+
}
101+
102+
export default readDicomEncapsulatedPdf
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import {
2+
BinaryStream,
3+
InterfaceTypes,
4+
runPipelineNode
5+
} from 'itk-wasm'
6+
7+
import ReadDicomEncapsulatedPdfOptions from './ReadDicomEncapsulatedPdfOptions.js'
8+
import ReadDicomEncapsulatedPdfNodeResult from './ReadDicomEncapsulatedPdfNodeResult.js'
9+
10+
11+
import path from 'path'
12+
13+
/**
14+
* Extract PDF file from DICOM encapsulated PDF.
15+
*
16+
* @param {Uint8Array} dicomFile - Input DICOM file
17+
*
18+
* @returns {Promise<ReadDicomEncapsulatedPdfNodeResult>} - result object
19+
*/
20+
async function readDicomEncapsulatedPdfNode( dicomFile: Uint8Array,
21+
options: ReadDicomEncapsulatedPdfOptions = {})
22+
: Promise<ReadDicomEncapsulatedPdfNodeResult> {
23+
24+
const desiredOutputs = [
25+
{ type: InterfaceTypes.BinaryStream },
26+
]
27+
const inputs = [
28+
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } },
29+
]
30+
31+
const args = []
32+
// Inputs
33+
args.push('file0')
34+
// Outputs
35+
args.push('0')
36+
// Options
37+
args.push('--memory-io')
38+
if (options.readFileOnly) {
39+
args.push('--read-file-only')
40+
}
41+
if (options.readDataset) {
42+
args.push('--read-dataset')
43+
}
44+
if (options.readXferAuto) {
45+
args.push('--read-xfer-auto')
46+
}
47+
if (options.readXferDetect) {
48+
args.push('--read-xfer-detect')
49+
}
50+
if (options.readXferLittle) {
51+
args.push('--read-xfer-little')
52+
}
53+
if (options.readXferBig) {
54+
args.push('--read-xfer-big')
55+
}
56+
if (options.readXferImplicit) {
57+
args.push('--read-xfer-implicit')
58+
}
59+
if (options.acceptOddLength) {
60+
args.push('--accept-odd-length')
61+
}
62+
if (options.assumeEvenLength) {
63+
args.push('--assume-even-length')
64+
}
65+
if (options.enableCp246) {
66+
args.push('--enable-cp246')
67+
}
68+
if (options.disableCp246) {
69+
args.push('--disable-cp246')
70+
}
71+
if (options.retainUn) {
72+
args.push('--retain-un')
73+
}
74+
if (options.convertUn) {
75+
args.push('--convert-un')
76+
}
77+
if (options.enableCorrection) {
78+
args.push('--enable-correction')
79+
}
80+
if (options.disableCorrection) {
81+
args.push('--disable-correction')
82+
}
83+
84+
const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), 'pipelines', 'read-dicom-encapsulated-pdf')
85+
86+
const {
87+
returnValue,
88+
stderr,
89+
outputs
90+
} = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs)
91+
if (returnValue !== 0) {
92+
throw new Error(stderr)
93+
}
94+
95+
const result = {
96+
pdfBinaryOutput: (outputs[0].data as BinaryStream).data,
97+
}
98+
return result
99+
}
100+
101+
export default readDicomEncapsulatedPdfNode

0 commit comments

Comments
 (0)