コード例 #1
0
ファイル: DicomFileWriter.cs プロジェクト: dremerdt/fo-dicom
		private void OnCompletePreamble(IByteTarget target, object state) {
			// recalculate FMI group length as required by standard
			_fileMetaInfo.RecalculateGroupLengths();

			DicomWriter writer = new DicomWriter(DicomTransferSyntax.ExplicitVRLittleEndian, _options, _target);
			DicomDatasetWalker walker = new DicomDatasetWalker(_fileMetaInfo);
			walker.BeginWalk(writer, OnCompleteFileMetaInfo, walker);
		}
コード例 #2
0
        /// <summary>
        /// Write DICOM file preamble.
        /// </summary>
        /// <param name="target">Byte target subject to writing.</param>
        private static Task WritePreambleAsync(IByteTarget target)
        {
            var preamble = new byte[132];
            preamble[128] = (byte)'D';
            preamble[129] = (byte)'I';
            preamble[130] = (byte)'C';
            preamble[131] = (byte)'M';

            return target.WriteAsync(preamble, 0, 132);
        }
コード例 #3
0
 public static IAsyncResult BeginWrite(
     this DicomFileWriter @this,
     IByteTarget target,
     DicomFileMetaInformation fileMetaInfo,
     DicomDataset dataset,
     AsyncCallback callback,
     object state)
 {
     return AsyncFactory.ToBegin(@this.WriteAsync(target, fileMetaInfo, dataset), callback, state);
 }
コード例 #4
0
        /// <summary>
        /// Write DICOM file preamble.
        /// </summary>
        /// <param name="target">Byte target subject to writing.</param>
        private static void WritePreamble(IByteTarget target)
        {
            var preamble = new byte[132];
            preamble[128] = (byte)'D';
            preamble[129] = (byte)'I';
            preamble[130] = (byte)'C';
            preamble[131] = (byte)'M';

            target.Write(preamble, 0, 132);
        }
コード例 #5
0
        /// <summary>
        /// Write DICOM file meta information.
        /// </summary>
        /// <param name="target">Byte target subject to writing.</param>
        /// <param name="fileMetaInfo">File meta information.</param>
        /// <param name="options">Writer options.</param>
        private static void WriteFileMetaInfo(
            IByteTarget target,
            DicomDataset fileMetaInfo,
            DicomWriteOptions options)
        {
            // recalculate FMI group length as required by standard
            fileMetaInfo.RecalculateGroupLengths();

            var writer = new DicomWriter(DicomTransferSyntax.ExplicitVRLittleEndian, options, target);
            var walker = new DicomDatasetWalker(fileMetaInfo);

            walker.Walk(writer);
        }
コード例 #6
0
 public void writeToTarget(IByteTarget target, IByteBuffer buff)
 {
     foreach (IByteBuffer buffer in Buffers)
     {
         if (buffer is StreamByteBuffer || buffer is FileByteBuffer || buffer is PInvokeByteBuffer)
         {
             buffer.writeToTarget(target, buff);
         }
         else
         {
             target.Write(buffer.Data, 0, buffer.Size);
         }
     }
 }
コード例 #7
0
        public void writeToTarget(IByteTarget _target, IByteBuffer buffer)
        {
            int count = 0;

            byte[] copyBuff = new byte[1024 * 1024];
            Stream.Position = Position;
            while (count + 1024 * 1024 < Size)
            {
                Stream.Read(copyBuff, 0, 1024 * 1024);
                count += 1024 * 1024;
                _target.Write(copyBuff, 0, 1024 * 1024);
            }
            Stream.Read(copyBuff, 0, (int)(Size - count));
            _target.Write(copyBuff, 0, (uint)(Size - count));
        }
コード例 #8
0
        private static void WriteBuffer(IByteTarget target, IByteBuffer buffer, uint largeObjectSize)
        {
            uint offset        = 0;
            uint remainingSize = buffer.Size;

            while (remainingSize > largeObjectSize)
            {
                byte[] range = GetBufferRange(buffer, offset, (int)largeObjectSize);
                target.Write(range, 0, largeObjectSize);

                offset        += largeObjectSize;
                remainingSize -= largeObjectSize;
            }
            byte[] endRange = GetBufferRange(buffer, offset, (int)remainingSize);
            target.Write(endRange, 0, remainingSize);
        }
コード例 #9
0
        private static void WriteBuffer(IByteTarget target, IByteBuffer buffer, uint largeObjectSize)
        {
            var offset        = 0;
            var remainingSize = buffer.Size;

            while (remainingSize > largeObjectSize)
            {
                var range = buffer.GetByteRange(offset, (int)largeObjectSize);
                target.Write(range, 0, largeObjectSize);

                offset        += (int)largeObjectSize;
                remainingSize -= largeObjectSize;
            }

            target.Write(buffer.GetByteRange(offset, (int)remainingSize), 0, remainingSize);
        }
