Add colour conversion identifier to video identifier.
authorCarl Hetherington <cth@carlh.net>
Sun, 18 Aug 2013 21:11:59 +0000 (22:11 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 18 Aug 2013 21:11:59 +0000 (22:11 +0100)
src/lib/colour_conversion.cc
src/lib/colour_conversion.h
src/lib/video_content.cc
test/colour_conversion_test.cc [new file with mode: 0644]
test/wscript

index cc25ccc67fce6bba6f71fcc0f944c1ab8d2082ad..5f8064dab817c13017d0adb8959f7e0b7c391249 100644 (file)
@@ -23,6 +23,7 @@
 #include <libcxml/cxml.h>
 #include "config.h"
 #include "colour_conversion.h"
+#include "util.h"
 
 #include "i18n.h"
 
@@ -116,6 +117,26 @@ ColourConversion::preset () const
        return i;
 }
 
+string
+ColourConversion::identifier () const
+{
+       double numbers[12];
+
+       int n = 0;
+       numbers[n++] = input_gamma;
+       numbers[n++] = input_gamma_linearised;
+       for (int i = 0; i < 3; ++i) {
+               for (int j = 0; j < 3; ++j) {
+                       numbers[n++] = matrix (i, j);
+               }
+       }
+       numbers[n++] = output_gamma;
+
+       assert (n == 12);
+
+       return md5_digest (numbers, 12 * sizeof (double));
+}
+
 PresetColourConversion::PresetColourConversion ()
        : name (_("Untitled"))
 {
index f6b5bc9f34f74f8022ffcfe7a67ff53e952a1e31..893148466bfcc715b04badc8fa9e109f57852012 100644 (file)
@@ -45,6 +45,7 @@ public:
        ColourConversion (boost::shared_ptr<cxml::Node>);
 
        virtual void as_xml (xmlpp::Node *) const;
+       std::string identifier () const;
 
        boost::optional<size_t> preset () const;
 
index 8b0ec4c997827619738cc56f62218c4797fa2219..3f6e171a549d2f6feefaca6deb3e3c5556805b66 100644 (file)
@@ -225,7 +225,8 @@ VideoContent::identifier () const
          << "_" << crop().left
          << "_" << crop().right
          << "_" << crop().top
-         << "_" << crop().bottom;
+         << "_" << crop().bottom
+         << "_" << colour_conversion().identifier ();
 
        if (ratio()) {
                s << "_" << ratio()->id ();
diff --git a/test/colour_conversion_test.cc b/test/colour_conversion_test.cc
new file mode 100644 (file)
index 0000000..3e90d54
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <boost/test/unit_test.hpp>
+#include <libdcp/colour_matrix.h>
+#include "lib/colour_conversion.h"
+
+using std::cout;
+
+/* Basic test of identifier() for ColourConversion (i.e. a hash of the numbers) */
+BOOST_AUTO_TEST_CASE (colour_conversion_test)
+{
+       ColourConversion A (2.4, true, libdcp::colour_matrix::srgb_to_xyz, 2.6);
+       ColourConversion B (2.4, false, libdcp::colour_matrix::srgb_to_xyz, 2.6);
+
+       BOOST_CHECK_EQUAL (A.identifier(), "246ff9b7dc32c0488948a32a713924b3");
+       BOOST_CHECK_EQUAL (B.identifier(), "a8d1da30f96a121d8db06a03409758b3");
+}
index 8cc50a683e33b2a76aa4ce702ea246aadc82dd27..7c7aee733bd51488f791a57887ea25fa7dcf3260 100644 (file)
@@ -16,6 +16,7 @@ def build(bld):
     obj.use    = 'libdcpomatic'
     obj.source = """
                  test.cc
+                 colour_conversion_test.cc
                  audio_delay_test.cc
                  silence_padding_test.cc
                  audio_merger_test.cc
@@ -40,5 +41,6 @@ def build(bld):
                  image_test.cc
                  4k_test.cc
                  """
+
     obj.target = 'unit-tests'
     obj.install_path = ''