Missing install file.
[libdcp.git] / src / util.cc
index 7543f8ba288db35d3d553f0443cc461ab05e90a2..6bee0dc76d34ff62ad460719bf4b81811ae20c35 100644 (file)
@@ -26,6 +26,7 @@
 #include <iostream>
 #include <iomanip>
 #include <boost/filesystem.hpp>
+#include <boost/lexical_cast.hpp>
 #include <openssl/sha.h>
 #include "KM_util.h"
 #include "KM_fileio.h"
 #include "types.h"
 #include "argb_frame.h"
 #include "gamma_lut.h"
-#include "xyz_srgb_lut.h"
 
 using std::string;
 using std::stringstream;
 using std::min;
 using std::max;
 using boost::shared_ptr;
+using boost::lexical_cast;
 using namespace libdcp;
 
 /** Create a UUID.
@@ -188,7 +189,7 @@ libdcp::decompress_j2k (uint8_t* data, int64_t size, int reduce)
        if (!image) {
                opj_destroy_decompress (decoder);
                opj_cio_close (cio);
-               boost::throw_exception (DCPReadError ("could not decode JPEG2000 codestream"));
+               boost::throw_exception (DCPReadError ("could not decode JPEG2000 codestream of " + lexical_cast<string> (size) + " bytes."));
        }
 
        opj_cio_close (cio);
@@ -203,23 +204,18 @@ libdcp::decompress_j2k (uint8_t* data, int64_t size, int reduce)
  *  @return RGB image.
  */
 shared_ptr<ARGBFrame>
-libdcp::xyz_to_rgb (opj_image_t* xyz_frame, shared_ptr<const GammaLUT> lut_in, shared_ptr<const XYZsRGBLUT> lut_out)
+libdcp::xyz_to_rgb (opj_image_t* xyz_frame, shared_ptr<const GammaLUT> lut_in, shared_ptr<const GammaLUT> lut_out)
 {
        float const dci_coefficient = 48.0 / 52.37;
 
-        /* sRGB color matrix for XYZ -> RGB */
-#if 0  
-       float const colour_matrix[3][3] = {
-               { 3.240454836, -1.537138850, -0.498531547},
-               {-0.969266390,  1.876010929,  0.041556082},
-               { 0.055643420, -0.204025854,  1.057225162}
-       };
-#endif
+        /* sRGB color matrix for XYZ -> RGB.  This is the same as the one used by the Fraunhofer
+          EasyDCP player, I think.
+       */
 
        float const colour_matrix[3][3] = {
-               { 3.1338561, -1.6168667, -0.4906146 },
-               { -0.9787684, 1.9161415, 0.0334540 },
-               { 0.0719453, -0.2289914, 1.4052427 }
+               {  3.24096989631653,   -1.5373831987381,  -0.498610764741898 },
+               { -0.96924364566803,    1.87596750259399,  0.0415550582110882 },
+               {  0.0556300804018974, -0.203976958990097, 1.05697154998779 }
        };
 
        int const max_colour = pow (2, lut_out->bit_depth()) - 1;
@@ -271,9 +267,9 @@ libdcp::xyz_to_rgb (opj_image_t* xyz_frame, shared_ptr<const GammaLUT> lut_in, s
                        d.b = max (d.b, 0.0);
                        
                        /* Out gamma LUT */
-                       *argb_line++ = lut_out->lut()[(int) (d.b * max_colour)];
-                       *argb_line++ = lut_out->lut()[(int) (d.g * max_colour)];
-                       *argb_line++ = lut_out->lut()[(int) (d.r * max_colour)];
+                       *argb_line++ = lut_out->lut()[(int) (d.b * max_colour)] * 0xff;
+                       *argb_line++ = lut_out->lut()[(int) (d.g * max_colour)] * 0xff;
+                       *argb_line++ = lut_out->lut()[(int) (d.r * max_colour)] * 0xff;
                        *argb_line++ = 0xff;
                }