Recognise JP2 files.
[dcpomatic.git] / src / lib / util.cc
index 1c99682063ff76d19279d0f8c73e0a6c5d7aa7cc..7d2ae2216735081b2be7f7807a2af5dfa4496e74 100644 (file)
@@ -37,6 +37,9 @@
 #include "safe_stringstream.h"
 #include <dcp/util.h>
 #include <dcp/signer.h>
+#include <dcp/picture_asset.h>
+#include <dcp/sound_asset.h>
+#include <dcp/subtitle_asset.h>
 #include <glib.h>
 #include <pangomm/init.h>
 #include <boost/algorithm/string.hpp>
@@ -322,6 +325,7 @@ dcpomatic_setup ()
        dcp::init ();
        
        Ratio::setup_ratios ();
+       PresetColourConversion::setup_colour_conversion_presets ();
        VideoContentScale::setup_scales ();
        DCPContentType::setup_dcp_content_types ();
        Filter::setup_filters ();
@@ -381,7 +385,7 @@ dcpomatic_setup_gettext_i18n (string lang)
 #endif 
 
 #ifdef DCPOMATIC_LINUX
-       bindtextdomain ("libdcpomatic", POSIX_LOCALE_PREFIX);
+       bindtextdomain ("libdcpomatic", LINUX_LOCALE_PREFIX);
 #endif
 }
 
@@ -509,12 +513,16 @@ audio_channel_name (int c)
 bool
 valid_image_file (boost::filesystem::path f)
 {
+       if (boost::starts_with (f.leaf().string(), "._")) {
+               return false;
+       }
+               
        string ext = f.extension().string();
        transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
        return (
                ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" ||
                ext == ".png" || ext == ".bmp" || ext == ".tga" || ext == ".dpx" ||
-               ext == ".j2c" || ext == ".j2k"
+               ext == ".j2c" || ext == ".j2k" || ext == ".jp2"
                );
 }
 
@@ -523,7 +531,7 @@ valid_j2k_file (boost::filesystem::path f)
 {
        string ext = f.extension().string();
        transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
-       return (ext == ".j2k" || ext == ".j2c");
+       return (ext == ".j2k" || ext == ".j2c" || ext == ".jp2");
 }
 
 string
@@ -542,13 +550,13 @@ tidy_for_filename (string f)
 }
 
 dcp::Size
-fit_ratio_within (float ratio, dcp::Size full_frame, int round)
+fit_ratio_within (float ratio, dcp::Size full_frame)
 {
        if (ratio < full_frame.ratio ()) {
-               return dcp::Size (round_to (full_frame.height * ratio, round), full_frame.height);
+               return dcp::Size (rint (full_frame.height * ratio), full_frame.height);
        }
        
-       return dcp::Size (full_frame.width, round_to (full_frame.width / ratio, round));
+       return dcp::Size (full_frame.width, rint (full_frame.width / ratio));
 }
 
 void *
@@ -560,18 +568,21 @@ wrapped_av_malloc (size_t s)
        }
        return p;
 }
-               
-ContentTimePeriod
+
+FFmpegSubtitlePeriod
 subtitle_period (AVSubtitle const & sub)
 {
        ContentTime const packet_time = ContentTime::from_seconds (static_cast<double> (sub.pts) / AV_TIME_BASE);
 
-       ContentTimePeriod period (
+       if (sub.end_display_time == static_cast<uint32_t> (-1)) {
+               /* End time is not known */
+               return FFmpegSubtitlePeriod (packet_time + ContentTime::from_seconds (sub.start_display_time / 1e3));
+       }
+       
+       return FFmpegSubtitlePeriod (
                packet_time + ContentTime::from_seconds (sub.start_display_time / 1e3),
                packet_time + ContentTime::from_seconds (sub.end_display_time / 1e3)
                );
-
-       return period;
 }
 
 map<string, string>
@@ -663,3 +674,15 @@ write_frame_info (FILE* file, int frame, Eyes eyes, dcp::FrameInfo info)
        fwrite (&info.size, sizeof (info.size), 1, file);
        fwrite (info.hash.c_str(), 1, info.hash.size(), file);
 }
+
+string
+video_asset_filename (shared_ptr<dcp::PictureAsset> asset)
+{
+       return "j2c_" + asset->id() + ".mxf";
+}
+
+string
+audio_asset_filename (shared_ptr<dcp::SoundAsset> asset)
+{
+       return "pcm_" + asset->id() + ".mxf";
+}