Support pixel format 46 in make_black().
[dcpomatic.git] / src / lib / image.cc
index 25d1ef2760b0e9faa82ace72b81d006ae1926d6b..f340637dc7ebf2d515983fe6921de162045e9afa 100644 (file)
@@ -26,11 +26,11 @@ extern "C" {
 #include <libswscale/swscale.h>
 #include <libavutil/pixfmt.h>
 #include <libavutil/pixdesc.h>
-#include <libpostproc/postprocess.h>
 }
 #include "image.h"
 #include "exceptions.h"
 #include "scaler.h"
+#include "md5_digester.h"
 
 #include "i18n.h"
 
@@ -38,6 +38,7 @@ using std::string;
 using std::min;
 using std::cout;
 using std::cerr;
+using std::stringstream;
 using boost::shared_ptr;
 using libdcp::Size;
 
@@ -318,6 +319,7 @@ Image::make_black ()
        case PIX_FMT_RGBA:
        case PIX_FMT_ABGR:
        case PIX_FMT_BGRA:
+       case PIX_FMT_RGB555LE:
                memset (data()[0], 0, lines(0) * stride()[0]);
                break;
 
@@ -489,8 +491,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);
        }
 }
 
@@ -620,3 +627,15 @@ Image::aligned () const
        return _aligned;
 }
 
+string
+Image::digest () const
+{
+       MD5Digester digester;
+
+       for (int i = 0; i < components(); ++i) {
+               digester.add (data()[i], line_size()[i]);
+       }
+
+       return digester.get ();
+}
+