public DicomWriteLengthCalculator(DicomTransferSyntax syntax, DicomWriteOptions options) {
			_syntax = syntax;
			_options = options;
		}
Example #2
0
 public DicomWriter(DicomTransferSyntax syntax, DicomWriteOptions options, IByteTarget target)
 {
     _syntax = syntax;
     _options = options ?? DicomWriteOptions.Default;
     _target = target;
 }
Example #3
0
 public DicomFileWriter(DicomWriteOptions options)
 {
     _options = options;
 }
Example #4
0
 /// <summary>
 /// If necessary, update dataset syntax and group lengths.
 /// </summary>
 /// <param name="syntax">Transfer syntax.</param>
 /// <param name="dataset">DICOM dataset.</param>
 /// <param name="options">Writer options.</param>
 private static void UpdateDatasetGroupLengths(
     DicomTransferSyntax syntax,
     DicomDataset dataset,
     DicomWriteOptions options)
 {
     if (options.KeepGroupLengths)
     {
         // update transfer syntax and recalculate existing group lengths
         dataset.InternalTransferSyntax = syntax;
         dataset.RecalculateGroupLengths(false);
     }
     else
     {
         // remove group lengths as suggested in PS 3.5 7.2
         //
         //	2. It is recommended that Group Length elements be removed during storage or transfer 
         //	   in order to avoid the risk of inconsistencies arising during coercion of data 
         //	   element values and changes in transfer syntax.
         dataset.RemoveGroupLengths();
     }
 }
Example #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);
        }
Example #6
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);
        }
Example #7
0
		public DicomWriteOptions(DicomWriteOptions options) {
			ExplicitLengthSequences = options.ExplicitLengthSequences;
			ExplicitLengthSequenceItems = options.ExplicitLengthSequenceItems;
			KeepGroupLengths = options.KeepGroupLengths;
			LargeObjectSize = options.LargeObjectSize;
		}
Example #8
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 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);
            }
        }
Example #9
0
 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);
 }
Example #10
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 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);
            }
        }