Skip to content

Commit

Permalink
feat(dcm2pdf): generate TS wrapper (bindgen) for read-dicom-encapsula…
Browse files Browse the repository at this point in the history
…ted-pdf

Generate typescript bindings for read-dicom-encapsulated-pdf operation.
  • Loading branch information
jadh4v committed Sep 27, 2022
1 parent 9cb3553 commit c2ef59f
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dist/dicom/src/ReadDicomEncapsulatedPdfNodeResult.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
interface ReadDicomEncapsulatedPdfNodeResult {
/** Output pdf file */
pdfBinaryOutput: Uint8Array

}

export default ReadDicomEncapsulatedPdfNodeResult
49 changes: 49 additions & 0 deletions dist/dicom/src/ReadDicomEncapsulatedPdfOptions.ts
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
10 changes: 10 additions & 0 deletions dist/dicom/src/ReadDicomEncapsulatedPdfResult.ts
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
10 changes: 10 additions & 0 deletions dist/dicom/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@


import ReadDicomEncapsulatedPdfResult from './ReadDicomEncapsulatedPdfResult.js'
export type { ReadDicomEncapsulatedPdfResult }

import ReadDicomEncapsulatedPdfOptions from './ReadDicomEncapsulatedPdfOptions.js'
export type { ReadDicomEncapsulatedPdfOptions }

import readDicomEncapsulatedPdf from './readDicomEncapsulatedPdf.js'
export { readDicomEncapsulatedPdf }


import StructuredReportToHtmlResult from './StructuredReportToHtmlResult.js'
export type { StructuredReportToHtmlResult }

Expand Down
10 changes: 10 additions & 0 deletions dist/dicom/src/indexNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@


import ReadDicomEncapsulatedPdfNodeResult from './ReadDicomEncapsulatedPdfNodeResult.js'
export type { ReadDicomEncapsulatedPdfNodeResult }

import ReadDicomEncapsulatedPdfOptions from './ReadDicomEncapsulatedPdfOptions.js'
export type { ReadDicomEncapsulatedPdfOptions }

import readDicomEncapsulatedPdfNode from './readDicomEncapsulatedPdfNode.js'
export { readDicomEncapsulatedPdfNode }


import StructuredReportToHtmlNodeResult from './StructuredReportToHtmlNodeResult.js'
export type { StructuredReportToHtmlNodeResult }

Expand Down
102 changes: 102 additions & 0 deletions dist/dicom/src/readDicomEncapsulatedPdf.ts
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
101 changes: 101 additions & 0 deletions dist/dicom/src/readDicomEncapsulatedPdfNode.ts
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

0 comments on commit c2ef59f

Please sign in to comment.