[Bf-blender-cvs] [f07962df947] greasepencil-object: GPencil: Fix extract palette from vertex color bug with linear colors

Antonio Vazquez noreply at git.blender.org
Tue Feb 18 20:06:14 CET 2020


Commit: f07962df947b4b61a8aa9fc1bc417633abcfe0e2
Author: Antonio Vazquez
Date:   Tue Feb 18 20:05:53 2020 +0100
Branches: greasepencil-object
https://developer.blender.org/rBf07962df947b4b61a8aa9fc1bc417633abcfe0e2

GPencil: Fix extract palette from vertex color bug with linear colors

The extract was not converting linear into sRGB for palettes.

Also added missing menu option in Materials menu.

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

M	release/scripts/startup/bl_ui/properties_material_gpencil.py
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/intern/paint.c
M	source/blender/editors/gpencil/gpencil_vertex_ops.c
M	source/blender/editors/sculpt_paint/paint_ops.c

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

diff --git a/release/scripts/startup/bl_ui/properties_material_gpencil.py b/release/scripts/startup/bl_ui/properties_material_gpencil.py
index 904f6c29c2c..56201b29e7f 100644
--- a/release/scripts/startup/bl_ui/properties_material_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_material_gpencil.py
@@ -51,6 +51,7 @@ class GPENCIL_MT_color_context_menu(Menu):
 
         layout.separator()
         layout.operator("gpencil.material_to_vertex_color", text="Convert Materials to Vertex Color")
+        layout.operator("gpencil.extract_palette_vertex", text="Extract Palette from Vertex Color")
 
 
 class GPENCIL_UL_matslots(UIList):
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index b7bb8434613..c26d8f8ec57 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -146,7 +146,10 @@ void BKE_palette_clear(struct Palette *palette);
 
 void BKE_palette_sort_hsv(struct tPaletteColorHSV *color_array, const int totcol);
 void BKE_palette_sort_svh(struct tPaletteColorHSV *color_array, const int totcol);
-bool BKE_palette_from_hash(struct Main *bmain, struct GHash *color_table, const char *name);
+bool BKE_palette_from_hash(struct Main *bmain,
+                           struct GHash *color_table,
+                           const char *name,
+                           const bool linear);
 
 /* paint curves */
 struct PaintCurve *BKE_paint_curve_add(struct Main *bmain, const char *name);
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 78b02acbb53..327ab9d30d4 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -766,7 +766,7 @@ void BKE_palette_sort_svh(tPaletteColorHSV *color_array, const int totcol)
   qsort(color_array, totcol, sizeof(tPaletteColorHSV), palettecolor_compare_svh);
 }
 
-bool BKE_palette_from_hash(Main *bmain, GHash *color_table, const char *name)
+bool BKE_palette_from_hash(Main *bmain, GHash *color_table, const char *name, const bool linear)
 {
   tPaletteColorHSV *color_array = NULL;
   tPaletteColorHSV *col_elm = NULL;
@@ -809,6 +809,9 @@ bool BKE_palette_from_hash(Main *bmain, GHash *color_table, const char *name)
         PaletteColor *palcol = BKE_palette_color_add(palette);
         if (palcol) {
           copy_v3_v3(palcol->rgb, col_elm->rgb);
+          if (linear) {
+            linearrgb_to_srgb_v3_v3(palcol->rgb, palcol->rgb);
+          }
         }
       }
       done = true;
diff --git a/source/blender/editors/gpencil/gpencil_vertex_ops.c b/source/blender/editors/gpencil/gpencil_vertex_ops.c
index 348655d5fe9..b77df4cef21 100644
--- a/source/blender/editors/gpencil/gpencil_vertex_ops.c
+++ b/source/blender/editors/gpencil/gpencil_vertex_ops.c
@@ -577,7 +577,7 @@ static bool gp_extract_palette_from_vertex(bContext *C, const bool selected, con
   CTX_DATA_END;
 
   /* Create the Palette. */
-  done = BKE_palette_from_hash(bmain, color_table, ob->id.name + 2);
+  done = BKE_palette_from_hash(bmain, color_table, ob->id.name + 2, true);
 
   /* Free memory. */
   BLI_ghash_free(color_table, NULL, NULL);
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index ddb2033e69b..e615f60a9ed 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -344,7 +344,7 @@ static int palette_extract_img_exec(bContext *C, wmOperator *op)
       }
     }
 
-    done = BKE_palette_from_hash(bmain, color_table, image->id.name + 2);
+    done = BKE_palette_from_hash(bmain, color_table, image->id.name + 2, false);
   }
 
   /* Free memory. */



More information about the Bf-blender-cvs mailing list