# HG changeset patch # User Matti Hamalainen # Date 1509245862 -7200 # Node ID eb98e57d396933ef0ee57fd353a01b0599ea8918 # Parent 7ec862ed65147302c10e17485d399f21096f1c30 Bring in mapBlockGetEntropy() as we will be using it in the search server. diff -r 7ec862ed6514 -r eb98e57d3969 mapsearch.c --- a/mapsearch.c Sun Oct 29 04:56:54 2017 +0200 +++ b/mapsearch.c Sun Oct 29 04:57:42 2017 +0200 @@ -538,6 +538,42 @@ } +int mapBlockGetEntropy(const MapBlock *map, const char *exclude, const int nexclude) +{ + unsigned char *list; + int num, i; + + // Allocate memory for entropy array + if ((list = th_malloc0(256)) == NULL) + return -1; + + // Collect sums into entropy array + for (int y = 0; y < map->height; y++) + { + unsigned char *c = map->data + (y * map->scansize); + for (int x = 0; x < map->width; x++) + { + list[*c]++; + c++; + } + } + + // Handle exclusions + if (exclude != NULL && nexclude > 0) + { + for (i = 0; i < nexclude; i++) + list[(int) exclude[i]] = 0; + } + + // Calculate simple entropy + for (num = 0, i = 0; i < 256; i++) + if (list[i]) num++; + + th_free(list); + return num; +} + + double mapMatchBlock(const MapBlock *map, const MapBlock *match, int ox, int oy, int fillCh, BOOL hardDrop) { int n, k;