bin: profile-aware babl format defaults.
authorJehan <jehan@girinstud.io>
Wed, 17 Aug 2022 13:53:25 +0000 (15:53 +0200)
committerJehan <jehan@girinstud.io>
Wed, 17 Aug 2022 13:53:25 +0000 (15:53 +0200)
Instead of always defaulting to "R'G'B' float", if a input/output
profile was set, check if it's CMYK, grayscale or RGB.

The defaults are:
* For a CMYK profile: "CMYK float"
* For a grayscale profile: "Y' float"
* For anything else (or no profile): "R'G'B' float"

bin/babl.c

index 75df2d6b94fc58472e25170568d7e2909f57aafa..964a3570cd4bf12b804e039502270337d400f319 100644 (file)
@@ -39,8 +39,8 @@ main (int    argc,
   const Babl    *to_format;
   const Babl    *to_space         = NULL;
   const Babl    *fish;
-  const char    *from             = "R'G'B' float";
-  const char    *to               = "R'G'B' float";
+  const char    *from             = NULL;
+  const char    *to               = NULL;
   const char    *from_profile     = NULL;
   const char    *to_profile       = NULL;
   BablIccIntent  intent           = BABL_ICC_INTENT_RELATIVE_COLORIMETRIC;
@@ -185,6 +185,25 @@ main (int    argc,
         return 6;
     }
 
+  if (from == NULL)
+    {
+      if (babl_space_is_cmyk (from_space))
+        from = "CMYK float";
+      else if (babl_space_is_gray (from_space))
+        from = "Y' float";
+      else
+        from = "R'G'B' float";
+    }
+  if (to == NULL)
+    {
+      if (babl_space_is_cmyk (to_space))
+        to = "CMYK float";
+      else if (babl_space_is_gray (to_space))
+        to = "Y' float";
+      else
+        to = "R'G'B' float";
+    }
+
   from_format  = babl_format_with_space (from, from_space);
   n_components = babl_format_get_n_components (from_format);
   source       = malloc (babl_format_get_bytes_per_pixel (from_format));