[babl/wip/Jehan/gimp-bug-6501: 1/2] babl: do not append space to the format name when explicitly set.




commit b996a1bbe678b0ec78423c479e213a49d1cbbdf6
Author: Jehan <jehan girinstud io>
Date:   Wed Mar 3 10:54:38 2021 +0100

    babl: do not append space to the format name when explicitly set.
    
    When a format is named explicitly by the caller, we should just keep the
    same name, not tweak it. Generating a name is only valid when no
    explicit name is given. Moreover this is the behavior as described in
    the docs of babl_format_new():
    
    > If no name is provided a (long) descriptive name is used.
    
    (which usually implies that with a name provided, this one will be used
    instead of a generated name)
    
    This is especially important for palette formats for which name is
    mostly not descriptive anyway (either caller-set or generated by babl
    with incremental number) and this fixes a bug when calling
    babl_new_palette_with_space() with the same name and space would fail to
    find the already created formats (yet would find the models and return
    NULL for both formats) because it would search without the space
    description appended. Yet the docs of babl_new_palette*() clearly says
    as well:
    
    > If you pass in the same name the previous formats will be provided
    > again.
    
    Moreover we actually already tweak a bit the palette format name by
    appending the space pointer. No need to tweak it twice appending the
    same information (space) in a different way.
    
    See also: https://gitlab.gnome.org/GNOME/gimp/-/issues/6501

 babl/babl-format.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/babl/babl-format.c b/babl/babl-format.c
index 2e4e3d718..c9a117560 100644
--- a/babl/babl-format.c
+++ b/babl/babl-format.c
@@ -468,16 +468,18 @@ babl_format_new (const void *first_arg,
   va_end (varg);
 
   if (!name)
-    name = create_name (model, components, component, type);
+    {
+      name = create_name (model, components, component, type);
 
-  if (space != babl_space ("sRGB"))
-  {
-    char *new_name = babl_malloc (strlen (name) +
-                                  strlen (babl_get_name ((Babl*)space)) + 1);
-    sprintf (new_name, "%s-%s", name, babl_get_name ((Babl*)space));
-    babl_free (name);
-    name = new_name;
-  }
+      if (space != babl_space ("sRGB"))
+        {
+          char *new_name = babl_malloc (strlen (name) +
+                                        strlen (babl_get_name ((Babl*)space)) + 1);
+          sprintf (new_name, "%s-%s", name, babl_get_name ((Babl*)space));
+          babl_free (name);
+          name = new_name;
+        }
+    }
 
   if (!model)
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]