Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const jpegBeforeEncode = (options, encoder) => {
const quality = options.quality ?? 99;
// First value is to encode as reversible lossless colour
return (encoder) => {
console.log("Calling setQuality", quality, !!encoder.setQuality);
encoder.setQuality(quality);
};
};
Expand Down Expand Up @@ -67,6 +66,10 @@ const transcodeDestinationMap = {
transcodeOp: transcodeOp.encode,
beforeEncode: htj2kBeforeEncode({ lossy: true }),
},
jxl: {
transferSyntaxUid: "1.2.840.10008.1.2.4.110",
transcodeOp: transcodeOp.encode,
},
jpeg: {
transferSyntaxUid: "1.2.840.10008.1.2.4.50",
transcodeOp: transcodeOp.encode,
Expand Down Expand Up @@ -115,6 +118,10 @@ const transcodeSourceMap = {
transcodeOp: transcodeOp.decode,
alias: "jhc",
},
"1.2.840.10008.1.2.4.110": {
transcodeOp: transcodeOp.decode,
alias: "jxl",
},
"1.2.840.10008.1.2.4.202": {
transcodeOp: transcodeOp.decode,
alias: "jhc",
Expand All @@ -135,7 +142,7 @@ function getDestinationTranscoder(id) {
const destinationTranscoderEntry =
transcodeDestinationMap[id] ||
Object.values(transcodeDestinationMap).find(
(value) => value.transferSyntaxUid === id,
(value) => value.transferSyntaxUid === id
);
return destinationTranscoderEntry;
}
Expand All @@ -149,7 +156,7 @@ function getDestinationTranscoder(id) {
function getTranscoder(
transferSyntaxUid,
{ contentType: greyContentType, colorContentType },
samplesPerPixel,
samplesPerPixel
) {
const contentType =
samplesPerPixel === 3 ? colorContentType : greyContentType;
Expand Down Expand Up @@ -188,7 +195,7 @@ function shouldTranscodeImageFrame(id, options, samplesPerPixel) {
console.verbose(
"Not transcoding because no decoder found for",
transferSyntaxUid,
samplesPerPixel,
samplesPerPixel
);
return false;
}
Expand All @@ -199,7 +206,7 @@ function shouldTranscodeImageFrame(id, options, samplesPerPixel) {
"Not transcoding because recompress",
recompress,
"does not include",
transcoder.alias,
transcoder.alias
);
return false;
}
Expand Down Expand Up @@ -262,7 +269,7 @@ function scale(imageFrame, imageInfo) {
samplesPerPixel,
};
dest.pixelData = new ArrayConstructor(
dest.rows * dest.columns * samplesPerPixel,
dest.rows * dest.columns * samplesPerPixel
);
replicate(src, dest);

Expand Down Expand Up @@ -295,7 +302,7 @@ async function generateLossyImage(id, decoded, options) {
...id,
imageFrameRootPath: id.imageFrameRootPath.replace(
"frames",
options.alternateName,
options.alternateName
),
transferSyntaxUid: transcodeDestinationMap.jhc.transferSyntaxUid,
};
Expand Down Expand Up @@ -329,13 +336,7 @@ async function generateLossyImage(id, decoded, options) {
imageFrame,
imageInfo,
lossyId.transferSyntaxUid,
encodeOptions,
);
console.log(
"Encoded alternate",
lossyId.transferSyntaxUid,
"of size",
lossyEncoding.imageFrame.length,
encodeOptions
);

return { id: lossyId, imageFrame: lossyEncoding.imageFrame };
Expand Down Expand Up @@ -363,7 +364,7 @@ async function transcodeImageFrame(
targetIdSrc,
imageFrame,
dataSet,
options = {},
options = {}
) {
let targetId = targetIdSrc;
let result = {};
Expand All @@ -386,7 +387,7 @@ async function transcodeImageFrame(
const transcoder = getTranscoder(
id.transferSyntaxUid,
options,
samplesPerPixel,
samplesPerPixel
);

// Don't transcode if not required
Expand All @@ -397,7 +398,7 @@ async function transcodeImageFrame(
console.verbose(
"Image is already in",
targetId.transferSyntaxUid,
"not transcoding",
"not transcoding"
);
return {
id,
Expand All @@ -411,6 +412,7 @@ async function transcodeImageFrame(
const imageInfo = getImageInfo(dataSet);
let done = false;
let processResultMsg = "";

const encodeOptions = {
beforeEncode: transcoder.beforeEncode,
};
Expand All @@ -421,53 +423,47 @@ async function transcodeImageFrame(
case transcodeOp.transcode:
transcodeLog(
options,
`Full transcoding image from \x1b[43m${id.transferSyntaxUid}\x1b[0m to \x1b[43m${targetId.transferSyntaxUid}\x1b[0m`,
`Full transcoding image from \x1b[43m${id.transferSyntaxUid}\x1b[0m to \x1b[43m${targetId.transferSyntaxUid}\x1b[0m`
);

decoded = await dicomCodec.decode(
imageFrame,
imageInfo,
id.transferSyntaxUid,
id.transferSyntaxUid
);
result = await dicomCodec.encode(
decoded.imageFrame,
decoded.imageInfo,
targetId.transferSyntaxUid,
encodeOptions,
encodeOptions
);

console.log(
"transcoded image to",
targetId.transferSyntaxUid,
"of size",
result.imageFrame.length,
);
processResultMsg = `Transcoding finished`;
break;
case transcodeOp.encode:
transcodeLog(
options,
`Encoding image to \x1b[43m${targetId.transferSyntaxUid}\x1b[0m`,
`Encoding image to \x1b[43m${targetId.transferSyntaxUid}\x1b[0m`
);

result = await dicomCodec.encode(
imageFrame,
imageInfo,
targetId.transferSyntaxUid,
encodeOptions,
encodeOptions
);

processResultMsg = `Encoding finished`;
break;
case transcodeOp.decode:
transcodeLog(
options,
`Decoding image from \x1b[43m${id.transferSyntaxUid}\x1b[0m`,
`Decoding image from \x1b[43m${id.transferSyntaxUid}\x1b[0m`
);
result = await dicomCodec.decode(
imageFrame,
imageInfo,
id.transferSyntaxUid,
id.transferSyntaxUid
);

processResultMsg = `Decoding finished`;
Expand All @@ -478,7 +474,7 @@ async function transcodeImageFrame(

done = !!result.imageFrame;
} catch (e) {
transcodeLog(options, "Failed to transcode image", e);
console.warn("Failed to transcode image", e);
}

// recover transfer syntax
Expand Down Expand Up @@ -519,7 +515,7 @@ function transcodeId(id, options, samplesPerPixel) {
const { transferSyntaxUid } = getTranscoder(
id.transferSyntaxUid,
options,
samplesPerPixel,
samplesPerPixel
);

targetId.transferSyntaxUid = transferSyntaxUid;
Expand Down Expand Up @@ -552,7 +548,7 @@ function transcodeMetadata(metadata, id, options) {
Tags.setValue(
result,
Tags.AvailableTransferSyntaxUID,
transcodedId.transferSyntaxUid,
transcodedId.transferSyntaxUid
);
console.verbose("Apply available tsuid", transcodeId.transferSyntaxUid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function validateMetadata(options) {
return function (id, result) {
const getValue = Tags.getValue.bind(null, result.metadata);
if (verify) {
console.verbose("Validating metadata", id, result);
console.verbose("Validating metadata", id);
if (id.studyInstanceUid.length > 64) {
throw new Error(`StudyInstanceUID too long: ${id.studyInstanceUid}`);
}
Expand Down Expand Up @@ -36,7 +36,7 @@ function validateMetadata(options) {
"\r\n--boundary-response\r\n" +
"content-type: application/json\r\n\r\n" +
responseMessage +
"\r\n--boundary-response--\r\n",
"\r\n--boundary-response--\r\n"
);
}
};
Expand Down