public void VobSubWriteAndReadTwoBitmaps() { string fileName = Guid.NewGuid() + ".sub"; using (var writer = new VobSubWriter(fileName, 800, 600, 10, 10, 32, Color.White, Color.Black, true, "English", "en")) { var p1 = new Paragraph("Line1", 0, 1000); var p2 = new Paragraph("Line2", 2000, 3000); writer.WriteParagraph(p1, new Bitmap(200, 20), ContentAlignment.BottomCenter); writer.WriteParagraph(p2, new Bitmap(200, 20), ContentAlignment.BottomCenter); } var reader = new VobSubParser(true); reader.Open(fileName); var list = reader.MergeVobSubPacks(); Assert.IsTrue(list.Count == 2); }
/// <summary> /// The button export click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void ButtonExportClick(object sender, EventArgs e) { this.FixStartEndWithSameTimeCode(); var errors = new List<string>(); this.buttonExport.Enabled = false; this.SetupImageParameters(); if (!string.IsNullOrEmpty(this._fileName)) { this.saveFileDialog1.FileName = Path.GetFileNameWithoutExtension(this._fileName); } if (this._exportType == "BLURAYSUP") { this.saveFileDialog1.Title = Configuration.Settings.Language.ExportPngXml.SaveBluRraySupAs; this.saveFileDialog1.DefaultExt = "*.sup"; this.saveFileDialog1.AddExtension = true; this.saveFileDialog1.Filter = "Blu-Ray sup|*.sup"; } else if (this._exportType == "VOBSUB") { this.saveFileDialog1.Title = Configuration.Settings.Language.ExportPngXml.SaveVobSubAs; this.saveFileDialog1.DefaultExt = "*.sub"; this.saveFileDialog1.AddExtension = true; this.saveFileDialog1.Filter = "VobSub|*.sub"; } else if (this._exportType == "FAB") { this.saveFileDialog1.Title = Configuration.Settings.Language.ExportPngXml.SaveFabImageScriptAs; this.saveFileDialog1.DefaultExt = "*.txt"; this.saveFileDialog1.AddExtension = true; this.saveFileDialog1.Filter = "FAB image scripts|*.txt"; } else if (this._exportType == "STL") { this.saveFileDialog1.Title = Configuration.Settings.Language.ExportPngXml.SaveDvdStudioProStlAs; this.saveFileDialog1.DefaultExt = "*.txt"; this.saveFileDialog1.AddExtension = true; this.saveFileDialog1.Filter = "DVD Studio Pro STL|*.stl"; } else if (this._exportType == "FCP") { this.saveFileDialog1.Title = Configuration.Settings.Language.ExportPngXml.SaveFcpAs; this.saveFileDialog1.DefaultExt = "*.xml"; this.saveFileDialog1.AddExtension = true; this.saveFileDialog1.Filter = "Xml files|*.xml"; } else if (this._exportType == "DOST") { this.saveFileDialog1.Title = Configuration.Settings.Language.ExportPngXml.SaveDostAs; this.saveFileDialog1.DefaultExt = "*.dost"; this.saveFileDialog1.AddExtension = true; this.saveFileDialog1.Filter = "Dost files|*.dost"; } else if (this._exportType == "DCINEMA_INTEROP") { this.saveFileDialog1.Title = Configuration.Settings.Language.ExportPngXml.SaveDigitalCinemaInteropAs; this.saveFileDialog1.DefaultExt = "*.xml"; this.saveFileDialog1.AddExtension = true; this.saveFileDialog1.Filter = "Xml files|*.xml"; } else if (this._exportType == "EDL") { this.saveFileDialog1.Title = Configuration.Settings.Language.ExportPngXml.SavePremiereEdlAs; this.saveFileDialog1.DefaultExt = "*.edl"; this.saveFileDialog1.AddExtension = true; this.saveFileDialog1.Filter = "EDL files|*.edl"; } if (this._exportType == "BLURAYSUP" && this.saveFileDialog1.ShowDialog(this) == DialogResult.OK || this._exportType == "VOBSUB" && this.saveFileDialog1.ShowDialog(this) == DialogResult.OK || this._exportType == "BDNXML" && this.folderBrowserDialog1.ShowDialog(this) == DialogResult.OK || this._exportType == "FAB" && this.folderBrowserDialog1.ShowDialog(this) == DialogResult.OK || this._exportType == "IMAGE/FRAME" && this.folderBrowserDialog1.ShowDialog(this) == DialogResult.OK || this._exportType == "STL" && this.folderBrowserDialog1.ShowDialog(this) == DialogResult.OK || this._exportType == "SPUMUX" && this.folderBrowserDialog1.ShowDialog(this) == DialogResult.OK || this._exportType == "FCP" && this.saveFileDialog1.ShowDialog(this) == DialogResult.OK || this._exportType == "DOST" && this.saveFileDialog1.ShowDialog(this) == DialogResult.OK || this._exportType == "DCINEMA_INTEROP" && this.saveFileDialog1.ShowDialog(this) == DialogResult.OK || this._exportType == "EDL" && this.saveFileDialog1.ShowDialog(this) == DialogResult.OK) { int width; int height; this.GetResolution(out width, out height); FileStream binarySubtitleFile = null; VobSubWriter vobSubWriter = null; if (this._exportType == "BLURAYSUP") { binarySubtitleFile = new FileStream(this.saveFileDialog1.FileName, FileMode.Create); } else if (this._exportType == "VOBSUB") { vobSubWriter = new VobSubWriter(this.saveFileDialog1.FileName, width, height, this.comboBoxBottomMargin.SelectedIndex, this.comboBoxLeftRightMargin.SelectedIndex, 32, this._subtitleColor, this._borderColor, !this.checkBoxTransAntiAliase.Checked, IfoParser.ArrayOfLanguage[this.comboBoxLanguage.SelectedIndex], IfoParser.ArrayOfLanguageCode[this.comboBoxLanguage.SelectedIndex]); } this.progressBar1.Value = 0; this.progressBar1.Maximum = this._subtitle.Paragraphs.Count - 1; this.progressBar1.Visible = true; int border = this.comboBoxBottomMargin.SelectedIndex; int imagesSavedCount = 0; var sb = new StringBuilder(); if (this._exportType == "STL") { sb.AppendLine("$SetFilePathToken =" + this.folderBrowserDialog1.SelectedPath); sb.AppendLine(); } if (this._vobSubOcr != null) { int i = 0; foreach (Paragraph p in this._subtitle.Paragraphs) { var mp = this.MakeMakeBitmapParameter(i, width, height); mp.Bitmap = this._vobSubOcr.GetSubtitleBitmap(i); if (this._exportType == "BLURAYSUP") { MakeBluRaySupImage(mp); } imagesSavedCount = this.WriteParagraph(width, sb, border, height, imagesSavedCount, vobSubWriter, binarySubtitleFile, mp, i); i++; this.progressBar1.Refresh(); Application.DoEvents(); if (i < this.progressBar1.Maximum) { this.progressBar1.Value = i; } } } else { var threadEqual = new Thread(DoWork); var paramEqual = this.MakeMakeBitmapParameter(0, width, height); var threadUnEqual = new Thread(DoWork); var paramUnEqual = this.MakeMakeBitmapParameter(1, width, height); threadEqual.Start(paramEqual); int i = 1; for (; i < this._subtitle.Paragraphs.Count; i++) { if (i % 2 == 0) { paramEqual = this.MakeMakeBitmapParameter(i, width, height); threadEqual = new Thread(DoWork); threadEqual.Start(paramEqual); if (threadUnEqual.ThreadState == ThreadState.Running) { threadUnEqual.Join(); } imagesSavedCount = this.WriteParagraph(width, sb, border, height, imagesSavedCount, vobSubWriter, binarySubtitleFile, paramUnEqual, i); if (!string.IsNullOrEmpty(paramUnEqual.Error)) { errors.Add(paramUnEqual.Error); } } else { paramUnEqual = this.MakeMakeBitmapParameter(i, width, height); threadUnEqual = new Thread(DoWork); threadUnEqual.Start(paramUnEqual); if (threadEqual.ThreadState == ThreadState.Running) { threadEqual.Join(); } imagesSavedCount = this.WriteParagraph(width, sb, border, height, imagesSavedCount, vobSubWriter, binarySubtitleFile, paramEqual, i); if (!string.IsNullOrEmpty(paramEqual.Error)) { errors.Add(paramEqual.Error); } } this.progressBar1.Refresh(); Application.DoEvents(); this.progressBar1.Value = i; } if (i % 2 == 0) { if (threadEqual.ThreadState == ThreadState.Running) { threadEqual.Join(); } imagesSavedCount = this.WriteParagraph(width, sb, border, height, imagesSavedCount, vobSubWriter, binarySubtitleFile, paramEqual, i); if (threadUnEqual.ThreadState == ThreadState.Running) { threadUnEqual.Join(); } imagesSavedCount = this.WriteParagraph(width, sb, border, height, imagesSavedCount, vobSubWriter, binarySubtitleFile, paramUnEqual, i); } else { if (threadUnEqual.ThreadState == ThreadState.Running) { threadUnEqual.Join(); } imagesSavedCount = this.WriteParagraph(width, sb, border, height, imagesSavedCount, vobSubWriter, binarySubtitleFile, paramUnEqual, i); if (threadEqual.ThreadState == ThreadState.Running) { threadEqual.Join(); } imagesSavedCount = this.WriteParagraph(width, sb, border, height, imagesSavedCount, vobSubWriter, binarySubtitleFile, paramEqual, i); } } if (errors.Count > 0) { var errorSb = new StringBuilder(); for (int i = 0; i < 20; i++) { if (i < errors.Count) { errorSb.AppendLine(errors[i]); } } if (errors.Count > 20) { errorSb.AppendLine("..."); } MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.SomeLinesWereTooLongX, errorSb)); } this.progressBar1.Visible = false; if (this._exportType == "BLURAYSUP") { binarySubtitleFile.Close(); MessageBox.Show(string.Format(Configuration.Settings.Language.Main.SavedSubtitleX, this.saveFileDialog1.FileName)); } else if (this._exportType == "VOBSUB") { vobSubWriter.WriteIdxFile(); vobSubWriter.Dispose(); MessageBox.Show(string.Format(Configuration.Settings.Language.Main.SavedSubtitleX, this.saveFileDialog1.FileName)); } else if (this._exportType == "FAB") { File.WriteAllText(Path.Combine(this.folderBrowserDialog1.SelectedPath, "Fab_Image_script.txt"), sb.ToString()); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, this.folderBrowserDialog1.SelectedPath)); } else if (this._exportType == "IMAGE/FRAME") { var empty = new Bitmap(width, height); imagesSavedCount++; string numberString = string.Format("{0:00000}", imagesSavedCount); string fileName = Path.Combine(this.folderBrowserDialog1.SelectedPath, numberString + "." + this.comboBoxImageFormat.Text.ToLower()); this.SaveImage(empty, fileName, this.ImageFormat); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, this.folderBrowserDialog1.SelectedPath)); } else if (this._exportType == "STL") { File.WriteAllText(Path.Combine(this.folderBrowserDialog1.SelectedPath, "DVD_Studio_Pro_Image_script.stl"), sb.ToString()); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, this.folderBrowserDialog1.SelectedPath)); } else if (this._exportType == "SPUMUX") { string s = "<subpictures>" + Environment.NewLine + "\t<stream>" + Environment.NewLine + sb + "\t</stream>" + Environment.NewLine + "</subpictures>"; File.WriteAllText(Path.Combine(this.folderBrowserDialog1.SelectedPath, "spu.xml"), s); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, this.folderBrowserDialog1.SelectedPath)); } else if (this._exportType == "FCP") { string fileNameNoPath = Path.GetFileName(this.saveFileDialog1.FileName); string fileNameNoExt = Path.GetFileNameWithoutExtension(fileNameNoPath); int duration = 0; if (this._subtitle.Paragraphs.Count > 0) { duration = (int)Math.Round(this._subtitle.Paragraphs[this._subtitle.Paragraphs.Count - 1].EndTime.TotalSeconds * 25.0); } string s = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine + "<!DOCTYPE xmeml[]>" + Environment.NewLine + "<xmeml version=\"4\">" + Environment.NewLine + " <sequence id=\"" + fileNameNoExt + "\">" + Environment.NewLine + " <updatebehavior>add</updatebehavior>" + Environment.NewLine + " <name>" + fileNameNoExt + @"</name> <duration>" + duration.ToString(CultureInfo.InvariantCulture) + @"</duration> <rate> <ntsc>FALSE</ntsc> <timebase>25</timebase> </rate> <timecode> <rate> <ntsc>FALSE</ntsc> <timebase>25</timebase> </rate> <string>00:00:00:00</string> <frame>0</frame> <source>source</source> <displayformat>NDF</displayformat> </timecode> <in>0</in> <out>[OUT]</out> <media> <video> <format> <samplecharacteristics> <rate> <timebase>25</timebase> </rate> <width>1920</width> <height>1080</height> <anamorphic>FALSE</anamorphic> <pixelaspectratio>square</pixelaspectratio> <fielddominance>none</fielddominance> <colordepth>32</colordepth> </samplecharacteristics> </format> <track> <enabled>TRUE</enabled> <locked>FALSE</locked> </track> <track> " + sb + @" <enabled>TRUE</enabled> <locked>FALSE</locked> </track> </video> <audio> <track> <enabled>TRUE</enabled> <locked>FALSE</locked> <outputchannelindex>1</outputchannelindex> </track> <track> <enabled>TRUE</enabled> <locked>FALSE</locked> <outputchannelindex>2</outputchannelindex> </track> <track> <enabled>TRUE</enabled> <locked>FALSE</locked> <outputchannelindex>3</outputchannelindex> </track> <track> <enabled>TRUE</enabled> <locked>FALSE</locked> <outputchannelindex>4</outputchannelindex> </track> </audio> </media> <ismasterclip>FALSE</ismasterclip> </sequence> </xmeml>"; s = s.Replace("<timebase>25</timebase>", "<timebase>" + this.comboBoxFrameRate.Text + "</timebase>"); if (this._subtitle.Paragraphs.Count > 0) { var end = (int)Math.Round(this._subtitle.Paragraphs[this._subtitle.Paragraphs.Count - 1].EndTime.TotalSeconds * this.FrameRate); end ++; s = s.Replace("[OUT]", end.ToString(CultureInfo.InvariantCulture)); } if (this.comboBoxLanguage.Text == "NTSC") { s = s.Replace("<ntsc>FALSE</ntsc>", "<ntsc>TRUE</ntsc>"); } s = s.Replace("<width>1920</width>", "<width>" + width.ToString(CultureInfo.InvariantCulture) + "</width>"); s = s.Replace("<height>1080</height>", "<height>" + height.ToString(CultureInfo.InvariantCulture) + "</height>"); if (this.comboBoxImageFormat.Text.Contains("8-bit")) { s = s.Replace("<colordepth>32</colordepth>", "<colordepth>8</colordepth>"); } File.WriteAllText(Path.Combine(this.folderBrowserDialog1.SelectedPath, this.saveFileDialog1.FileName), s); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, Path.GetDirectoryName(this.saveFileDialog1.FileName))); } else if (this._exportType == "DOST") { string header = @"$FORMAT=480 $VERSION=1.2 $ULEAD=TRUE $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine + "NO\tINTIME\t\tOUTTIME\t\tXPOS\tYPOS\tFILENAME\tFADEIN\tFADEOUT"; string dropValue = "30000"; if (this.comboBoxFrameRate.Items[this.comboBoxFrameRate.SelectedIndex].ToString() == "23.98") { dropValue = "23976"; } else if (this.comboBoxFrameRate.Items[this.comboBoxFrameRate.SelectedIndex].ToString() == "24") { dropValue = "24000"; } else if (this.comboBoxFrameRate.Items[this.comboBoxFrameRate.SelectedIndex].ToString() == "25") { dropValue = "25000"; } else if (this.comboBoxFrameRate.Items[this.comboBoxFrameRate.SelectedIndex].ToString() == "29.97") { dropValue = "29970"; } else if (this.comboBoxFrameRate.Items[this.comboBoxFrameRate.SelectedIndex].ToString() == "30") { dropValue = "30000"; } else if (this.comboBoxFrameRate.Items[this.comboBoxFrameRate.SelectedIndex].ToString() == "59.94") { dropValue = "59940"; } header = header.Replace("[DROPVALUE]", dropValue); File.WriteAllText(this.saveFileDialog1.FileName, header + Environment.NewLine + sb); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, Path.GetDirectoryName(this.saveFileDialog1.FileName))); } else if (this._exportType == "DCINEMA_INTEROP") { var doc = new XmlDocument(); string title = "unknown"; if (!string.IsNullOrEmpty(this._fileName)) { title = Path.GetFileNameWithoutExtension(this._fileName); } string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Insert(8, "-").Insert(13, "-").Insert(18, "-").Insert(23, "-"); doc.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Environment.NewLine + "<DCSubtitle Version=\"1.1\">" + Environment.NewLine + "<SubtitleID>" + guid + "</SubtitleID>" + Environment.NewLine + "<MovieTitle>" + title + "</MovieTitle>" + Environment.NewLine + "<ReelNumber>1</ReelNumber>" + Environment.NewLine + "<Language>English</Language>" + Environment.NewLine + sb + "</DCSubtitle>"); string fName = this.saveFileDialog1.FileName; if (!fName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase)) { fName += ".xml"; } File.WriteAllText(fName, SubtitleFormat.ToUtf8XmlString(doc)); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, Path.GetDirectoryName(fName))); } else if (this._exportType == "EDL") { string header = "TITLE: ( no title )" + Environment.NewLine + Environment.NewLine; File.WriteAllText(this.saveFileDialog1.FileName, header + sb); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, Path.GetDirectoryName(this.saveFileDialog1.FileName))); } else if (this._exportType == "DCINEMA_INTEROP") { var doc = new XmlDocument(); string title = "unknown"; if (!string.IsNullOrEmpty(this._fileName)) { title = Path.GetFileNameWithoutExtension(this._fileName); } string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Insert(8, "-").Insert(13, "-").Insert(18, "-").Insert(23, "-"); doc.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Environment.NewLine + "<DCSubtitle Version=\"1.1\">" + Environment.NewLine + "<SubtitleID>" + guid + "</SubtitleID>" + Environment.NewLine + "<MovieTitle>" + title + "</MovieTitle>" + Environment.NewLine + "<ReelNumber>1</ReelNumber>" + Environment.NewLine + "<Language>English</Language>" + Environment.NewLine + sb + "</DCSubtitle>"); string fName = this.saveFileDialog1.FileName; if (!fName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase)) { fName += ".xml"; } File.WriteAllText(fName, SubtitleFormat.ToUtf8XmlString(doc)); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, Path.GetDirectoryName(fName))); } else { int resW; int resH; this.GetResolution(out resW, out resH); string videoFormat = "1080p"; if (resW == 1920 && resH == 1080) { videoFormat = "1080p"; } else if (resW == 1280 && resH == 720) { videoFormat = "720p"; } else if (resW == 848 && resH == 480) { videoFormat = "480p"; } else if (resW > 0 && resH > 0) { videoFormat = resW + "x" + resH; } var doc = new XmlDocument(); Paragraph first = this._subtitle.Paragraphs[0]; Paragraph last = this._subtitle.Paragraphs[this._subtitle.Paragraphs.Count - 1]; doc.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Environment.NewLine + "<BDN Version=\"0.93\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"BD-03-006-0093b BDN File Format.xsd\">" + Environment.NewLine + "<Description>" + Environment.NewLine + "<Name Title=\"subtitle_exp\" Content=\"\"/>" + Environment.NewLine + "<Language Code=\"eng\"/>" + Environment.NewLine + "<Format VideoFormat=\"" + videoFormat + "\" FrameRate=\"" + this.FrameRate.ToString(CultureInfo.InvariantCulture) + "\" DropFrame=\"False\"/>" + Environment.NewLine + "<Events Type=\"Graphic\" FirstEventInTC=\"" + this.BdnXmlTimeCode(first.StartTime) + "\" LastEventOutTC=\"" + this.BdnXmlTimeCode(last.EndTime) + "\" NumberofEvents=\"" + imagesSavedCount.ToString(CultureInfo.InvariantCulture) + "\"/>" + Environment.NewLine + "</Description>" + Environment.NewLine + "<Events>" + Environment.NewLine + "</Events>" + Environment.NewLine + "</BDN>"); XmlNode events = doc.DocumentElement.SelectSingleNode("Events"); doc.PreserveWhitespace = true; events.InnerXml = sb.ToString(); File.WriteAllText(Path.Combine(this.folderBrowserDialog1.SelectedPath, "BDN_Index.xml"), FormatUtf8Xml(doc), Encoding.UTF8); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, this.folderBrowserDialog1.SelectedPath)); } } this.buttonExport.Enabled = true; }
/// <summary> /// The write paragraph. /// </summary> /// <param name="width"> /// The width. /// </param> /// <param name="sb"> /// The sb. /// </param> /// <param name="border"> /// The border. /// </param> /// <param name="height"> /// The height. /// </param> /// <param name="imagesSavedCount"> /// The images saved count. /// </param> /// <param name="vobSubWriter"> /// The vob sub writer. /// </param> /// <param name="binarySubtitleFile"> /// The binary subtitle file. /// </param> /// <param name="param"> /// The param. /// </param> /// <param name="i"> /// The i. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> private int WriteParagraph(int width, StringBuilder sb, int border, int height, int imagesSavedCount, VobSubWriter vobSubWriter, FileStream binarySubtitleFile, MakeBitmapParameter param, int i) { if (param.Bitmap != null) { if (this._exportType == "BLURAYSUP") { if (!param.Saved) { binarySubtitleFile.Write(param.Buffer, 0, param.Buffer.Length); } param.Saved = true; } else if (this._exportType == "VOBSUB") { if (!param.Saved) { vobSubWriter.WriteParagraph(param.P, param.Bitmap, param.Alignment); } param.Saved = true; } else if (this._exportType == "FAB") { if (!param.Saved) { string numberString = string.Format("IMAGE{0:000}", i); string fileName = Path.Combine(this.folderBrowserDialog1.SelectedPath, numberString + "." + this.comboBoxImageFormat.Text.ToLower()); if (this.checkBoxFullFrameImage.Visible && this.checkBoxFullFrameImage.Checked) { var nbmp = new NikseBitmap(param.Bitmap); nbmp.ReplaceTransparentWith(this.panelFullFrameBackground.BackColor); using (var bmp = nbmp.GetBitmap()) { // param.Bitmap.Save(fileName, ImageFormat); imagesSavedCount++; // RACE001.TIF 00;00;02;02 00;00;03;15 000 000 720 480 // RACE002.TIF 00;00;05;18 00;00;09;20 000 000 720 480 int top = param.ScreenHeight - (param.Bitmap.Height + param.BottomMargin); int left = (param.ScreenWidth - param.Bitmap.Width) / 2; var b = new NikseBitmap(param.ScreenWidth, param.ScreenHeight); { b.Fill(this.panelFullFrameBackground.BackColor); using (var fullSize = b.GetBitmap()) { if (param.Alignment == ContentAlignment.BottomLeft || param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.TopLeft) { left = param.LeftRightMargin; } else if (param.Alignment == ContentAlignment.BottomRight || param.Alignment == ContentAlignment.MiddleRight || param.Alignment == ContentAlignment.TopRight) { left = param.ScreenWidth - param.Bitmap.Width - param.LeftRightMargin; } if (param.Alignment == ContentAlignment.TopLeft || param.Alignment == ContentAlignment.TopCenter || param.Alignment == ContentAlignment.TopRight) { top = param.BottomMargin; } if (param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.MiddleCenter || param.Alignment == ContentAlignment.MiddleRight) { top = param.ScreenHeight - (param.Bitmap.Height / 2); } using (var g = Graphics.FromImage(fullSize)) { g.DrawImage(bmp, left, top); g.Dispose(); } this.SaveImage(fullSize, fileName, this.ImageFormat); } } left = 0; top = 0; sb.AppendLine(string.Format("{0} {1} {2} {3} {4} {5} {6}", Path.GetFileName(fileName), FormatFabTime(param.P.StartTime, param), FormatFabTime(param.P.EndTime, param), left, top, left + param.ScreenWidth, top + param.ScreenHeight)); } } else { this.SaveImage(param.Bitmap, fileName, this.ImageFormat); imagesSavedCount++; // RACE001.TIF 00;00;02;02 00;00;03;15 000 000 720 480 // RACE002.TIF 00;00;05;18 00;00;09;20 000 000 720 480 int top = param.ScreenHeight - (param.Bitmap.Height + param.BottomMargin); int left = (param.ScreenWidth - param.Bitmap.Width) / 2; if (param.Alignment == ContentAlignment.BottomLeft || param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.TopLeft) { left = param.LeftRightMargin; } else if (param.Alignment == ContentAlignment.BottomRight || param.Alignment == ContentAlignment.MiddleRight || param.Alignment == ContentAlignment.TopRight) { left = param.ScreenWidth - param.Bitmap.Width - param.LeftRightMargin; } if (param.Alignment == ContentAlignment.TopLeft || param.Alignment == ContentAlignment.TopCenter || param.Alignment == ContentAlignment.TopRight) { top = param.BottomMargin; } if (param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.MiddleCenter || param.Alignment == ContentAlignment.MiddleRight) { top = param.ScreenHeight - (param.Bitmap.Height / 2); } sb.AppendLine(string.Format("{0} {1} {2} {3} {4} {5} {6}", Path.GetFileName(fileName), FormatFabTime(param.P.StartTime, param), FormatFabTime(param.P.EndTime, param), left, top, left + param.Bitmap.Width, top + param.Bitmap.Height)); } param.Saved = true; } } else if (this._exportType == "STL") { if (!param.Saved) { string numberString = string.Format("IMAGE{0:000}", i); string fileName = Path.Combine(this.folderBrowserDialog1.SelectedPath, numberString + "." + this.comboBoxImageFormat.Text.ToLower()); this.SaveImage(param.Bitmap, fileName, this.ImageFormat); imagesSavedCount++; const string paragraphWriteFormat = "{0} , {1} , {2}\r\n"; const string timeFormat = "{0:00}:{1:00}:{2:00}:{3:00}"; double factor = TimeCode.BaseUnit / Configuration.Settings.General.CurrentFrameRate; string startTime = string.Format(timeFormat, param.P.StartTime.Hours, param.P.StartTime.Minutes, param.P.StartTime.Seconds, (int)Math.Round(param.P.StartTime.Milliseconds / factor)); string endTime = string.Format(timeFormat, param.P.EndTime.Hours, param.P.EndTime.Minutes, param.P.EndTime.Seconds, (int)Math.Round(param.P.EndTime.Milliseconds / factor)); sb.AppendFormat(paragraphWriteFormat, startTime, endTime, fileName); param.Saved = true; } } else if (this._exportType == "SPUMUX") { if (!param.Saved) { string numberString = string.Format("IMAGE{0:000}", i); string fileName = Path.Combine(this.folderBrowserDialog1.SelectedPath, numberString + "." + this.comboBoxImageFormat.Text.ToLower()); foreach (var encoder in ImageCodecInfo.GetImageEncoders()) { if (encoder.FormatID == ImageFormat.Png.Guid) { var parameters = new EncoderParameters(); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8); var nbmp = new NikseBitmap(param.Bitmap); var b = nbmp.ConverTo8BitsPerPixel(); b.Save(fileName, encoder, parameters); b.Dispose(); break; } } imagesSavedCount++; const string paragraphWriteFormat = "\t\t<spu start=\"{0}\" end=\"{1}\" image=\"{2}\" />"; const string timeFormat = "{0:00}:{1:00}:{2:00}:{3:00}"; double factor = TimeCode.BaseUnit / Configuration.Settings.General.CurrentFrameRate; string startTime = string.Format(timeFormat, param.P.StartTime.Hours, param.P.StartTime.Minutes, param.P.StartTime.Seconds, (int)Math.Round(param.P.StartTime.Milliseconds / factor)); string endTime = string.Format(timeFormat, param.P.EndTime.Hours, param.P.EndTime.Minutes, param.P.EndTime.Seconds, (int)Math.Round(param.P.EndTime.Milliseconds / factor)); sb.AppendLine(string.Format(paragraphWriteFormat, startTime, endTime, fileName)); param.Saved = true; } } else if (this._exportType == "FCP") { if (!param.Saved) { string numberString = string.Format(Path.GetFileNameWithoutExtension(Path.GetFileName(param.SavDialogFileName)) + "{0:0000}", i); string fileName = numberString + "." + this.comboBoxImageFormat.Text.ToLower(); string fileNameNoPath = Path.GetFileName(fileName); string fileNameNoExt = Path.GetFileNameWithoutExtension(fileNameNoPath); string template = " <clipitem id=\"" + fileNameNoPath + "\">" + Environment.NewLine + // <pathurl>file://localhost/" + fileNameNoPath.Replace(" ", "%20") + @"</pathurl> @" <name>" + fileNameNoPath + @"</name> <duration>[DURATION]</duration> <rate> <ntsc>FALSE</ntsc> <timebase>25</timebase> </rate> <in>[IN]</in> <out>[OUT]</out> <start>[START]</start> <end>[END]</end> <pixelaspectratio>" + param.VideoResolution + @"</pixelaspectratio> <stillframe>TRUE</stillframe> <anamorphic>FALSE</anamorphic> <alphatype>straight</alphatype> <masterclipid>" + fileNameNoPath + @"1</masterclipid>" + Environment.NewLine + " <file id=\"" + fileNameNoExt + "\">" + @" <name>" + fileNameNoPath + @"</name> <pathurl>" + fileNameNoPath.Replace(" ", "%20") + @"</pathurl> <rate> <timebase>25</timebase> </rate> <duration>[DURATION]</duration> <width>" + param.ScreenWidth + @"</width> <height>" + param.ScreenHeight + @"</height> <media> <video> <duration>[DURATION]</duration> <stillframe>TRUE</stillframe> <samplecharacteristics> <width>" + param.ScreenWidth + @"</width> <height>" + param.ScreenHeight + @"</height> </samplecharacteristics> </video> </media> </file> <sourcetrack> <mediatype>video</mediatype> </sourcetrack> <fielddominance>none</fielddominance> </clipitem>"; fileName = Path.Combine(Path.GetDirectoryName(param.SavDialogFileName), fileName); if (this.comboBoxImageFormat.Text == "8-bit png") { foreach (var encoder in ImageCodecInfo.GetImageEncoders()) { if (encoder.FormatID == ImageFormat.Png.Guid) { var parameters = new EncoderParameters(); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8); var nbmp = new NikseBitmap(param.Bitmap); var b = nbmp.ConverTo8BitsPerPixel(); b.Save(fileName, encoder, parameters); b.Dispose(); break; } } } else { this.SaveImage(param.Bitmap, fileName, this.ImageFormat); } imagesSavedCount++; int duration = (int)Math.Round(param.P.Duration.TotalSeconds * param.FramesPerSeconds); int start = (int)Math.Round(param.P.StartTime.TotalSeconds * param.FramesPerSeconds); int end = (int)Math.Round(param.P.EndTime.TotalSeconds * param.FramesPerSeconds); template = template.Replace("[DURATION]", duration.ToString(CultureInfo.InvariantCulture)); template = template.Replace("[IN]", start.ToString(CultureInfo.InvariantCulture)); template = template.Replace("[OUT]", end.ToString(CultureInfo.InvariantCulture)); template = template.Replace("[START]", start.ToString(CultureInfo.InvariantCulture)); template = template.Replace("[END]", end.ToString(CultureInfo.InvariantCulture)); sb.AppendLine(template); param.Saved = true; } } else if (this._exportType == "DOST") { if (!param.Saved) { string numberString = string.Format("{0:0000}", i); string fileName = Path.Combine(Path.GetDirectoryName(this.saveFileDialog1.FileName), Path.GetFileNameWithoutExtension(this.saveFileDialog1.FileName).Replace(" ", "_")) + "_" + numberString + ".png"; foreach (var encoder in ImageCodecInfo.GetImageEncoders()) { if (encoder.FormatID == ImageFormat.Png.Guid) { var parameters = new EncoderParameters(); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8); var nbmp = new NikseBitmap(param.Bitmap); var b = nbmp.ConverTo8BitsPerPixel(); b.Save(fileName, encoder, parameters); b.Dispose(); break; } } imagesSavedCount++; const string paragraphWriteFormat = "{0}\t{1}\t{2}\t{4}\t{5}\t{3}\t0\t0"; int top = param.ScreenHeight - (param.Bitmap.Height + param.BottomMargin); int left = (param.ScreenWidth - param.Bitmap.Width) / 2; if (param.Alignment == ContentAlignment.BottomLeft || param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.TopLeft) { left = param.LeftRightMargin; } else if (param.Alignment == ContentAlignment.BottomRight || param.Alignment == ContentAlignment.MiddleRight || param.Alignment == ContentAlignment.TopRight) { left = param.ScreenWidth - param.Bitmap.Width - param.LeftRightMargin; } if (param.Alignment == ContentAlignment.TopLeft || param.Alignment == ContentAlignment.TopCenter || param.Alignment == ContentAlignment.TopRight) { top = param.BottomMargin; } if (param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.MiddleCenter || param.Alignment == ContentAlignment.MiddleRight) { top = param.ScreenHeight - (param.Bitmap.Height / 2); } string startTime = this.BdnXmlTimeCode(param.P.StartTime); string endTime = this.BdnXmlTimeCode(param.P.EndTime); sb.AppendLine(string.Format(paragraphWriteFormat, numberString, startTime, endTime, Path.GetFileName(fileName), left, top)); param.Saved = true; } } else if (this._exportType == "IMAGE/FRAME") { if (!param.Saved) { var imageFormat = this.ImageFormat; int lastFrame = imagesSavedCount; int startFrame = (int)Math.Round(param.P.StartTime.TotalMilliseconds / (TimeCode.BaseUnit / param.FramesPerSeconds)); var empty = new Bitmap(param.ScreenWidth, param.ScreenHeight); if (imagesSavedCount == 0 && this.checkBoxSkipEmptyFrameAtStart.Checked) { } else { // Save empty picture for each frame up to start frame for (int k = lastFrame + 1; k < startFrame; k++) { string numberString = string.Format("{0:00000}", k); string fileName = Path.Combine(this.folderBrowserDialog1.SelectedPath, numberString + "." + this.comboBoxImageFormat.Text.ToLower()); empty.Save(fileName, imageFormat); imagesSavedCount++; } } int endFrame = (int)Math.Round(param.P.EndTime.TotalMilliseconds / (TimeCode.BaseUnit / param.FramesPerSeconds)); var fullSize = new Bitmap(param.ScreenWidth, param.ScreenHeight); Graphics g = Graphics.FromImage(fullSize); g.DrawImage(param.Bitmap, (param.ScreenWidth - param.Bitmap.Width) / 2, param.ScreenHeight - (param.Bitmap.Height + param.BottomMargin)); g.Dispose(); if (imagesSavedCount > startFrame) { startFrame = imagesSavedCount; // no overlapping } // Save sub picture for each frame in duration for (int k = startFrame; k <= endFrame; k++) { string numberString = string.Format("{0:00000}", k); string fileName = Path.Combine(this.folderBrowserDialog1.SelectedPath, numberString + "." + this.comboBoxImageFormat.Text.ToLower()); fullSize.Save(fileName, imageFormat); imagesSavedCount++; } fullSize.Dispose(); param.Saved = true; } } else if (this._exportType == "DCINEMA_INTEROP") { if (!param.Saved) { string numberString = string.Format("{0:0000}", i); string fileName = Path.Combine(Path.GetDirectoryName(this.saveFileDialog1.FileName), numberString + ".png"); param.Bitmap.Save(fileName, ImageFormat.Png); imagesSavedCount++; param.Saved = true; sb.AppendLine("<Subtitle FadeDownTime=\"" + 0 + "\" FadeUpTime=\"" + 0 + "\" TimeOut=\"" + DCSubtitle.ConvertToTimeString(param.P.EndTime) + "\" TimeIn=\"" + DCSubtitle.ConvertToTimeString(param.P.StartTime) + "\" SpotNumber=\"" + param.P.Number + "\">"); if (param.Depth3D == 0) { sb.AppendLine("<Image VPosition=\"9.7\" VAlign=\"bottom\" HAlign=\"center\">" + numberString + ".png" + "</Image>"); } else { sb.AppendLine("<Image VPosition=\"9.7\" ZPosition=\"" + param.Depth3D + "\" VAlign=\"bottom\" HAlign=\"center\">" + numberString + ".png" + "</Image>"); } sb.AppendLine("</Subtitle>"); } } else if (this._exportType == "EDL") { if (!param.Saved) { // 001 7M6C7986 V C 14:14:55:21 14:15:16:24 01:00:10:18 01:00:31:21 var fileName1 = "IMG" + i.ToString(CultureInfo.InvariantCulture).PadLeft(5, '0'); var fullSize = new Bitmap(param.ScreenWidth, param.ScreenHeight); using (var g = Graphics.FromImage(fullSize)) { g.DrawImage(param.Bitmap, (param.ScreenWidth - param.Bitmap.Width) / 2, param.ScreenHeight - (param.Bitmap.Height + param.BottomMargin)); } var fileName2 = Path.Combine(Path.GetDirectoryName(param.SavDialogFileName), fileName1 + ".PNG"); fullSize.Save(fileName2, ImageFormat.Png); fullSize.Dispose(); string line = string.Format("{0:000} {1} V C {2} {3} {4} {5}", i, fileName1, new TimeCode(0).ToHHMMSSFF(), param.P.Duration.ToHHMMSSFF(), param.P.StartTime.ToHHMMSSFF(), param.P.EndTime.ToHHMMSSFF()); sb.AppendLine(line); sb.AppendLine(); imagesSavedCount++; param.Saved = true; } } else { // BDNXML if (!param.Saved) { string numberString = string.Format("{0:0000}", i); string fileName = Path.Combine(this.folderBrowserDialog1.SelectedPath, numberString + ".png"); if (this.comboBoxImageFormat.Text == "Png 8-bit") { foreach (var encoder in ImageCodecInfo.GetImageEncoders()) { if (encoder.FormatID == ImageFormat.Png.Guid) { var parameters = new EncoderParameters(); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8); var nbmp = new NikseBitmap(param.Bitmap); var b = nbmp.ConverTo8BitsPerPixel(); b.Save(fileName, encoder, parameters); b.Dispose(); break; } } } else { param.Bitmap.Save(fileName, ImageFormat.Png); } imagesSavedCount++; // <Event InTC="00:00:24:07" OutTC="00:00:31:13" Forced="False"> // <Graphic Width="696" Height="111" X="612" Y="930">subtitle_exp_0001.png</Graphic> // </Event> sb.AppendLine("<Event InTC=\"" + this.BdnXmlTimeCode(param.P.StartTime) + "\" OutTC=\"" + this.BdnXmlTimeCode(param.P.EndTime) + "\" Forced=\"" + param.Forced.ToString().ToLower() + "\">"); int x = (width - param.Bitmap.Width) / 2; int y = height - (param.Bitmap.Height + param.BottomMargin); switch (param.Alignment) { case ContentAlignment.BottomLeft: x = border; y = height - (param.Bitmap.Height + param.BottomMargin); break; case ContentAlignment.BottomRight: x = height - param.Bitmap.Width - border; y = height - (param.Bitmap.Height + param.BottomMargin); break; case ContentAlignment.MiddleCenter: x = (width - param.Bitmap.Width) / 2; y = (height - param.Bitmap.Height) / 2; break; case ContentAlignment.MiddleLeft: x = border; y = (height - param.Bitmap.Height) / 2; break; case ContentAlignment.MiddleRight: x = width - param.Bitmap.Width - border; y = (height - param.Bitmap.Height) / 2; break; case ContentAlignment.TopCenter: x = (width - param.Bitmap.Width) / 2; y = border; break; case ContentAlignment.TopLeft: x = border; y = border; break; case ContentAlignment.TopRight: x = width - param.Bitmap.Width - border; y = border; break; } sb.AppendLine(" <Graphic Width=\"" + param.Bitmap.Width.ToString(CultureInfo.InvariantCulture) + "\" Height=\"" + param.Bitmap.Height.ToString(CultureInfo.InvariantCulture) + "\" X=\"" + x.ToString(CultureInfo.InvariantCulture) + "\" Y=\"" + y.ToString(CultureInfo.InvariantCulture) + "\">" + numberString + ".png</Graphic>"); sb.AppendLine("</Event>"); param.Saved = true; } } } return imagesSavedCount; }
private void ButtonExportClick(object sender, EventArgs e) { FixStartEndWithSameTimeCode(); var errors = new List<string>(); buttonExport.Enabled = false; SetupImageParameters(); if (!string.IsNullOrEmpty(_fileName)) saveFileDialog1.FileName = Path.GetFileNameWithoutExtension(_fileName); if (_exportType == "BLURAYSUP") { saveFileDialog1.Title = Configuration.Settings.Language.ExportPngXml.SaveBluRraySupAs; saveFileDialog1.DefaultExt = "*.sup"; saveFileDialog1.AddExtension = true; saveFileDialog1.Filter = "Blu-Ray sup|*.sup"; } else if (_exportType == "VOBSUB") { saveFileDialog1.Title = Configuration.Settings.Language.ExportPngXml.SaveVobSubAs; saveFileDialog1.DefaultExt = "*.sub"; saveFileDialog1.AddExtension = true; saveFileDialog1.Filter = "VobSub|*.sub"; } else if (_exportType == "FAB") { saveFileDialog1.Title = Configuration.Settings.Language.ExportPngXml.SaveFabImageScriptAs; saveFileDialog1.DefaultExt = "*.txt"; saveFileDialog1.AddExtension = true; saveFileDialog1.Filter = "FAB image scripts|*.txt"; } else if (_exportType == "STL") { saveFileDialog1.Title = Configuration.Settings.Language.ExportPngXml.SaveDvdStudioProStlAs; saveFileDialog1.DefaultExt = "*.txt"; saveFileDialog1.AddExtension = true; saveFileDialog1.Filter = "DVD Studio Pro STL|*.stl"; } else if (_exportType == "FCP") { saveFileDialog1.Title = "Save FCP XML as..."; //TODO: Configuration.Settings.Language.ExportPngXml.SaveFcpAs; saveFileDialog1.DefaultExt = "*.xml"; saveFileDialog1.AddExtension = true; saveFileDialog1.Filter = "Xml files|*.xml"; } else if (_exportType == "DOST") { saveFileDialog1.Title = "Save DOST XML as..."; //TODO: Configuration.Settings.Language.ExportPngXml.SaveDostAs; saveFileDialog1.DefaultExt = "*.dost"; saveFileDialog1.AddExtension = true; saveFileDialog1.Filter = "Dost files|*.dost"; } else if (_exportType == "DCINEMA_INTEROP") { saveFileDialog1.Title = "Save D-Cinema interop as..."; //TODO: Configuration.Settings.Language.ExportPngXml.SaveDostAs; saveFileDialog1.DefaultExt = "*.xml"; saveFileDialog1.AddExtension = true; saveFileDialog1.Filter = "Xml files|*.xml"; } if (_exportType == "BLURAYSUP" && saveFileDialog1.ShowDialog(this) == DialogResult.OK || _exportType == "VOBSUB" && saveFileDialog1.ShowDialog(this) == DialogResult.OK || _exportType == "BDNXML" && folderBrowserDialog1.ShowDialog(this) == DialogResult.OK || _exportType == "FAB" && folderBrowserDialog1.ShowDialog(this) == DialogResult.OK || _exportType == "IMAGE/FRAME" && folderBrowserDialog1.ShowDialog(this) == DialogResult.OK || _exportType == "STL" && folderBrowserDialog1.ShowDialog(this) == DialogResult.OK || _exportType == "SPUMUX" && folderBrowserDialog1.ShowDialog(this) == DialogResult.OK || _exportType == "FCP" && saveFileDialog1.ShowDialog(this) == DialogResult.OK || _exportType == "DOST" && saveFileDialog1.ShowDialog(this) == DialogResult.OK || _exportType == "DCINEMA_INTEROP" && saveFileDialog1.ShowDialog(this) == DialogResult.OK) { int width = 1920; int height = 1080; GetResolution(ref width, ref height); FileStream binarySubtitleFile = null; VobSubWriter vobSubWriter = null; if (_exportType == "BLURAYSUP") binarySubtitleFile = new FileStream(saveFileDialog1.FileName, FileMode.Create); else if (_exportType == "VOBSUB") vobSubWriter = new VobSubWriter(saveFileDialog1.FileName, width, height, comboBoxBottomMargin.SelectedIndex, 32, _subtitleColor, _borderColor, !checkBoxTransAntiAliase.Checked, IfoParser.ArrayOfLanguage[comboBoxLanguage.SelectedIndex], IfoParser.ArrayOfLanguageCode[comboBoxLanguage.SelectedIndex]); progressBar1.Value = 0; progressBar1.Maximum = _subtitle.Paragraphs.Count-1; progressBar1.Visible = true; int border = comboBoxBottomMargin.SelectedIndex; int imagesSavedCount = 0; var sb = new StringBuilder(); if (_exportType == "STL") { sb.AppendLine("$SetFilePathToken =" + folderBrowserDialog1.SelectedPath); sb.AppendLine(); } if (_vobSubOcr != null) { int i = 0; foreach (Paragraph p in _subtitle.Paragraphs) { var mp = MakeMakeBitmapParameter(i, width, height); mp.Bitmap = _vobSubOcr.GetSubtitleBitmap(i); if (_exportType == "BLURAYSUP") { var brSub = new Logic.BluRaySup.BluRaySupPicture { StartTime = (long)mp.P.StartTime.TotalMilliseconds, EndTime = (long)mp.P.EndTime.TotalMilliseconds, Width = mp.ScreenWidth, Height = mp.ScreenHeight }; mp.Buffer = Logic.BluRaySup.BluRaySupPicture.CreateSupFrame(brSub, mp.Bitmap, mp.FramesPerSeconds, mp.BottomMargin, mp.Alignment); } imagesSavedCount = WriteParagraph(width, sb, border, height, imagesSavedCount, vobSubWriter, binarySubtitleFile, mp, i); i++; progressBar1.Refresh(); Application.DoEvents(); if (i < progressBar1.Maximum) progressBar1.Value = i; } } else { var threadEqual = new Thread(DoWork); var paramEqual = MakeMakeBitmapParameter(0, width, height); var threadUnEqual = new Thread(DoWork); var paramUnEqual = MakeMakeBitmapParameter(1, width, height); threadEqual.Start(paramEqual); int i = 1; for (; i < _subtitle.Paragraphs.Count; i++) { if (i % 2 == 0) { paramEqual = MakeMakeBitmapParameter(i, width, height); threadEqual = new Thread(DoWork); threadEqual.Start(paramEqual); if (threadUnEqual.ThreadState == ThreadState.Running) threadUnEqual.Join(); imagesSavedCount = WriteParagraph(width, sb, border, height, imagesSavedCount, vobSubWriter, binarySubtitleFile, paramUnEqual, i); if (!string.IsNullOrEmpty(paramUnEqual.Error)) { errors.Add(paramUnEqual.Error); } } else { paramUnEqual = MakeMakeBitmapParameter(i, width, height); threadUnEqual = new Thread(DoWork); threadUnEqual.Start(paramUnEqual); if (threadEqual.ThreadState == ThreadState.Running) threadEqual.Join(); imagesSavedCount = WriteParagraph(width, sb, border, height, imagesSavedCount, vobSubWriter, binarySubtitleFile, paramEqual, i); if (!string.IsNullOrEmpty(paramEqual.Error)) { errors.Add(paramEqual.Error); } } progressBar1.Refresh(); Application.DoEvents(); progressBar1.Value = i; } if (i % 2 == 0) { if (threadEqual.ThreadState == ThreadState.Running) threadEqual.Join(); imagesSavedCount = WriteParagraph(width, sb, border, height, imagesSavedCount, vobSubWriter, binarySubtitleFile, paramEqual, i); if (threadUnEqual.ThreadState == ThreadState.Running) threadUnEqual.Join(); imagesSavedCount = WriteParagraph(width, sb, border, height, imagesSavedCount, vobSubWriter, binarySubtitleFile, paramUnEqual, i); } else { if (threadUnEqual.ThreadState == ThreadState.Running) threadUnEqual.Join(); imagesSavedCount = WriteParagraph(width, sb, border, height, imagesSavedCount, vobSubWriter, binarySubtitleFile, paramUnEqual, i); if (threadEqual.ThreadState == ThreadState.Running) threadEqual.Join(); imagesSavedCount = WriteParagraph(width, sb, border, height, imagesSavedCount, vobSubWriter, binarySubtitleFile, paramEqual, i); } } if (errors.Count > 0) { var errorSb = new StringBuilder(); for (int i = 0; i < 20; i++) { if (i < errors.Count) errorSb.AppendLine(errors[i]); } if (errors.Count > 20) errorSb.AppendLine("..."); if (!string.IsNullOrEmpty(Configuration.Settings.Language.ExportPngXml.SomeLinesWereTooLongX)) //TODO: Fix in 3.4 MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.SomeLinesWereTooLongX, errorSb)); } progressBar1.Visible = false; if (_exportType == "BLURAYSUP") { binarySubtitleFile.Close(); MessageBox.Show(string.Format(Configuration.Settings.Language.Main.SavedSubtitleX, saveFileDialog1.FileName)); } else if (_exportType == "VOBSUB") { vobSubWriter.CloseSubFile(); vobSubWriter.WriteIdxFile(); MessageBox.Show(string.Format(Configuration.Settings.Language.Main.SavedSubtitleX, saveFileDialog1.FileName)); } else if (_exportType == "FAB") { File.WriteAllText(Path.Combine(folderBrowserDialog1.SelectedPath, "Fab_Image_script.txt"), sb.ToString()); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, folderBrowserDialog1.SelectedPath)); } else if (_exportType == "IMAGE/FRAME") { var empty = new Bitmap(width, height); imagesSavedCount++; string numberString = string.Format("{0:00000}", imagesSavedCount); string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + "." + comboBoxImageFormat.Text.ToLower()); empty.Save(fileName, ImageFormat); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, folderBrowserDialog1.SelectedPath)); } else if (_exportType == "STL") { File.WriteAllText(Path.Combine(folderBrowserDialog1.SelectedPath, "DVD_Studio_Pro_Image_script.stl"), sb.ToString()); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, folderBrowserDialog1.SelectedPath)); } else if (_exportType == "SPUMUX") { string s = "<subpictures>" + Environment.NewLine + "\t<stream>" + Environment.NewLine + sb + "\t</stream>" + Environment.NewLine + "</subpictures>"; File.WriteAllText(Path.Combine(folderBrowserDialog1.SelectedPath, "spu.xml"), s); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, folderBrowserDialog1.SelectedPath)); } else if (_exportType == "FCP") { string fileNameNoPath = Path.GetFileName(saveFileDialog1.FileName); string fileNameNoExt = Path.GetFileNameWithoutExtension(fileNameNoPath); int duration = 0; if (_subtitle.Paragraphs.Count > 0) duration = (int)Math.Round(_subtitle.Paragraphs[_subtitle.Paragraphs.Count - 1].EndTime.TotalSeconds * 25.0); string s = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine + "<!DOCTYPE xmeml[]>" + Environment.NewLine + "<xmeml version=\"4\">" + Environment.NewLine + " <sequence id=\"" + fileNameNoExt + "\">" + Environment.NewLine + " <updatebehavior>add</updatebehavior>" + Environment.NewLine + " <name>" + fileNameNoExt + @"</name> <duration>" + duration.ToString(CultureInfo.InvariantCulture) + @"</duration> <rate> <ntsc>FALSE</ntsc> <timebase>25</timebase> </rate> <timecode> <rate> <ntsc>FALSE</ntsc> <timebase>25</timebase> </rate> <string>00:00:00:00</string> <frame>0</frame> <source>source</source> <displayformat>NDF</displayformat> </timecode> <in>0</in> <out>36066</out> <media> <video> <track> <enabled>TRUE</enabled> <locked>FALSE</locked> </track> <track> " + sb + @" <enabled>TRUE</enabled> <locked>FALSE</locked> </track> </video> <audio> <track> <enabled>TRUE</enabled> <locked>FALSE</locked> <outputchannelindex>1</outputchannelindex> </track> <track> <enabled>TRUE</enabled> <locked>FALSE</locked> <outputchannelindex>2</outputchannelindex> </track> <track> <enabled>TRUE</enabled> <locked>FALSE</locked> <outputchannelindex>3</outputchannelindex> </track> <track> <enabled>TRUE</enabled> <locked>FALSE</locked> <outputchannelindex>4</outputchannelindex> </track> </audio> </media> <ismasterclip>FALSE</ismasterclip> </sequence> </xmeml>"; File.WriteAllText(Path.Combine(folderBrowserDialog1.SelectedPath, saveFileDialog1.FileName), s); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, Path.GetDirectoryName(saveFileDialog1.FileName))); } else if (_exportType == "DOST") { string header = @"$FORMAT=480 $VERSION=1.2 $ULEAD=TRUE $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine + "NO\tINTIME\t\tOUTTIME\t\tXPOS\tYPOS\tFILENAME\tFADEIN\tFADEOUT"; string dropValue = "30000"; if (comboBoxFramerate.Items[comboBoxFramerate.SelectedIndex].ToString() == "23.98") dropValue = "23976"; else if (comboBoxFramerate.Items[comboBoxFramerate.SelectedIndex].ToString() == "24") dropValue = "24000"; else if (comboBoxFramerate.Items[comboBoxFramerate.SelectedIndex].ToString() == "25") dropValue = "25000"; else if (comboBoxFramerate.Items[comboBoxFramerate.SelectedIndex].ToString() == "29.97") dropValue = "29970"; else if (comboBoxFramerate.Items[comboBoxFramerate.SelectedIndex].ToString() == "30") dropValue = "30000"; else if (comboBoxFramerate.Items[comboBoxFramerate.SelectedIndex].ToString() == "59.94") dropValue = "59940"; header = header.Replace("[DROPVALUE]", dropValue); File.WriteAllText(saveFileDialog1.FileName, header + Environment.NewLine + sb); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, Path.GetDirectoryName(saveFileDialog1.FileName))); } else if (_exportType == "DCINEMA_INTEROP") { var doc = new XmlDocument(); string title = "unknown"; if (!string.IsNullOrEmpty(_fileName)) title = Path.GetFileNameWithoutExtension(_fileName); string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Insert(8, "-").Insert(13, "-").Insert(18, "-").Insert(23, "-"); doc.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Environment.NewLine + "<DCSubtitle Version=\"1.1\">" + Environment.NewLine + "<SubtitleID>" + guid + "</SubtitleID>" + Environment.NewLine + "<MovieTitle>" + title + "</MovieTitle>" + Environment.NewLine + "<ReelNumber>1</ReelNumber>" + Environment.NewLine + "<Language>English</Language>" + Environment.NewLine + sb + "</DCSubtitle>"); string fName = saveFileDialog1.FileName; if (!fName.ToLower().EndsWith(".xml")) fName += ".xml"; File.WriteAllText(fName, SubtitleFormat.ToUtf8XmlString(doc)); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, Path.GetDirectoryName(fName))); } else { int resW = 0; int resH = 0; GetResolution(ref resW, ref resH); string videoFormat = "1080p"; if (resW == 1920 && resH == 1080) videoFormat = "1080p"; else if (resW == 1280 && resH == 720) videoFormat = "720p"; else if (resW == 848 && resH == 480) videoFormat = "480p"; else videoFormat = resW + "x" + resH; var doc = new XmlDocument(); Paragraph first = _subtitle.Paragraphs[0]; Paragraph last = _subtitle.Paragraphs[_subtitle.Paragraphs.Count - 1]; doc.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Environment.NewLine + "<BDN Version=\"0.93\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"BD-03-006-0093b BDN File Format.xsd\">" + Environment.NewLine + "<Description>" + Environment.NewLine + "<Name Title=\"subtitle_exp\" Content=\"\"/>" + Environment.NewLine + "<Language Code=\"eng\"/>" + Environment.NewLine + "<Format VideoFormat=\"" + videoFormat + "\" FrameRate=\"" + FrameRate.ToString(CultureInfo.InvariantCulture) + "\" DropFrame=\"False\"/>" + Environment.NewLine + "<Events Type=\"Graphic\" FirstEventInTC=\"" + BdnXmlTimeCode(first.StartTime) + "\" LastEventOutTC=\"" + BdnXmlTimeCode(last.EndTime) + "\" NumberofEvents=\"" + imagesSavedCount.ToString(CultureInfo.InvariantCulture) + "\"/>" + Environment.NewLine + "</Description>" + Environment.NewLine + "<Events>" + Environment.NewLine + "</Events>" + Environment.NewLine + "</BDN>"); XmlNode events = doc.DocumentElement.SelectSingleNode("Events"); events.InnerXml = sb.ToString(); File.WriteAllText(Path.Combine(folderBrowserDialog1.SelectedPath, "BDN_Index.xml"), doc.OuterXml); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, folderBrowserDialog1.SelectedPath)); } } buttonExport.Enabled = true; }
private int WriteParagraph(int width, StringBuilder sb, int border, int height, int imagesSavedCount, VobSubWriter vobSubWriter, FileStream binarySubtitleFile, MakeBitmapParameter param, int i) { if (param.Bitmap != null) { if (_exportType == "BLURAYSUP") { if (!param.Saved) binarySubtitleFile.Write(param.Buffer, 0, param.Buffer.Length); param.Saved = true; } else if (_exportType == "VOBSUB") { if (!param.Saved) vobSubWriter.WriteParagraph(param.P, param.Bitmap, param.Alignment); param.Saved = true; } else if (_exportType == "FAB") { if (!param.Saved) { string numberString = string.Format("IMAGE{0:000}", i); string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + "." + comboBoxImageFormat.Text.ToLower()); param.Bitmap.Save(fileName, ImageFormat); imagesSavedCount++; //RACE001.TIF 00;00;02;02 00;00;03;15 000 000 720 480 //RACE002.TIF 00;00;05;18 00;00;09;20 000 000 720 480 int top = param.ScreenHeight - (param.Bitmap.Height + param.BottomMargin); int left = (param.ScreenWidth - param.Bitmap.Width) / 2; if (param.Alignment == ContentAlignment.BottomLeft || param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.TopLeft) left = param.BottomMargin; else if (param.Alignment == ContentAlignment.BottomRight || param.Alignment == ContentAlignment.MiddleRight || param.Alignment == ContentAlignment.TopRight) left = param.ScreenWidth - param.Bitmap.Width - param.BottomMargin; if (param.Alignment == ContentAlignment.TopLeft || param.Alignment == ContentAlignment.TopCenter || param.Alignment == ContentAlignment.TopRight) top = param.BottomMargin; if (param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.MiddleCenter || param.Alignment == ContentAlignment.MiddleRight) top = param.ScreenHeight - (param.Bitmap.Height / 2); sb.AppendLine(string.Format("{0} {1} {2} {3} {4} {5} {6}", Path.GetFileName(fileName), FormatFabTime(param.P.StartTime, param), FormatFabTime(param.P.EndTime, param), left, top, left + param.Bitmap.Width, top + param.Bitmap.Height)); param.Saved = true; } } else if (_exportType == "STL") { if (!param.Saved) { string numberString = string.Format("IMAGE{0:000}", i); string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + "." + comboBoxImageFormat.Text.ToLower()); param.Bitmap.Save(fileName, ImageFormat); imagesSavedCount++; const string paragraphWriteFormat = "{0} , {1} , {2}\r\n"; const string timeFormat = "{0:00}:{1:00}:{2:00}:{3:00}"; double factor = (1000.0 / Configuration.Settings.General.CurrentFrameRate); string startTime = string.Format(timeFormat, param.P.StartTime.Hours, param.P.StartTime.Minutes, param.P.StartTime.Seconds, (int)Math.Round(param.P.StartTime.Milliseconds / factor)); string endTime = string.Format(timeFormat, param.P.EndTime.Hours, param.P.EndTime.Minutes, param.P.EndTime.Seconds, (int)Math.Round(param.P.EndTime.Milliseconds / factor)); sb.Append(string.Format(paragraphWriteFormat, startTime, endTime, fileName)); param.Saved = true; } } else if (_exportType == "SPUMUX") { if (!param.Saved) { string numberString = string.Format("IMAGE{0:000}", i); string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + "." + comboBoxImageFormat.Text.ToLower()); foreach (var encoder in ImageCodecInfo.GetImageEncoders()) { if (encoder.FormatID == ImageFormat.Png.Guid) { var parameters = new EncoderParameters(); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8); var nbmp = new NikseBitmap(param.Bitmap); var b = nbmp.ConverTo8BitsPerPixel(); b.Save(fileName, encoder, parameters); b.Dispose(); break; } } imagesSavedCount++; const string paragraphWriteFormat = "\t\t<spu start=\"{0}\" end=\"{1}\" image=\"{2}\" />"; const string timeFormat = "{0:00}:{1:00}:{2:00}:{3:00}"; double factor = (1000.0 / Configuration.Settings.General.CurrentFrameRate); string startTime = string.Format(timeFormat, param.P.StartTime.Hours, param.P.StartTime.Minutes, param.P.StartTime.Seconds, (int)Math.Round(param.P.StartTime.Milliseconds / factor)); string endTime = string.Format(timeFormat, param.P.EndTime.Hours, param.P.EndTime.Minutes, param.P.EndTime.Seconds, (int)Math.Round(param.P.EndTime.Milliseconds / factor)); sb.AppendLine(string.Format(paragraphWriteFormat, startTime, endTime, fileName)); param.Saved = true; } } else if (_exportType == "FCP") { if (!param.Saved) { string numberString = string.Format(Path.GetFileNameWithoutExtension(Path.GetFileName(param.SavDialogFileName)) + "{0:0000}", i); string fileName = numberString + "." + comboBoxImageFormat.Text.ToLower(); string fileNameNoPath = Path.GetFileName(fileName); string fileNameNoExt = Path.GetFileNameWithoutExtension(fileNameNoPath); string template = " <clipitem id=\"" + fileNameNoPath + "\">" + Environment.NewLine + @" <name>" + fileNameNoPath + @"</name> <duration>[DURATION]</duration> <rate> <ntsc>FALSE</ntsc> <timebase>25</timebase> </rate> <in>[IN]</in> <out>[OUT]</out> <start>[START]</start> <end>[END]</end> <pixelaspectratio>PAL-601</pixelaspectratio> <stillframe>TRUE</stillframe> <anamorphic>FALSE</anamorphic> <alphatype>straight</alphatype> <masterclipid>" + fileNameNoPath + @"1</masterclipid>" + Environment.NewLine + " <file id=\"" + fileNameNoExt + "\">" + @" <name>" + fileNameNoPath + @"</name> <pathurl>file://localhost/" + fileNameNoPath + @"</pathurl> <rate> <timebase>25</timebase> </rate> <duration>[DURATION]</duration> <width>" + param.ScreenWidth.ToString() + @"</width> <height>" + param.ScreenHeight.ToString() + @"</height> <media> <video> <duration>[DURATION]</duration> <stillframe>TRUE</stillframe> <samplecharacteristics> <width>720</width> <height>576</height> </samplecharacteristics> </video> </media> </file> <sourcetrack> <mediatype>video</mediatype> </sourcetrack> <fielddominance>none</fielddominance> </clipitem>"; fileName = Path.Combine(Path.GetDirectoryName(param.SavDialogFileName), fileName); if (comboBoxImageFormat.Text == "8-bit png") { foreach (var encoder in ImageCodecInfo.GetImageEncoders()) { if (encoder.FormatID == ImageFormat.Png.Guid) { var parameters = new EncoderParameters(); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8); var nbmp = new NikseBitmap(param.Bitmap); var b = nbmp.ConverTo8BitsPerPixel(); b.Save(fileName, encoder, parameters); b.Dispose(); break; } } } else { param.Bitmap.Save(fileName, ImageFormat); } imagesSavedCount++; int duration = (int)Math.Round(param.P.Duration.TotalSeconds * 25.0); int start = (int)Math.Round(param.P.StartTime.TotalSeconds * 25.0); int end = (int)Math.Round(param.P.EndTime.TotalSeconds * 25.0); template = template.Replace("[DURATION]", duration.ToString(CultureInfo.InvariantCulture)); template = template.Replace("[IN]", start.ToString(CultureInfo.InvariantCulture)); template = template.Replace("[OUT]", end.ToString(CultureInfo.InvariantCulture)); template = template.Replace("[START]", start.ToString(CultureInfo.InvariantCulture)); template = template.Replace("[END]", end.ToString(CultureInfo.InvariantCulture)); sb.AppendLine(template); param.Saved = true; } } else if (_exportType == "DOST") { if (!param.Saved) { string numberString = string.Format("{0:0000}", i); string fileName = Path.Combine(Path.GetDirectoryName(saveFileDialog1.FileName), Path.GetFileNameWithoutExtension(saveFileDialog1.FileName)).Replace(" ", "_") + "_" + numberString + ".png"; foreach (var encoder in ImageCodecInfo.GetImageEncoders()) { if (encoder.FormatID == ImageFormat.Png.Guid) { var parameters = new EncoderParameters(1); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8); var nbmp = new NikseBitmap(param.Bitmap); var b = nbmp.ConverTo8BitsPerPixel(); b.Save(fileName, encoder, parameters); b.Dispose(); break; } } imagesSavedCount++; const string paragraphWriteFormat = "{0}\t{1}\t{2}\t{4}\t{5}\t{3}\t0\t0"; int top = param.ScreenHeight - (param.Bitmap.Height + param.BottomMargin); int left = (param.ScreenWidth - param.Bitmap.Width) / 2; if (param.Alignment == ContentAlignment.BottomLeft || param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.TopLeft) left = param.BottomMargin; else if (param.Alignment == ContentAlignment.BottomRight || param.Alignment == ContentAlignment.MiddleRight || param.Alignment == ContentAlignment.TopRight) left = param.ScreenWidth - param.Bitmap.Width - param.BottomMargin; if (param.Alignment == ContentAlignment.TopLeft || param.Alignment == ContentAlignment.TopCenter || param.Alignment == ContentAlignment.TopRight) top = param.BottomMargin; if (param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.MiddleCenter || param.Alignment == ContentAlignment.MiddleRight) top = param.ScreenHeight - (param.Bitmap.Height / 2); string startTime = BdnXmlTimeCode(param.P.StartTime); string endTime = BdnXmlTimeCode(param.P.EndTime); sb.AppendLine(string.Format(paragraphWriteFormat, numberString, startTime, endTime, Path.GetFileName(fileName), left, top)); param.Saved = true; } } else if (_exportType == "IMAGE/FRAME") { if (!param.Saved) { var imageFormat = ImageFormat; int lastFrame = imagesSavedCount; int startFrame = (int)Math.Round(param.P.StartTime.TotalMilliseconds / (1000.0 / param.FramesPerSeconds)); var empty = new Bitmap(param.ScreenWidth, param.ScreenHeight); if (imagesSavedCount == 0 && checkBoxSkipEmptyFrameAtStart.Checked) { } else { // Save empty picture for each frame up to start frame for (int k = lastFrame + 1; k < startFrame; k++) { string numberString = string.Format("{0:00000}", k); string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + "." + comboBoxImageFormat.Text.ToLower()); empty.Save(fileName, imageFormat); imagesSavedCount++; } } int endFrame = (int)Math.Round(param.P.EndTime.TotalMilliseconds / (1000.0 / param.FramesPerSeconds)); var fullSize = new Bitmap(param.ScreenWidth, param.ScreenHeight); Graphics g = Graphics.FromImage(fullSize); g.DrawImage(param.Bitmap, (param.ScreenWidth - param.Bitmap.Width) / 2, param.ScreenHeight - (param.Bitmap.Height + param.BottomMargin)); g.Dispose(); if (imagesSavedCount > startFrame) startFrame = imagesSavedCount; // no overlapping // Save sub picture for each frame in duration for (int k = startFrame; k <= endFrame; k++) { string numberString = string.Format("{0:00000}", k); string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + "." + comboBoxImageFormat.Text.ToLower()); fullSize.Save(fileName, imageFormat); imagesSavedCount++; } fullSize.Dispose(); param.Saved = true; } } else { if (!param.Saved) { string numberString = string.Format("{0:0000}", i); string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + ".png"); param.Bitmap.Save(fileName, ImageFormat.Png); imagesSavedCount++; //<Event InTC="00:00:24:07" OutTC="00:00:31:13" Forced="False"> // <Graphic Width="696" Height="111" X="612" Y="930">subtitle_exp_0001.png</Graphic> //</Event> sb.AppendLine("<Event InTC=\"" + BdnXmlTimeCode(param.P.StartTime) + "\" OutTC=\"" + BdnXmlTimeCode(param.P.EndTime) + "\" Forced=\"False\">"); int x = (width - param.Bitmap.Width) / 2; int y = height - (param.Bitmap.Height + param.BottomMargin); switch (param.Alignment) { case ContentAlignment.BottomLeft: x = border; y = height - (param.Bitmap.Height + param.BottomMargin); break; case ContentAlignment.BottomRight: x = height - param.Bitmap.Width - border; y = height - (param.Bitmap.Height + param.BottomMargin); break; case ContentAlignment.MiddleCenter: x = (width - param.Bitmap.Width) / 2; y = (height - param.Bitmap.Height) / 2; break; case ContentAlignment.MiddleLeft: x = border; y = (height - param.Bitmap.Height) / 2; break; case ContentAlignment.MiddleRight: x = width - param.Bitmap.Width - border; y = (height - param.Bitmap.Height) / 2; break; case ContentAlignment.TopCenter: x = (width - param.Bitmap.Width) / 2; y = border; break; case ContentAlignment.TopLeft: x = border; y = border; break; case ContentAlignment.TopRight: x = width - param.Bitmap.Width - border; y = border; break; default: // ContentAlignment.BottomCenter: break; } sb.AppendLine(" <Graphic Width=\"" + param.Bitmap.Width.ToString(CultureInfo.InvariantCulture) + "\" Height=\"" + param.Bitmap.Height.ToString(CultureInfo.InvariantCulture) + "\" X=\"" + x.ToString(CultureInfo.InvariantCulture) + "\" Y=\"" + y.ToString(CultureInfo.InvariantCulture) + "\">" + numberString + ".png</Graphic>"); sb.AppendLine("</Event>"); param.Saved = true; } } } return imagesSavedCount; }