Esempio n. 1
0
        public static void ToStream(Stream writer, SubtitleSectionText section, bool useDouble)
        {
            var textBuffer = new byte[0];

            if (section.Text != null)
            {
                textBuffer = TextTable.GetBytes(section.Text, useDouble);
            }

            int length = textBuffer.Length;

            if ((length & 3) != 0)
            {
                length = (length & ~3) + 4;
            }

            writer.Write(section.Start);
            writer.Write(section.End);
            writer.Write(section.Unknown1);
            writer.Write((ushort)(length + 0x10));
            writer.Write(section.Unknown2);

            writer.Write(textBuffer);

            writer.WriteOffset(4);
        }
Esempio n. 2
0
        public static void ToStream(Stream writer, SubtitleSection section)
        {
            byte[] rawText = null;

            using (var content = new MemoryStream())
            {
                foreach (var text in section.Texts)
                {
                    SubtitleSectionText.ToStream(content, text, section.LanguageID == 7);
                }

                rawText = content.ToArray();
            }

            writer.WriteBE(section.LanguageID);
            writer.WriteBE(section.StreamID);

            if (section.LanguageID == 1 || section.LanguageID == 7)
            {
                var total = 16 + rawText.Length + 4 + 4 + section.FontData?.Length ?? 0;
                total = ((total + 16 - 1) / 16) * 16;
                writer.WriteBE(total);


                writer.WriteBE(section.BaseTime);

                writer.Write(0u);
                writer.Write((uint)rawText.Length);

                writer.Write(rawText);

                //if (section.LanguageID == 7)
                {
                    if (section.FontData == null)
                    {
                        writer.Write(0);
                    }
                    else
                    {
                        writer.Write(section.FontData.Length);
                        writer.Write(section.FontData);
                    }
                }

                writer.WriteOffset(16);
            }
            else
            {
                writer.WriteBE(section.Length);
                writer.WriteBE(section.BaseTime);

                writer.Write(section.RawData);
            }
        }
Esempio n. 3
0
        public new static SubtitleSection FromStream(Stream reader)
        {
            var section      = new SubtitleSection();
            var basePosition = reader.Position;

            section.Offset = reader.Position;

            section.LanguageID = reader.ReadUInt16BE();
            section.StreamID   = reader.ReadUInt16BE();

            section.Length   = reader.ReadUInt32BE();
            section.BaseTime = reader.ReadUInt32BE();

            var endPosition = basePosition + section.Length;


            if (section.LanguageID == 1 || section.LanguageID == 7)
            {
                var dummy = reader.ReadUInt32();
                Debug.Assert(dummy == 0);

                var dataLength = reader.ReadUInt32();

                var textStart = reader.Position;

                while (reader.Position < textStart + dataLength)
                {
                    var text = SubtitleSectionText.FromStream(reader);

                    section.Texts.Add(text);
                }

                Debug.Assert(reader.Position == textStart + dataLength);

                var fontLength = reader.ReadUInt32();
                section.FontData = reader.ReadBytes((int)fontLength);

                if (endPosition != reader.Position)
                {
                    var rem = reader.ReadBytes((int)(endPosition - reader.Position));
                    Debug.Assert(rem.Count(x => x == 0) == rem.Length);
                }
                Debug.Assert(endPosition % 0x10 == 0);
                reader.Seek(endPosition, SeekOrigin.Begin);
            }
            else
            {
                section.RawData = reader.ReadBytes((int)(endPosition - reader.Position));
            }

            return(section);
        }
Esempio n. 4
0
        public static SubtitleSectionText FromStream(Stream reader)
        {
            var section = new SubtitleSectionText();

            section.Start = reader.ReadUInt32();
            section.End   = reader.ReadUInt32();

            section.Unknown1 = reader.ReadUInt32();
            section.Length   = reader.ReadUInt16();

            Debug.Assert(section.Length % 4 == 0);

            section.Unknown2 = reader.ReadUInt16();

            byte[] textBuffer = new byte[section.Length - 0x10];
            reader.Read(textBuffer, 0, textBuffer.Length);
            section.Text = TextTable.GetString(textBuffer);

            return(section);
        }