Mercurial > hg > orthanc
comparison Core/DicomParsing/DcmtkTranscoder.cpp @ 3906:f0dd5ded8927 transcoding
refactoring using IDicomTranscoder::TranscodedDicom
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 08 May 2020 11:16:16 +0200 |
parents | c62f84c7eda9 |
children | 1555feda39e2 |
comparison
equal
deleted
inserted
replaced
3905:061f3d031b5d | 3906:f0dd5ded8927 |
---|---|
369 } | 369 } |
370 #endif | 370 #endif |
371 | 371 |
372 return false; | 372 return false; |
373 } | 373 } |
374 | |
375 | |
376 | |
377 bool DcmtkTranscoder::TranscodeParsedToBuffer( | |
378 std::string& target /* out */, | |
379 DicomTransferSyntax& sourceSyntax /* out */, | |
380 DicomTransferSyntax& targetSyntax /* out */, | |
381 bool& hasSopInstanceUidChanged /* out */, | |
382 DcmFileFormat& dicom /* in, possibly modified */, | |
383 const std::set<DicomTransferSyntax>& allowedSyntaxes, | |
384 bool allowNewSopInstanceUid) | |
385 { | |
386 if (dicom.getDataset() == NULL) | |
387 { | |
388 throw OrthancException(ErrorCode_InternalError); | |
389 } | |
390 | |
391 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, dicom)) | |
392 { | |
393 LOG(ERROR) << "Unsupport transfer syntax for transcoding"; | |
394 return false; | |
395 } | |
396 | |
397 if (InplaceTranscode(hasSopInstanceUidChanged, dicom, allowedSyntaxes, allowNewSopInstanceUid)) | |
398 { | |
399 if (FromDcmtkBridge::LookupOrthancTransferSyntax(targetSyntax, dicom) && | |
400 allowedSyntaxes.find(targetSyntax) != allowedSyntaxes.end() && | |
401 dicom.getDataset() != NULL) | |
402 { | |
403 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom.getDataset()); | |
404 return true; | |
405 } | |
406 else | |
407 { | |
408 throw OrthancException(ErrorCode_InternalError); | |
409 } | |
410 } | |
411 else | |
412 { | |
413 return false; | |
414 } | |
415 } | |
416 | |
417 | |
418 IDicomTranscoder::TranscodedDicom* DcmtkTranscoder::TranscodeToParsed2( | |
419 DcmFileFormat& dicom /* in, possibly modified */, | |
420 const void* buffer /* in, same DICOM file as "dicom" */, | |
421 size_t size, | |
422 const std::set<DicomTransferSyntax>& allowedSyntaxes, | |
423 bool allowNewSopInstanceUid) | |
424 { | |
425 DicomTransferSyntax sourceSyntax; | |
426 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, dicom)) | |
427 { | |
428 LOG(ERROR) << "Unsupport transfer syntax for transcoding"; | |
429 return NULL; | |
430 } | |
431 | |
432 bool hasSopInstanceUidChanged; | |
433 | |
434 if (allowedSyntaxes.find(sourceSyntax) != allowedSyntaxes.end()) | |
435 { | |
436 // No transcoding is needed | |
437 return TranscodedDicom::CreateFromExternal(dicom, false /* no change in UID */); | |
438 } | |
439 else if (InplaceTranscode(hasSopInstanceUidChanged, dicom, | |
440 allowedSyntaxes, allowNewSopInstanceUid)) | |
441 { | |
442 return TranscodedDicom::CreateFromExternal(dicom, hasSopInstanceUidChanged); | |
443 } | |
444 else | |
445 { | |
446 // Cannot transcode | |
447 return NULL; | |
448 } | |
449 } | |
374 } | 450 } |