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 + @"</width> <height>" + param.ScreenHeight + @"</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(); 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 (_exportType == "DCINEMA_INTEROP") { if (!param.Saved) { string numberString = string.Format("{0:0000}", i); string fileName = Path.Combine(Path.GetDirectoryName(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 (!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; }