# HG changeset patch # User Sebastien Jodogne # Date 1592585116 -7200 # Node ID eab8010c05fc4b930d48a4c0e6837bd222905236 # Parent ea95eecead6f328766716bfe54cc1e37a449ba99 avoid relying on boost::bad_lexical_cast in DicomImageInformation diff -r ea95eecead6f -r eab8010c05fc OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp --- a/OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp Wed Jun 17 18:19:45 2020 +0200 +++ b/OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp Fri Jun 19 18:45:16 2020 +0200 @@ -52,8 +52,8 @@ { DicomImageInformation::DicomImageInformation(const DicomMap& values) { - unsigned int pixelRepresentation; - unsigned int planarConfiguration = 0; + uint32_t pixelRepresentation = 0; + uint32_t planarConfiguration = 0; try { @@ -120,40 +120,27 @@ values.GetValue(DICOM_TAG_COLUMNS).ParseFirstUnsignedInteger(width_); // in some US images, we've seen tag values of "800\0"; that's why we parse the 'first' value values.GetValue(DICOM_TAG_ROWS).ParseFirstUnsignedInteger(height_); - bitsAllocated_ = boost::lexical_cast(values.GetValue(DICOM_TAG_BITS_ALLOCATED).GetContent()); - - try + if (!values.ParseUnsignedInteger32(bitsAllocated_, DICOM_TAG_BITS_ALLOCATED)) { - samplesPerPixel_ = boost::lexical_cast(values.GetValue(DICOM_TAG_SAMPLES_PER_PIXEL).GetContent()); + throw OrthancException(ErrorCode_BadFileFormat); } - catch (OrthancException&) + + if (!values.ParseUnsignedInteger32(samplesPerPixel_, DICOM_TAG_SAMPLES_PER_PIXEL)) { samplesPerPixel_ = 1; // Assume 1 color channel } - try - { - bitsStored_ = boost::lexical_cast(values.GetValue(DICOM_TAG_BITS_STORED).GetContent()); - } - catch (OrthancException&) + if (!values.ParseUnsignedInteger32(bitsStored_, DICOM_TAG_BITS_STORED)) { bitsStored_ = bitsAllocated_; } - try - { - highBit_ = boost::lexical_cast(values.GetValue(DICOM_TAG_HIGH_BIT).GetContent()); - } - catch (OrthancException&) + if (!values.ParseUnsignedInteger32(highBit_, DICOM_TAG_HIGH_BIT)) { highBit_ = bitsStored_ - 1; } - try - { - pixelRepresentation = boost::lexical_cast(values.GetValue(DICOM_TAG_PIXEL_REPRESENTATION).GetContent()); - } - catch (OrthancException&) + if (!values.ParseUnsignedInteger32(pixelRepresentation, DICOM_TAG_PIXEL_REPRESENTATION)) { pixelRepresentation = 0; // Assume unsigned pixels } @@ -162,11 +149,8 @@ { // The "Planar Configuration" is only set when "Samples per Pixels" is greater than 1 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.7.6.3.1.3 - try - { - planarConfiguration = boost::lexical_cast(values.GetValue(DICOM_TAG_PLANAR_CONFIGURATION).GetContent()); - } - catch (OrthancException&) + + if (!values.ParseUnsignedInteger32(planarConfiguration, DICOM_TAG_PLANAR_CONFIGURATION)) { planarConfiguration = 0; // Assume interleaved color channels } @@ -181,13 +165,10 @@ throw OrthancException(ErrorCode_NotImplemented); } + if (values.HasTag(DICOM_TAG_NUMBER_OF_FRAMES)) { - try - { - numberOfFrames_ = boost::lexical_cast(values.GetValue(DICOM_TAG_NUMBER_OF_FRAMES).GetContent()); - } - catch (boost::bad_lexical_cast&) + if (!values.ParseUnsignedInteger32(numberOfFrames_, DICOM_TAG_NUMBER_OF_FRAMES)) { throw OrthancException(ErrorCode_NotImplemented); } diff -r ea95eecead6f -r eab8010c05fc OrthancFramework/Sources/DicomFormat/DicomImageInformation.h --- a/OrthancFramework/Sources/DicomFormat/DicomImageInformation.h Wed Jun 17 18:19:45 2020 +0200 +++ b/OrthancFramework/Sources/DicomFormat/DicomImageInformation.h Fri Jun 19 18:45:16 2020 +0200 @@ -45,15 +45,15 @@ unsigned int width_; unsigned int height_; unsigned int samplesPerPixel_; - unsigned int numberOfFrames_; + uint32_t numberOfFrames_; bool isPlanar_; bool isSigned_; size_t bytesPerValue_; - unsigned int bitsAllocated_; - unsigned int bitsStored_; - unsigned int highBit_; + uint32_t bitsAllocated_; + uint32_t bitsStored_; + uint32_t highBit_; PhotometricInterpretation photometric_;