[babl/wip/pippin/inverted-cmyk: 6/9] cmyk: register model conversions to/from cmykA



commit b8c1cd223bbce4f37b56c01f605b85ff09afbe14
Author: Øyvind Kolås <pippin gimp org>
Date:   Mon Nov 5 21:41:56 2018 +0100

    cmyk: register model conversions to/from cmykA
    
    This can make the CMYK related spaces able to convert among themselves similar
    to the RGB spaces. Grayscale doesnt need this and fully share such conversions
    with the RGB spaces.

 extensions/CMYK.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 126 insertions(+)
---
diff --git a/extensions/CMYK.c b/extensions/CMYK.c
index c1028ce..b16f8be 100644
--- a/extensions/CMYK.c
+++ b/extensions/CMYK.c
@@ -61,6 +61,37 @@ static void  cmy_to_rgba  (const Babl *conversion,char *src,
                            char *dst,
                            long  n);
 
+
+static void
+cmy_to_cmyka (const Babl *conversion,char *src,
+              char *dst,
+              long  n);
+
+static void
+cmy_to_cmyka (const Babl *conversion,char *src,
+              char *dst,
+              long  n);
+
+static void
+cmyk_to_cmyka (const Babl *conversion,char *src,
+               char *dst,
+               long  n);
+
+static void
+cmyka_to_cmyk (const Babl *conversion,char *src,
+               char *dst,
+               long  n);
+
+static void
+cmykA_to_cmyka (const Babl *conversion,char *src,
+                    char *dst,
+                    long  n);
+
+static void
+cmyka_to_cmykA(const Babl *conversion,char *src,
+               char *dst,
+               long  n);
+
 int init (void);
 
 int
@@ -115,6 +146,20 @@ init (void)
     NULL
   );
 
+  babl_conversion_new (
+    babl_model ("cmykA"),
+    babl_model ("camayakaA"),
+    "linear", cmyka_to_cmykA,
+    NULL
+  );
+  babl_conversion_new (
+    babl_model ("camayakaA"),
+    babl_model ("cmykA"),
+    "linear", cmykA_to_cmyka,
+    NULL
+  );
+
+
   babl_conversion_new (
     babl_model ("RGBA"),
     babl_model ("camayakaA"),
@@ -152,6 +197,12 @@ init (void)
     "linear", cmyk_to_rgba,
     NULL
   );
+  babl_conversion_new (
+    babl_model ("cmyk"),
+    babl_model ("cmykA"),
+    "linear", cmyk_to_cmyka,
+    NULL
+  );
   babl_conversion_new (
     babl_model ("RGBA"),
     babl_model ("cmy"),
@@ -284,6 +335,30 @@ rgba_to_cmykA (const Babl *conversion,char *src,
     }
 }
 
+static void
+cmyka_to_cmykA (const Babl *conversion,char *src,
+                char *dst,
+                long  n)
+{
+  while (n--)
+    {
+      double cyan = ((double *) src)[0];
+      double magenta = ((double *) src)[1];
+      double yellow = ((double *) src)[2];
+      double key = ((double *) src)[3];
+      double alpha = ((double *) src)[4];
+
+      ((double *) dst)[0] = (1.0-cyan) * alpha;
+      ((double *) dst)[1] = (1.0-magenta) * alpha;
+      ((double *) dst)[2] = (1.0-yellow) * alpha;
+      ((double *) dst)[3] = (1.0-key) * alpha;
+      ((double *) dst)[4] = alpha;
+
+      src += 5 * sizeof (double);
+      dst += 5 * sizeof (double);
+    }
+}
+
 static void
 cmykA_to_rgba (const Babl *conversion,char *src,
                char *dst,
@@ -330,6 +405,32 @@ cmykA_to_rgba (const Babl *conversion,char *src,
     }
 }
 
+static void
+cmykA_to_cmyka (const Babl *conversion,char *src,
+                char *dst,
+                long  n)
+{
+  while (n--)
+    {
+      double alpha   = ((double *) src)[4];
+      double ralpha  = alpha>0.000001?1.0/alpha:0.0;
+      double cyan   = ((double *) src)[0] * ralpha;
+      double magenta= ((double *) src)[1] * ralpha;
+      double yellow = ((double *) src)[2] * ralpha;
+      double key    = ((double *) src)[3] * ralpha;
+
+      ((double *) dst)[0] = cyan;
+      ((double *) dst)[1] = magenta;
+      ((double *) dst)[2] = yellow;
+      ((double *) dst)[3] = key;
+      ((double *) dst)[4] = alpha;
+
+      src += 5 * sizeof (double);
+      dst += 5 * sizeof (double);
+    }
+}
+
+
 static void
 rgba_to_cmyka (const Babl *conversion,char *src,
                char *dst,
@@ -510,6 +611,31 @@ cmyk_to_rgba (const Babl *conversion,char *src,
     }
 }
 
+static void
+cmyk_to_cmyka (const Babl *conversion,char *src,
+               char *dst,
+               long  n)
+{
+  while (n--)
+    {
+      double cyan    = ((double *) src)[0];
+      double magenta = ((double *) src)[1];
+      double yellow  = ((double *) src)[2];
+      double key     = ((double *) src)[3];
+
+      ((double *) dst)[0] = cyan;
+      ((double *) dst)[1] = magenta;
+      ((double *) dst)[2] = yellow;
+      ((double *) dst)[3] = key;
+      ((double *) dst)[4] = 1.0;
+
+      src += 4 * sizeof (double);
+      dst += 5 * sizeof (double);
+    }
+}
+
+
+
 static void
 rgba_to_cmy (const Babl *conversion,char *src,
              char *dst,


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