From 52011d90847162cebcd1da155f0cd91239fca724 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 24 Aug 2019 22:40:44 +0000 Subject: 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 --- analyzer/ppmhist.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'analyzer') diff --git a/analyzer/ppmhist.c b/analyzer/ppmhist.c index c4ab3581..62345fa1 100644 --- a/analyzer/ppmhist.c +++ b/analyzer/ppmhist.c @@ -119,25 +119,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) { -- cgit 1.4.1