From 01636ed159c7dede57236f7a801d3cfcae0b9750 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Wed, 12 Aug 2020 19:18:59 +0200 Subject: GPencil: Fix unreported problem in merge similar materials When two similar colors were adjacent, the colors were not merged. --- source/blender/blenkernel/intern/gpencil.c | 38 +++++++++++++++++------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'source/blender/blenkernel/intern/gpencil.c') diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 3039879799d..09ea6ec17bc 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -1879,6 +1879,7 @@ bool BKE_gpencil_merge_materials_table_get(Object *ob, Material *ma_secondary = NULL; MaterialGPencilStyle *gp_style_primary = NULL; MaterialGPencilStyle *gp_style_secondary = NULL; + GHash *mat_used = BLI_ghash_int_new(__func__); short *totcol = BKE_object_material_len_p(ob); if (totcol == 0) { @@ -1891,12 +1892,14 @@ bool BKE_gpencil_merge_materials_table_get(Object *ob, if (ma_primary == NULL) { continue; } - for (int idx_secondary = 0; idx_secondary < *totcol; idx_secondary++) { if ((idx_secondary == idx_primary) || BLI_ghash_haskey(r_mat_table, POINTER_FROM_INT(idx_secondary))) { continue; } + if (BLI_ghash_haskey(mat_used, POINTER_FROM_INT(idx_secondary))) { + continue; + } /* Read secondary material to compare with primary material. */ ma_secondary = BKE_gpencil_material(ob, idx_secondary + 1); @@ -1950,32 +1953,35 @@ bool BKE_gpencil_merge_materials_table_get(Object *ob, copy_v3_v3(col, gp_style_secondary->fill_rgba); rgb_to_hsv_compat_v(col, f_hsv_b); - /* Check stroke and fill color (only Hue and Saturation). */ + /* Check stroke and fill color. */ if ((!compare_ff(s_hsv_a[0], s_hsv_b[0], hue_threshold)) || (!compare_ff(s_hsv_a[1], s_hsv_b[1], sat_threshold)) || (!compare_ff(s_hsv_a[2], s_hsv_b[2], val_threshold)) || (!compare_ff(f_hsv_a[0], f_hsv_b[0], hue_threshold)) || (!compare_ff(f_hsv_a[1], f_hsv_b[1], sat_threshold)) || - (!compare_ff(f_hsv_a[2], f_hsv_b[2], val_threshold))) { + (!compare_ff(f_hsv_a[2], f_hsv_b[2], val_threshold)) || + (!compare_ff(gp_style_primary->stroke_rgba[3], + gp_style_secondary->stroke_rgba[3], + val_threshold)) || + (!compare_ff( + gp_style_primary->fill_rgba[3], gp_style_secondary->fill_rgba[3], val_threshold))) { continue; } - gp_style_secondary->stroke_rgba[0] = 0.0f; - gp_style_secondary->stroke_rgba[1] = 1.0f; - gp_style_secondary->stroke_rgba[2] = 0.0f; - gp_style_secondary->stroke_rgba[3] = 1.0f; - - gp_style_secondary->fill_rgba[0] = 1.0f; - gp_style_secondary->fill_rgba[1] = 0.0f; - gp_style_secondary->fill_rgba[2] = 0.0f; - gp_style_secondary->fill_rgba[3] = 1.0f; - /* Save conversion indexes. */ - BLI_ghash_insert( - r_mat_table, POINTER_FROM_INT(idx_secondary), POINTER_FROM_INT(idx_primary)); - changed = true; + if (!BLI_ghash_haskey(r_mat_table, POINTER_FROM_INT(idx_secondary))) { + BLI_ghash_insert( + r_mat_table, POINTER_FROM_INT(idx_secondary), POINTER_FROM_INT(idx_primary)); + changed = true; + + if (!BLI_ghash_haskey(mat_used, POINTER_FROM_INT(idx_primary))) { + BLI_ghash_insert(mat_used, POINTER_FROM_INT(idx_primary), POINTER_FROM_INT(idx_primary)); + } + } } } + /* Free hash memory. */ + BLI_ghash_free(mat_used, NULL, NULL); return changed; } -- cgit v1.2.3