comparison Core/DicomParsing/DcmtkTranscoder.cpp @ 3894:8f7ad4989fec transcoding

transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 07 May 2020 11:13:29 +0200
parents 7a5fa8f307e9
children 7459fcb1bdf7
comparison
equal deleted inserted replaced
3893:7a5fa8f307e9 3894:8f7ad4989fec
127 lossyQuality_ = quality; 127 lossyQuality_ = quality;
128 } 128 }
129 } 129 }
130 130
131 131
132 DcmFileFormat* DcmtkTranscoder::TranscodeToParsed(const void* buffer, 132 DcmFileFormat* DcmtkTranscoder::TranscodeToParsed(bool& hasSopInstanceUidChanged /* out */,
133 const void* buffer,
133 size_t size, 134 size_t size,
134 const std::set<DicomTransferSyntax>& allowedSyntaxes, 135 const std::set<DicomTransferSyntax>& allowedSyntaxes,
135 bool allowNewSopInstanceUid) 136 bool allowNewSopInstanceUid)
136 { 137 {
137 std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(buffer, size)); 138 std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(buffer, size));
139 if (dicom.get() == NULL) 140 if (dicom.get() == NULL)
140 { 141 {
141 throw OrthancException(ErrorCode_InternalError); 142 throw OrthancException(ErrorCode_InternalError);
142 } 143 }
143 144
144 if (InplaceTranscode(*dicom, allowedSyntaxes, allowNewSopInstanceUid)) 145 if (InplaceTranscode(hasSopInstanceUidChanged, *dicom, allowedSyntaxes, allowNewSopInstanceUid))
145 { 146 {
146 return dicom.release(); 147 return dicom.release();
147 } 148 }
148 else 149 else
149 { 150 {
150 return NULL; 151 return NULL;
151 } 152 }
152 } 153 }
153 154
154 155
155 bool DcmtkTranscoder::InplaceTranscode(DcmFileFormat& dicom, 156 bool DcmtkTranscoder::InplaceTranscode(bool& hasSopInstanceUidChanged /* out */,
157 DcmFileFormat& dicom,
156 const std::set<DicomTransferSyntax>& allowedSyntaxes, 158 const std::set<DicomTransferSyntax>& allowedSyntaxes,
157 bool allowNewSopInstanceUid) 159 bool allowNewSopInstanceUid)
158 { 160 {
159 if (dicom.getDataset() == NULL) 161 if (dicom.getDataset() == NULL)
160 { 162 {
161 throw OrthancException(ErrorCode_InternalError); 163 throw OrthancException(ErrorCode_InternalError);
162 } 164 }
163 165
166 hasSopInstanceUidChanged = false;
167
164 DicomTransferSyntax syntax; 168 DicomTransferSyntax syntax;
165 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(syntax, dicom)) 169 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(syntax, dicom))
166 { 170 {
167 throw OrthancException(ErrorCode_BadFileFormat, 171 throw OrthancException(ErrorCode_BadFileFormat,
168 "Cannot determine the transfer syntax"); 172 "Cannot determine the transfer syntax");
169 } 173 }
170 174
171 const uint16_t bitsStored = GetBitsStored(*dicom.getDataset()); 175 const uint16_t bitsStored = GetBitsStored(*dicom.getDataset());
172 std::string sourceSopInstanceUid = GetSopInstanceUid(*dicom.getDataset()); 176 std::string sourceSopInstanceUid = GetSopInstanceUid(*dicom.getDataset());
173 177
174 if (allowedSyntaxes.find(syntax) != allowedSyntaxes.end()) 178 if (allowedSyntaxes.find(syntax) != allowedSyntaxes.end())
175 { 179 {
176 // No transcoding is needed 180 // No transcoding is needed
177 return true; 181 return true;
178 } 182 }
214 DJ_RPLossy parameters(lossyQuality_); 218 DJ_RPLossy parameters(lossyQuality_);
215 219
216 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess1, &parameters)) 220 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess1, &parameters))
217 { 221 {
218 CheckSopInstanceUid(dicom, sourceSopInstanceUid, false); 222 CheckSopInstanceUid(dicom, sourceSopInstanceUid, false);
223 hasSopInstanceUidChanged = true;
219 return true; 224 return true;
220 } 225 }
221 } 226 }
222 #endif 227 #endif
223 228
229 // Check out "dcmjpeg/apps/dcmcjpeg.cc" 234 // Check out "dcmjpeg/apps/dcmcjpeg.cc"
230 DJ_RPLossy parameters(lossyQuality_); 235 DJ_RPLossy parameters(lossyQuality_);
231 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess2_4, &parameters)) 236 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess2_4, &parameters))
232 { 237 {
233 CheckSopInstanceUid(dicom, sourceSopInstanceUid, false); 238 CheckSopInstanceUid(dicom, sourceSopInstanceUid, false);
239 hasSopInstanceUidChanged = true;
234 return true; 240 return true;
235 } 241 }
236 } 242 }
237 #endif 243 #endif
238 244
282 * the DCMTK package 3.6.2 from Ubuntu 18.04. 288 * the DCMTK package 3.6.2 from Ubuntu 18.04.
283 **/ 289 **/
284 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGLSLossy, &parameters)) 290 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGLSLossy, &parameters))
285 { 291 {
286 CheckSopInstanceUid(dicom, sourceSopInstanceUid, false); 292 CheckSopInstanceUid(dicom, sourceSopInstanceUid, false);
293 hasSopInstanceUidChanged = true;
287 return true; 294 return true;
288 } 295 }
289 } 296 }
290 #endif 297 #endif
291 298
292 return false; 299 return false;
293 } 300 }
294 301
295 302
296 bool DcmtkTranscoder::TranscodeToBuffer(std::string& target, 303 bool DcmtkTranscoder::TranscodeToBuffer(std::string& target,
304 bool& hasSopInstanceUidChanged /* out */,
297 const void* buffer, 305 const void* buffer,
298 size_t size, 306 size_t size,
299 const std::set<DicomTransferSyntax>& allowedSyntaxes, 307 const std::set<DicomTransferSyntax>& allowedSyntaxes,
300 bool allowNewSopInstanceUid) 308 bool allowNewSopInstanceUid)
301 { 309 {
302 std::unique_ptr<DcmFileFormat> transcoded( 310 std::unique_ptr<DcmFileFormat> transcoded(
303 TranscodeToParsed(buffer, size, allowedSyntaxes, allowNewSopInstanceUid)); 311 TranscodeToParsed(hasSopInstanceUidChanged, buffer, size, allowedSyntaxes, allowNewSopInstanceUid));
304 312
305 if (transcoded.get() == NULL) 313 if (transcoded.get() == NULL)
306 { 314 {
307 return false; 315 return false;
308 } 316 }