/** * cd_util_get_coverage: * @profile: A valid #CdUtil * @filename_in: A filename to proof against * @error: A #GError, or %NULL * * Gets the gamut coverage of two profiles * * Return value: A positive value for success, or -1.0 for error. **/ static gdouble cd_util_get_coverage (cmsHPROFILE profile_proof, const gchar *filename_in, GError **error) { gdouble coverage = -1.0; gboolean ret; GFile *file = NULL; CdIcc *icc = NULL; CdIcc *icc_ref; /* load proofing profile */ icc_ref = cd_icc_new (); ret = cd_icc_load_handle (icc_ref, profile_proof, CD_ICC_LOAD_FLAGS_NONE, error); if (!ret) goto out; /* load target profile */ icc = cd_icc_new (); file = g_file_new_for_path (filename_in); ret = cd_icc_load_file (icc, file, CD_ICC_LOAD_FLAGS_NONE, NULL, error); if (!ret) goto out; /* get coverage */ ret = cd_icc_utils_get_coverage (icc, icc_ref, &coverage, error); if (!ret) return FALSE; out: if (file != NULL) g_object_unref (file); if (icc != NULL) g_object_unref (icc); g_object_unref (icc_ref); return ret; }
/** * cd_util_create_from_xml: **/ static gboolean cd_util_create_from_xml (CdUtilPrivate *priv, const gchar *filename, GError **error) { const GNode *profile; const GNode *tmp; gboolean ret = TRUE; GHashTable *hash; gssize data_len = -1; g_autofree gchar *data = NULL; g_autoptr(CdDom) dom = NULL; /* parse the XML into DOM */ if (!g_file_get_contents (filename, &data, (gsize *) &data_len, error)) return FALSE; dom = cd_dom_new (); if (!cd_dom_parse_xml_data (dom, data, data_len, error)) return FALSE; /* get root */ profile = cd_dom_get_node (dom, NULL, "profile"); if (profile == NULL) { g_set_error_literal (error, 1, 0, "invalid XML, expected profile"); return FALSE; } /* get type */ if (cd_dom_get_node (dom, profile, "primaries") != NULL) { if (!cd_util_create_standard_space (priv, dom, profile, error)) return FALSE; } else if (cd_dom_get_node (dom, profile, "temperature") != NULL) { if (!cd_util_create_temperature (priv, dom, profile, error)) return FALSE; } else if (cd_dom_get_node (dom, profile, "x11_gamma") != NULL) { if (!cd_util_create_x11_gamma (priv, dom, profile, error)) return FALSE; } else if (cd_dom_get_node (dom, profile, "named") != NULL) { if (!cd_util_create_named_color (priv, dom, profile, error)) return FALSE; } else if (cd_dom_get_node (dom, profile, "data_ti3") != NULL) { if (!cd_util_create_colprof (priv, dom, profile, error)) return FALSE; } else { g_set_error_literal (error, 1, 0, "invalid XML, unknown type"); return FALSE; } /* convert into a CdIcc object */ ret = cd_icc_load_handle (priv->icc, priv->lcms_profile, CD_ICC_LOAD_FLAGS_NONE, error); if (!ret) return FALSE; /* also write metadata */ tmp = cd_dom_get_node (dom, profile, "license"); if (tmp != NULL) { cd_icc_add_metadata (priv->icc, CD_PROFILE_METADATA_LICENSE, cd_dom_get_node_data (tmp)); } tmp = cd_dom_get_node (dom, profile, "standard_space"); if (tmp != NULL) { cd_icc_add_metadata (priv->icc, CD_PROFILE_METADATA_STANDARD_SPACE, cd_dom_get_node_data (tmp)); if (!cd_util_icc_set_metadata_coverage (priv->icc, error)) return FALSE; } tmp = cd_dom_get_node (dom, profile, "data_source"); if (tmp != NULL) { cd_icc_add_metadata (priv->icc, CD_PROFILE_METADATA_DATA_SOURCE, cd_dom_get_node_data (tmp)); } /* add CMS defines */ cd_icc_add_metadata (priv->icc, CD_PROFILE_METADATA_CMF_PRODUCT, PACKAGE_NAME); cd_icc_add_metadata (priv->icc, CD_PROFILE_METADATA_CMF_BINARY, "cd-create-profile"); cd_icc_add_metadata (priv->icc, CD_PROFILE_METADATA_CMF_VERSION, PACKAGE_VERSION); /* optional localized keys */ hash = cd_dom_get_node_localized (profile, "description"); if (hash != NULL) cd_icc_set_description_items (priv->icc, hash); hash = cd_dom_get_node_localized (profile, "copyright"); if (hash != NULL) cd_icc_set_copyright_items (priv->icc, hash); hash = cd_dom_get_node_localized (profile, "model"); if (hash != NULL) cd_icc_set_model_items (priv->icc, hash); hash = cd_dom_get_node_localized (profile, "manufacturer"); if (hash != NULL) cd_icc_set_manufacturer_items (priv->icc, hash); return TRUE; }