[babl] add a format for muxing cmyk u8 in and out of rgba u8 buffers



commit 8a0aafc5f2007d9c506fd38f629f621ea50dcc75
Author: Øyvind Kolås <pippin gimp org>
Date:   Sun Dec 2 23:49:21 2018 +0100

    add a format for muxing cmyk u8 in and out of rgba u8 buffers

 extensions/naive-CMYK.c | 59 +++++++++++++++++++++++++++++++++++-
 tests/Makefile.am       |  1 +
 tests/cairo_cmyk_hack.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 138 insertions(+), 1 deletion(-)
---
diff --git a/extensions/naive-CMYK.c b/extensions/naive-CMYK.c
index a8a874a..1e1c905 100644
--- a/extensions/naive-CMYK.c
+++ b/extensions/naive-CMYK.c
@@ -28,10 +28,67 @@
 
 int init (void);
 
+/* implement a hacky way to do cmyk with cairo  */
+/* CMYKA                                        */
+/* CMKA                                         */
+/* CKYA                                         */
+
+
 int
 init (void)
 {
-  /* do nothing, drop this whole file after a couple of releases */
+  babl_format_new ("name", "ckyA u16",
+                   babl_model ("cmykA"),
+                   babl_type ("u16"),
+                   babl_component ("cyan"),
+                   babl_component ("key"),
+                   babl_component ("yellow"),
+                   babl_component ("A"),
+                   NULL);
+  babl_format_new ("name", "cmkA u16",
+                   babl_model ("cmykA"),
+                   babl_type ("u16"),
+                   babl_component ("cyan"),
+                   babl_component ("magenta"),
+                   babl_component ("key"),
+                   babl_component ("A"),
+                   NULL);
+
+  babl_format_new ("name", "camakaA u8",
+                   babl_model ("camayakaA"),
+                   babl_type ("u8"),
+                   babl_component ("ka"),
+                   babl_component ("ma"),
+                   babl_component ("ca"),
+                   babl_component ("A"),
+                   NULL);
+  babl_format_new ("name", "cakayaA u8",
+                   babl_model ("camayakaA"),
+                   babl_type ("u8"),
+                   babl_component ("ya"),
+                   babl_component ("ka"),
+                   babl_component ("ca"),
+                   babl_component ("A"),
+                   NULL);
+  babl_format_new ("name", "camaPadkaA u8",
+                   babl_model ("camayakaA"),
+                   babl_type ("u8"),
+                   babl_component ("ca"),
+                   babl_component ("ma"),
+                   babl_component ("PAD"),
+                   babl_component ("ka"),
+                   babl_component ("A"),
+                   NULL);
+  babl_format_new ("name", "caPadyakaA u8",
+                   babl_model ("camayakaA"),
+                   babl_type ("u8"),
+                   babl_component ("ca"),
+                   babl_component ("PAD"),
+                   babl_component ("ya"),
+                   babl_component ("ka"),
+                   babl_component ("A"),
+                   NULL);
+
   return 0;
 }
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e48b1dd..8c5abb7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -5,6 +5,7 @@ CONCURRENCY_STRESS_TESTS =              \
 endif
 
 C_TESTS =                              \
+       cairo_cmyk_hack \
        grayscale_to_rgb        \
        chromaticities          \
        rgb_to_bgr              \
diff --git a/tests/cairo_cmyk_hack.c b/tests/cairo_cmyk_hack.c
new file mode 100644
index 0000000..3996402
--- /dev/null
+++ b/tests/cairo_cmyk_hack.c
@@ -0,0 +1,79 @@
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2005, Øyvind Kolås.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+
+#include <math.h>
+#include <babl/babl.h>
+#include <stdio.h>
+
+#define PIXELS       6
+#define TOLERANCE    0
+
+unsigned char source_buf [PIXELS * 5] =
+{ 0,     0,   0, 22, 33,
+  127, 127, 127, 12, 33,
+  255, 225, 255, 33, 33,
+  255, 0.0, 0.0, 4,  33,
+  0.0, 255, 0.0, 122,33,
+  0.0, 0.0, 255, 222,33};
+
+unsigned char cmk_buf [PIXELS * 4];
+unsigned char cky_buf [PIXELS * 4];
+unsigned char dest_buf [PIXELS * 5];
+
+static int
+test (void)
+{
+  int i;
+  int OK = 1;
+
+  babl_process (babl_fish ("camayakaA u8", "camakaA u8"),
+                source_buf, cmk_buf,
+                PIXELS);
+  babl_process (babl_fish ("camayakaA u8", "cakayaA u8"),
+                source_buf, cky_buf,
+                PIXELS);
+  babl_process (babl_fish ("cakayaA u8", "camayakaA u8"),
+                cky_buf, dest_buf,
+                PIXELS);
+  babl_process (babl_fish ("camakaA u8", "camayakaA u8"),
+                cmk_buf, dest_buf,
+                PIXELS);
+
+  for (i = 0; i < PIXELS * 5; i++)
+    {
+      if (fabs (dest_buf[i] - source_buf[i]) > TOLERANCE)
+        {
+          fprintf (stderr, "%i is wrong\n", i);
+          OK = 0;
+        }
+    }
+  if (!OK)
+    return -1;
+  return 0;
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+  babl_init ();
+  if (test ())
+    return -1;
+  babl_exit ();
+  return 0;
+}


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