Merge branch 'master' into 12bit
[dcpomatic.git] / src / lib / image.cc
index 1fa55e24209ed099ba43bf03cda8693c13e57067..3b8c1a28ef48aa1d9b96638b708fb8a19a8f944b 100644 (file)
@@ -22,7 +22,6 @@
  */
 
 #include <iostream>
-#include <openssl/md5.h>
 extern "C" {
 #include <libswscale/swscale.h>
 #include <libavutil/pixfmt.h>
@@ -31,6 +30,7 @@ extern "C" {
 #include "image.h"
 #include "exceptions.h"
 #include "scaler.h"
+#include "md5_digester.h"
 
 #include "i18n.h"
 
@@ -38,7 +38,6 @@ using std::string;
 using std::min;
 using std::cout;
 using std::cerr;
-using std::stringstream;
 using boost::shared_ptr;
 using libdcp::Size;
 
@@ -319,6 +318,9 @@ Image::make_black ()
        case PIX_FMT_RGBA:
        case PIX_FMT_ABGR:
        case PIX_FMT_BGRA:
+       case PIX_FMT_RGB555LE:
+       case PIX_FMT_RGB48LE:
+       case PIX_FMT_RGB48BE:
                memset (data()[0], 0, lines(0) * stride()[0]);
                break;
 
@@ -490,8 +492,13 @@ Image::allocate ()
                   OS X crashes on this illegal read, though other operating systems don't
                   seem to mind.  The nasty + 1 in this malloc makes sure there is always a byte
                   for that instruction to read safely.
+
+                  Further to the above, valgrind is now telling me that ff_rgb24ToY_ssse3
+                  over-reads by more then _avx.  I can't follow the code to work out how much,
+                  so I'll just over-allocate by 32 bytes and have done with it.  Empirical
+                  testing suggests that it works.
                */
-               _data[i] = (uint8_t *) wrapped_av_malloc (_stride[i] * lines (i) + 1);
+               _data[i] = (uint8_t *) wrapped_av_malloc (_stride[i] * lines (i) + 32);
        }
 }
 
@@ -624,21 +631,12 @@ Image::aligned () const
 string
 Image::digest () const
 {
-       MD5_CTX md5_context;
-       MD5_Init (&md5_context);
+       MD5Digester digester;
 
        for (int i = 0; i < components(); ++i) {
-               MD5_Update (&md5_context, data()[i], line_size()[i]);
-       }
-       
-       unsigned char digest[MD5_DIGEST_LENGTH];
-       MD5_Final (digest, &md5_context);
-       
-       stringstream s;
-       for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
-               s << std::hex << std::setfill('0') << std::setw(2) << ((int) digest[i]);
+               digester.add (data()[i], line_size()[i]);
        }
 
-       return s.str ();
+       return digester.get ();
 }