示例#1
0
        public SubtitleSegment(byte[] buffer, int index)
        {
            if (buffer == null || buffer.Length < 7)
            {
                return;
            }

            SyncByte      = buffer[index];
            SegmentType   = buffer[index + 1];
            PageId        = Helper.GetEndianWord(buffer, index + 2);
            SegmentLength = Helper.GetEndianWord(buffer, index + 4);

            if (buffer.Length - 6 < SegmentLength)
            {
                return;
            }

            if (index + 6 + SegmentLength > buffer.Length)
            {
                return;
            }

            IsValid = true;

            switch (SegmentType)
            {
            case PageCompositionSegment:
                PageComposition = new PageCompositionSegment(buffer, index + 6, SegmentLength - 2);
                break;

            case RegionCompositionSegment:
                RegionComposition = new RegionCompositionSegment(buffer, index + 6, SegmentLength - 10);
                break;

            case ClutDefinitionSegment:
                ClutDefinition = new ClutDefinitionSegment(buffer, index + 6, SegmentLength);
                break;

            case ObjectDataSegment:
                ObjectData = new ObjectDataSegment(buffer, index + 6);
                break;

            case DisplayDefinitionSegment:
                DisplayDefinition = new DisplayDefinitionSegment(buffer, index + 6);
                break;

            case EndOfDisplaySetSegment:
                EndOfDisplaySet = new EndOfDisplaySetSegment(buffer, index + 6);
                break;

            default:
                System.Console.WriteLine("unkown");
                break;
            }
        }
        public SubtitleSegment(byte[] buffer, int index)
        {
            if (buffer == null || buffer.Length < 7)
            {
                return;
            }

            SyncByte = buffer[index];
            SegmentType = buffer[index + 1];
            PageId = Helper.GetEndianWord(buffer, index + 2);
            SegmentLength = Helper.GetEndianWord(buffer, index + 4);

            if (buffer.Length - 6 < SegmentLength)
            {
                return;
            }

            if (index + 6 + SegmentLength > buffer.Length)
            {
                return;
            }

            IsValid = true;

            switch (SegmentType)
            {
                case PageCompositionSegment:
                    PageComposition = new PageCompositionSegment(buffer, index + 6, SegmentLength - 2);
                    break;
                case RegionCompositionSegment:
                    RegionComposition = new RegionCompositionSegment(buffer, index + 6, SegmentLength - 10);
                    break;
                case ClutDefinitionSegment:
                    ClutDefinition = new ClutDefinitionSegment(buffer, index + 6, SegmentLength);
                    break;
                case ObjectDataSegment:
                    ObjectData = new ObjectDataSegment(buffer, index + 6);
                    break;
                case DisplayDefinitionSegment:
                    DisplayDefinition = new DisplayDefinitionSegment(buffer, index + 6);
                    break;
                case EndOfDisplaySetSegment:
                    break;
            }
        }