[babl] bin: profile-aware babl format defaults.



commit 035c7b7661c90e264bbf06ecc9f25fc1e0d3c03c
Author: Jehan <jehan girinstud io>
Date:   Wed Aug 17 15:53:25 2022 +0200

    bin: profile-aware babl format defaults.
    
    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 | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/bin/babl.c b/bin/babl.c
index 75df2d6b9..964a3570c 100644
--- a/bin/babl.c
+++ b/bin/babl.c
@@ -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));


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