Exemplo n.º 1
0
        public Bitmap GetImage(ObjectDataSegment ods)
        {
            if (SubtitleSegments == null)
            {
                ParseSegments();
            }

            if (ods.Image != null)
            {
                return(ods.Image);
            }

            int width  = 720;
            int height = 576;

            ClutDefinitionSegment cds = GetClutDefinitionSegment(ods);
            var segments = SubtitleSegments;

            foreach (SubtitleSegment ss in segments)
            {
                if (ss.DisplayDefinition != null)
                {
                    width  = ss.DisplayDefinition.DisplayWith;
                    height = ss.DisplayDefinition.DisplayHeight;
                }
            }

            if (ods == null)
            {
                return(new Bitmap(1, 1));
            }

            ods.DecodeImage(DataBuffer, ods.BufferIndex, cds);
            return(ods.Image);
        }
Exemplo n.º 2
0
        private ClutDefinitionSegment GetClutDefinitionSegment(ObjectDataSegment ods)
        {
            foreach (RegionCompositionSegment rcs in RegionCompositions)
            {
                foreach (RegionCompositionSegmentObject o in rcs.Objects)
                {
                    if (o.ObjectId == ods.ObjectId)
                    {
                        foreach (ClutDefinitionSegment cds in ClutDefinitions)
                        {
                            if (cds.ClutId == rcs.RegionClutId)
                            {
                                return(cds);
                            }
                        }
                    }
                }
            }

            if (ClutDefinitions.Count > 0)
            {
                return(ClutDefinitions[0]);
            }

            return(null); //TODO: Return default clut
        }
Exemplo n.º 3
0
        public Point GetImagePosition(ObjectDataSegment ods)
        {
            if (SubtitleSegments == null)
            {
                ParseSegments();
            }

            var p = new Point(0, 0);

            foreach (RegionCompositionSegment rcs in RegionCompositions)
            {
                foreach (RegionCompositionSegmentObject o in rcs.Objects)
                {
                    if (o.ObjectId == ods.ObjectId)
                    {
                        foreach (PageCompositionSegment cds in PageCompositions)
                        {
                            foreach (var r in cds.Regions)
                            {
                                if (r.RegionId == rcs.RegionId)
                                {
                                    p.X = r.RegionHorizontalAddress + o.ObjectHorizontalPosition;
                                    p.Y = r.RegionVerticalAddress + o.ObjectVerticalPosition;
                                    return(p);
                                }
                            }
                        }
                        p.X = o.ObjectHorizontalPosition;
                        p.Y = o.ObjectVerticalPosition;
                    }
                }
            }

            return(p);
        }
Exemplo n.º 4
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:
                break;
            }
        }
Exemplo n.º 5
0
        public Bitmap GetImage(ObjectDataSegment ods)
        {
            if (SubtitleSegments == null)
            {
                ParseSegments();
            }

            if (ods.Image != null)
            {
                return(ods.Image);
            }

            ClutDefinitionSegment cds = GetClutDefinitionSegment(ods);

            ods.DecodeImage(_dataBuffer, ods.BufferIndex, cds);
            return(ods.Image);
        }
Exemplo n.º 6
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:
                    break;
            }
        }
Exemplo n.º 7
0
        private ClutDefinitionSegment GetClutDefinitionSegment(ObjectDataSegment ods)
        {
            foreach (RegionCompositionSegment rcs in RegionCompositions)
            {
                foreach (RegionCompositionSegmentObject o in rcs.Objects)
                {
                    if (o.ObjectId == ods.ObjectId)
                    {
                        foreach (ClutDefinitionSegment cds in ClutDefinitions)
                        {
                            if (cds.ClutId == rcs.RegionClutId)
                                return cds;
                        }
                    }
                }
            }

            if (ClutDefinitions.Count > 0)
                return ClutDefinitions[0];

            return null; //TODO: Return default clut
        }
Exemplo n.º 8
0
        public Point GetImagePosition(ObjectDataSegment ods)
        {
            if (SubtitleSegments == null)
                ParseSegments();

            var p = new Point(0, 0);

            foreach (RegionCompositionSegment rcs in RegionCompositions)
            {
                foreach (RegionCompositionSegmentObject o in rcs.Objects)
                {
                    if (o.ObjectId == ods.ObjectId)
                    {
                        foreach (PageCompositionSegment cds in PageCompositions)
                        {
                            foreach (var r in cds.Regions)
                            {
                                if (r.RegionId == rcs.RegionId)
                                {
                                    p.X = r.RegionHorizontalAddress + o.ObjectHorizontalPosition;
                                    p.Y = r.RegionVerticalAddress + o.ObjectVerticalPosition;
                                    return p;
                                }
                            }
                        }
                        p.X = o.ObjectHorizontalPosition;
                        p.Y = o.ObjectVerticalPosition;
                    }
                }
            }

            return p;
        }
Exemplo n.º 9
0
        public Bitmap GetImage(ObjectDataSegment ods)
        {
            if (SubtitleSegments == null)
                ParseSegments();

            if (ods.Image != null)
                return ods.Image;

            ClutDefinitionSegment cds = GetClutDefinitionSegment(ods);
            ods.DecodeImage(DataBuffer, ods.BufferIndex, cds);
            return ods.Image;
        }
Exemplo n.º 10
0
        public Bitmap GetImage(ObjectDataSegment ods)
        {
            if (SubtitleSegments == null)
                ParseSegments();

            if (ods.Image != null)
                return ods.Image;

            int width = 720;
            int height = 576;

            ClutDefinitionSegment cds = GetClutDefinitionSegment(ods);
            var segments = SubtitleSegments;
            foreach (SubtitleSegment ss in segments)
            {
                if (ss.DisplayDefinition != null)
                {
                    width = ss.DisplayDefinition.DisplayWith;
                    height = ss.DisplayDefinition.DisplayHeight;
                }
            }

            if (ods == null)
                return new Bitmap(1, 1);

            ods.DecodeImage(DataBuffer, ods.BufferIndex, cds);
            return ods.Image;
        }
        /// <summary>
        /// The get image.
        /// </summary>
        /// <param name="ods">
        /// The ods.
        /// </param>
        /// <returns>
        /// The <see cref="Bitmap"/>.
        /// </returns>
        public Bitmap GetImage(ObjectDataSegment ods)
        {
            if (this.SubtitleSegments == null)
            {
                this.ParseSegments();
            }

            if (ods.Image != null)
            {
                return ods.Image;
            }

            ClutDefinitionSegment cds = this.GetClutDefinitionSegment(ods);
            ods.DecodeImage(this._dataBuffer, ods.BufferIndex, cds);
            return ods.Image;
        }
Exemplo n.º 12
0
        private ClutDefinitionSegment GetClutDefinitionSegment(ObjectDataSegment ods)
        {
            foreach (RegionCompositionSegment rcs in RegionCompositions)
            {
                foreach (RegionCompositionSegmentObject o in rcs.Objects)
                {
                    if (o.ObjectId != ods.ObjectId)
                    {
                        continue;
                    }
                    foreach (ClutDefinitionSegment cds in ClutDefinitions.Where(cds => cds.ClutId == rcs.RegionClutId))
                    {
                        return cds;
                    }
                }
            }

            return ClutDefinitions.Count > 0 ? ClutDefinitions[0] : null;
        }