コード例 #10
0
        private static async Task WriteBufferAsync(IByteTarget target, IByteBuffer buffer, uint largeObjectSize)
        {
            var offset        = 0;
            var remainingSize = buffer.Size;

            while (remainingSize > largeObjectSize)
            {
                var range = buffer.GetByteRange(offset, (int)largeObjectSize);
                await target.WriteAsync(range, 0, largeObjectSize).ConfigureAwait(false);

                offset        += (int)largeObjectSize;
                remainingSize -= largeObjectSize;
            }

            target.Write(buffer.GetByteRange(offset, (int)remainingSize), 0, remainingSize);
        }
コード例 #11
0
ファイル: DicomFileWriter.cs プロジェクト: dremerdt/fo-dicom
		public IAsyncResult BeginWrite(IByteTarget target, DicomFileMetaInformation fileMetaInfo, DicomDataset dataset, AsyncCallback callback, object state) {
			_target = target;
			_fileMetaInfo = fileMetaInfo;
			_dataset = dataset;

			_async = new EventAsyncResult(callback, state);

			byte[] preamble = new byte[132];
			preamble[128] = (byte)'D';
			preamble[129] = (byte)'I';
			preamble[130] = (byte)'C';
			preamble[131] = (byte)'M';

			_target.Write(preamble, 0, 132, OnCompletePreamble, null);

			return _async;
		}
コード例 #12
0
        public IAsyncResult BeginWrite(IByteTarget target, DicomFileMetaInformation fileMetaInfo, DicomDataset dataset, AsyncCallback callback, object state)
        {
            _target       = target;
            _fileMetaInfo = fileMetaInfo;
            _dataset      = dataset;

            _async = new EventAsyncResult(callback, state);

            byte[] preamble = new byte[132];
            preamble[128] = (byte)'D';
            preamble[129] = (byte)'I';
            preamble[130] = (byte)'C';
            preamble[131] = (byte)'M';

            _target.Write(preamble, 0, 132, OnCompletePreamble, null);

            return(_async);
        }
コード例 #13
0
        //直接写入target,避免调用 public byte[] Data 占用内存
        public void writeToTarget(IByteTarget target)
        {
            foreach (IByteBuffer buffer in Buffers)
            {
                if (buffer is PInvokeByteBuffer)
                {
                    var pb = buffer as PInvokeByteBuffer;

                    var rowBuffer = new byte[pb.RowBufferSize];
                    for (int i = 0; i < pb.Height; i++)
                    {
                        pb.GetByteRange(i, rowBuffer);
                        target.Write(rowBuffer, 0, (uint)rowBuffer.Length);
                    }
                    rowBuffer = null;
                }
                else
                {
                    var data = buffer.Data;
                    target.Write(data, 0, (uint)data.Length);
                }
            }
        }
コード例 #14
0
 /// <summary>
 /// Write DICOM Part 10 object to <paramref name="target"/> asynchronously.
 /// </summary>
 /// <param name="target">Byte target subject to writing.</param>
 /// <param name="fileMetaInfo">File meta information.</param>
 /// <param name="dataset">Dataset.</param>
 /// <returns>Awaitable <see cref="Task"/>.</returns>
 public async Task WriteAsync(IByteTarget target, DicomFileMetaInformation fileMetaInfo, DicomDataset dataset)
 {
     await WritePreambleAsync(target).ConfigureAwait(false);
     await WriteFileMetaInfoAsync(target, fileMetaInfo, _options).ConfigureAwait(false);
     await WriteDatasetAsync(target, fileMetaInfo.TransferSyntax, dataset, _options).ConfigureAwait(false);
 }
コード例 #15
0
ファイル: DicomWriter.cs プロジェクト: GMZ/fo-dicom
 private void OnEndWriteBuffer(IByteTarget target, object state)
 {
     _callback();
 }
コード例 #16
0
 public void Write(IByteTarget target, DicomFileMetaInformation fileMetaInfo, DicomDataset dataset)
 {
     EndWrite(BeginWrite(target, fileMetaInfo, dataset, null, null));
 }
コード例 #17
0
 public void writeToTarget(IByteTarget target)
 {
     throw new NotImplementedException();
 }
コード例 #18
0
ファイル: DicomWriter.cs プロジェクト: sczx888/fo-dicom
 public DicomWriter(DicomTransferSyntax syntax, DicomWriteOptions options, IByteTarget target)
 {
     _syntax  = syntax;
     _options = new DicomWriteOptions();
     _target  = target;
 }
