[Bf-blender-cvs] [5e804d1d171] greasepencil-object: GPencil: More tweaks to sort colors
Antonio Vazquez
noreply at git.blender.org
Mon Nov 18 17:10:16 CET 2019
Commit: 5e804d1d1711e93c256c5bdd7bb77aaf78095d1c
Author: Antonio Vazquez
Date: Mon Nov 18 17:10:08 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rB5e804d1d1711e93c256c5bdd7bb77aaf78095d1c
GPencil: More tweaks to sort colors
===================================================================
M source/blender/blenkernel/intern/paint.c
===================================================================
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 0a15a1897ed..4e6654c0fdf 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -647,12 +647,24 @@ bool BKE_palette_is_empty(const struct Palette *palette)
return BLI_listbase_is_empty(&palette->colors);
}
+static double palettecolor_make_sortkey(float h, float s, float v)
+{
+ /* Round values. */
+ int hi = h * 1000;
+ int si = s * 1000;
+ int vi = v * 1000;
+
+ double key = (hi * 1e8) + (si * 1e4) + vi;
+
+ return key;
+}
+
/* helper function to sort using qsort */
static int palettecolor_compare_hsv(const void *a1, const void *a2)
{
const tPaletteColorHSV *ps1 = a1, *ps2 = a2;
- double a = (ps1->h * 1e11) + (ps1->s * 1e7) + ((1.0f - ps1->v) * 1e3);
- double b = (ps2->h * 1e11) + (ps2->s * 1e7) + ((1.0f - ps2->v) * 1e3);
+ double a = palettecolor_make_sortkey(ps1->h, ps1->s, 1.0f - ps1->v);
+ double b = palettecolor_make_sortkey(ps2->h, ps2->s, 1.0f - ps2->v);
if (a < b) {
return -1;
More information about the Bf-blender-cvs
mailing list