Exemplo n.º 1
0
        private void SetupEncapsulatedImageWithIconSequence(DicomFile file, bool encapsulateIconPixelData)
        {
            var codec = new NullDicomCodec();

            DicomAttributeCollection dataSet = file.DataSet;

            SetupSecondaryCapture(dataSet);

            SetupMetaInfo(file);

            file.TransferSyntax = TransferSyntax.ImplicitVrLittleEndian;
            file.ChangeTransferSyntax(codec.CodecTransferSyntax);

            // explicitly create the icon sequence as either encapsulated or native, so that we are not depending on correct behaviour elsewhere...
            CreateIconImageSequence(dataSet);

            if (encapsulateIconPixelData)
            {
                var dataset   = ((DicomAttributeSQ)dataSet[DicomTags.IconImageSequence])[0];
                var pixelData = dataset[DicomTags.PixelData];

                var pd = new DicomUncompressedPixelData(dataset);
                using (var pixelStream = ((DicomAttributeBinary)pixelData).AsStream())
                {
                    //Before compression, make the pixel data more "typical", so it's harder to mess up the codecs.
                    //NOTE: Could combine mask and align into one method so we're not iterating twice, but I prefer having the methods separate.
                    if (DicomUncompressedPixelData.RightAlign(pixelStream, pd.BitsAllocated, pd.BitsStored, pd.HighBit))
                    {
                        var newHighBit = (ushort)(pd.HighBit - pd.LowBit);

                        pd.HighBit = newHighBit;                         //correct high bit after right-aligning.
                        dataset[DicomTags.HighBit].SetUInt16(0, newHighBit);
                    }
                    DicomUncompressedPixelData.ZeroUnusedBits(pixelStream, pd.BitsAllocated, pd.BitsStored, pd.HighBit);
                }

                // Set transfer syntax before compression, the codecs need it.
                var fragments = new DicomCompressedPixelData(pd)
                {
                    TransferSyntax = codec.CodecTransferSyntax
                };
                codec.Encode(pd, fragments, null);
                fragments.UpdateAttributeCollection(dataset);
            }
        }
Exemplo n.º 2
0
 public void TestFixtureTearDown()
 {
     NullDicomCodec.Unregister();
     DicomImplementation.UnitTest = false;
 }
Exemplo n.º 3
0
 public void TestFixtureSetUp()
 {
     DicomImplementation.UnitTest = true;
     NullDicomCodec.Register();
 }