babl: make babl_format_with_space not crash with palette based formats
authorØyvind Kolås <pippin@gimp.org>
Thu, 6 Dec 2018 18:19:40 +0000 (19:19 +0100)
committerØyvind Kolås <pippin@gimp.org>
Thu, 6 Dec 2018 18:19:40 +0000 (19:19 +0100)
Now, both palettes referred to by their string name and palettes passed
directly in with a cast get passed through without modification, for
correct behavior their palette entries should also be re-created

(the only way to read out the palette is currently to do an exhaustive buffer
conversion.)

babl/babl-format.c

index e5324176df3611a18d05700a534670953387438e..019744ad32ffea7dce2a677259c884709a0488e8 100644 (file)
@@ -727,13 +727,6 @@ babl_format_with_space (const char *encoding, const Babl *space)
 
   if (BABL_IS_BABL (example_format))
   {
-    if (babl_format_is_palette (example_format))
-    {
-      /* XXX we should allocate a new palette name, and 
-             duplicate the path data, converted for new space
-       */
-      return example_format;
-    }
     encoding = babl_get_name (example_format);
     if (babl_format_get_space (example_format) != babl_space ("sRGB"))
     {
@@ -756,10 +749,20 @@ babl_format_with_space (const char *encoding, const Babl *space)
   {
     return NULL;
   }
+  example_format = babl_format (encoding);
+
   if (space == babl_space("sRGB"))
-    return babl_format (encoding);
+    return example_format;
+
+  if (babl_format_is_palette (example_format))
+  {
+    /* XXX we should allocate a new palette name, and 
+           duplicate the path data, converted for new space
+     */
+    return example_format;
+  }
 
-  return format_new_from_format_with_space (babl_format (encoding), space);
+  return format_new_from_format_with_space (example_format, space);
 }
 
 int