forked from chafey/DICOMHTJ2K
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriteDICOMP10File.js
27 lines (24 loc) · 1.04 KB
/
writeDICOMP10File.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const fs = require('fs');
const dcmjs = require('dcmjs');
/**
* Writes the resulting DICOM part10 file.
* @param {Object} dataset - The DICOM dataset object.
* @param {Object} meta - The DICOM file meta header object.
* @param {Boolean} isUsingColorTransform - Flag indicating whether a color transform is used.
* @param {Array<ArrayBuffer>} encodedFrames - Array of HTJ2K encoded frame pixel data.
* @param {string} outputFilePath - The output file path.
*/
const writeDICOMP10File = (dataset, meta, isUsingColorTransform, encodedFrames, outputFilePath) => {
// Update the photometric interpretation
if (isUsingColorTransform) {
dataset.PhotometricInterpretation = 'YBR_RCT';
}
meta.TransferSyntaxUID = { Value: ['1.2.840.10008.1.2.4.202'] }; // HTJ2K Constrained Transfer Syntax
dataset._meta = meta;
dataset.PixelData = encodedFrames;
const dicomP10New = Buffer.from(
dcmjs.data.datasetToDict(dataset).write({ fragmentMultiframe: false })
);
fs.writeFileSync(outputFilePath, dicomP10New);
};
module.exports = writeDICOMP10File;