From aeb1c726b983a00cbb4a6a61d3b35de1f9dff8a8 Mon Sep 17 00:00:00 2001 From: Jacob Boerema Date: Thu, 4 Jan 2024 15:24:30 -0500 Subject: [PATCH] libgimpbase: fix #10557 missing XMP namespace "Item" With the sample image that contains the XMP namespace Item with the correct url included, it is not returning the url when we ask for it. This seems to be an exiv2 issue, but needs more research. What GIMP doesn't do, is report that the namespace url we were looking for wasn't found, and make sure that this doesn't block us from handling all XMP tags. To improve this on our end, we check if there was an error getting the url, and if yes: - We generate a warning message - We create a dummy namespace url, with a special check for the missing Item namespace to give it the correct known namespace url. --- libgimpbase/gimpmetadata.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/libgimpbase/gimpmetadata.c b/libgimpbase/gimpmetadata.c index e9aa59e9e5..d2704ef972 100644 --- a/libgimpbase/gimpmetadata.c +++ b/libgimpbase/gimpmetadata.c @@ -915,9 +915,37 @@ gimp_metadata_add_namespace (GHashTable *namespaces, { if (! g_hash_table_lookup (namespaces, prefix)) { - gchar *namespace_url; + gchar *namespace_url; + GError *error = NULL; - namespace_url = gexiv2_metadata_try_get_xmp_namespace_for_tag (prefix, NULL); + namespace_url = gexiv2_metadata_try_get_xmp_namespace_for_tag (prefix, &error); + + if (! namespace_url) + { + /* Weird, we didn't find the namespace url. + Let's add a dummy url, that way we can keep the tags. */ + if (error) + { + g_warning ("XMP namespace url not found! %s", error->message); + g_clear_error (&error); + } + + /* Fix the one namespace url we know of, and add a generic fix for + any others. */ + if (g_strcmp0 (prefix, "Item") == 0) + /* FIXME Remove this specific check for Item after this is fixed + in our dependencies (exiv2?), see issue #10557. */ + namespace_url = g_strdup ("http://ns.google.com/photos/1.0/container/item/"); + else + namespace_url = g_strdup_printf ("http://missing-url.org/%s/", prefix); + + if (! gexiv2_metadata_try_register_xmp_namespace (namespace_url, + prefix, &error)) + { + g_warning ("Registering XMP namespace failed! %s\n", error->message); + g_clear_error (&error); + } + } if (namespace_url) {