[Bf-blender-cvs] [451a55a1596] greasepencil-object: GPencil: Add SVG gray scale option

Antonio Vazquez noreply at git.blender.org
Sat Aug 1 23:02:08 CEST 2020


Commit: 451a55a1596a232a03c749be2200e5ebeaa79b7b
Author: Antonio Vazquez
Date:   Sat Aug 1 23:01:57 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB451a55a1596a232a03c749be2200e5ebeaa79b7b

GPencil: Add SVG gray scale option

Now it's possible export in gray scale.

===================================================================

M	source/blender/editors/io/io_gpencil.c
M	source/blender/io/gpencil/gpencil_io_exporter.h
M	source/blender/io/gpencil/intern/gpencil_io_base.cc
M	source/blender/io/gpencil/intern/gpencil_io_base.h
M	source/blender/io/gpencil/intern/gpencil_io_svg.cc

===================================================================

diff --git a/source/blender/editors/io/io_gpencil.c b/source/blender/editors/io/io_gpencil.c
index 75a7cf52735..d9fddeb3704 100644
--- a/source/blender/editors/io/io_gpencil.c
+++ b/source/blender/editors/io/io_gpencil.c
@@ -170,6 +170,7 @@ static int wm_gpencil_export_exec(bContext *C, wmOperator *op)
   const bool use_norm_thickness = RNA_boolean_get(op->ptr, "use_normalized_thickness");
   const bool use_selected_objects = RNA_boolean_get(op->ptr, "use_selected_objects");
   const bool use_clip_camera = RNA_boolean_get(op->ptr, "use_clip_camera");
+  const bool use_gray_scale = RNA_boolean_get(op->ptr, "use_gray_scale");
 
   /* Set flags. */
   int flag = 0;
@@ -177,7 +178,7 @@ static int wm_gpencil_export_exec(bContext *C, wmOperator *op)
   SET_FLAG_FROM_TEST(flag, use_norm_thickness, GP_EXPORT_NORM_THICKNESS);
   SET_FLAG_FROM_TEST(flag, use_selected_objects, GP_EXPORT_SELECTED_OBJECTS);
   SET_FLAG_FROM_TEST(flag, use_clip_camera, GP_EXPORT_CLIP_CAMERA);
-
+  SET_FLAG_FROM_TEST(flag, use_gray_scale, GP_EXPORT_GRAY_SCALE);
   struct GpencilExportParams params = {
       .C = C,
       .region = region,
@@ -269,6 +270,7 @@ static void ui_gpencil_export_settings(uiLayout *layout, PointerRNA *imfptr)
   sub = uiLayoutColumn(col, true);
   uiItemR(sub, imfptr, "use_fill", 0, NULL, ICON_NONE);
   uiItemR(sub, imfptr, "use_normalized_thickness", 0, NULL, ICON_NONE);
+  uiItemR(sub, imfptr, "use_gray_scale", 0, NULL, ICON_NONE);
   uiItemR(sub, imfptr, "use_clip_camera", 0, NULL, ICON_NONE);
   uiItemR(sub, imfptr, "stroke_sample", 0, NULL, ICON_NONE);
 }
@@ -387,6 +389,11 @@ void WM_OT_gpencil_export(wmOperatorType *ot)
                   false,
                   "Clip Camera",
                   "Clip drawings to camera size when export in camera view");
+  RNA_def_boolean(ot->srna,
+                  "use_gray_scale",
+                  false,
+                  "Gray Scale",
+                  "Export in gray scale instead of full color");
   RNA_def_float(ot->srna,
                 "stroke_sample",
                 0.03f,
diff --git a/source/blender/io/gpencil/gpencil_io_exporter.h b/source/blender/io/gpencil/gpencil_io_exporter.h
index cfcb7fc1296..09df8cb9664 100644
--- a/source/blender/io/gpencil/gpencil_io_exporter.h
+++ b/source/blender/io/gpencil/gpencil_io_exporter.h
@@ -62,6 +62,8 @@ typedef enum eGpencilExportParams_Flag {
   GP_EXPORT_SELECTED_OBJECTS = (1 << 2),
   /* Clip camera area. */
   GP_EXPORT_CLIP_CAMERA = (1 << 3),
+  /* Gray Scale. */
+  GP_EXPORT_GRAY_SCALE = (1 << 4),
 } eGpencilExportParams_Flag;
 
 bool gpencil_io_export(const struct GpencilExportParams *params);
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc
index 328b859a5af..c0dd177a15f 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc
@@ -296,6 +296,17 @@ std::string GpencilExporter::rgb_to_hex(float color[3])
   return hexstr;
 }
 
+/**
+ * Convert a color to gray scale.
+ */
+void GpencilExporter::rgb_to_grayscale(float color[3])
+{
+  float grayscale = ((0.3f * color[0]) + (0.59f * color[1]) + (0.11f * color[2]));
+  color[0] = grayscale;
+  color[1] = grayscale;
+  color[2] = grayscale;
+}
+
 /**
  * Convert a full string to lowercase
  * \param input_text: Input input_text
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.h b/source/blender/io/gpencil/intern/gpencil_io_base.h
index c0739af0aad..037395c3b72 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.h
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.h
@@ -54,6 +54,7 @@ class GpencilExporter {
   float stroke_point_radius_get(struct bGPDstroke *gps);
 
   std::string rgb_to_hex(float color[3]);
+  void rgb_to_grayscale(float color[3]);
   std::string to_lower_string(char *input_text);
 
  protected:
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
index 00fc15f44ad..bcef9db97a2 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_svg.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
@@ -290,6 +290,10 @@ void GpencilExporterSVG::export_stroke_path(pugi::xml_node gpl_node, const bool
 
     interp_v3_v3v3(col, stroke_color_, gpl->tintcolor, gpl->tintcolor[3]);
   }
+  if ((params_.flag & GP_EXPORT_GRAY_SCALE) != 0) {
+    rgb_to_grayscale(col);
+  }
+
   linearrgb_to_srgb_v3_v3(col, col);
   stroke_hex = rgb_to_hex(col);
 
@@ -380,6 +384,9 @@ void GpencilExporterSVG::color_string_set(pugi::xml_node gps_node, const bool is
   float col[3];
   if (is_fill) {
     interp_v3_v3v3(col, fill_color_, gpl->tintcolor, gpl->tintcolor[3]);
+    if ((params_.flag & GP_EXPORT_GRAY_SCALE) != 0) {
+      rgb_to_grayscale(col);
+    }
     linearrgb_to_srgb_v3_v3(col, col);
     std::string stroke_hex = rgb_to_hex(col);
     gps_node.append_attribute("fill").set_value(stroke_hex.c_str());
@@ -388,6 +395,9 @@ void GpencilExporterSVG::color_string_set(pugi::xml_node gps_node, const bool is
   }
   else {
     interp_v3_v3v3(col, stroke_color_, gpl->tintcolor, gpl->tintcolor[3]);
+    if ((params_.flag & GP_EXPORT_GRAY_SCALE) != 0) {
+      rgb_to_grayscale(col);
+    }
     linearrgb_to_srgb_v3_v3(col, col);
     std::string stroke_hex = rgb_to_hex(col);
     gps_node.append_attribute("stroke").set_value(stroke_hex.c_str());



More information about the Bf-blender-cvs mailing list