Use better J2KImageProxy::same() method.
authorCarl Hetherington <cth@carlh.net>
Thu, 11 Jun 2015 15:31:20 +0000 (16:31 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 11 Jun 2015 15:31:20 +0000 (16:31 +0100)
src/lib/image_proxy.cc
src/lib/image_proxy.h
src/lib/j2k_image_proxy.cc
src/lib/j2k_image_proxy.h

index 0b079725d79eca4db822f2ead1d29f829e76c094..c803e6bd06601e8cf7ab6b808a86acc3c27b88d2 100644 (file)
@@ -46,9 +46,3 @@ image_proxy_factory (shared_ptr<cxml::Node> xml, shared_ptr<Socket> socket)
 
        throw NetworkError (_("Unexpected image type received by server"));
 }
-
-bool
-ImageProxy::same (shared_ptr<const ImageProxy> other) const
-{
-       return image()->digest() == other->image()->digest();
-}
index 9367bc0a7ad4ec3309b8347c6f85ae17d5cb021c..1f19a4160b312ce436994ba8aec6ecb53273c02d 100644 (file)
@@ -64,7 +64,7 @@ public:
        virtual void add_metadata (xmlpp::Node *) const = 0;
        virtual void send_binary (boost::shared_ptr<Socket>) const = 0;
        /** @return true if our image is definitely the same as another, false if it is probably not */
-       virtual bool same (boost::shared_ptr<const ImageProxy>) const;
+       virtual bool same (boost::shared_ptr<const ImageProxy>) const = 0;
 };
 
 boost::shared_ptr<ImageProxy> image_proxy_factory (boost::shared_ptr<cxml::Node> xml, boost::shared_ptr<Socket> socket);
index 7dca3d8a9faca7324e49a5bbc32a3c4b2008d6b1..ce0b88265ee8259e44b3cc3b93879c08b638d01a 100644 (file)
@@ -35,6 +35,7 @@ using std::string;
 using std::cout;
 using boost::shared_ptr;
 using boost::optional;
+using boost::dynamic_pointer_cast;
 
 /** Construct a J2KImageProxy from a JPEG2000 file */
 J2KImageProxy::J2KImageProxy (boost::filesystem::path path, dcp::Size size)
@@ -132,3 +133,18 @@ J2KImageProxy::send_binary (shared_ptr<Socket> socket) const
 {
        socket->write (_data.data().get(), _data.size());
 }
+
+bool
+J2KImageProxy::same (shared_ptr<const ImageProxy> other) const
+{
+       shared_ptr<const J2KImageProxy> jp = dynamic_pointer_cast<const J2KImageProxy> (other);
+       if (!jp) {
+               return false;
+       }
+
+       if (_data.size() != jp->_data.size()) {
+               return false;
+       }
+
+       return memcmp (_data.data().get(), jp->_data.data().get(), _data.size()) == 0;
+}
index 34b1490b3858fb0a2eee07f693d8573a25ced4e6..fa2df8cd8788d370858393d5423dd0bcb4ecc8fb 100644 (file)
@@ -34,6 +34,8 @@ public:
        boost::shared_ptr<Image> image (boost::optional<dcp::NoteHandler> note = boost::optional<dcp::NoteHandler> ()) const;
        void add_metadata (xmlpp::Node *) const;
        void send_binary (boost::shared_ptr<Socket>) const;
+       /** @return true if our image is definitely the same as another, false if it is probably not */
+       virtual bool same (boost::shared_ptr<const ImageProxy>) const;
 
        Data j2k () const {
                return _data;