diff --git a/dist/dicom/src/ReadDicomEncapsulatedPdfNodeResult.ts b/dist/dicom/src/ReadDicomEncapsulatedPdfNodeResult.ts new file mode 100644 index 000000000..7c03d0699 --- /dev/null +++ b/dist/dicom/src/ReadDicomEncapsulatedPdfNodeResult.ts @@ -0,0 +1,7 @@ +interface ReadDicomEncapsulatedPdfNodeResult { + /** Output pdf file */ + pdfBinaryOutput: Uint8Array + +} + +export default ReadDicomEncapsulatedPdfNodeResult diff --git a/dist/dicom/src/ReadDicomEncapsulatedPdfOptions.ts b/dist/dicom/src/ReadDicomEncapsulatedPdfOptions.ts new file mode 100644 index 000000000..73e2f2e27 --- /dev/null +++ b/dist/dicom/src/ReadDicomEncapsulatedPdfOptions.ts @@ -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 diff --git a/dist/dicom/src/ReadDicomEncapsulatedPdfResult.ts b/dist/dicom/src/ReadDicomEncapsulatedPdfResult.ts new file mode 100644 index 000000000..fa43753c5 --- /dev/null +++ b/dist/dicom/src/ReadDicomEncapsulatedPdfResult.ts @@ -0,0 +1,10 @@ +interface ReadDicomEncapsulatedPdfResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Output pdf file */ + pdfBinaryOutput: Uint8Array + +} + +export default ReadDicomEncapsulatedPdfResult diff --git a/dist/dicom/src/index.ts b/dist/dicom/src/index.ts index 5aa31545a..4ebeff972 100644 --- a/dist/dicom/src/index.ts +++ b/dist/dicom/src/index.ts @@ -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 } diff --git a/dist/dicom/src/indexNode.ts b/dist/dicom/src/indexNode.ts index c6f142d0e..c17909986 100644 --- a/dist/dicom/src/indexNode.ts +++ b/dist/dicom/src/indexNode.ts @@ -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 } diff --git a/dist/dicom/src/readDicomEncapsulatedPdf.ts b/dist/dicom/src/readDicomEncapsulatedPdf.ts new file mode 100644 index 000000000..18d1c1e5b --- /dev/null +++ b/dist/dicom/src/readDicomEncapsulatedPdf.ts @@ -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} - result object + */ +async function readDicomEncapsulatedPdf( + webWorker: null | Worker, + dicomFile: Uint8Array, + options: ReadDicomEncapsulatedPdfOptions = {}) + : Promise { + + 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 diff --git a/dist/dicom/src/readDicomEncapsulatedPdfNode.ts b/dist/dicom/src/readDicomEncapsulatedPdfNode.ts new file mode 100644 index 000000000..bbcba315d --- /dev/null +++ b/dist/dicom/src/readDicomEncapsulatedPdfNode.ts @@ -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} - result object + */ +async function readDicomEncapsulatedPdfNode( dicomFile: Uint8Array, + options: ReadDicomEncapsulatedPdfOptions = {}) + : Promise { + + 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