Exemplo n.º 1
0
            private bool ParseItemSequenceValue(IByteSource source)
            {
                if (_parseStage == ParseStage.Value)
                {
                    if (_length != _undefinedLength)
                    {
                        if (!source.Require(_length))
                        {
                            _result = DicomReaderResult.Suspended;
                            return(false);
                        }

                        source.PushMilestone(_length);
                    }

                    _observer.OnBeginSequenceItem(source, _length);

                    ResetState();
                    ++_sequenceDepth;
                    ParseDataset(source);
                    --_sequenceDepth;
                    // bugfix k-pacs. there a sequence was not ended by ItemDelimitationItem>SequenceDelimitationItem, but directly with SequenceDelimitationItem
                    bool isEndSequence = (_tag == DicomTag.SequenceDelimitationItem);
                    ResetState();

                    _observer.OnEndSequenceItem();

                    if (isEndSequence)
                    {
                        // end of sequence
                        _observer.OnEndSequence();
                        // #565 Only reset the badPrivate sequence if we're in the correct depth
                        // This prevents prematurely resetting in case of sub-sequences contained in the bad private sequence
                        if (_badPrivateSequence && _sequenceDepth == _badPrivateSequenceDepth)
                        {
                            _isExplicitVR       = !_isExplicitVR;
                            _badPrivateSequence = false;
                        }
                        ResetState();
                        return(false);
                    }
                }
                return(true);
            }
Exemplo n.º 2
0
        private void ParseItemSequence(IByteSource source, object state)
        {
            try {
                _result = DicomReaderResult.Processing;

                while (!source.IsEOF && !source.HasReachedMilestone())
                {
                    if (_state == ParseState.Tag)
                    {
                        source.Mark();

                        if (!source.Require(8, ParseItemSequence, state))
                        {
                            _result = DicomReaderResult.Suspended;
                            return;
                        }

                        ushort group   = source.GetUInt16();
                        ushort element = source.GetUInt16();

                        _tag = new DicomTag(group, element);

                        if (_tag != DicomTag.Item && _tag != DicomTag.SequenceDelimitationItem)
                        {
                            // assume invalid sequence
                            source.Rewind();
                            if (!_implicit)
                            {
                                source.PopMilestone();
                            }
                            _observer.OnEndSequence();
                            if (_badPrivateSequence)
                            {
                                _explicit           = !_explicit;
                                _badPrivateSequence = false;
                            }
                            return;
                        }

                        _length = source.GetUInt32();

                        if (_tag == DicomTag.SequenceDelimitationItem)
                        {
                            // end of sequence
                            _observer.OnEndSequence();
                            if (_badPrivateSequence)
                            {
                                _explicit           = !_explicit;
                                _badPrivateSequence = false;
                            }
                            ResetState();
                            return;
                        }

                        _state = ParseState.Value;
                    }

                    if (_state == ParseState.Value)
                    {
                        if (_length != UndefinedLength)
                        {
                            if (!source.Require(_length, ParseItemSequence, state))
                            {
                                _result = DicomReaderResult.Suspended;
                                return;
                            }

                            source.PushMilestone(_length);
                        }

                        _observer.OnBeginSequenceItem(source, _length);

                        ResetState();
                        ParseDataset(source, state);
                        ResetState();

                        _observer.OnEndSequenceItem();
                        continue;
                    }
                }

                // end of explicit length sequence
                if (source.HasReachedMilestone())
                {
                    source.PopMilestone();
                }

                _observer.OnEndSequence();
                if (_badPrivateSequence)
                {
                    _explicit           = !_explicit;
                    _badPrivateSequence = false;
                }
            } catch (Exception e) {
                _exception = e;
                _result    = DicomReaderResult.Error;
            } finally {
                if (_result != DicomReaderResult.Processing && _result != DicomReaderResult.Suspended)
                {
                    _async.Set();
                }
            }
        }