- create_openjpeg_container ();
-
- struct {
- double r, g, b;
- } s;
-
- struct {
- double x, y, z;
- } d;
-
- /* Copy our RGB into the openjpeg container, converting to XYZ in the process */
-
- int jn = 0;
- for (int y = 0; y < _image->size().height; ++y) {
- uint8_t* p = _image->data()[0] + y * _image->stride()[0];
- for (int x = 0; x < _image->size().width; ++x) {
-
- /* In gamma LUT (converting 8-bit input to 12-bit) */
- s.r = lut_in[_colour_lut][*p++ << 4];
- s.g = lut_in[_colour_lut][*p++ << 4];
- s.b = lut_in[_colour_lut][*p++ << 4];
-
- /* RGB to XYZ Matrix */
- d.x = ((s.r * color_matrix[_colour_lut][0][0]) +
- (s.g * color_matrix[_colour_lut][0][1]) +
- (s.b * color_matrix[_colour_lut][0][2]));
-
- d.y = ((s.r * color_matrix[_colour_lut][1][0]) +
- (s.g * color_matrix[_colour_lut][1][1]) +
- (s.b * color_matrix[_colour_lut][1][2]));
-
- d.z = ((s.r * color_matrix[_colour_lut][2][0]) +
- (s.g * color_matrix[_colour_lut][2][1]) +
- (s.b * color_matrix[_colour_lut][2][2]));
-
- /* DCI companding */
- d.x = d.x * DCI_COEFFICENT * (DCI_LUT_SIZE - 1);
- d.y = d.y * DCI_COEFFICENT * (DCI_LUT_SIZE - 1);
- d.z = d.z * DCI_COEFFICENT * (DCI_LUT_SIZE - 1);
-
- /* Out gamma LUT */
- _opj_image->comps[0].data[jn] = lut_out[LO_DCI][(int) d.x];
- _opj_image->comps[1].data[jn] = lut_out[LO_DCI][(int) d.y];
- _opj_image->comps[2].data[jn] = lut_out[LO_DCI][(int) d.z];
-
- ++jn;
+ shared_ptr<dcp::GammaLUT> in_lut = dcp::GammaLUT::cache.get (
+ 12, _frame->colour_conversion().input_gamma, _frame->colour_conversion().input_gamma_linearised
+ );
+
+ /* XXX: libdcp should probably use boost */
+
+ double matrix[3][3];
+ for (int i = 0; i < 3; ++i) {
+ for (int j = 0; j < 3; ++j) {
+ matrix[i][j] = _frame->colour_conversion().matrix (i, j);
+ }
+ }
+
+ shared_ptr<dcp::XYZFrame> xyz = dcp::rgb_to_xyz (
+ _frame->image(),
+ in_lut,
+ dcp::GammaLUT::cache.get (16, 1 / _frame->colour_conversion().output_gamma, false),
+ matrix
+ );
+
+ {
+ MD5_CTX md5_context;
+ MD5_Init (&md5_context);
+ MD5_Update (&md5_context, xyz->data(0), 1998 * 1080 * 4);
+ MD5_Update (&md5_context, xyz->data(1), 1998 * 1080 * 4);
+ MD5_Update (&md5_context, xyz->data(2), 1998 * 1080 * 4);
+ 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]);