public static void DoWork(object data) { var parameter = (MakeBitmapParameter)data; if (parameter.Type == "VOBSUB" || parameter.Type == "STL" || parameter.Type == "SPUMUX") { parameter.LineJoinRound = true; } parameter.Bitmap = GenerateImageFromTextWithStyle(parameter); if (parameter.Type == "BLURAYSUP") { var brSub = new Logic.BluRaySup.BluRaySupPicture { StartTime = (long) parameter.P.StartTime.TotalMilliseconds, EndTime = (long) parameter.P.EndTime.TotalMilliseconds, Width = parameter.ScreenWidth, Height = parameter.ScreenHeight }; parameter.Buffer = Logic.BluRaySup.BluRaySupPicture.CreateSupFrame(brSub, parameter.Bitmap, parameter.FramesPerSeconds, parameter.BottomMargin, parameter.Alignment); } }
/// <summary> /// The make blu ray sup image. /// </summary> /// <param name="param"> /// The param. /// </param> private static void MakeBluRaySupImage(MakeBitmapParameter param) { var brSub = new Logic.BluRaySup.BluRaySupPicture { StartTime = (long)param.P.StartTime.TotalMilliseconds, EndTime = (long)param.P.EndTime.TotalMilliseconds, Width = param.ScreenWidth, Height = param.ScreenHeight, IsForced = param.Forced }; if (param.FullFrame) { var nbmp = new NikseBitmap(param.Bitmap); nbmp.ReplaceTransparentWith(param.FullFrameBackgroundcolor); using (var bmp = nbmp.GetBitmap()) { 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(param.FullFrameBackgroundcolor); 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(); } param.Buffer = Logic.BluRaySup.BluRaySupPicture.CreateSupFrame(brSub, fullSize, param.FramesPerSeconds, 0, 0, ContentAlignment.BottomCenter); } } } } else { param.Buffer = Logic.BluRaySup.BluRaySupPicture.CreateSupFrame(brSub, param.Bitmap, param.FramesPerSeconds, param.BottomMargin, param.LeftRightMargin, param.Alignment); } }
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; }