[Bf-blender-cvs] [b35a58e9877] greasepencil-object: GPencil: Add color threshold
Antonio Vazquez
noreply at git.blender.org
Thu Apr 9 18:56:33 CEST 2020
Commit: b35a58e9877a11a9f6b6dbbb9cc11b1caf3eaddc
Author: Antonio Vazquez
Date: Wed Apr 8 19:48:26 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rBb35a58e9877a11a9f6b6dbbb9cc11b1caf3eaddc
GPencil: Add color threshold
===================================================================
M release/scripts/addons
M source/blender/editors/gpencil/gpencil_trace.h
M source/blender/editors/gpencil/gpencil_trace_ops.c
M source/blender/editors/gpencil/gpencil_trace_utils.c
===================================================================
diff --git a/release/scripts/addons b/release/scripts/addons
index d348bde0f96..8e6f485cf5b 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit d348bde0f96809e289b0514c015cafb97f2dcf79
+Subproject commit 8e6f485cf5b160c425d7da7c743879b20f3d6a96
diff --git a/source/blender/editors/gpencil/gpencil_trace.h b/source/blender/editors/gpencil/gpencil_trace.h
index e5008a0df9a..a020785fc07 100644
--- a/source/blender/editors/gpencil/gpencil_trace.h
+++ b/source/blender/editors/gpencil/gpencil_trace.h
@@ -61,7 +61,9 @@ potrace_bitmap_t *ED_gpencil_trace_bm_new(int w, int h);
void ED_gpencil_trace_bm_free(const potrace_bitmap_t *bm);
void ED_gpencil_trace_bm_invert(const potrace_bitmap_t *bm);
-void ED_gpencil_trace_image_to_bm(struct ImBuf *ibuf, const potrace_bitmap_t *bm);
+void ED_gpencil_trace_image_to_bm(struct ImBuf *ibuf,
+ const potrace_bitmap_t *bm,
+ const float threshold);
void ED_gpencil_trace_data_to_gp(potrace_state_t *st,
struct Object *ob,
struct bGPDframe *gpf,
diff --git a/source/blender/editors/gpencil/gpencil_trace_ops.c b/source/blender/editors/gpencil/gpencil_trace_ops.c
index 0f2caa4dff1..6960269f35f 100644
--- a/source/blender/editors/gpencil/gpencil_trace_ops.c
+++ b/source/blender/editors/gpencil/gpencil_trace_ops.c
@@ -87,6 +87,7 @@ static int gp_trace_image_exec(bContext *C, wmOperator *op)
char target[64];
RNA_string_get(op->ptr, "target", target);
const int frame_target = RNA_int_get(op->ptr, "frame_target");
+ const float threshold = RNA_float_get(op->ptr, "threshold");
ImBuf *ibuf;
void *lock;
@@ -141,7 +142,7 @@ static int gp_trace_image_exec(bContext *C, wmOperator *op)
bGPDframe *gpf = BKE_gpencil_layer_frame_get(gpl, frame_target, GP_GETFRAME_ADD_NEW);
/* Load BW bitmap with image. */
- ED_gpencil_trace_image_to_bm(ibuf, bm);
+ ED_gpencil_trace_image_to_bm(ibuf, bm, threshold);
/* Trace the bitmap. */
st = potrace_trace(param, bm);
@@ -203,4 +204,13 @@ void GPENCIL_OT_trace_image(wmOperatorType *ot)
"",
"Target grease pencil object name. Leave empty for new object");
RNA_def_int(ot->srna, "frame_target", 1, 1, 100000, "Frame Target", "", 1, 100000);
+ RNA_def_float_factor(ot->srna,
+ "thershold",
+ 0.5f,
+ 0.0f,
+ 1.0f,
+ "Color Threshold",
+ "Determine what is considered whithe and what black",
+ 0.0f,
+ 1.0f);
}
diff --git a/source/blender/editors/gpencil/gpencil_trace_utils.c b/source/blender/editors/gpencil/gpencil_trace_utils.c
index 069ab638d56..defa3fb80c7 100644
--- a/source/blender/editors/gpencil/gpencil_trace_utils.c
+++ b/source/blender/editors/gpencil/gpencil_trace_utils.c
@@ -163,7 +163,7 @@ static void pixel_at_index(const ImBuf *ibuf, const int idx, float r_col[4])
* \param ibuf: ImBuf of the image
* \param bm: Trace bitmap
*/
-void ED_gpencil_trace_image_to_bm(ImBuf *ibuf, const potrace_bitmap_t *bm)
+void ED_gpencil_trace_image_to_bm(ImBuf *ibuf, const potrace_bitmap_t *bm, const float threshold)
{
float rgba[4];
int pixel = 0;
@@ -175,7 +175,7 @@ void ED_gpencil_trace_image_to_bm(ImBuf *ibuf, const potrace_bitmap_t *bm)
/* Get a BW color. */
mul_v3_fl(rgba, rgba[3]);
float color = (rgba[0] + rgba[1] + rgba[2]) / 3.0f;
- int bw = (color > 0.5f) ? 0 : 1;
+ int bw = (color > threshold) ? 0 : 1;
BM_PUT(bm, x, y, bw);
}
}
More information about the Bf-blender-cvs
mailing list