[Bf-blender-cvs] [56bdf8f9be6] greasepencil-object: GPencil: Change sort comparison function
Antonio Vazquez
noreply at git.blender.org
Mon Nov 18 20:04:42 CET 2019
Commit: 56bdf8f9be6ce64a460e1f122030d7f3b5a66a0c
Author: Antonio Vazquez
Date: Mon Nov 18 20:04:33 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rB56bdf8f9be6ce64a460e1f122030d7f3b5a66a0c
GPencil: Change sort comparison function
===================================================================
M source/blender/blenkernel/intern/paint.c
===================================================================
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 4e6654c0fdf..831f6da8d2c 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -647,31 +647,46 @@ 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 = 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) {
+ /* Hue */
+ if (ps1->h > ps2->h) {
+ return 1;
+ }
+ else if (ps1->h < ps2->h) {
return -1;
}
- else if (a > b) {
+
+#if 0
+ /* Luminance. */
+ float lum1 = sqrt(0.241f * ps1->h + 0.691f * ps1->s + 0.068f * ps1->v);
+ float lum2 = sqrt(0.241f * ps2->h + 0.691f * ps2->s + 0.068f * ps2->v);
+ if (lum1 > lum2) {
return 1;
}
+ else if (lum1 < lum2) {
+ return -1;
+ }
+#endif
+
+ /* Saturation. */
+ if (ps1->s > ps2->s) {
+ return 1;
+ }
+ else if (ps1->s < ps2->s) {
+ return -1;
+ }
+
+ /* Value. */
+ if (1.0f - ps1->v > 1.0f - ps2->v) {
+ return 1;
+ }
+ else if (1.0f - ps1->v < 1.0f - ps2->v) {
+ return -1;
+ }
return 0;
}
More information about the Bf-blender-cvs
mailing list