[Bf-blender-cvs] [fec2b2a809a] master: Palettes: Remove threshold parameter when extract from images

Antonio Vazquez noreply at git.blender.org
Sat Jun 27 10:40:55 CEST 2020


Commit: fec2b2a809a8ff16e0c19c42f122d0f649258d02
Author: Antonio Vazquez
Date:   Sat Jun 27 10:26:46 2020 +0200
Branches: master
https://developer.blender.org/rBfec2b2a809a8ff16e0c19c42f122d0f649258d02

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.

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

M	source/blender/editors/sculpt_paint/paint_ops.c

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

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. */



More information about the Bf-blender-cvs mailing list