comparison OrthancServer/ServerContext.cpp @ 3945:0b3256c3ee14 transcoding

simplified IDicomTranscoder
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 19 May 2020 11:24:00 +0200
parents aae045f802f4
children cf6eb4fc6841
comparison
equal deleted inserted replaced
3944:aae045f802f4 3945:0b3256c3ee14
549 return StoreAfterTranscoding(resultPublicId, dicom, mode); 549 return StoreAfterTranscoding(resultPublicId, dicom, mode);
550 } 550 }
551 else 551 else
552 { 552 {
553 // Automated transcoding of incoming DICOM files 553 // Automated transcoding of incoming DICOM files
554 554
555 DicomTransferSyntax sourceSyntax; 555 DicomTransferSyntax sourceSyntax;
556 if (!FromDcmtkBridge::LookupOrthancTransferSyntax( 556 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(
557 sourceSyntax, dicom.GetParsedDicomFile().GetDcmtkObject()) || 557 sourceSyntax, dicom.GetParsedDicomFile().GetDcmtkObject()) ||
558 sourceSyntax == ingestTransferSyntax_) 558 sourceSyntax == ingestTransferSyntax_)
559 { 559 {
563 else 563 else
564 { 564 {
565 std::set<DicomTransferSyntax> syntaxes; 565 std::set<DicomTransferSyntax> syntaxes;
566 syntaxes.insert(ingestTransferSyntax_); 566 syntaxes.insert(ingestTransferSyntax_);
567 567
568 std::unique_ptr<IDicomTranscoder::TranscodedDicom> transcoded( 568 IDicomTranscoder::DicomImage source;
569 TranscodeToParsed(dicom.GetParsedDicomFile().GetDcmtkObject(), 569 source.SetExternalBuffer(dicom.GetBufferData(), dicom.GetBufferSize());
570 dicom.GetBufferData(), dicom.GetBufferSize(), 570
571 syntaxes, true /* allow new SOP instance UID */)); 571 IDicomTranscoder::DicomImage transcoded;
572 572 bool hasSopInstanceUidChanged;
573 if (transcoded.get() == NULL) 573 if (Transcode(transcoded, hasSopInstanceUidChanged,
574 { 574 source, syntaxes, true /* allow new SOP instance UID */))
575 // Cannot transcode => store the original file 575 {
576 return StoreAfterTranscoding(resultPublicId, dicom, mode); 576 std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile());
577 } 577
578 else
579 {
580 std::unique_ptr<ParsedDicomFile> tmp(
581 ParsedDicomFile::AcquireDcmtkObject(transcoded->ReleaseDicom()));
582
583 DicomInstanceToStore toStore; 578 DicomInstanceToStore toStore;
584 toStore.SetParsedDicomFile(*tmp); 579 toStore.SetParsedDicomFile(*tmp);
585 toStore.SetOrigin(dicom.GetOrigin()); 580 toStore.SetOrigin(dicom.GetOrigin());
586 581
587 StoreStatus ok = StoreAfterTranscoding(resultPublicId, toStore, mode); 582 StoreStatus ok = StoreAfterTranscoding(resultPublicId, toStore, mode);
588 assert(resultPublicId == tmp->GetHasher().HashInstance()); 583 assert(resultPublicId == tmp->GetHasher().HashInstance());
589 584
590 return ok; 585 return ok;
586 }
587 else
588 {
589 // Cannot transcode => store the original file
590 return StoreAfterTranscoding(resultPublicId, dicom, mode);
591 } 591 }
592 } 592 }
593 } 593 }
594 } 594 }
595 595
1320 hasMoveOriginator, moveOriginatorAet, moveOriginatorId); 1320 hasMoveOriginator, moveOriginatorAet, moveOriginatorId);
1321 } 1321 }
1322 } 1322 }
1323 1323
1324 1324
1325 bool ServerContext::TranscodeParsedToBuffer(std::string& target /* out */,
1326 bool& hasSopInstanceUidChanged /* out */,
1327 DcmFileFormat& dicom /* in, possibly modified */,
1328 DicomTransferSyntax targetSyntax,
1329 bool allowNewSopInstanceUid)
1330 {
1331 if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_Before)
1332 {
1333 if (dcmtkTranscoder_->TranscodeParsedToBuffer(target, hasSopInstanceUidChanged, dicom,
1334 targetSyntax, allowNewSopInstanceUid))
1335 {
1336 return true;
1337 }
1338 }
1339
1340 #if ORTHANC_ENABLE_PLUGINS == 1
1341 if (HasPlugins() &&
1342 GetPlugins().HasCustomTranscoder())
1343 {
1344 if (GetPlugins().TranscodeParsedToBuffer(target, hasSopInstanceUidChanged, dicom,
1345 targetSyntax, allowNewSopInstanceUid))
1346 {
1347 return true;
1348 }
1349 else if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After)
1350 {
1351 LOG(INFO) << "The installed transcoding plugins cannot handle an image, "
1352 << "fallback to the built-in DCMTK transcoder";
1353 }
1354 }
1355 #endif
1356
1357 if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After)
1358 {
1359 return dcmtkTranscoder_->TranscodeParsedToBuffer(target, hasSopInstanceUidChanged, dicom,
1360 targetSyntax, allowNewSopInstanceUid);
1361 }
1362 else
1363 {
1364 return false;
1365 }
1366 }
1367
1368
1369 IDicomTranscoder::TranscodedDicom*
1370 ServerContext::TranscodeToParsed(DcmFileFormat& dicom,
1371 const void* buffer,
1372 size_t size,
1373 const std::set<DicomTransferSyntax>& allowedSyntaxes,
1374 bool allowNewSopInstanceUid)
1375 {
1376 if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_Before)
1377 {
1378 std::unique_ptr<IDicomTranscoder::TranscodedDicom> transcoded(
1379 dcmtkTranscoder_->TranscodeToParsed(dicom, buffer, size, allowedSyntaxes,
1380 allowNewSopInstanceUid));
1381 if (transcoded.get() != NULL)
1382 {
1383 return transcoded.release();
1384 }
1385 }
1386
1387 #if ORTHANC_ENABLE_PLUGINS == 1
1388 if (HasPlugins() &&
1389 GetPlugins().HasCustomTranscoder())
1390 {
1391 std::unique_ptr<IDicomTranscoder::TranscodedDicom> transcoded(
1392 GetPlugins().TranscodeToParsed(dicom, buffer, size, allowedSyntaxes, allowNewSopInstanceUid));
1393
1394 if (transcoded.get() != NULL)
1395 {
1396 return transcoded.release();
1397 }
1398 else if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After)
1399 {
1400 LOG(INFO) << "The installed transcoding plugins cannot handle an image, "
1401 << "fallback to the built-in DCMTK transcoder";
1402 }
1403 }
1404 #endif
1405
1406 if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After)
1407 {
1408 return dcmtkTranscoder_->TranscodeToParsed(
1409 dicom, buffer, size, allowedSyntaxes, allowNewSopInstanceUid);
1410 }
1411 else
1412 {
1413 return NULL;
1414 }
1415 }
1416
1417
1418 bool ServerContext::Transcode(DicomImage& target, 1325 bool ServerContext::Transcode(DicomImage& target,
1419 bool& hasSopInstanceUidChanged /* out */, 1326 bool& hasSopInstanceUidChanged /* out */,
1420 DicomImage& source /* in, "GetParsed()" possibly modified */, 1327 DicomImage& source /* in, "GetParsed()" possibly modified */,
1421 const std::set<DicomTransferSyntax>& allowedSyntaxes, 1328 const std::set<DicomTransferSyntax>& allowedSyntaxes,
1422 bool allowNewSopInstanceUid) 1329 bool allowNewSopInstanceUid)