- float const colour_matrix[3][3] = {
- { 3.1338561, -1.6168667, -0.4906146 },
- { -0.9787684, 1.9161415, 0.0334540 },
- { 0.0719453, -0.2289914, 1.4052427 }
- };
-
- int const max_colour = pow (2, lut_out->bit_depth()) - 1;
-
- struct {
- double x, y, z;
- } s;
-
- struct {
- double r, g, b;
- } d;
-
- int* xyz_x = xyz_frame->comps[0].data;
- int* xyz_y = xyz_frame->comps[1].data;
- int* xyz_z = xyz_frame->comps[2].data;
-
- shared_ptr<ARGBFrame> argb_frame (new ARGBFrame (Size (xyz_frame->x1, xyz_frame->y1)));
-
- uint8_t* argb = argb_frame->data ();
-
- for (int y = 0; y < xyz_frame->y1; ++y) {
- uint8_t* argb_line = argb;
- for (int x = 0; x < xyz_frame->x1; ++x) {
-
- assert (*xyz_x >= 0 && *xyz_y >= 0 && *xyz_z >= 0 && *xyz_x < 4096 && *xyz_x < 4096 && *xyz_z < 4096);
-
- /* In gamma LUT */
- s.x = lut_in->lut()[*xyz_x++];
- s.y = lut_in->lut()[*xyz_y++];
- s.z = lut_in->lut()[*xyz_z++];
-
- /* DCI companding */
- s.x /= dci_coefficient;
- s.y /= dci_coefficient;
- s.z /= dci_coefficient;
-
- /* XYZ to RGB */
- d.r = ((s.x * colour_matrix[0][0]) + (s.y * colour_matrix[0][1]) + (s.z * colour_matrix[0][2]));
- d.g = ((s.x * colour_matrix[1][0]) + (s.y * colour_matrix[1][1]) + (s.z * colour_matrix[1][2]));
- d.b = ((s.x * colour_matrix[2][0]) + (s.y * colour_matrix[2][1]) + (s.z * colour_matrix[2][2]));
-
- d.r = min (d.r, 1.0);
- d.r = max (d.r, 0.0);
-
- d.g = min (d.g, 1.0);
- d.g = max (d.g, 0.0);
-
- d.b = min (d.b, 1.0);
- 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++ = 0xff;
+
+bool
+dcp::ids_equal (string a, string b)
+{
+ transform (a.begin(), a.end(), a.begin(), ::tolower);
+ transform (b.begin(), b.end(), b.begin(), ::tolower);
+ trim (a);
+ trim (b);
+ return a == b;
+}
+
+
+string
+dcp::file_to_string (boost::filesystem::path p, uintmax_t max_length)
+{
+ auto len = boost::filesystem::file_size (p);
+ if (len > max_length) {
+ throw MiscError (String::compose("Unexpectedly long file (%1)", p.string()));
+ }
+
+ auto f = fopen_boost (p, "r");
+ if (!f) {
+ throw FileError ("could not open file", p, errno);
+ }
+
+ char* c = new char[len];
+ /* This may read less than `len' if we are on Windows and we have CRLF in the file */
+ int const N = fread (c, 1, len, f);
+ fclose (f);
+
+ string s (c, N);
+ delete[] c;
+
+ return s;
+}
+
+
+string
+dcp::private_key_fingerprint (string key)
+{
+ boost::replace_all (key, "-----BEGIN RSA PRIVATE KEY-----\n", "");
+ boost::replace_all (key, "\n-----END RSA PRIVATE KEY-----\n", "");
+
+ unsigned char buffer[4096];
+ int const N = base64_decode (key, buffer, sizeof (buffer));
+
+ SHA_CTX sha;
+ SHA1_Init (&sha);
+ SHA1_Update (&sha, buffer, N);
+ uint8_t digest[20];
+ SHA1_Final (digest, &sha);
+
+ char digest_base64[64];
+ return Kumu::base64encode (digest, 20, digest_base64, 64);
+}
+
+
+xmlpp::Node *
+dcp::find_child (xmlpp::Node const * node, string name)
+{
+ auto c = node->get_children ();
+ auto i = c.begin();
+ while (i != c.end() && (*i)->get_name() != name) {
+ ++i;
+ }
+
+ DCP_ASSERT (i != c.end ());
+ return *i;
+}
+
+
+string
+dcp::remove_urn_uuid (string raw)
+{
+ DCP_ASSERT (raw.substr(0, 9) == "urn:uuid:");
+ return raw.substr (9);
+}
+
+
+string
+dcp::openjpeg_version ()
+{
+ return opj_version ();
+}
+
+
+string
+dcp::spaces (int n)
+{
+ string s = "";
+ for (int i = 0; i < n; ++i) {
+ s += " ";
+ }
+ return s;
+}
+
+
+void
+dcp::indent (xmlpp::Element* element, int initial)
+{
+ xmlpp::Node* last = nullptr;
+ for (auto n: element->get_children()) {
+ auto e = dynamic_cast<xmlpp::Element*>(n);
+ if (e) {
+ element->add_child_text_before (e, "\n" + spaces(initial + 2));
+ indent (e, initial + 2);
+ last = n;