Make PlayerText comparable.
authorCarl Hetherington <cth@carlh.net>
Thu, 19 Dec 2019 15:31:42 +0000 (16:31 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 12 Jan 2020 21:47:45 +0000 (22:47 +0100)
src/lib/bitmap_text.cc [new file with mode: 0644]
src/lib/bitmap_text.h
src/lib/player_text.cc
src/lib/rect.h
src/lib/string_text.cc [new file with mode: 0644]
src/lib/string_text.h
src/lib/util.h
src/lib/wscript

diff --git a/src/lib/bitmap_text.cc b/src/lib/bitmap_text.cc
new file mode 100644 (file)
index 0000000..6e690b3
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+    Copyright (C) 2014-2019 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic 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.
+
+    DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "bitmap_text.h"
+#include "image.h"
+
+bool
+operator== (BitmapText const & a, BitmapText const & b)
+{
+       if (!a.rectangle.equal(b.rectangle, 0.000001)) {
+               return false;
+       }
+
+       return *a.image == *b.image;
+}
+
+bool
+operator!= (BitmapText const & a, BitmapText const & b)
+{
+       return !(a == b);
+}
+
+
index 2314c2db0cec2ad1a521c24fcc008bd640e20cca..e9d7c3b796211a367d5ac9bb1ade3890c48f5025 100644 (file)
@@ -45,4 +45,7 @@ public:
        dcpomatic::Rect<double> rectangle;
 };
 
+extern bool operator== (BitmapText const & a, BitmapText const & b);
+extern bool operator!= (BitmapText const & a, BitmapText const & b);
+
 #endif
index d31c7d02467b0507e83fc93e1485a5abcda4fa61..429f85ddf7a87a4ef1b7f66959e9942a741b8195 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -20,6 +20,7 @@
 
 #include "player_text.h"
 #include "font.h"
+#include "util.h"
 #include <boost/foreach.hpp>
 
 using std::list;
@@ -41,3 +42,9 @@ PlayerText::add_fonts (list<shared_ptr<Font> > fonts_)
                }
        }
 }
+
+bool
+operator== (PlayerText const & a, PlayerText const & b)
+{
+       return deep_equals(a.fonts, b.fonts) && deep_equals(a.bitmap, b.bitmap) && deep_equals(a.string, b.string);
+}
index 4851ad007fe11c6ce7b7469c2cb6f7367dd2eccd..4e4020073057980fd94b49821221b58f6037d867 100644 (file)
@@ -112,6 +112,14 @@ public:
        {
                return (p.x >= x && p.x <= (x + width) && p.y >= y && p.y <= (y + height));
        }
+
+       bool equal (Rect<T> const & other, T threshold) const
+       {
+               return std::abs(x - other.x) < threshold &&
+                       std::abs(y - other.y) < threshold &&
+                       std::abs(width - other.width) < threshold &&
+                       std::abs(height - other.height) < threshold;
+       }
 };
 
 }
diff --git a/src/lib/string_text.cc b/src/lib/string_text.cc
new file mode 100644 (file)
index 0000000..54ff325
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+    Copyright (C) 2016-2019 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic 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.
+
+    DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "string_text.h"
+
+bool
+operator== (StringText const & a, StringText const & b)
+{
+       return static_cast<dcp::SubtitleString const &>(a) == static_cast<dcp::SubtitleString const &>(b) && a.outline_width == b.outline_width;
+}
+
index 4f4958163c4f2773fae426ce02b9c73208fd366f..4063a688d96669ead8628b88f0a6d459c0c3fc4f 100644 (file)
@@ -38,4 +38,6 @@ public:
        int outline_width;
 };
 
+extern bool operator== (StringText const & a, StringText const & b);
+
 #endif
index c8dcb29d6913c49ccef30bf92ee9393514824b91..36f8cec9ef58dbbcb06e96c2d651f2c302e9fbb0 100644 (file)
@@ -128,4 +128,49 @@ vector_to_list (std::vector<T> v)
        return l;
 }
 
+template <class T>
+bool
+deep_equals (std::list<boost::shared_ptr<T> > a, std::list<boost::shared_ptr<T> > b)
+{
+       if (a.size() != b.size()) {
+               return false;
+       }
+
+       typename std::list<boost::shared_ptr<T> >::const_iterator i = a.begin();
+       typename std::list<boost::shared_ptr<T> >::const_iterator j = b.begin();
+
+       while (i != a.end()) {
+               if (**i != **j) {
+                       return false;
+               }
+               ++i;
+               ++j;
+       }
+
+       return true;
+}
+
+template <class T>
+bool
+deep_equals (std::list<T> a, std::list<T> b)
+{
+       if (a.size() != b.size()) {
+               return false;
+       }
+
+       typename std::list<T>::const_iterator i = a.begin();
+       typename std::list<T>::const_iterator j = b.begin();
+
+       while (i != a.end()) {
+               if (*i != *j) {
+                       return false;
+               }
+               ++i;
+               ++j;
+       }
+
+       return true;
+}
+
 #endif
+
index b78586843aef7d4f7f1f35a101e112631c1acc70..94102430e110b16618e293d48d10444e5f415687 100644 (file)
@@ -39,6 +39,7 @@ sources = """
           audio_processor.cc
           audio_ring_buffers.cc
           audio_stream.cc
+          bitmap_text.cc
           butler.cc
           text_content.cc
           text_decoder.cc
@@ -149,6 +150,7 @@ sources = """
           server.cc
           shuffler.cc
           state.cc
+          string_text.cc
           spl.cc
           spl_entry.cc
           string_log_entry.cc