コード例 #19
0
ファイル: DicomWriter.cs プロジェクト: sczx888/fo-dicom
 private void OnEndWriteBuffer(IByteTarget target, object state)
 {
     _callback();
 }
コード例 #20
0
ファイル: DicomFileWriter.cs プロジェクト: aerik/fo-dicom
        /// <summary>
        /// Write DICOM dataset.
        /// </summary>
        /// <param name="target">Byte target subject to writing.</param>
        /// <param name="syntax">Transfer syntax applicable to dataset.</param>
        /// <param name="dataset">Dataset.</param>
        /// <param name="options">Writer options.</param>
        private static async Task WriteDatasetAsync(
            IByteTarget target,
            DicomTransferSyntax syntax,
            DicomDataset dataset,
            DicomWriteOptions options)
        {
            UpdateDatasetGroupLengths(syntax, dataset, options);


            if (syntax.IsDeflate)
            {
                using (var uncompressed = new MemoryStream())
                {
                    var temp = new StreamByteTarget(uncompressed);
                    await WalkDatasetAsync(temp, syntax, dataset, options).ConfigureAwait(false);

                    uncompressed.Seek(0, SeekOrigin.Begin);
                    using (var compressed = new MemoryStream())
                    using (var compressor = new DeflateStream(compressed, CompressionMode.Compress))
                    {
                        uncompressed.CopyTo(compressor);
                        target.Write(compressed.ToArray(), 0, (uint)compressed.Length);
                    }
                }
            }
            else
            {
                await WalkDatasetAsync(target, syntax, dataset, options).ConfigureAwait(false);
            }
        }
コード例 #21
0
ファイル: DicomFileWriter.cs プロジェクト: jwake/fo-dicom
 private void OnCompletePreamble(IByteTarget target, object state)
 {
     DicomWriter writer = new DicomWriter(DicomTransferSyntax.ExplicitVRLittleEndian, _options, _target);
     DicomDatasetWalker walker = new DicomDatasetWalker(_fileMetaInfo);
     walker.BeginWalk(writer, OnCompleteFileMetaInfo, walker);
 }
コード例 #22
0
ファイル: DicomFileWriter.cs プロジェクト: aerik/fo-dicom
        /// <summary>
        /// Write DICOM dataset.
        /// </summary>
        /// <param name="target">Byte target subject to writing.</param>
        /// <param name="syntax">Transfer syntax applicable to dataset.</param>
        /// <param name="dataset">Dataset.</param>
        /// <param name="options">Writer options.</param>
        private static void WriteDataset(
            IByteTarget target,
            DicomTransferSyntax syntax,
            DicomDataset dataset,
            DicomWriteOptions options)
        {
            UpdateDatasetGroupLengths(syntax, dataset, options);

            if (syntax.IsDeflate)
            {
#if NET35
                throw new NotSupportedException("Deflated datasets not supported in Unity.");
#else
                using (var uncompressed = new MemoryStream())
                {
                    var temp = new StreamByteTarget(uncompressed);
                    WalkDataset(temp, syntax, dataset, options);

                    uncompressed.Seek(0, SeekOrigin.Begin);
                    using (var compressed = new MemoryStream())
                    using (var compressor = new DeflateStream(compressed, CompressionMode.Compress))
                    {
                        uncompressed.CopyTo(compressor);
                        target.Write(compressed.ToArray(), 0, (uint)compressed.Length);
                    }
                }
#endif
            }
            else
            {
                WalkDataset(target, syntax, dataset, options);
            }
        }
コード例 #23
0
ファイル: DicomWriter.cs プロジェクト: GMZ/fo-dicom
 public DicomWriter(DicomTransferSyntax syntax, DicomWriteOptions options, IByteTarget target)
 {
     _syntax = syntax;
     _options = options ?? DicomWriteOptions.Default;
     _target = target;
 }
コード例 #24
0
 /// <summary>
 /// Write DICOM Part 10 object to <paramref name="target"/> asynchronously.
 /// </summary>
 /// <param name="target">Byte target subject to writing.</param>
 /// <param name="fileMetaInfo">File meta information.</param>
 /// <param name="dataset">Dataset.</param>
 /// <returns>Awaitable <see cref="Task"/>.</returns>
 public async Task WriteAsync(IByteTarget target, DicomFileMetaInformation fileMetaInfo, DicomDataset dataset)
 {
     await WritePreambleAsync(target).ConfigureAwait(false);
     await WriteFileMetaInfoAsync(target, fileMetaInfo, this.options).ConfigureAwait(false);
     await WriteDatasetAsync(target, fileMetaInfo.TransferSyntax, dataset, this.options).ConfigureAwait(false);
 }
