private void UnregisterUnregistersTransferSyntax()
        {
            var uid = new DicomUID("0", "testing", DicomUidType.TransferSyntax);

            DicomTransferSyntax.Register(uid);
            Assert.NotNull(DicomTransferSyntax.Query(uid));

            DicomTransferSyntax.Unregister(uid);
            Assert.Null(DicomTransferSyntax.Query(uid));
        }
Esempio n. 2
0
        /// <summary>
        /// Add or update the image pixel data element in the dataset
        /// </summary>
        /// <param name="vr">DICOM vr of the image pixel. For a PixelData element this value should be either DicomVR.OB or DicomVR.OW DICOM VR.</param>
        /// <param name="pixelData">An <see cref="IByteBuffer"/> that holds the image pixel data </param>
        /// <param name="transferSyntax">A DicomTransferSyntax object of the <paramref name="pixelData"/> parameter.
        /// If parameter is not provided (null), then the default TransferSyntax "ExplicitVRLittleEndian" will be applied to the dataset</param>
        /// <remarks>Use this method whenever you are attaching an external image pixel data to the dataset and provide the proper TransferSyntax</remarks>
        /// <returns>The dataset instance.</returns>
        public DicomDataset AddOrUpdatePixelData(DicomVR vr, IByteBuffer pixelData, DicomTransferSyntax transferSyntax = null)
        {
            this.AddOrUpdate(vr, DicomTag.PixelData, pixelData);

            if (null != transferSyntax)
            {
                InternalTransferSyntax = transferSyntax;
            }

            return(this);
        }
        private void RegisterHandlesMultipleRegistrations()
        {
            var uid = new DicomUID("0", "testing", DicomUidType.TransferSyntax);

            //  should not matter if 2 instances are same.
            Assert.NotNull(DicomTransferSyntax.Register(uid));
            Assert.NotNull(DicomTransferSyntax.Register(uid));

            //  just to be sure
            DicomTransferSyntax.Unregister(uid);
        }
        public void CanParseUnkownTransferSyntax()
        {
            var ts = DicomTransferSyntax.Parse("1.2.3.4.5.6.7.8.9.0");

            Assert.Equal(Endian.Little, ts.Endian);
            Assert.False(ts.IsRetired);
            Assert.True(ts.IsExplicitVR);
            Assert.True(ts.IsEncapsulated);
            Assert.Equal("Unknown", ts.UID.Name);
            Assert.Equal(DicomUidType.TransferSyntax, ts.UID.Type);
            Assert.Equal("1.2.3.4.5.6.7.8.9.0", ts.UID.UID);
        }
		public bool ChangeTransferSyntax(DicomTransferSyntax newTransferSyntax)
		{
			try
			{
				DicomFile = DicomFile.ChangeTransferSyntax(newTransferSyntax);
				return true;
			}
			catch (Exception)
			{
				return false;
			}
		}
        private void QueryReturnsRegisteredTransferSyntax()
        {
            var uid = new DicomUID("0", "testing", DicomUidType.TransferSyntax);

            DicomTransferSyntax.Register(uid);

            var ts = DicomTransferSyntax.Query(uid);

            Assert.NotNull(ts);
            Assert.Equal(uid, ts.UID);

            DicomTransferSyntax.Unregister(uid);
        }
        private void UnregisterHandleMultipleUnregistrations()
        {
            var uid = new DicomUID("0", "testing", DicomUidType.TransferSyntax);

            DicomTransferSyntax.Register(uid);
            Assert.NotNull(DicomTransferSyntax.Query(uid));

            Assert.True(DicomTransferSyntax.Unregister(uid));
            Assert.Null(DicomTransferSyntax.Query(uid));

            Assert.False(DicomTransferSyntax.Unregister(uid));
            Assert.Null(DicomTransferSyntax.Query(uid));
        }
        private void LookupReturnsAdHocTransferSyntax()
        {
            var uid = new DicomUID("0", "testing", DicomUidType.TransferSyntax);

            var ts = DicomTransferSyntax.Lookup(uid);

            Assert.NotNull(ts);
            Assert.Equal(uid, ts.UID);

            //  Lookup must not auto-register, as it is invoked from DicomServer.
            //  auto-registration may cause DoS by sending crafted transfer syntaxes repeatedly,
            //  which causes internal static dictionary to hold all the transfer syntaxes.
            Assert.Null(DicomTransferSyntax.Query(uid));
        }
        private void RegisterRegistersTransferSyntax()
        {
            var uid = new DicomUID("0", "testing", DicomUidType.TransferSyntax);

            Assert.Null(DicomTransferSyntax.Query(uid));

            var ts1 = DicomTransferSyntax.Register(uid);

            Assert.NotNull(ts1);

            var ts2 = DicomTransferSyntax.Query(uid);

            Assert.Equal(uid, ts2.UID);

            DicomTransferSyntax.Unregister(uid);
        }
 /// <summary>
 /// unregister transfer syntax from internal dictionary.
 /// </summary>
 /// <param name="ts"></param>
 /// <returns></returns>
 public static bool Unregister(DicomTransferSyntax ts)
 {
     return(Unregister(ts.UID));
 }
