summaryrefslogtreecommitdiffstats
path: root/core/save-profiledata.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/save-profiledata.c')
-rw-r--r--core/save-profiledata.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/core/save-profiledata.c b/core/save-profiledata.c
index 603045fe0..09ac76886 100644
--- a/core/save-profiledata.c
+++ b/core/save-profiledata.c
@@ -5,6 +5,7 @@
#include "core/membuffer.h"
#include "core/subsurface-string.h"
#include "core/save-profiledata.h"
+#include "core/version.h"
static void put_int(struct membuffer *b, int val)
{
@@ -21,6 +22,15 @@ static void put_double(struct membuffer *b, double val)
put_format(b, "\"%f\" ", val);
}
+static void put_video_time(struct membuffer *b, int secs)
+{
+ int hours = secs / 3600;
+ secs -= hours * 3600;
+ int mins = secs / 60;
+ secs -= mins * 60;
+ put_format(b, "%d:%02d:%02d.000,", hours, mins, secs);
+}
+
static void put_pd(struct membuffer *b, struct plot_data *entry)
{
if (!entry)
@@ -148,6 +158,39 @@ static void put_headers(struct membuffer *b)
put_csv_string(b, "icd_warning");
}
+static void put_st_event(struct membuffer *b, struct plot_data *entry, int offset, int length)
+{
+ double value;
+ int decimals;
+ const char *unit;
+
+ if (entry->sec < offset || entry->sec > offset + length)
+ return;
+
+ put_format(b, "Dialogue: 0,");
+ put_video_time(b, entry->sec - offset);
+ put_video_time(b, (entry+1)->sec - offset < length ? (entry+1)->sec - offset : length);
+ put_format(b, "Default,,0,0,0,,");
+ put_format(b, "%d:%02d ", FRACTION(entry->sec, 60));
+ value = get_depth_units(entry->depth, &decimals, &unit);
+ put_format(b, "D=%02.2f %s ", value, unit);
+ if (entry->temperature) {
+ value = get_temp_units(entry->temperature, &unit);
+ put_format(b, "T=%.1f%s ", value, unit);
+ }
+ // Only show NDL if it is not essentially infinite, show TTS for mandatory stops.
+ if (entry->ndl_calc < 3600) {
+ if (entry->ndl_calc > 0)
+ put_format(b, "NDL=%d:%02d ", FRACTION(entry->ndl_calc, 60));
+ else
+ if (entry->tts_calc > 0)
+ put_format(b, "TTS=%d:%02d ", FRACTION(entry->tts_calc, 60));
+ }
+ if (entry->surface_gf > 0.0) {
+ put_format(b, "sGF=%.1f%% ", entry->surface_gf);
+ }
+ put_format(b, "\n");
+}
static void save_profiles_buffer(struct membuffer *b, bool select_only)
{
int i;
@@ -171,6 +214,27 @@ static void save_profiles_buffer(struct membuffer *b, bool select_only)
}
}
+void save_subtitles_buffer(struct membuffer *b, struct dive *dive, int offset, int length)
+{
+ struct plot_info pi;
+ struct deco_state *planner_deco_state = NULL;
+
+ pi = calculate_max_limits_new(dive, &dive->dc);
+ create_plot_info_new(dive, &dive->dc, &pi, false, planner_deco_state);
+
+ put_format(b, "[Script Info]\n");
+ put_format(b, "; Script generated by Subsurface %s\n", subsurface_canonical_version());
+ put_format(b, "ScriptType: v4.00+\nPlayResX: 384\nPlayResY: 288\n\n");
+ put_format(b, "[V4+ Styles]\nFormat: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\n");
+ put_format(b, "Style: Default,Arial,12,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,7,10,10,10,0\n\n");
+ put_format(b, "[Events]\nFormat: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n");
+
+ for (int i = 0; i < pi.nr; i++) {
+ put_st_event(b, &pi.entry[i], offset, length);
+ }
+ put_format(b, "\n");
+}
+
int save_profiledata(const char *filename, const bool select_only)
{
struct membuffer buf = { 0 };