Mercurial > hg > orthanc
comparison Core/DicomNetworking/DicomStoreUserConnection.cpp @ 3893:7a5fa8f307e9 transcoding
reorganization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 06 May 2020 12:48:28 +0200 |
parents | 904575738462 |
children | 8f7ad4989fec |
comparison
equal
deleted
inserted
replaced
3891:5571082a9df6 | 3893:7a5fa8f307e9 |
---|---|
437 { | 437 { |
438 acceptedSyntaxes.insert(it->first); | 438 acceptedSyntaxes.insert(it->first); |
439 } | 439 } |
440 } | 440 } |
441 } | 441 } |
442 | |
443 | |
444 void DicomStoreUserConnection::Transcode(std::string& sopClassUid /* out */, | |
445 std::string& sopInstanceUid /* out */, | |
446 IDicomTranscoder& transcoder, | |
447 const void* buffer, | |
448 size_t size, | |
449 const std::string& moveOriginatorAET, | |
450 uint16_t moveOriginatorID) | |
451 { | |
452 std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(buffer, size)); | |
453 if (dicom.get() == NULL || | |
454 dicom->getDataset() == NULL) | |
455 { | |
456 throw OrthancException(ErrorCode_NullPointer); | |
457 } | |
458 | |
459 DicomTransferSyntax inputSyntax; | |
460 LookupParameters(sopClassUid, sopInstanceUid, inputSyntax, *dicom); | |
461 | |
462 std::set<DicomTransferSyntax> accepted; | |
463 LookupTranscoding(accepted, sopClassUid, inputSyntax); | |
464 | |
465 if (accepted.find(inputSyntax) != accepted.end()) | |
466 { | |
467 // No need for transcoding | |
468 Store(sopClassUid, sopInstanceUid, *dicom, moveOriginatorAET, moveOriginatorID); | |
469 } | |
470 else | |
471 { | |
472 // Transcoding is needed | |
473 std::set<DicomTransferSyntax> uncompressedSyntaxes; | |
474 | |
475 if (accepted.find(DicomTransferSyntax_LittleEndianImplicit) != accepted.end()) | |
476 { | |
477 uncompressedSyntaxes.insert(DicomTransferSyntax_LittleEndianImplicit); | |
478 } | |
479 | |
480 if (accepted.find(DicomTransferSyntax_LittleEndianExplicit) != accepted.end()) | |
481 { | |
482 uncompressedSyntaxes.insert(DicomTransferSyntax_LittleEndianExplicit); | |
483 } | |
484 | |
485 if (accepted.find(DicomTransferSyntax_BigEndianExplicit) != accepted.end()) | |
486 { | |
487 uncompressedSyntaxes.insert(DicomTransferSyntax_BigEndianExplicit); | |
488 } | |
489 | |
490 std::unique_ptr<DcmFileFormat> transcoded; | |
491 | |
492 if (transcoder.HasInplaceTranscode()) | |
493 { | |
494 if (transcoder.InplaceTranscode(*dicom, uncompressedSyntaxes, false)) | |
495 { | |
496 // In-place transcoding is supported and has succeeded | |
497 transcoded.reset(dicom.release()); | |
498 } | |
499 } | |
500 else | |
501 { | |
502 transcoded.reset(transcoder.TranscodeToParsed(buffer, size, uncompressedSyntaxes, false)); | |
503 } | |
504 | |
505 // WARNING: The "dicom" variable must not be used below this | |
506 // point. The "sopInstanceUid" might also have changed (if | |
507 // using lossy compression). | |
508 | |
509 if (transcoded == NULL || | |
510 transcoded->getDataset() == NULL) | |
511 { | |
512 throw OrthancException( | |
513 ErrorCode_NotImplemented, | |
514 "Cannot transcode from \"" + std::string(GetTransferSyntaxUid(inputSyntax)) + | |
515 "\" to an uncompressed syntax for modality: " + | |
516 GetParameters().GetRemoteModality().GetApplicationEntityTitle()); | |
517 } | |
518 else | |
519 { | |
520 DicomTransferSyntax transcodedSyntax; | |
521 | |
522 // Sanity check | |
523 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(transcodedSyntax, *transcoded) || | |
524 accepted.find(transcodedSyntax) == accepted.end()) | |
525 { | |
526 throw OrthancException(ErrorCode_InternalError); | |
527 } | |
528 else | |
529 { | |
530 Store(sopClassUid, sopInstanceUid, *transcoded, moveOriginatorAET, moveOriginatorID); | |
531 } | |
532 } | |
533 } | |
534 } | |
442 } | 535 } |