# HG changeset patch # User Sebastien Jodogne # Date 1779180720 -7200 # Node ID 68d9bad294115d1bad22770c16d55d1301e4c4a3 # Parent 91cb6f565e7dda0bcd1f30d920f7e573d5a96f4f added StorageAreaDataSource::Range::Copy() diff -r 91cb6f565e7d -r 68d9bad29411 OrthancFramework/Sources/DataSource/DicomDataSource.cpp --- a/OrthancFramework/Sources/DataSource/DicomDataSource.cpp Tue May 19 07:28:08 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/DicomDataSource.cpp Tue May 19 10:52:00 2026 +0200 @@ -35,6 +35,28 @@ namespace Orthanc { + static size_t ComputeValueSize(size_t size, + bool isKeepRawBuffer) + { + if (isKeepRawBuffer) + { + uint64_t s = 2 * static_cast(size); + if (s != static_cast(static_cast(s))) + { + return std::numeric_limits::max(); + } + else + { + return static_cast(s); + } + } + else + { + return size; + } + } + + class DicomDataSource::BaseIdentifier : public IDataIdentifier { public: @@ -71,15 +93,7 @@ virtual bool EstimateValueSize(size_t& target) const ORTHANC_OVERRIDE { - if (keepRawBuffer_) - { - target = 2 * attachment_.GetUncompressedSize(); - } - else - { - target = attachment_.GetUncompressedSize(); - } - + target = ComputeValueSize(attachment_.GetUncompressedSize(), keepRawBuffer_); return true; } @@ -225,19 +239,12 @@ const size_t size = range->GetSize(); { - // Sanity check + // Sanity check bool ok = false; size_t estimatedSize; if (obj.EstimateValueSize(estimatedSize)) { - if (id.IsKeepRawBuffer()) - { - ok = (estimatedSize == 2 * size); - } - else - { - ok = (estimatedSize == size); - } + ok = (estimatedSize == ComputeValueSize(size, id.IsKeepRawBuffer())); } if (!ok) @@ -265,15 +272,7 @@ size_t DicomDataSource::GetValueSize(const IDynamicObject& obj) const { const Value& value = dynamic_cast(obj); - - if (value.HasRawBuffer()) - { - return 2 * value.GetRawBufferSize(); - } - else - { - return value.GetRawBufferSize(); - } + return ComputeValueSize(value.GetRawBufferSize(), value.HasRawBuffer()); } @@ -324,9 +323,14 @@ DicomDataSource::Dicom* DicomDataSource::ReadUntilPixelData(DataSourceReader& reader, const FileInfo& attachment, - size_t pixelDataOffset) + uint64_t pixelDataOffset) { - std::unique_ptr id(new BeginningIdentifier(attachment, pixelDataOffset)); + if (static_cast(static_cast(pixelDataOffset)) != pixelDataOffset) + { + throw OrthancException(ErrorCode_NotEnoughMemory); + } + + std::unique_ptr id(new BeginningIdentifier(attachment, static_cast(pixelDataOffset))); boost::shared_ptr value = reader.ReadSingle(id.release()); return new Dicom(value); } diff -r 91cb6f565e7d -r 68d9bad29411 OrthancFramework/Sources/DataSource/DicomDataSource.h --- a/OrthancFramework/Sources/DataSource/DicomDataSource.h Tue May 19 07:28:08 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/DicomDataSource.h Tue May 19 10:52:00 2026 +0200 @@ -107,6 +107,6 @@ static Dicom* ReadUntilPixelData(DataSourceReader& reader, const FileInfo& attachment, - size_t pixelDataOffset); + uint64_t pixelDataOffset); }; } diff -r 91cb6f565e7d -r 68d9bad29411 OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp --- a/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp Tue May 19 07:28:08 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp Tue May 19 10:52:00 2026 +0200 @@ -162,6 +162,13 @@ } + void StorageAreaDataSource::Range::Copy(std::string& to) const + { + const IMemoryBuffer& buffer = GetValue().GetBuffer(); + to.assign(reinterpret_cast(buffer.GetData()), buffer.GetSize()); + } + + StorageAreaDataSource::Range* StorageAreaDataSource::ReadRange(DataSourceReader& reader, const std::string& uuid, FileContentType type, @@ -252,7 +259,7 @@ StorageAreaDataSource::Range* StorageAreaDataSource::ReadBeginning(DataSourceReader& reader, const FileInfo& attachment, - size_t untilPosition) + uint64_t untilPosition) { if (attachment.GetCompressionType() != CompressionType_None) { diff -r 91cb6f565e7d -r 68d9bad29411 OrthancFramework/Sources/DataSource/StorageAreaDataSource.h --- a/OrthancFramework/Sources/DataSource/StorageAreaDataSource.h Tue May 19 07:28:08 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/StorageAreaDataSource.h Tue May 19 10:52:00 2026 +0200 @@ -72,6 +72,8 @@ const void* GetData() const; size_t GetSize() const; + + void Copy(std::string& to) const; }; static Range* ReadRange(DataSourceReader& reader, @@ -88,6 +90,6 @@ static Range* ReadBeginning(DataSourceReader& reader, const FileInfo& attachment, - size_t untilPosition); + uint64_t untilPosition); }; }