Mercurial > hg > orthanc
changeset 4955:1610e56cadfb
fix ParsedDicomFile::DecodeOverlay() for WebAssembly
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Mar 2022 11:44:40 +0100 |
parents | 60cb4b379485 |
children | 964bbf5cb365 |
files | OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp |
diffstat | 1 files changed, 18 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp Tue Mar 22 12:37:24 2022 +0100 +++ b/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp Wed Mar 23 11:44:40 2022 +0100 @@ -1962,8 +1962,8 @@ Uint16 rows, columns, bitsAllocated, bitPosition; const Sint16* origin = NULL; unsigned long originSize = 0; - const Uint8* overlayData = NULL; - unsigned long overlaySize = 0; + DcmElement* overlay = NULL; + Uint8* overlayData = NULL; if (dataset.findAndGetUint16(DcmTagKey(group, 0x0010), rows).good() && dataset.findAndGetUint16(DcmTagKey(group, 0x0011), columns).good() && @@ -1974,11 +1974,25 @@ bitsAllocated == 1 && dataset.findAndGetUint16(DcmTagKey(group, 0x0102), bitPosition).good() && bitPosition == 0 && - dataset.findAndGetUint8Array(DcmTagKey(group, 0x3000), overlayData, &overlaySize).good() && + dataset.findAndGetElement(DcmTagKey(group, 0x3000), overlay).good() && + overlay != NULL && + overlay->getUint8Array(overlayData).good() && overlayData != NULL) { + /** + * WARNING - It might seem easier to use + * "dataset.findAndGetUint8Array()" that directly gives the size + * of the overlay data (using the "count" parameter), instead of + * "dataset.findAndGetElement()". Unfortunately, this does *not* + * work with Emscripten/WebAssembly, that reports a "count" that + * is half the number of bytes, presumably because of + * discrepancies in the way sizeof are computed inside DCMTK. + * The method "getLengthField()" reports the correct number of + * bytes, even if targeting WebAssembly. + **/ + unsigned int expectedSize = Ceiling(rows * columns, 8); - if (overlaySize < expectedSize) + if (overlay->getLengthField() < expectedSize) { throw OrthancException(ErrorCode_CorruptedFile, "Overlay doesn't have a valid number of bits"); }