コード例 #25
0
 /// <summary>
 /// Write DICOM Part 10 object to <paramref name="target"/>.
 /// </summary>
 /// <param name="target">Byte target subject to writing.</param>
 /// <param name="fileMetaInfo">File meta information.</param>
 /// <param name="dataset">Dataset.</param>
 public void Write(IByteTarget target, DicomFileMetaInformation fileMetaInfo, DicomDataset dataset)
 {
     WritePreamble(target);
     WriteFileMetaInfo(target, fileMetaInfo, this.options);
     WriteDataset(target, fileMetaInfo.TransferSyntax, dataset, this.options);
 }
コード例 #26
0
        /// <summary>
        /// Write DICOM dataset.
        /// </summary>
        /// <param name="target">Byte target subject to writing.</param>
        /// <param name="syntax">Transfer syntax applicable to dataset.</param>
        /// <param name="dataset">Dataset.</param>
        /// <param name="options">Writer options.</param>
        private static Task WriteDatasetAsync(
            IByteTarget target,
            DicomTransferSyntax syntax,
            DicomDataset dataset,
            DicomWriteOptions options)
        {
            UpdateDatasetGroupLengths(syntax, dataset, options);

            var writer = new DicomWriter(syntax, options, target);
            var walker = new DicomDatasetWalker(dataset);
            return walker.WalkAsync(writer);
        }
コード例 #27
0
 public void writeToTarget(IByteTarget target, IByteBuffer buffer)
 {
     throw new System.NotImplementedException();
 }
コード例 #28
0
 /// <summary>
 /// Write DICOM Part 10 object to <paramref name="target"/>.
 /// </summary>
 /// <param name="target">Byte target subject to writing.</param>
 /// <param name="fileMetaInfo">File meta information.</param>
 /// <param name="dataset">Dataset.</param>
 public void Write(IByteTarget target, DicomFileMetaInformation fileMetaInfo, DicomDataset dataset)
 {
     WritePreamble(target);
     WriteFileMetaInfo(target, fileMetaInfo, this.options);
     WriteDataset(target, fileMetaInfo.TransferSyntax, dataset, this.options);
 }
コード例 #29
0
 /// <summary>
 /// Initializes an instance of <see cref="DicomWriter"/>.
 /// </summary>
 /// <param name="syntax">Writer transfer syntax.</param>
 /// <param name="options">Writer options.</param>
 /// <param name="target">Target to which to write the DICOM object.</param>
 public DicomWriter(DicomTransferSyntax syntax, DicomWriteOptions options, IByteTarget target)
 {
     _syntax  = syntax;
     _options = options ?? DicomWriteOptions.Default;
     _target  = target;
 }
コード例 #30
0
ファイル: DicomFileWriter.cs プロジェクト: aerik/fo-dicom
 private static void WalkDataset(
     IByteTarget target,
     DicomTransferSyntax syntax,
     DicomDataset dataset,
     DicomWriteOptions options)
 {
     var writer = new DicomWriter(syntax, options, target);
     var walker = new DicomDatasetWalker(dataset);
     walker.Walk(writer);
 }
コード例 #31
0
ファイル: DicomFileWriter.cs プロジェクト: GMZ/fo-dicom
 public void Write(IByteTarget target, DicomFileMetaInformation fileMetaInfo, DicomDataset dataset)
 {
     EndWrite(BeginWrite(target, fileMetaInfo, dataset, null, null));
 }
コード例 #32
0
ファイル: DicomWriter.cs プロジェクト: fo-dicom/fo-dicom
 private static Task WriteBufferAsync(IByteTarget target, IByteBuffer buffer, CancellationToken cancellationToken)
 => buffer.CopyToStreamAsync(target.AsWritableStream(), cancellationToken);
コード例 #33
0
ファイル: DicomWriter.cs プロジェクト: fo-dicom/fo-dicom
 private static void WriteBuffer(IByteTarget target, IByteBuffer buffer)
 => buffer.CopyToStream(target.AsWritableStream());
コード例 #34
0
        /// <summary>
        /// Write DICOM file meta information.
        /// </summary>
        /// <param name="target">Byte target subject to writing.</param>
        /// <param name="fileMetaInfo">File meta information.</param>
        /// <param name="options">Writer options.</param>
        private static void WriteFileMetaInfo(
            IByteTarget target,
            DicomDataset fileMetaInfo,
            DicomWriteOptions options)
        {
            // recalculate FMI group length as required by standard
            fileMetaInfo.RecalculateGroupLengths();

            var writer = new DicomWriter(DicomTransferSyntax.ExplicitVRLittleEndian, options, target);
            var walker = new DicomDatasetWalker(fileMetaInfo);
            walker.Walk(writer);
        }