-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dcm2pdf): generate TS wrapper (bindgen) for read-dicom-encapsula…
…ted-pdf Generate typescript bindings for read-dicom-encapsulated-pdf operation.
- Loading branch information
Showing
7 changed files
with
289 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface ReadDicomEncapsulatedPdfNodeResult { | ||
/** Output pdf file */ | ||
pdfBinaryOutput: Uint8Array | ||
|
||
} | ||
|
||
export default ReadDicomEncapsulatedPdfNodeResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
interface ReadDicomEncapsulatedPdfOptions { | ||
/** read file format only */ | ||
readFileOnly?: boolean | ||
|
||
/** read data set without file meta information */ | ||
readDataset?: boolean | ||
|
||
/** use TS recognition (default) */ | ||
readXferAuto?: boolean | ||
|
||
/** ignore TS specified in the file meta header */ | ||
readXferDetect?: boolean | ||
|
||
/** read with explicit VR little endian TS */ | ||
readXferLittle?: boolean | ||
|
||
/** read with explicit VR big endian TS */ | ||
readXferBig?: boolean | ||
|
||
/** read with implicit VR little endian TS */ | ||
readXferImplicit?: boolean | ||
|
||
/** accept odd length attributes (default) */ | ||
acceptOddLength?: boolean | ||
|
||
/** assume real length is one byte larger */ | ||
assumeEvenLength?: boolean | ||
|
||
/** read undefined len UN as implicit VR (default) */ | ||
enableCp246?: boolean | ||
|
||
/** read undefined len UN as explicit VR */ | ||
disableCp246?: boolean | ||
|
||
/** retain elements as UN (default) */ | ||
retainUn?: boolean | ||
|
||
/** convert to real VR if known */ | ||
convertUn?: boolean | ||
|
||
/** enable automatic data correction (default) */ | ||
enableCorrection?: boolean | ||
|
||
/** disable automatic data correction */ | ||
disableCorrection?: boolean | ||
|
||
} | ||
|
||
export default ReadDicomEncapsulatedPdfOptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
interface ReadDicomEncapsulatedPdfResult { | ||
/** WebWorker used for computation */ | ||
webWorker: Worker | null | ||
|
||
/** Output pdf file */ | ||
pdfBinaryOutput: Uint8Array | ||
|
||
} | ||
|
||
export default ReadDicomEncapsulatedPdfResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { | ||
BinaryStream, | ||
InterfaceTypes, | ||
runPipeline | ||
} from 'itk-wasm' | ||
|
||
import ReadDicomEncapsulatedPdfOptions from './ReadDicomEncapsulatedPdfOptions.js' | ||
import ReadDicomEncapsulatedPdfResult from './ReadDicomEncapsulatedPdfResult.js' | ||
|
||
/** | ||
* Extract PDF file from DICOM encapsulated PDF. | ||
* | ||
* @param {Uint8Array} dicomFile - Input DICOM file | ||
* | ||
* @returns {Promise<ReadDicomEncapsulatedPdfResult>} - result object | ||
*/ | ||
async function readDicomEncapsulatedPdf( | ||
webWorker: null | Worker, | ||
dicomFile: Uint8Array, | ||
options: ReadDicomEncapsulatedPdfOptions = {}) | ||
: Promise<ReadDicomEncapsulatedPdfResult> { | ||
|
||
const desiredOutputs = [ | ||
{ type: InterfaceTypes.BinaryStream }, | ||
] | ||
const inputs = [ | ||
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } }, | ||
] | ||
|
||
const args = [] | ||
// Inputs | ||
args.push('file0') | ||
// Outputs | ||
args.push('0') | ||
// Options | ||
args.push('--memory-io') | ||
if (options.readFileOnly) { | ||
args.push('--read-file-only') | ||
} | ||
if (options.readDataset) { | ||
args.push('--read-dataset') | ||
} | ||
if (options.readXferAuto) { | ||
args.push('--read-xfer-auto') | ||
} | ||
if (options.readXferDetect) { | ||
args.push('--read-xfer-detect') | ||
} | ||
if (options.readXferLittle) { | ||
args.push('--read-xfer-little') | ||
} | ||
if (options.readXferBig) { | ||
args.push('--read-xfer-big') | ||
} | ||
if (options.readXferImplicit) { | ||
args.push('--read-xfer-implicit') | ||
} | ||
if (options.acceptOddLength) { | ||
args.push('--accept-odd-length') | ||
} | ||
if (options.assumeEvenLength) { | ||
args.push('--assume-even-length') | ||
} | ||
if (options.enableCp246) { | ||
args.push('--enable-cp246') | ||
} | ||
if (options.disableCp246) { | ||
args.push('--disable-cp246') | ||
} | ||
if (options.retainUn) { | ||
args.push('--retain-un') | ||
} | ||
if (options.convertUn) { | ||
args.push('--convert-un') | ||
} | ||
if (options.enableCorrection) { | ||
args.push('--enable-correction') | ||
} | ||
if (options.disableCorrection) { | ||
args.push('--disable-correction') | ||
} | ||
|
||
const pipelinePath = 'read-dicom-encapsulated-pdf' | ||
|
||
const { | ||
webWorker: usedWebWorker, | ||
returnValue, | ||
stderr, | ||
outputs | ||
} = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs) | ||
if (returnValue !== 0) { | ||
throw new Error(stderr) | ||
} | ||
|
||
const result = { | ||
webWorker: usedWebWorker as Worker, | ||
pdfBinaryOutput: (outputs[0].data as BinaryStream).data, | ||
} | ||
return result | ||
} | ||
|
||
export default readDicomEncapsulatedPdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { | ||
BinaryStream, | ||
InterfaceTypes, | ||
runPipelineNode | ||
} from 'itk-wasm' | ||
|
||
import ReadDicomEncapsulatedPdfOptions from './ReadDicomEncapsulatedPdfOptions.js' | ||
import ReadDicomEncapsulatedPdfNodeResult from './ReadDicomEncapsulatedPdfNodeResult.js' | ||
|
||
|
||
import path from 'path' | ||
|
||
/** | ||
* Extract PDF file from DICOM encapsulated PDF. | ||
* | ||
* @param {Uint8Array} dicomFile - Input DICOM file | ||
* | ||
* @returns {Promise<ReadDicomEncapsulatedPdfNodeResult>} - result object | ||
*/ | ||
async function readDicomEncapsulatedPdfNode( dicomFile: Uint8Array, | ||
options: ReadDicomEncapsulatedPdfOptions = {}) | ||
: Promise<ReadDicomEncapsulatedPdfNodeResult> { | ||
|
||
const desiredOutputs = [ | ||
{ type: InterfaceTypes.BinaryStream }, | ||
] | ||
const inputs = [ | ||
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } }, | ||
] | ||
|
||
const args = [] | ||
// Inputs | ||
args.push('file0') | ||
// Outputs | ||
args.push('0') | ||
// Options | ||
args.push('--memory-io') | ||
if (options.readFileOnly) { | ||
args.push('--read-file-only') | ||
} | ||
if (options.readDataset) { | ||
args.push('--read-dataset') | ||
} | ||
if (options.readXferAuto) { | ||
args.push('--read-xfer-auto') | ||
} | ||
if (options.readXferDetect) { | ||
args.push('--read-xfer-detect') | ||
} | ||
if (options.readXferLittle) { | ||
args.push('--read-xfer-little') | ||
} | ||
if (options.readXferBig) { | ||
args.push('--read-xfer-big') | ||
} | ||
if (options.readXferImplicit) { | ||
args.push('--read-xfer-implicit') | ||
} | ||
if (options.acceptOddLength) { | ||
args.push('--accept-odd-length') | ||
} | ||
if (options.assumeEvenLength) { | ||
args.push('--assume-even-length') | ||
} | ||
if (options.enableCp246) { | ||
args.push('--enable-cp246') | ||
} | ||
if (options.disableCp246) { | ||
args.push('--disable-cp246') | ||
} | ||
if (options.retainUn) { | ||
args.push('--retain-un') | ||
} | ||
if (options.convertUn) { | ||
args.push('--convert-un') | ||
} | ||
if (options.enableCorrection) { | ||
args.push('--enable-correction') | ||
} | ||
if (options.disableCorrection) { | ||
args.push('--disable-correction') | ||
} | ||
|
||
const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), 'pipelines', 'read-dicom-encapsulated-pdf') | ||
|
||
const { | ||
returnValue, | ||
stderr, | ||
outputs | ||
} = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs) | ||
if (returnValue !== 0) { | ||
throw new Error(stderr) | ||
} | ||
|
||
const result = { | ||
pdfBinaryOutput: (outputs[0].data as BinaryStream).data, | ||
} | ||
return result | ||
} | ||
|
||
export default readDicomEncapsulatedPdfNode |