Beispiel #1
0
        private void InsertDatasetItem(DcmItem item, DicomReadOptions options)
        {
            if (_sds.Count > 0 && _sds.Count == _sqs.Count)
            {
                DcmDataset ds = _sds.Peek();

                if (_tag.Element == 0x0000)
                {
                    if (Flags.IsSet(options, DicomReadOptions.KeepGroupLengths))
                    {
                        ds.AddItem(item);
                    }
                }
                else
                {
                    ds.AddItem(item);
                }

                if (ds.StreamLength != UndefinedLength)
                {
                    long end = ds.StreamPosition + ds.StreamLength;
                    if ((_stream.Position - _offset) >= end)
                    {
                        _sds.Pop();
                    }
                }
            }
            else
            {
                if (_tag.Element == 0x0000)
                {
                    if (Flags.IsSet(options, DicomReadOptions.KeepGroupLengths))
                    {
                        _dataset.AddItem(item);
                    }
                }
                else
                {
                    _dataset.AddItem(item);
                }
            }

            if (_tag == DicomTags.SpecificCharacterSet && item is DcmCodeString)
            {
                DcmCodeString cs = (DcmCodeString)item;
                if (cs.Length > 0)
                {
                    string[] values = cs.GetValues();
                    for (int i = 0; i < values.Length; i++)
                    {
                        if (String.IsNullOrEmpty(values[i]))
                        {
                            continue;
                        }
                        _encoding = DcmEncoding.GetEncodingForSpecificCharacterSet(values[i]);
                        break;
                    }
                }
            }
        }
Beispiel #2
0
        public void UpdateDataset(DcmDataset dataset)
        {
            if (_lossy)
            {
                DcmCodeString cs = dataset.GetCS(DicomTags.ImageType);
                if (cs != null)
                {
                    string[] values = cs.GetValues();
                    values[0] = "DERIVED";
                    cs.SetValues(values);
                }

                dataset.AddElementWithValue(DicomTags.SOPInstanceUID, DicomUID.Generate());

                // FIXME: append existing values
                dataset.AddElementWithValue(DicomTags.LossyImageCompression, "01");
                dataset.AddElementWithValue(DicomTags.LossyImageCompressionMethod, _lossyMethod);
                dataset.AddElementWithValue(DicomTags.LossyImageCompressionRatio, _lossyRatio);
            }
            dataset.AddElementWithValue(DicomTags.NumberOfFrames, _frames);
            dataset.AddElementWithValue(DicomTags.Columns, _width);
            dataset.AddElementWithValue(DicomTags.Rows, _height);
            dataset.AddElementWithValue(DicomTags.HighBit, _highBit);
            dataset.AddElementWithValue(DicomTags.BitsStored, _bitsStored);
            dataset.AddElementWithValue(DicomTags.BitsAllocated, _bitsAllocated);
            dataset.AddElementWithValue(DicomTags.SamplesPerPixel, _samplesPerPixel);
            dataset.AddElementWithValue(DicomTags.PixelRepresentation, _pixelRepresentation);
            dataset.AddElementWithValue(DicomTags.PhotometricInterpretation, _photometricInterpretation);
            if (SamplesPerPixel == 1)
            {
                dataset.AddElementWithValue(DicomTags.RescaleSlope, _rescaleSlope);
                dataset.AddElementWithValue(DicomTags.RescaleIntercept, _rescaleIntercept);
                //if (_pixelPaddingValue != 0)
                //    dataset.AddElementWithValue(DicomTags.PixelPaddingValue, _pixelPaddingValue);
            }
            else
            {
                dataset.AddElementWithValue(DicomTags.PlanarConfiguration, _planarConfiguration);
            }
            dataset.AddItem(_pixelDataItem);
        }