Mercurial > hg > orthanc
comparison OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp @ 4955:1610e56cadfb
fix ParsedDicomFile::DecodeOverlay() for WebAssembly
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Mar 2022 11:44:40 +0100 |
parents | dfbe764995cf |
children | 964bbf5cb365 |
comparison
equal
deleted
inserted
replaced
4953:60cb4b379485 | 4955:1610e56cadfb |
---|---|
1960 DcmDataset& dataset = *const_cast<ParsedDicomFile&>(*this).GetDcmtkObject().getDataset(); | 1960 DcmDataset& dataset = *const_cast<ParsedDicomFile&>(*this).GetDcmtkObject().getDataset(); |
1961 | 1961 |
1962 Uint16 rows, columns, bitsAllocated, bitPosition; | 1962 Uint16 rows, columns, bitsAllocated, bitPosition; |
1963 const Sint16* origin = NULL; | 1963 const Sint16* origin = NULL; |
1964 unsigned long originSize = 0; | 1964 unsigned long originSize = 0; |
1965 const Uint8* overlayData = NULL; | 1965 DcmElement* overlay = NULL; |
1966 unsigned long overlaySize = 0; | 1966 Uint8* overlayData = NULL; |
1967 | 1967 |
1968 if (dataset.findAndGetUint16(DcmTagKey(group, 0x0010), rows).good() && | 1968 if (dataset.findAndGetUint16(DcmTagKey(group, 0x0010), rows).good() && |
1969 dataset.findAndGetUint16(DcmTagKey(group, 0x0011), columns).good() && | 1969 dataset.findAndGetUint16(DcmTagKey(group, 0x0011), columns).good() && |
1970 dataset.findAndGetSint16Array(DcmTagKey(group, 0x0050), origin, &originSize).good() && | 1970 dataset.findAndGetSint16Array(DcmTagKey(group, 0x0050), origin, &originSize).good() && |
1971 origin != NULL && | 1971 origin != NULL && |
1972 originSize == 2 && | 1972 originSize == 2 && |
1973 dataset.findAndGetUint16(DcmTagKey(group, 0x0100), bitsAllocated).good() && | 1973 dataset.findAndGetUint16(DcmTagKey(group, 0x0100), bitsAllocated).good() && |
1974 bitsAllocated == 1 && | 1974 bitsAllocated == 1 && |
1975 dataset.findAndGetUint16(DcmTagKey(group, 0x0102), bitPosition).good() && | 1975 dataset.findAndGetUint16(DcmTagKey(group, 0x0102), bitPosition).good() && |
1976 bitPosition == 0 && | 1976 bitPosition == 0 && |
1977 dataset.findAndGetUint8Array(DcmTagKey(group, 0x3000), overlayData, &overlaySize).good() && | 1977 dataset.findAndGetElement(DcmTagKey(group, 0x3000), overlay).good() && |
1978 overlay != NULL && | |
1979 overlay->getUint8Array(overlayData).good() && | |
1978 overlayData != NULL) | 1980 overlayData != NULL) |
1979 { | 1981 { |
1982 /** | |
1983 * WARNING - It might seem easier to use | |
1984 * "dataset.findAndGetUint8Array()" that directly gives the size | |
1985 * of the overlay data (using the "count" parameter), instead of | |
1986 * "dataset.findAndGetElement()". Unfortunately, this does *not* | |
1987 * work with Emscripten/WebAssembly, that reports a "count" that | |
1988 * is half the number of bytes, presumably because of | |
1989 * discrepancies in the way sizeof are computed inside DCMTK. | |
1990 * The method "getLengthField()" reports the correct number of | |
1991 * bytes, even if targeting WebAssembly. | |
1992 **/ | |
1993 | |
1980 unsigned int expectedSize = Ceiling(rows * columns, 8); | 1994 unsigned int expectedSize = Ceiling(rows * columns, 8); |
1981 if (overlaySize < expectedSize) | 1995 if (overlay->getLengthField() < expectedSize) |
1982 { | 1996 { |
1983 throw OrthancException(ErrorCode_CorruptedFile, "Overlay doesn't have a valid number of bits"); | 1997 throw OrthancException(ErrorCode_CorruptedFile, "Overlay doesn't have a valid number of bits"); |
1984 } | 1998 } |
1985 | 1999 |
1986 originX = origin[1]; | 2000 originX = origin[1]; |