Mercurial > hg > orthanc
changeset 6831:616e673d1499 streaming
replaced ServerContext::ReadDicomForHeader() by ReadDicomUntilPixelData()
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Thu, 21 May 2026 10:27:22 +0200 |
| parents | da03aa08b9aa |
| children | 2e85b570380c |
| files | OrthancFramework/Sources/DataSource/DicomDataSource.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerContext.h |
| diffstat | 4 files changed, 39 insertions(+), 67 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Sources/DataSource/DicomDataSource.cpp Thu May 21 09:49:09 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/DicomDataSource.cpp Thu May 21 10:27:22 2026 +0200 @@ -227,6 +227,11 @@ throw OrthancException(ErrorCode_NotEnoughMemory); } + if (attachment.GetCompressionType() != CompressionType_None) + { + throw OrthancException(ErrorCode_BadParameterType); + } + std::unique_ptr<IDataIdentifier> id(new BeginningIdentifier(attachment, static_cast<size_t>(pixelDataOffset))); boost::shared_ptr<IDynamicObject> value = reader.ReadSingle(id.release()); return new Dicom(value);
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Thu May 21 09:49:09 2026 +0200 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Thu May 21 10:27:22 2026 +0200 @@ -3895,16 +3895,16 @@ std::string publicId = call.GetUriComponent("id", ""); - std::string dicomContent; - context.ReadDicomForHeader(dicomContent, publicId); - - // TODO Consider using "DicomMap::ParseDicomMetaInformation()" to - // speed up things here - - ParsedDicomFile dicom(dicomContent); - Json::Value header; - OrthancConfiguration::DefaultDicomHeaderToJson(header, dicom); + + { + std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadDicomUntilPixelData(publicId)); + DicomDataSource::Dicom::Lock lock(*dicom); + + // TODO Consider using "DicomMap::ParseDicomMetaInformation()" to + // speed up things here + OrthancConfiguration::DefaultDicomHeaderToJson(header, lock.GetContent()); + } AnswerDicomAsJson(call, header, OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full)); }
--- a/OrthancServer/Sources/ServerContext.cpp Thu May 21 09:49:09 2026 +0200 +++ b/OrthancServer/Sources/ServerContext.cpp Thu May 21 10:27:22 2026 +0200 @@ -1483,72 +1483,44 @@ } - void ServerContext::ReadDicomForHeader(std::string& dicom, - const std::string& instancePublicId) - { - if (!ReadDicomUntilPixelData(dicom, instancePublicId)) - { - std::unique_ptr<StorageAreaDataSource::Range> raw(ReadRawDicom(instancePublicId)); - raw->Copy(dicom); - } - } - - bool ServerContext::ReadDicomUntilPixelData(std::string& dicom, - const std::string& instancePublicId) + DicomDataSource::Dicom* ServerContext::ReadDicomUntilPixelData(const std::string& instancePublicId) { FileInfo attachment; int64_t revision; // Ignored - if (index_.LookupAttachment(attachment, revision, ResourceType_Instance, instancePublicId, FileContentType_DicomUntilPixelData)) - { - std::unique_ptr<StorageAreaDataSource::Range> range( - StorageAreaDataSource::ReadAttachment( - *storageAreaReader_, attachment, true /* uncompress */, checkMD5_)); - - assert(range->GetSize() == attachment.GetUncompressedSize()); - range->Copy(dicom); - - return true; - } - if (!area_.HasEfficientReadRange()) + if (index_.LookupAttachment(attachment, revision, ResourceType_Instance, + instancePublicId, FileContentType_DicomUntilPixelData)) { - return false; + return DicomDataSource::ReadWhole(*dicomReader_, attachment, checkMD5_); } - - if (!index_.LookupAttachment(attachment, revision, ResourceType_Instance, instancePublicId, FileContentType_Dicom)) + else { - throw OrthancException(ErrorCode_InternalError, - "Unable to read the DICOM file of instance " + instancePublicId); - } + attachment = LookupDicomForInstance(instancePublicId); - std::string s; + std::string metadata; - if (attachment.GetCompressionType() == CompressionType_None && - index_.LookupMetadata(s, instancePublicId, ResourceType_Instance, - MetadataType_Instance_PixelDataOffset) && - !s.empty()) - { - uint64_t pixelDataOffset = 0; - - if (SerializationToolbox::ParseUnsignedInteger64(pixelDataOffset, s)) + if (attachment.GetCompressionType() == CompressionType_None && + index_.LookupMetadata(metadata, instancePublicId, ResourceType_Instance, + MetadataType_Instance_PixelDataOffset) && + !metadata.empty()) { - std::unique_ptr<StorageAreaDataSource::Range> range( - StorageAreaDataSource::ReadBeginning(*storageAreaReader_, attachment, pixelDataOffset)); + uint64_t pixelDataOffset = 0; - assert(range->GetSize() == pixelDataOffset); - range->Copy(dicom); - - return true; // Success + if (SerializationToolbox::ParseUnsignedInteger64(pixelDataOffset, metadata)) + { + return DicomDataSource::ReadUntilPixelData(*dicomReader_, attachment, pixelDataOffset); + } + else + { + LOG(ERROR) << "Metadata \"PixelDataOffset\" is corrupted for instance: " << instancePublicId; + } } - else - { - LOG(ERROR) << "Metadata \"PixelDataOffset\" is corrupted for instance: " << instancePublicId; - } + + // Fallback: The pixel data offset is not present or cannot be used, the whole DICOM file must be read + return DicomDataSource::ReadWhole(*dicomReader_, attachment, checkMD5_); } + } - return false; - } - void ServerContext::SetStoreMD5ForAttachments(bool storeMD5) {
--- a/OrthancServer/Sources/ServerContext.h Thu May 21 09:49:09 2026 +0200 +++ b/OrthancServer/Sources/ServerContext.h Thu May 21 10:27:22 2026 +0200 @@ -388,12 +388,7 @@ DicomDataSource::Dicom* ReadParsedDicom(const std::string& instancePublicId); - // TODO-Streaming : Remove - void ReadDicomForHeader(std::string& dicom, - const std::string& instancePublicId); - - bool ReadDicomUntilPixelData(std::string& dicom, - const std::string& instancePublicId); + DicomDataSource::Dicom* ReadDicomUntilPixelData(const std::string& instancePublicId); void SetStoreMD5ForAttachments(bool storeMD5);
