diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2020-06-27 11:26:46 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2020-06-27 11:40:37 +0300 |
commit | fec2b2a809a8ff16e0c19c42f122d0f649258d02 (patch) | |
tree | 507f76a3ec43422ca19b88e25854808288a09a09 /source/blender/editors/sculpt_paint/paint_ops.c | |
parent | 4b96f4783197c6bbf34230385b711d685df2b545 (diff) |
Palettes: Remove threshold parameter when extract from images
Using a number greater than 1 produce a huge number of entries in the palette because any small variation in the color create a new entry.
Remove the threshold reduce the precision of the color extracted, but always is better than having a palette with thounsands of colors.
Related to T78317
Still pending the memory crash when it's impossible to allocate memory for the palette in the popover, but with this change I don't think we get this error again.
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_ops.c')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_ops.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 0f0af335481..191ae1da343 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -331,14 +331,14 @@ static int palette_extract_img_exec(bContext *C, wmOperator *op) if (ibuf && ibuf->rect) { /* Extract all colors. */ + const int range = (int)pow(10.0f, threshold); for (int row = 0; row < ibuf->y; row++) { for (int col = 0; col < ibuf->x; col++) { float color[4]; IMB_sampleImageAtLocation(ibuf, (float)col, (float)row, false, color); - const float range = pow(10.0f, threshold); - color[0] = truncf(color[0] * range) / range; - color[1] = truncf(color[1] * range) / range; - color[2] = truncf(color[2] * range) / range; + for (int i = 0; i < 3; i++) { + color[i] = truncf(color[i] * range) / range; + } uint key = rgb_to_cpack(color[0], color[1], color[2]); if (!BLI_ghash_haskey(color_table, POINTER_FROM_INT(key))) { @@ -363,6 +363,8 @@ static int palette_extract_img_exec(bContext *C, wmOperator *op) static void PALETTE_OT_extract_from_image(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name = "Extract Palette from Image"; ot->idname = "PALETTE_OT_extract_from_image"; @@ -376,7 +378,8 @@ static void PALETTE_OT_extract_from_image(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - RNA_def_int(ot->srna, "threshold", 1, 1, 4, "Threshold", "", 1, 4); + prop = RNA_def_int(ot->srna, "threshold", 1, 1, 1, "Threshold", "", 1, 1); + RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); } /* Sort Palette color by Hue and Saturation. */ |