diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2019-08-24 22:40:44 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2019-08-24 22:40:44 +0000 |
commit | 52011d90847162cebcd1da155f0cd91239fca724 (patch) | |
tree | 9a025fe237a6102a05405398aaccdf90dd538396 | |
parent | 7e8bc6e8ef4ad76cfc6b542f9af541b2c89b08f9 (diff) | |
download | netpbm-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
-rw-r--r-- | analyzer/ppmhist.c | 44 | ||||
-rw-r--r-- | doc/HISTORY | 3 |
2 files changed, 28 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) { diff --git a/doc/HISTORY b/doc/HISTORY index b73c1938..a4783184 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -6,6 +6,9 @@ CHANGE HISTORY not yet BJH Release 10.88.00 + ppmhist: sort secondarily by RGB with -sort=frequency, so + output is repeatable. + pnmtorle, rletopnm: fix wild pointer dereference when memory allocation fails. Always broken (programs were added to Netpbm in Release 9.0 (April 2000). |