+RGBTriplet get_neutral_color(AVDictionary *metadata)
+{
+ if (metadata == nullptr) {
+ return RGBTriplet(1.0f, 1.0f, 1.0f);
+ }
+ AVDictionaryEntry *entry = av_dict_get(metadata, "WhitePoint", nullptr, 0);
+ if (entry == nullptr) {
+ return RGBTriplet(1.0f, 1.0f, 1.0f);
+ }
+
+ unsigned x_nom, x_den, y_nom, y_den;
+ if (sscanf(entry->value, " %u:%u , %u:%u", &x_nom, &x_den, &y_nom, &y_den) != 4) {
+ fprintf(stderr, "WARNING: Unable to parse white point '%s', using default white point\n", entry->value);
+ return RGBTriplet(1.0f, 1.0f, 1.0f);
+ }
+
+ double x = double(x_nom) / x_den;
+ double y = double(y_nom) / y_den;
+ double z = 1.0 - x - y;
+
+ Matrix3d rgb_to_xyz_matrix = movit::ColorspaceConversionEffect::get_xyz_matrix(COLORSPACE_sRGB);
+ Vector3d rgb = rgb_to_xyz_matrix.inverse() * Vector3d(x, y, z);
+
+ return RGBTriplet(rgb[0], rgb[1], rgb[2]);
+}
+