Esempio n. 11
0
		private void ChangeSyntax(DicomTransferSyntax syntax, DicomCodecParams param = null) {
			var file = _file.ChangeTransferSyntax(syntax, param);
			OpenFile(file);
		}
Esempio n. 12
0
        public void DicomUniqueIdentifier_GetKnownTransferSyntax_ReturnsFullField(DicomUID uid, DicomTransferSyntax expected)
        {
            var tag    = DicomTag.ReferencedTransferSyntaxUIDInFile;
            var ui     = new DicomUniqueIdentifier(tag, uid);
            var actual = ui.Get <DicomTransferSyntax>(0);

            Assert.Equal(expected.UID, actual.UID);
            Assert.Equal(expected.Endian, actual.Endian);
            Assert.Equal(expected.LossyCompressionMethod, actual.LossyCompressionMethod);
        }
        public void CanParseKnownTransferSyntax()
        {
            var ts = DicomTransferSyntax.Parse("1.2.840.10008.1.2");

            Assert.Same(DicomTransferSyntax.ImplicitVRLittleEndian, ts);
        }
Esempio n. 14
0
		private void ChangeSyntax(DicomTransferSyntax syntax) {
			var file = _file.ChangeTransferSyntax(syntax);
			OpenFile(file);
		}
Esempio n. 15
0
        private void ReadElement
        (
            fo.DicomDataset ds,
            XElement element,
            fo.DicomTag tag,
            fo.DicomVR dicomVr,
            int level
        )
        {
            if (dicomVr == fo.DicomVR.PN)
            {
                string personNameValue = "";

                foreach (var personNameElementValue in element.Elements( ).OrderBy(n => n.Attribute(Constants.ATTRIBUTE_NUMBER)))
                {
                    foreach (var personNameComponent in personNameElementValue.Elements( ))
                    {
                        if (personNameComponent.Name == Utilities.PersonNameComponents.PN_COMP_ALPHABETIC ||
                            personNameComponent.Name == Utilities.PersonNameComponents.PN_COMP_IDEOGRAPHIC ||
                            personNameComponent.Name == Utilities.PersonNameComponents.PN_COMP_PHONETIC)
                        {
                            personNameValue = UpdatePersonName(personNameValue, personNameComponent, Utilities.PersonNameParts.PN_Family);
                            personNameValue = UpdatePersonName(personNameValue, personNameComponent, Utilities.PersonNameParts.PN_Given);
                            personNameValue = UpdatePersonName(personNameValue, personNameComponent, Utilities.PersonNameParts.PN_Midlle);
                            personNameValue = UpdatePersonName(personNameValue, personNameComponent, Utilities.PersonNameParts.PN_Prefix);
                            personNameValue = UpdatePersonName(personNameValue, personNameComponent, Utilities.PersonNameParts.PN_Suffix, true);

                            personNameValue = personNameValue.TrimEnd('^');    // extra cleanup

                            personNameValue += "=";
                        }
                    }

                    personNameValue = personNameValue.TrimEnd('=');

                    personNameValue += "\\";
                }

                personNameValue = personNameValue.TrimEnd('\\');
                ds.AddOrUpdate <string> (dicomVr, tag, personNameValue);
            }
            else if (Utilities.IsBinaryVR(dicomVr))
            {
                var dataElement = element.Elements( ).OfType <XElement> ( ).FirstOrDefault( );

                if (null != dataElement)
                {
                    fo.IO.Buffer.IByteBuffer data;


                    if (dataElement.Name == Constants.ELEMENT_BULKDATA)
                    {
                        string uri = dataElement.Attribute(Constants.ATTRIBUTE_BULKDATAURI).Value;


                        data = new fo.IO.Buffer.BulkDataUriByteBuffer(uri);
                    }
                    else
                    {
                        var base64 = System.Convert.FromBase64String(dataElement.Value);


                        data = new fo.IO.Buffer.MemoryByteBuffer(base64);
                    }

                    if (tag == fo.DicomTag.PixelData && level == 0)
                    {
                        ds.AddOrUpdatePixelData(dicomVr, data, TransferSyntax);
                    }
                    else
                    {
                        ds.AddOrUpdate <fo.IO.Buffer.IByteBuffer> (dicomVr, tag, data);
                    }
                }
            }
            else
            {
                var values = ReadValue(element);

                if (tag == fo.DicomTag.TransferSyntaxUID)
                {
                    TransferSyntax = fo.DicomTransferSyntax.Parse(values.FirstOrDefault( ));
                }

                ds.AddOrUpdate <string> (dicomVr, tag, values.ToArray( ));
            }
        }