comparison OrthancServer/Plugins/Engine/OrthancPlugins.cpp @ 5332:f5cb6310e0dc

fix handling of DICOM files without pixel data
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 27 Jun 2023 09:35:31 +0200
parents 808319c1e22b
children b376abae664a
comparison
equal deleted inserted replaced
5331:f294780f0642 5332:f5cb6310e0dc
4454 4454
4455 parsed->RemoveFromPixelData(); 4455 parsed->RemoveFromPixelData();
4456 4456
4457 if (params.mode == OrthancPluginLoadDicomInstanceMode_EmptyPixelData) 4457 if (params.mode == OrthancPluginLoadDicomInstanceMode_EmptyPixelData)
4458 { 4458 {
4459 ValueRepresentation vr = parsed->GuessPixelDataValueRepresentation(); 4459 bool hasPixelData = false;
4460 4460 ValueRepresentation pixelDataVR = parsed->GuessPixelDataValueRepresentation();
4461 // Try and retrieve the VR of pixel data from the metadata of the instance 4461
4462 { 4462 {
4463 PImpl::ServerContextLock lock(*pimpl_); 4463 PImpl::ServerContextLock lock(*pimpl_);
4464 4464
4465 std::string s; 4465 std::string s;
4466 int64_t revision; // unused 4466 int64_t revision; // unused
4467 if (lock.GetContext().GetIndex().LookupMetadata( 4467 if (lock.GetContext().GetIndex().LookupMetadata(
4468 s, revision, params.instanceId, 4468 s, revision, params.instanceId,
4469 ResourceType_Instance, MetadataType_Instance_PixelDataVR)) 4469 ResourceType_Instance, MetadataType_Instance_PixelDataVR))
4470 { 4470 {
4471 hasPixelData = true;
4471 if (s == "OB") 4472 if (s == "OB")
4472 { 4473 {
4473 vr = ValueRepresentation_OtherByte; 4474 pixelDataVR = ValueRepresentation_OtherByte;
4474 } 4475 }
4475 else if (s == "OW") 4476 else if (s == "OW")
4476 { 4477 {
4477 vr = ValueRepresentation_OtherWord; 4478 pixelDataVR = ValueRepresentation_OtherWord;
4478 } 4479 }
4479 else 4480 else
4480 { 4481 {
4481 LOG(WARNING) << "Corrupted PixelDataVR metadata associated with instance " 4482 LOG(WARNING) << "Corrupted PixelDataVR metadata associated with instance "
4482 << params.instanceId << ": " << s; 4483 << params.instanceId << ": " << s;
4483 } 4484 }
4484 } 4485 }
4486 else if (lock.GetContext().GetIndex().LookupMetadata(
4487 s, revision, params.instanceId,
4488 ResourceType_Instance, MetadataType_Instance_PixelDataOffset))
4489 {
4490 // This file was stored by an older version of Orthanc,
4491 // "PixelDataVR" is not available, so use the guess
4492 hasPixelData = true;
4493 }
4494 else
4495 {
4496 hasPixelData = false;
4497 }
4485 } 4498 }
4486 4499
4487 parsed->InjectEmptyPixelData(vr); 4500 if (hasPixelData)
4501 {
4502 parsed->InjectEmptyPixelData(pixelDataVR);
4503 }
4488 } 4504 }
4489 4505
4490 target.reset(new DicomInstanceFromParsed(parsed.release())); 4506 target.reset(new DicomInstanceFromParsed(parsed.release()));
4491 break; 4507 break;
4492 } 4508 }