重新造bot,方便下载的时候识别具体帧
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
c804bdb5a1
commit
9f060c900f
|
|
@ -478,8 +478,37 @@ namespace IRaCIS.Core.SCP.Service
|
|||
// 每个 fragment 固定大小 (64KB 示例,可以自己调整)
|
||||
int fragmentSize = 20 * 1024;
|
||||
|
||||
if (syntax.IsEncapsulated)
|
||||
//var numberOfFrames = dicomFile.Dataset.GetSingleValueOrDefault(DicomTag.NumberOfFrames, 1);
|
||||
|
||||
var frag = dicomFile.Dataset.GetDicomItem<DicomOtherByteFragment>(DicomTag.PixelData);
|
||||
|
||||
int fragmentCount = frag.Fragments.Count();
|
||||
|
||||
var originOffsetTable = frag.OffsetTable; //有可能没有表,需要自己重建
|
||||
|
||||
var bot = new List<uint>();
|
||||
|
||||
uint botOffset = 0;
|
||||
|
||||
if (syntax.IsEncapsulated && fragmentCount == pixelData.NumberOfFrames)
|
||||
{
|
||||
//// ① 先复制 Dataset(非常关键)
|
||||
//var newDataset = dicomFile.Dataset.Clone();
|
||||
|
||||
//// ② 从“旧 dataset”读 PixelData
|
||||
//var srcPd = DicomPixelData.Create(dicomFile.Dataset);
|
||||
|
||||
//// ③ 在“新 dataset”中创建新的 PixelData
|
||||
//var dstPd = DicomPixelData.Create(newDataset, true);
|
||||
|
||||
//// ④ 重建 PixelData(自动 BOT)
|
||||
//for (int i = 0; i < srcPd.NumberOfFrames; i++)
|
||||
//{
|
||||
// var frame = srcPd.GetFrame(i);
|
||||
// dstPd.AddFrame(frame);
|
||||
//}
|
||||
|
||||
|
||||
var newFragments = new DicomOtherByteFragment(DicomTag.PixelData);
|
||||
|
||||
for (int n = 0; n < pixelData.NumberOfFrames; n++)
|
||||
|
|
@ -488,6 +517,10 @@ namespace IRaCIS.Core.SCP.Service
|
|||
var data = frameData.Data;
|
||||
int offset = 0;
|
||||
|
||||
bot.Add(botOffset);
|
||||
|
||||
botOffset += (uint)data.Length; // 累加帧长度
|
||||
|
||||
while (offset < data.Length)
|
||||
{
|
||||
int size = Math.Min(fragmentSize, data.Length - offset);
|
||||
|
|
@ -495,10 +528,25 @@ namespace IRaCIS.Core.SCP.Service
|
|||
Buffer.BlockCopy(data, offset, buffer, 0, size);
|
||||
|
||||
newFragments.Fragments.Add(new MemoryByteBuffer(buffer));
|
||||
|
||||
offset += size;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//保留原始偏移表
|
||||
|
||||
if (originOffsetTable.Count == pixelData.NumberOfFrames)
|
||||
{
|
||||
newFragments.OffsetTable.AddRange(originOffsetTable.ToArray());
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
newFragments.OffsetTable.AddRange(bot.ToArray());
|
||||
}
|
||||
|
||||
|
||||
// 替换原 PixelData
|
||||
dicomFile.Dataset.AddOrUpdate(newFragments);
|
||||
|
||||
|
|
@ -515,13 +563,13 @@ namespace IRaCIS.Core.SCP.Service
|
|||
|
||||
|
||||
#region 本地测试
|
||||
//// --- 保存到本地文件测试 ---
|
||||
//var localPath = @"D:\TestDicom.dcm";
|
||||
//using (var fs = new FileStream(localPath, FileMode.Create, FileAccess.Write))
|
||||
//{
|
||||
// ms.CopyTo(fs);
|
||||
//}
|
||||
//return new DicomCStoreResponse(request, DicomStatus.Success);
|
||||
// --- 保存到本地文件测试 ---
|
||||
var localPath = @"D:\TestDicom-5.dcm";
|
||||
using (var fs = new FileStream(localPath, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
ms.CopyTo(fs);
|
||||
}
|
||||
return new DicomCStoreResponse(request, DicomStatus.Success);
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue