[gegl] vector-stroke: handle CMYK



commit 78ffacaf6e0ce886fc61692913fbdc6873847036
Author: Øyvind Kolås <pippin gimp org>
Date:   Tue Dec 4 00:34:36 2018 +0100

    vector-stroke: handle CMYK

 operations/external/vector-stroke.c | 103 +++++++++++++++++++++++++++---------
 1 file changed, 79 insertions(+), 24 deletions(-)
---
diff --git a/operations/external/vector-stroke.c b/operations/external/vector-stroke.c
index 786fb0953..94ebdae3c 100644
--- a/operations/external/vector-stroke.c
+++ b/operations/external/vector-stroke.c
@@ -78,7 +78,17 @@ static void
 prepare (GeglOperation *operation)
 {
   GeglProperties *o = GEGL_PROPERTIES (operation);
-  gegl_operation_set_format (operation, "output", babl_format ("R'aG'aB'aA float"));
+const Babl *color_format = gegl_color_get_format (o->color);
+  BablModelFlag model_flags = babl_get_model_flags (color_format);
+
+  if (model_flags & BABL_MODEL_FLAG_CMYK)
+  {
+    gegl_operation_set_format (operation, "output", babl_format ("camayakaA float"));
+  }
+  else
+  {
+    gegl_operation_set_format (operation, "output", babl_format ("R'aG'aB'aA float"));
+  }
 
   if (o->transform && o->transform[0] != '\0')
     {
@@ -152,7 +162,10 @@ process (GeglOperation       *operation,
 {
   GeglProperties *o = GEGL_PROPERTIES (operation);
   gboolean need_stroke = FALSE;
-  gdouble color[4] = {0, 0, 0, 0};
+  const Babl *format =  gegl_operation_get_format (operation, "output");
+  gdouble color[5] = {0, 0, 0, 0, 0};
+
+  int is_cmyk = babl_get_model_flags (format) & BABL_MODEL_FLAG_CMYK?1:0;
 
   if (input)
     {
@@ -166,41 +179,83 @@ process (GeglOperation       *operation,
 
   if (o->width > 0.1 && o->opacity > 0.0001)
     {
-      gegl_color_get_pixel (o->color, babl_format ("R'G'B'A double"), color);
-      color[3] *= o->opacity;
-      if (color[3] > 0.001)
-          need_stroke=TRUE;
+      if (is_cmyk)
+      {
+        gegl_color_get_pixel (o->color, babl_format ("cmykA double"), color);
+        color[4] *= o->opacity;
+        if (color[4] > 0.001)
+            need_stroke=TRUE;
+      }
+      else
+      {
+        gegl_color_get_pixel (o->color, babl_format ("R'G'B'A double"), color);
+        color[3] *= o->opacity;
+        if (color[3] > 0.001)
+            need_stroke=TRUE;
+      }
     }
 
   if (need_stroke)
     {
+      const Babl *formats[4]={NULL, NULL, NULL};
+
       static GMutex mutex = { 0, };
       cairo_t *cr;
       cairo_surface_t *surface;
       guchar *data;
+      int i;
 
       g_mutex_lock (&mutex);
-      data = gegl_buffer_linear_open (output, result, NULL, babl_format ("cairo-ARGB32"));
-      surface = cairo_image_surface_create_for_data (data,
-                                                     CAIRO_FORMAT_ARGB32,
-                                                     result->width,
-                                                     result->height,
-                                                     result->width * 4);
-
-      cr = cairo_create (surface);
-
-      cairo_translate (cr, -result->x, -result->y);
 
-      cairo_set_line_width  (cr, o->width);
-      cairo_set_line_cap    (cr, CAIRO_LINE_CAP_ROUND);
-      cairo_set_line_join   (cr, CAIRO_LINE_JOIN_ROUND);
+      if (is_cmyk)
+      {
+        formats[0]=babl_format ("cairo-ACYK32");
+        formats[1]=babl_format ("cairo-ACMK32");
+      }
+      else
+      {
+        formats[0]=babl_format ("cairo-ARGB32");
+      }
+
+      for (i = 0; formats[i]; i++)
+      {
+        data = gegl_buffer_linear_open (output, result, NULL, formats[i]);
+        surface = cairo_image_surface_create_for_data (data,
+                                                       CAIRO_FORMAT_ARGB32,
+                                                       result->width,
+                                                       result->height,
+                                                       result->width * 4);
+
+        cr = cairo_create (surface);
+
+        cairo_translate (cr, -result->x, -result->y);
+
+        cairo_set_line_width  (cr, o->width);
+        cairo_set_line_cap    (cr, CAIRO_LINE_CAP_ROUND);
+        cairo_set_line_join   (cr, CAIRO_LINE_JOIN_ROUND);
+
+        gegl_path_cairo_play (o->d, cr);
+
+        switch (i + is_cmyk)
+        {
+          case 0:
+            cairo_set_source_rgba (cr, color[0], color[1], color[2], color[3]);
+            break;
+          case 1:
+            cairo_set_source_rgba (cr, color[0], color[2], color[3], color[4]);
+            break;
+          case 2:
+            cairo_set_source_rgba (cr, color[0], color[1], color[3], color[4]);
+            break;
+        }
+
+        cairo_stroke (cr);
+        cairo_destroy (cr);
+
+        gegl_buffer_linear_close (output, data);
+      }
 
-      gegl_path_cairo_play (o->d, cr);
-      cairo_set_source_rgba (cr, color[0], color[1], color[2], color[3]);
-      cairo_stroke (cr);
-      cairo_destroy (cr);
 
-      gegl_buffer_linear_close (output, data);
       g_mutex_unlock (&mutex);
     }
   return  TRUE;


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