about summary refs log tree commit diff
path: root/analyzer
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2019-08-24 22:40:44 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2019-08-24 22:40:44 +0000
commit52011d90847162cebcd1da155f0cd91239fca724 (patch)
tree9a025fe237a6102a05405398aaccdf90dd538396 /analyzer
parent7e8bc6e8ef4ad76cfc6b542f9af541b2c89b08f9 (diff)
downloadnetpbm-mirror-52011d90847162cebcd1da155f0cd91239fca724.tar.gz
netpbm-mirror-52011d90847162cebcd1da155f0cd91239fca724.tar.xz
netpbm-mirror-52011d90847162cebcd1da155f0cd91239fca724.zip
Sort secondarily by RGB with -sort=frequency so output is repeatable
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3662 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'analyzer')
-rw-r--r--analyzer/ppmhist.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/analyzer/ppmhist.c b/analyzer/ppmhist.c
index c4ab3581..62345fa1 100644
--- a/analyzer/ppmhist.c
+++ b/analyzer/ppmhist.c
@@ -120,25 +120,6 @@ cmpUint(unsigned int const a,
 
 
 #ifndef LITERAL_FN_DEF_MATCH
-static qsort_comparison_fn countcompare;
-#endif
-
-
-static int
-countcompare(const void * const a,
-             const void * const b) {
-/*----------------------------------------------------------------------------
-   This is a 'qsort' collation function.
------------------------------------------------------------------------------*/
-    const struct colorhist_item * const histItem1P = a;
-    const struct colorhist_item * const histItem2P = b;
-
-    return cmpUint(histItem2P->value, histItem1P->value);
-}
-
-
-
-#ifndef LITERAL_FN_DEF_MATCH
 static qsort_comparison_fn rgbcompare;
 #endif
 
@@ -167,6 +148,31 @@ rgbcompare(const void * const a,
 
 
 
+#ifndef LITERAL_FN_DEF_MATCH
+static qsort_comparison_fn countcompare;
+#endif
+
+
+static int
+countcompare(const void * const a,
+             const void * const b) {
+/*----------------------------------------------------------------------------
+   This is a 'qsort' collation function.
+-----------------------------------------------------------------------------*/
+    const struct colorhist_item * const histItem1P = a;
+    const struct colorhist_item * const histItem2P = b;
+
+    int const countComparison = cmpUint(histItem2P->value, histItem1P->value);
+
+    if (countComparison == 0) {
+        /* Counts are the same; use RGB secondary sort */
+        return rgbcompare(a, b);
+    } else
+        return countComparison;
+}
+
+
+
 static pixval
 universalMaxval(pixval const maxval,
                 int    const format) {