comparison Core/DicomFormat/DicomValue.cpp @ 3519:fc26659493b6

added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
author amazy
date Thu, 19 Sep 2019 13:10:10 +0200
parents 4e43e67f8ecf
children 94f4a18a79cc
comparison
equal deleted inserted replaced
3513:7db879b014ff 3519:fc26659493b6
92 Toolbox::EncodeBase64(target, GetContent()); 92 Toolbox::EncodeBase64(target, GetContent());
93 target.insert(0, "data:" + mime + ";base64,"); 93 target.insert(0, "data:" + mime + ";base64,");
94 } 94 }
95 #endif 95 #endif
96 96
97 // same as ParseValue but in case the value actually contains a sequence,
98 // it will return the first value
99 // this has been introduced to support invalid "width/height" DICOM tags in some US
100 // images where the width is stored as "800\0" !
101 template <typename T,
102 bool allowSigned>
103 static bool ParseFirstValue(T& result,
104 const DicomValue& source)
105 {
106 if (source.IsBinary() ||
107 source.IsNull())
108 {
109 return false;
110 }
111
112 try
113 {
114 std::string value = Toolbox::StripSpaces(source.GetContent());
115 if (value.empty())
116 {
117 return false;
118 }
119
120 if (!allowSigned &&
121 value[0] == '-')
122 {
123 return false;
124 }
125
126 if (value.find("\\") == std::string::npos)
127 {
128 result = boost::lexical_cast<T>(value);
129 return true;
130 }
131 else
132 {
133 std::vector<std::string> tokens;
134 Toolbox::TokenizeString(tokens, value, '\\');
135
136 if (tokens.size() >= 1)
137 {
138 result = boost::lexical_cast<T>(tokens[0]);
139 return true;
140 }
141
142 return false;
143 }
144 }
145 catch (boost::bad_lexical_cast&)
146 {
147 return false;
148 }
149 }
150
97 151
98 template <typename T, 152 template <typename T,
99 bool allowSigned> 153 bool allowSigned>
100 static bool ParseValue(T& result, 154 static bool ParseValue(T& result,
101 const DicomValue& source) 155 const DicomValue& source)
175 bool DicomValue::ParseDouble(double& result) const 229 bool DicomValue::ParseDouble(double& result) const
176 { 230 {
177 return ParseValue<double, true>(result, *this); 231 return ParseValue<double, true>(result, *this);
178 } 232 }
179 233
234 bool DicomValue::ParseFirstUnsignedInteger(unsigned int& result) const
235 {
236 return ParseFirstValue<unsigned int, true>(result, *this);
237 }
238
180 bool DicomValue::CopyToString(std::string& result, 239 bool DicomValue::CopyToString(std::string& result,
181 bool allowBinary) const 240 bool allowBinary) const
182 { 241 {
183 if (IsNull()) 242 if (IsNull())
184 { 243 {