Raise ValueError if kmeans is negative by radarhere · Pull Request #7891 · python-pillow/Pillow

#7890 (comment) found that if kmeans if negative, im.quantize() can become stuck in an infinite loop.

Investigating, I was able to reproduce this for MEDIANCUT and MAXCOVERAGE.

This PR updates the docstring to specify that kmeans should not be negative, raises a ValueError if kmeans is negative, and to be safe, also updates the C code to not use negative kmeans either.